From 23e7d8693a19666c03d4acf40ed46a13e811d53d Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Sun, 18 Aug 2024 00:35:14 +0930 Subject: [PATCH] Put disabled page thumbnails in an upper red-background row --- app/src/main/java/com/lhw/pdf/MainActivity.kt | 21 +++++++++++++++---- app/src/main/res/layout/content_main.xml | 20 ++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/lhw/pdf/MainActivity.kt b/app/src/main/java/com/lhw/pdf/MainActivity.kt index 5ebca8c..335efdd 100644 --- a/app/src/main/java/com/lhw/pdf/MainActivity.kt +++ b/app/src/main/java/com/lhw/pdf/MainActivity.kt @@ -36,6 +36,7 @@ class MainActivity : AppCompatActivity() { private var presentation: MyPresentation? = null private lateinit var pdfDocument: PdfDocument private val showPages = mutableListOf() + private val thumbnailImageViews = mutableListOf() private val defaultCachedFileName = "cached.pdf" private fun inputStreamToCache(outputFilename: String, inputStream: InputStream): File { @@ -73,6 +74,17 @@ class MainActivity : AppCompatActivity() { } } + private fun reLayoutThumbnails() { + val container = binding.appBarMain.contentMain.thumbnailsLayout + val disabledContainer = binding.appBarMain.contentMain.thumbnailsDisabledLayout + container.removeAllViewsInLayout() + disabledContainer.removeAllViewsInLayout() + showPages.map { if (it) container else disabledContainer }.zip(thumbnailImageViews).forEach { (cont, img) -> + cont.addView(img) + } + updatePresentationImages(false) + } + private fun populateThumbnails() { val container = binding.appBarMain.contentMain.thumbnailsLayout for ((index, bitmap) in pdfDocument.bitmapThumbnails) { @@ -80,12 +92,13 @@ class MainActivity : AppCompatActivity() { img.setImageBitmap(bitmap) img.setOnClickListener { showPages[index] = !showPages[index] - img.setColorFilter(if (showPages[index]) 0 else 0x7F000000, PorterDuff.Mode.DARKEN) - updatePresentationImages(false) + //img.setColorFilter(if (showPages[index]) 0 else 0x7F000000, PorterDuff.Mode.DARKEN) + reLayoutThumbnails() } - container.addView(img) + thumbnailImageViews.add(img) showPages.add(true) } + reLayoutThumbnails() } override fun onCreate(savedInstanceState: Bundle?) { @@ -109,8 +122,8 @@ class MainActivity : AppCompatActivity() { handleIntent(intent) pdfDocument.renderThumbnails(thumbnailWidth, thumbnailHeight) - populateThumbnails() makePresentationView() + populateThumbnails() val container = binding.appBarMain.contentMain.thumbnailsLayout val containerScroll = binding.appBarMain.contentMain.thumbnailsScroll diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml index 5fbb131..c1892e8 100644 --- a/app/src/main/res/layout/content_main.xml +++ b/app/src/main/res/layout/content_main.xml @@ -18,10 +18,30 @@ app:layout_constraintTop_toTopOf="parent" app:navGraph="@navigation/mobile_navigation" /> + + + + +