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" /> + + + + +