From 62192f79e05cf9072dbeba2e5ef21d98436f55c6 Mon Sep 17 00:00:00 2001 From: Dima Date: Fri, 28 Jun 2024 18:08:33 +0900 Subject: [PATCH] Limiting the options available in PSPDFKIT's Text Selection Popup Toolbar to Copy, Text Highlight, Share. Upping versionCode to 80 --- .../android/pdf/reader/PdfReaderViewModel.kt | 58 ++++++++++++------- buildSrc/src/main/kotlin/BuildConfig.kt | 2 +- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/org/zotero/android/pdf/reader/PdfReaderViewModel.kt b/app/src/main/java/org/zotero/android/pdf/reader/PdfReaderViewModel.kt index 0f4bd326..263460ad 100644 --- a/app/src/main/java/org/zotero/android/pdf/reader/PdfReaderViewModel.kt +++ b/app/src/main/java/org/zotero/android/pdf/reader/PdfReaderViewModel.kt @@ -357,23 +357,35 @@ class PdfReaderViewModel @Inject constructor( }) this@PdfReaderViewModel.fragment.addDocumentListener(pdfThumbnailBar.documentListener) - this.fragment.addOnAnnotationCreationModeChangeListener(object: - AnnotationManager.OnAnnotationCreationModeChangeListener { - override fun onEnterAnnotationCreationMode(p0: AnnotationCreationController) { - set(true) - } - - override fun onChangeAnnotationCreationMode(p0: AnnotationCreationController) { - set(true) - } + addOnAnnotationCreationModeChangeListener() + setOnPreparePopupToolbarListener() + fragmentManager.commit { + add(containerId, this@PdfReaderViewModel.fragment) + } + } - override fun onExitAnnotationCreationMode(p0: AnnotationCreationController) { - set(false) + private fun setOnPreparePopupToolbarListener() { + this.fragment.setOnPreparePopupToolbarListener { toolbar -> + val sourceItems = toolbar.menuItems + val menuItems = sourceItems.listIterator() + + while (menuItems.hasNext()) { + val item = menuItems.next() + when (item.id) { + com.pspdfkit.R.id.pspdf__text_selection_toolbar_item_underline, + com.pspdfkit.R.id.pspdf__text_selection_toolbar_item_strikeout, + com.pspdfkit.R.id.pspdf__text_selection_toolbar_item_speak, + com.pspdfkit.R.id.pspdf__text_selection_toolbar_item_search, + com.pspdfkit.R.id.pspdf__text_selection_toolbar_item_redact, + com.pspdfkit.R.id.pspdf__text_selection_toolbar_item_paste_annotation, + com.pspdfkit.R.id.pspdf__text_selection_toolbar_item_link, + -> { + menuItems.remove() + } + } } - }) - fragmentManager.commit { - add(containerId, this@PdfReaderViewModel.fragment) + toolbar.menuItems = sourceItems } } @@ -1638,7 +1650,6 @@ class PdfReaderViewModel @Inject constructor( .invertColors(isCalculatedThemeDark) .themeMode(themeMode) .showNoteEditorForNewNoteAnnotations(false) - .textSelectionPopupToolbarEnabled(false) // .disableFormEditing() // .disableAnnotationRotation() // .setSelectedAnnotationResizeEnabled(false) @@ -1931,7 +1942,17 @@ class PdfReaderViewModel @Inject constructor( } }) this@PdfReaderViewModel.fragment.addDocumentListener(pdfThumbnailBar.documentListener) - this.fragment.addOnAnnotationCreationModeChangeListener(object: + setOnPreparePopupToolbarListener() + addOnAnnotationCreationModeChangeListener() + + fragmentManager.commit { + replace(containerId, this@PdfReaderViewModel.fragment) + } + updateVisibilityOfAnnotations() + } + + private fun addOnAnnotationCreationModeChangeListener() { + this.fragment.addOnAnnotationCreationModeChangeListener(object : AnnotationManager.OnAnnotationCreationModeChangeListener { override fun onEnterAnnotationCreationMode(p0: AnnotationCreationController) { set(true) @@ -1946,11 +1967,6 @@ class PdfReaderViewModel @Inject constructor( } }) - - fragmentManager.commit { - replace(containerId, this@PdfReaderViewModel.fragment) - } - updateVisibilityOfAnnotations() } private fun toggleTopAndBottomBarVisibility() { diff --git a/buildSrc/src/main/kotlin/BuildConfig.kt b/buildSrc/src/main/kotlin/BuildConfig.kt index 3bf7db90..1d8a446c 100644 --- a/buildSrc/src/main/kotlin/BuildConfig.kt +++ b/buildSrc/src/main/kotlin/BuildConfig.kt @@ -4,7 +4,7 @@ object BuildConfig { const val compileSdkVersion = 34 const val targetSdk = 33 - val versionCode = 79 // Must be updated on every build + val versionCode = 80 // Must be updated on every build val version = Version( major = 1, minor = 0,