diff --git a/README.md b/README.md index 3a30f15..74b97ca 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/app/src/main/java/com/lhw/pdf/MainActivity.kt b/app/src/main/java/com/lhw/pdf/MainActivity.kt index 5b39bdb..4b6e2d7 100644 --- a/app/src/main/java/com/lhw/pdf/MainActivity.kt +++ b/app/src/main/java/com/lhw/pdf/MainActivity.kt @@ -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() 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()