Put disabled page thumbnails in an upper red-background row

This commit is contained in:
Luke Hubmayer-Werner 2024-08-18 00:35:14 +09:30
parent 7cf7731541
commit 23e7d8693a
2 changed files with 37 additions and 4 deletions

View File

@ -36,6 +36,7 @@ class MainActivity : AppCompatActivity() {
private var presentation: MyPresentation? = null private var presentation: MyPresentation? = null
private lateinit var pdfDocument: PdfDocument private lateinit var pdfDocument: PdfDocument
private val showPages = mutableListOf<Boolean>() private val showPages = mutableListOf<Boolean>()
private val thumbnailImageViews = mutableListOf<ImageView>()
private val defaultCachedFileName = "cached.pdf" private val defaultCachedFileName = "cached.pdf"
private fun inputStreamToCache(outputFilename: String, inputStream: InputStream): File { 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() { private fun populateThumbnails() {
val container = binding.appBarMain.contentMain.thumbnailsLayout val container = binding.appBarMain.contentMain.thumbnailsLayout
for ((index, bitmap) in pdfDocument.bitmapThumbnails) { for ((index, bitmap) in pdfDocument.bitmapThumbnails) {
@ -80,12 +92,13 @@ class MainActivity : AppCompatActivity() {
img.setImageBitmap(bitmap) img.setImageBitmap(bitmap)
img.setOnClickListener { img.setOnClickListener {
showPages[index] = !showPages[index] showPages[index] = !showPages[index]
img.setColorFilter(if (showPages[index]) 0 else 0x7F000000, PorterDuff.Mode.DARKEN) //img.setColorFilter(if (showPages[index]) 0 else 0x7F000000, PorterDuff.Mode.DARKEN)
updatePresentationImages(false) reLayoutThumbnails()
} }
container.addView(img) thumbnailImageViews.add(img)
showPages.add(true) showPages.add(true)
} }
reLayoutThumbnails()
} }
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -109,8 +122,8 @@ class MainActivity : AppCompatActivity() {
handleIntent(intent) handleIntent(intent)
pdfDocument.renderThumbnails(thumbnailWidth, thumbnailHeight) pdfDocument.renderThumbnails(thumbnailWidth, thumbnailHeight)
populateThumbnails()
makePresentationView() makePresentationView()
populateThumbnails()
val container = binding.appBarMain.contentMain.thumbnailsLayout val container = binding.appBarMain.contentMain.thumbnailsLayout
val containerScroll = binding.appBarMain.contentMain.thumbnailsScroll val containerScroll = binding.appBarMain.contentMain.thumbnailsScroll

View File

@ -18,10 +18,30 @@
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/mobile_navigation" /> app:navGraph="@navigation/mobile_navigation" />
<HorizontalScrollView
android:id="@+id/thumbnails_disabled_scroll"
android:layout_width="0dp"
android:layout_height="300dp"
android:background="#80C01010"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<LinearLayout
android:id="@+id/thumbnails_disabled_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:showIn="@layout/content_main" />
</HorizontalScrollView>
<HorizontalScrollView <HorizontalScrollView
android:id="@+id/thumbnails_scroll" android:id="@+id/thumbnails_scroll"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_marginTop="300dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"