Show/hide presented pages by tapping thumbnails

This commit is contained in:
Luke Hubmayer-Werner 2024-08-14 23:51:38 +09:30
parent f10c9a9ae7
commit 75be87a8fe
2 changed files with 21 additions and 6 deletions

View File

@ -6,6 +6,9 @@ Minimum Viable Goals:
- [x] Autocrop margins
- [ ] Open files the Android way - currently just a bundled test file
- [ ] Delete+Reorder Pages - doesn't have to save the source file, but does need to save a change journal
- - [x] Tap thumbnails to hide/show pages
- - [ ] Drag thumbnails to rearrange pages
- - [ ] Save metadata of these actions between sessions
- [ ] Text Annotations - as above
Stretch Goals:
@ -14,4 +17,5 @@ Stretch Goals:
- - [ ] synchronize views for different readers
- - [ ] coordinate views for one reader multiscreen
- [ ] Pen Annotations
- [ ] Autocrop undesired elements (e.g. logo in top right corner, copyright footer)
- [ ] Improve overall UI

View File

@ -2,6 +2,7 @@ package com.lhw.pdf
import android.app.Presentation
import android.content.Context
import android.graphics.PorterDuff
import android.media.MediaRouter
import android.os.Bundle
import android.util.DisplayMetrics
@ -40,6 +41,7 @@ class MainActivity : AppCompatActivity() {
private lateinit var pdfDocument: PdfDocument
private lateinit var presentationScroll: HorizontalScrollView
private lateinit var presentationLayout: LinearLayout
private val showPages = mutableListOf<Boolean>()
private fun inputStreamToCache(outputFilename: String, inputStream: InputStream): File {
val fileCached = File(cacheDir, outputFilename)
@ -61,12 +63,15 @@ class MainActivity : AppCompatActivity() {
}
private fun updatePresentationImages() {
val maxHeight: Int = presentationDisplayMetrics.heightPixels
val maxWidth: Int = min(maxHeight*5/7, (presentationDisplayMetrics.widthPixels/pagesPerLandscape).toInt())
pdfDocument.renderPagesPresentation(maxWidth, maxHeight, renderAutoCrop)
private fun updatePresentationImages(rerender: Boolean = true) {
if (rerender) {
val maxHeight: Int = presentationDisplayMetrics.heightPixels
val maxWidth: Int = min(maxHeight*5/7, (presentationDisplayMetrics.widthPixels/pagesPerLandscape).toInt())
pdfDocument.renderPagesPresentation(maxWidth, maxHeight, renderAutoCrop)
}
presentationLayout.removeAllViewsInLayout()
for (bitmap in pdfDocument.bitmapPagesPresentation.values) {
showPages.withIndex().filter { (i, show) -> (show) }.forEach { (i, show) ->
val bitmap = pdfDocument.bitmapPagesPresentation[i]
val img = ImageView(this)
img.setImageBitmap(bitmap)
presentationLayout.addView(img)
@ -110,10 +115,16 @@ class MainActivity : AppCompatActivity() {
initializePdfDocument()
pdfDocument.renderThumbnails(thumbnailWidth, thumbnailHeight)
val container = binding.appBarMain.contentMain.thumbnailsLayout
for (bitmap in pdfDocument.bitmapThumbnails.values) {
for ((index, bitmap) in pdfDocument.bitmapThumbnails) {
val img = ImageView(this)
img.setImageBitmap(bitmap)
img.setOnClickListener {
showPages[index] = !showPages[index]
img.setColorFilter(if (showPages[index]) 0 else 0x7F000000, PorterDuff.Mode.DARKEN)
updatePresentationImages(false)
}
container.addView(img)
showPages.add(true)
}
presentationView()