Browse Source

Merge branch '130-api-adapter' into 'master'

Resolve "加入跨版本 api 轉換接口"

Closes #130

See merge request kdanandroid/pdf/pdfreaderreadermodule!62
Wayne Huang 5 years ago
parent
commit
6ac8ecdb84

+ 27 - 0
src/main/java/com/kdanmobile/reader/MyKMPDFFactory.kt

@@ -0,0 +1,27 @@
+package com.kdanmobile.reader
+
+import android.content.Context
+import android.net.Uri
+import com.kdanmobile.kmpdfkit.manager.KMPDFFactory
+import java.io.File
+
+object MyKMPDFFactory {
+
+    fun open(
+            context: Context,
+            uri: Uri,
+            magic: String? = null
+    ): KMPDFFactory? = KMPDFFactory.open(context, uri, magic)
+
+    fun open(
+            context: Context,
+            path: String,
+            magic: String? = null
+    ) = open(context, File(path), magic)
+
+    fun open(
+            context: Context,
+            file: File,
+            magic: String? = null
+    ) = open(context, Uri.fromFile(file), magic)
+}

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

@@ -1,12 +1,12 @@
 package com.kdanmobile.reader
 
-import androidx.lifecycle.LiveData
-import androidx.lifecycle.MutableLiveData
-import androidx.lifecycle.ViewModel
 import android.content.Context
 import android.graphics.Color
 import android.net.Uri
 import androidx.core.content.ContextCompat
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.MutableLiveData
+import androidx.lifecycle.ViewModel
 import com.kdanmobile.kmpdfkit.annotation.Annotation
 import com.kdanmobile.kmpdfkit.annotation.bean.*
 import com.kdanmobile.kmpdfkit.annotation.link.listener.OnLinkInfoChangeListener
@@ -221,7 +221,7 @@ class ReaderViewModel(
 
     private fun openPdfFileImp(context: Context, password: String, requestPassword: Runnable, type: String?): OpenFileResult {
         file = File(uri.path)
-        val factory = KMPDFFactory.open(context, uri, type) ?: return OpenFileResult.FAILED
+        val factory = MyKMPDFFactory.open(context, uri) ?: return OpenFileResult.FAILED
         readerModel.initKMPDFFactory(factory, uri.path, password)
         kmpdfFactory?.also {
             fileNameLiveData.postValue(it.fileName)