diff --git a/app/src/main/java/org/zotero/android/pdf/reader/PdfReaderPspdfKitView.kt b/app/src/main/java/org/zotero/android/pdf/reader/PdfReaderPspdfKitView.kt index bd479302..e34ea966 100644 --- a/app/src/main/java/org/zotero/android/pdf/reader/PdfReaderPspdfKitView.kt +++ b/app/src/main/java/org/zotero/android/pdf/reader/PdfReaderPspdfKitView.kt @@ -3,6 +3,9 @@ package org.zotero.android.pdf.reader import android.content.res.Resources import android.net.Uri import android.util.TypedValue +import android.view.Gravity +import android.view.ViewGroup +import android.widget.FrameLayout import androidx.appcompat.app.AppCompatActivity import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable @@ -10,6 +13,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.viewinterop.AndroidView import androidx.fragment.app.FragmentContainerView +import com.pspdfkit.ui.PdfThumbnailBar import org.zotero.android.R import org.zotero.android.architecture.ui.CustomLayoutSize @@ -22,18 +26,32 @@ fun PdfReaderPspdfKitView(uri: Uri, viewModel: PdfReaderViewModel) { AndroidView( modifier = Modifier.fillMaxSize(), factory = { context -> + val frameLayout = FrameLayout(context) + val containerId = R.id.container val fragmentContainerView = FragmentContainerView(context).apply { id = containerId } + frameLayout.addView(fragmentContainerView) + + val pdfThumbnailBar = PdfThumbnailBar(context) + val thumbnailBarLayoutParams = FrameLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) + thumbnailBarLayoutParams.gravity = Gravity.BOTTOM + pdfThumbnailBar.layoutParams = thumbnailBarLayoutParams + frameLayout.addView(pdfThumbnailBar) + viewModel.init( isTablet = layoutType.isTablet(), uri = uri, containerId = fragmentContainerView.id, fragmentManager = fragmentManager, + pdfThumbnailBar = pdfThumbnailBar, annotationMaxSideSize = annotationMaxSideSize ) - fragmentContainerView + frameLayout }, update = { _ -> } 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 bc906fb3..6c6e9a25 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 @@ -5,6 +5,8 @@ import android.graphics.PointF import android.graphics.RectF import android.net.Uri import android.os.Handler +import android.view.MotionEvent +import androidx.core.view.isVisible import androidx.fragment.app.FragmentManager import androidx.fragment.app.commit import androidx.lifecycle.viewModelScope @@ -31,6 +33,7 @@ import com.pspdfkit.document.PdfDocumentLoader import com.pspdfkit.listeners.DocumentListener import com.pspdfkit.preferences.PSPDFKitPreferences import com.pspdfkit.ui.PdfFragment +import com.pspdfkit.ui.PdfThumbnailBar import com.pspdfkit.ui.special_mode.controller.AnnotationCreationController import com.pspdfkit.ui.special_mode.controller.AnnotationSelectionController import com.pspdfkit.ui.special_mode.controller.AnnotationTool @@ -155,6 +158,7 @@ class PdfReaderViewModel @Inject constructor( private val onSearchStateFlow = MutableStateFlow("") private val onCommentChangeFlow = MutableStateFlow?>(null) private lateinit var fragmentManager: FragmentManager + private lateinit var pdfThumbnailBar: PdfThumbnailBar private var isTablet: Boolean = false private val handler = Handler(context.mainLooper) @@ -284,9 +288,11 @@ class PdfReaderViewModel @Inject constructor( containerId: Int, fragmentManager: FragmentManager, isTablet: Boolean, + pdfThumbnailBar: PdfThumbnailBar, ) { this.isTablet = isTablet this.fragmentManager = fragmentManager + this.pdfThumbnailBar = pdfThumbnailBar this.containerId = containerId this.annotationMaxSideSize = annotationMaxSideSize @@ -311,7 +317,20 @@ class PdfReaderViewModel @Inject constructor( override fun onDocumentLoaded(document: PdfDocument) { this@PdfReaderViewModel.onDocumentLoaded(document) } + + override fun onPageClick( + document: PdfDocument, + pageIndex: Int, + event: MotionEvent?, + pagePosition: PointF?, + clickedAnnotation: Annotation? + ): Boolean { + pdfThumbnailBar.isVisible = !pdfThumbnailBar.isVisible + return false + } }) + + this@PdfReaderViewModel.fragment.addDocumentListener(pdfThumbnailBar.documentListener) this.fragment.addOnAnnotationCreationModeChangeListener(object: AnnotationManager.OnAnnotationCreationModeChangeListener { override fun onEnterAnnotationCreationMode(p0: AnnotationCreationController) { @@ -420,6 +439,8 @@ class PdfReaderViewModel @Inject constructor( fragment.addOnAnnotationDeselectedListener { annotation, _ -> deselectSelectedAnnotation(annotation) } + pdfThumbnailBar.setOnPageChangedListener { _, pageIndex: Int -> fragment.pageIndex = pageIndex } + pdfThumbnailBar.setDocument(document, fragment.configuration) } private fun initState() { @@ -1559,7 +1580,6 @@ class PdfReaderViewModel @Inject constructor( } private fun generatePdfConfiguration(pdfSettings: PDFSettings): PdfConfiguration { - if (!PSPDFKitPreferences.get(context).isAnnotationCreatorSet) { PSPDFKitPreferences.get(context).setAnnotationCreator(viewState.displayName) } @@ -1598,6 +1618,7 @@ class PdfReaderViewModel @Inject constructor( // .disableAnnotationRotation() // .setSelectedAnnotationResizeEnabled(false) .autosaveEnabled(false) + .scrollbarsEnabled(true) .build() } @@ -1873,7 +1894,18 @@ class PdfReaderViewModel @Inject constructor( } } + override fun onPageClick( + document: PdfDocument, + pageIndex: Int, + event: MotionEvent?, + pagePosition: PointF?, + clickedAnnotation: Annotation? + ): Boolean { + pdfThumbnailBar.isVisible = !pdfThumbnailBar.isVisible + return false + } }) + this@PdfReaderViewModel.fragment.addDocumentListener(pdfThumbnailBar.documentListener) this.fragment.addOnAnnotationCreationModeChangeListener(object: AnnotationManager.OnAnnotationCreationModeChangeListener { override fun onEnterAnnotationCreationMode(p0: AnnotationCreationController) { diff --git a/app/src/main/res/values-night-v23/styles.xml b/app/src/main/res/values-night-v23/styles.xml index 63fb1e34..ff4a2c9a 100644 --- a/app/src/main/res/values-night-v23/styles.xml +++ b/app/src/main/res/values-night-v23/styles.xml @@ -11,5 +11,11 @@ @color/checkbox_dark @color/white false + + @style/CustomPspdfDocumentViewStyleDark + @style/CustomPspdfThumbnailBarStyle + @color/pdf_view_background_color + + diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index 5fbd6281..44e97596 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -29,4 +29,6 @@ #282828 #FF4072E5 #FF335BB8 + #FF2D2D2D + #FF1C1C1E diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 19e12644..3e21f0d2 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -62,4 +62,6 @@ #E4E4E7 #77767B #FAFAFD + #FFE8E8ED + #FFF2F2F7 diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 50a85ccf..43b0208a 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -33,6 +33,17 @@ + + + +