Просмотр исходного кода

Add ThumbnailHandler & implementations

cooperku_kdanmobile 5 лет назад
Родитель
Сommit
7fbe65ced1

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

@@ -3,14 +3,16 @@ package com.kdanmobile.reader
 import android.arch.lifecycle.MutableLiveData
 import android.arch.lifecycle.ViewModel
 import android.content.Context
+import android.graphics.Bitmap
 import android.net.Uri
 import com.kdanmobile.kmpdfkit.annotation.bean.*
 import com.kdanmobile.kmpdfkit.globaldata.Config
 import com.kdanmobile.kmpdfkit.manager.KMPDFFactory
 import com.kdanmobile.kmpdfkit.manager.controller.KMPDFDocumentController
 import com.kdanmobile.kmpdfkit.pdfcommon.KMPDFReaderView
+import com.kdanmobile.reader.screen.view.ThumbnailHandler
 
-class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMsg: String) : ViewModel() {
+class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMsg: String) : ViewModel(), ThumbnailHandler {
     enum class ViewDirection(val mode: Config.PDFViewMode) {
         VerticalSinglePageContinues(Config.PDFViewMode.VERTICAL_SINGLE_PAGE_CONTINUES),
         VerticalSinglePage(Config.PDFViewMode.VERTICAL_SINGLE_PAGE),
@@ -160,4 +162,26 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
             refresh(false)
         }
     }
+
+    //  ====================================================================
+    //  implement ThumbnailHandler
+    //  ====================================================================
+
+    override fun getPdfPageCount(): Int? {
+        return kmpdfDocumentController?.getDocumentPageCount(false)
+    }
+
+    override fun getCurrentPage(): Int? {
+        return kmpdfDocumentController?.currentPageNum
+    }
+
+    override fun setCurrentPage(page: Int): Boolean? {
+        return kmpdfDocumentController?.gotoPage(page)
+    }
+
+    override fun getPdfBitmap(position: Int, picWidth: Int, mode: Int, isDrawAnnot: Boolean): Bitmap? {
+        return kmpdfDocumentController?.covertPDFToBitmap(position, picWidth, mode, isDrawAnnot)
+    }
+
+    //  ====================================================================
 }

+ 23 - 0
reader/src/main/java/com/kdanmobile/reader/screen/view/ThumbnailHandler.kt

@@ -0,0 +1,23 @@
+package com.kdanmobile.reader.screen.view
+
+import android.graphics.Bitmap
+
+interface ThumbnailHandler {
+
+    companion object {
+        val MODE_DAY = 0
+        val MODE_NIGHT = 1
+        val MODE_SEFIA = 2
+        val MODE_ETON_BLUE = 3
+        val MODE_CHROME_WHITE = 4
+        val MODE_WHITE_LILAC = 5
+    }
+
+    fun getPdfPageCount(): Int?
+
+    fun getCurrentPage(): Int?
+
+    fun setCurrentPage(page: Int): Boolean?
+
+    fun getPdfBitmap(position: Int, picWidth: Int, mode: Int = MODE_DAY, isDrawAnnot: Boolean = true): Bitmap?
+}