Bläddra i källkod

AdditionalPageManager koin inject

cooperku_kdanmobile 5 år sedan
förälder
incheckning
57f1ad8505

+ 3 - 1
src/main/java/com/kdanmobile/reader/ReaderActivity.kt

@@ -82,6 +82,7 @@ abstract class ReaderActivity :
     open fun onFilePathOrUriError(filePath: String?) { println("onFilePathOrUriError: $filePath") }
     //  子類別可複寫此方法以客製化KMPDFPageAdapter
     abstract fun providePdfPageAdapter(context: Context, filePickerSupport: FilePicker.FilePickerSupport, kmpdfFactory: KMPDFFactory): KMPDFPageAdapter
+    open fun provideAdditionalPageManager(): AdditionalPageManager = AdditionalPageManager()
     protected open fun onEvent(hookEvent: HookEvent) { /* do nothing */ }
 
     companion object {
@@ -126,6 +127,7 @@ abstract class ReaderActivity :
         }
 
     private val viewModel: ReaderViewModel by viewModel {
+        val additionalPageManager = provideAdditionalPageManager()
         val filePath = intent.getStringExtra(KEY_FILE_ABSOLUTE)
         if (!filePath.isNullOrEmpty()) {
             insertToRecentDocumentList(filePath as String)
@@ -133,7 +135,7 @@ abstract class ReaderActivity :
         val uri = if (!filePath.isNullOrEmpty()) Uri.parse(Uri.encode(filePath)) else null
         // The URI may be null in some special case.
         // Just use Uri.EMPTY and show an alert dialog in onCreate() when the uri is null.
-        parametersOf(uri ?: Uri.EMPTY)
+        parametersOf(additionalPageManager, uri ?: Uri.EMPTY)
     }
     private var isShowPasswordActivity = false
 

+ 4 - 2
src/main/java/com/kdanmobile/reader/ReaderViewModel.kt

@@ -39,7 +39,9 @@ import java.util.*
 import kotlin.collections.ArrayList
 
 class ReaderViewModel(
-        private val readerModelManager: ReaderModelManager, val uri: Uri,
+        private val readerModelManager: ReaderModelManager,
+        additionalPageManager: AdditionalPageManager,
+        val uri: Uri,
         private val pdfSdkLicense: String,
         private val pdfSdkRsaMsg: String,
         private val eventManager: EventManager<Event> = EventManager()
@@ -207,7 +209,7 @@ class ReaderViewModel(
 
     private var onClickLinkListener: OnClickLinkListener? = null
 
-    var additionalPageManager: AdditionalPageManager = AdditionalPageManager().also {
+    var additionalPageManager: AdditionalPageManager = additionalPageManager.also {
         readerModel.initAdditionalPageManager(it)
     }
         set(value) {

+ 3 - 1
src/main/java/com/kdanmobile/reader/koin/KoinModule.kt

@@ -9,6 +9,7 @@ import com.kdanmobile.reader.Config
 import com.kdanmobile.reader.ReaderModel
 import com.kdanmobile.reader.ReaderModelManager
 import com.kdanmobile.reader.ReaderViewModel
+import com.kdanmobile.reader.additionalpage.AdditionalPageManager
 import com.kdanmobile.reader.thumb.PdfThumbViewModel
 import org.koin.android.viewmodel.dsl.viewModel
 import org.koin.dsl.module
@@ -20,9 +21,10 @@ internal object KoinModule {
         viewModel { (applicationContext: Context, intent: Intent, copiedFileFolder: File) ->
             CopyFileViewModel(applicationContext, intent, copiedFileFolder)
         }
-        viewModel { (uri: Uri) ->
+        viewModel { (additionalPageManager: AdditionalPageManager, uri: Uri) ->
             ReaderViewModel(
                     get(),
+                    additionalPageManager,
                     uri,
                     Config.PDF_SDK_LICENSE,
                     Config.PDF_SDK_RSA_MSG