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 - [x] Autocrop margins
- [ ] Open files the Android way - currently just a bundled test file - [ ] 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 - [ ] 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 - [ ] Text Annotations - as above
Stretch Goals: Stretch Goals:
@ -14,4 +17,5 @@ Stretch Goals:
- - [ ] synchronize views for different readers - - [ ] synchronize views for different readers
- - [ ] coordinate views for one reader multiscreen - - [ ] coordinate views for one reader multiscreen
- [ ] Pen Annotations - [ ] Pen Annotations
- [ ] Autocrop undesired elements (e.g. logo in top right corner, copyright footer)
- [ ] Improve overall UI - [ ] Improve overall UI

View File

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