|
@@ -3,6 +3,7 @@ package com.kdanmobile.reader
|
|
|
import android.annotation.SuppressLint
|
|
|
import android.app.Activity
|
|
|
import android.app.Dialog
|
|
|
+import android.content.Context
|
|
|
import androidx.lifecycle.Observer
|
|
|
import android.content.Intent
|
|
|
import android.net.Uri
|
|
@@ -18,9 +19,11 @@ import android.view.*
|
|
|
import android.view.animation.AnimationUtils
|
|
|
import android.widget.*
|
|
|
import com.kdanmobile.base.KdanBaseActivity
|
|
|
-import com.kdanmobile.kmpdfkit.pdfcommon.KMPDFReaderView
|
|
|
import com.kdanmobile.kmpdfkit.pdfcommon.PDFInfo
|
|
|
+import com.kdanmobile.kmpdfkit.manager.KMPDFFactory
|
|
|
+import com.kdanmobile.kmpdfkit.pdfcommon.*
|
|
|
import com.kdanmobile.reader.Utils.applyConstraintSet
|
|
|
+import com.kdanmobile.reader.additionalpage.*
|
|
|
import com.kdanmobile.reader.annotationattribute.AnnotationAttribute
|
|
|
import com.kdanmobile.reader.annotationattribute.AnnotationColor
|
|
|
import com.kdanmobile.reader.annotationattribute.InkAttribute
|
|
@@ -77,6 +80,9 @@ abstract class ReaderActivity :
|
|
|
open fun loadCurrentPageIndex(filename: String, defaultValue: Int): Int = 0
|
|
|
open fun onOpenedFile() { /* do nothing */ }
|
|
|
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 {
|
|
@@ -115,8 +121,13 @@ abstract class ReaderActivity :
|
|
|
get() {
|
|
|
return viewModel.readerModel
|
|
|
}
|
|
|
+ protected val additionalPageManager: AdditionalPageManager
|
|
|
+ get() {
|
|
|
+ return viewModel.additionalPageManager
|
|
|
+ }
|
|
|
|
|
|
private val viewModel: ReaderViewModel by viewModel {
|
|
|
+ val additionalPageManager = provideAdditionalPageManager()
|
|
|
val filePath = intent.getStringExtra(KEY_FILE_ABSOLUTE)
|
|
|
if (!filePath.isNullOrEmpty()) {
|
|
|
insertToRecentDocumentList(filePath as String)
|
|
@@ -124,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
|
|
|
|
|
@@ -449,13 +460,13 @@ abstract class ReaderActivity :
|
|
|
container.removeAllViews()
|
|
|
if (!isOpened) return
|
|
|
val context = this
|
|
|
- val readerView = object : KMPDFReaderView(context) {
|
|
|
+ // 採用客製化的KMPDFReaderView以覆寫畫面點擊判斷和當前頁面計算方法
|
|
|
+ val readerView = object : AdditionalPageReaderView(context, additionalPageManager.pageConverter) {
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
|
|
override fun onTouchEvent(motionEvent: MotionEvent): Boolean {
|
|
|
if (motionEvent.action == MotionEvent.ACTION_UP) {
|
|
|
if (viewModel.isCopyModeLiveData.value == true) {
|
|
|
if (viewModel.copySelection()) {
|
|
|
- val context = this@ReaderActivity
|
|
|
Toast.makeText(context, R.string.reader_copy_text_success, Toast.LENGTH_SHORT).show()
|
|
|
}
|
|
|
}
|
|
@@ -465,6 +476,8 @@ abstract class ReaderActivity :
|
|
|
|
|
|
override fun onMoveToChild(pageIndex: Int) {
|
|
|
viewModel.setPageIndex(pageIndex)
|
|
|
+ // 畫面更新時應通知additionalPageManager
|
|
|
+ additionalPageManager.onPageChanged(pageIndex)
|
|
|
}
|
|
|
|
|
|
override fun onScrolling() {
|
|
@@ -493,6 +506,20 @@ abstract class ReaderActivity :
|
|
|
}
|
|
|
}
|
|
|
viewModel.setReaderView(readerView)
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 使用客製化KMPDFPageAdapter取代內建的Adapter
|
|
|
+ * 注意,需要在KMPDFFactory::setReaderView之後調用才不會被複寫
|
|
|
+ */
|
|
|
+ viewModel.getReaderView()?.apply {
|
|
|
+ adapter = providePdfPageAdapter(
|
|
|
+ context,
|
|
|
+ FilePicker.FilePickerSupport {},
|
|
|
+ viewModel.readerModel.kmpdfFactory!!
|
|
|
+ )
|
|
|
+ refresh(true)
|
|
|
+ }
|
|
|
+
|
|
|
if (!filePath.isNullOrEmpty()) {
|
|
|
val defaultValue = viewModel.pageIndexLiveData.value ?: 0
|
|
|
val pageIndex = loadCurrentPageIndex(filePath as String, defaultValue)
|
|
@@ -511,6 +538,15 @@ abstract class ReaderActivity :
|
|
|
onOpenedFile()
|
|
|
}
|
|
|
|
|
|
+ fun removeAdditionalPages() {
|
|
|
+ if (additionalPageManager.displayStrategyType == AdditionalPageDisplayStrategyType.HIDE) return
|
|
|
+ val handler = viewModel.pdfInfoHandler
|
|
|
+ val pageIndex = currentPageIndex
|
|
|
+ additionalPageManager.displayStrategyType = AdditionalPageDisplayStrategyType.HIDE
|
|
|
+ viewModel.getReaderView()?.refresh(true)
|
|
|
+ handler.goToCurrentPage(pageIndex)
|
|
|
+ }
|
|
|
+
|
|
|
private fun initTextBoxContextMenuActions() {
|
|
|
viewModel.setTextBoxContextMenuActions(object : TextBoxContextMenuActionListener {
|
|
|
override fun onDelete(): Boolean {
|