diff --git a/app/src/main/java/com/lhw/pdf/MainActivity.kt b/app/src/main/java/com/lhw/pdf/MainActivity.kt index ff56d7f..634469f 100644 --- a/app/src/main/java/com/lhw/pdf/MainActivity.kt +++ b/app/src/main/java/com/lhw/pdf/MainActivity.kt @@ -58,17 +58,9 @@ class MainActivity : AppCompatActivity() { } private val displayListener = object: DisplayListener { - override fun onDisplayAdded(p0: Int) { - reevaluateDisplay(p0) - } - - override fun onDisplayChanged(p0: Int) { - reevaluateDisplay(p0) - } - - override fun onDisplayRemoved(p0: Int) { - reevaluateDisplay(p0) - } + override fun onDisplayAdded(p0: Int) { reevaluateDisplay(p0) } + override fun onDisplayChanged(p0: Int) { reevaluateDisplay(p0) } + override fun onDisplayRemoved(p0: Int) { reevaluateDisplay(p0) } } private fun reevaluateDisplay(p0: Int) { @@ -102,13 +94,13 @@ class MainActivity : AppCompatActivity() { updateBitmaps(maxWidth, maxHeight) val key = Pair(maxWidth, maxHeight) val bitmapPages = pdfDocument.bitmapPages[key] - val bitmaps = pageGroups.withIndex() - .mapNotNull { (i, group) -> if (group in hiddenPageGroups) null else bitmapPages?.get(i) } - .toList() + val bitmaps = viewModel.enabledPageIds.value?.mapNotNull { bitmapPages?.get(it) }?.toList() ?: listOf() p.updateImages(bitmaps) } private fun updatePresentations(reRender: Boolean = true) { + viewModel.enabledPageIds.value = pageGroups.mapIndexedNotNull { i, group -> if (group !in hiddenPageGroups) i else null }.toList() + if (reRender) pdfDocument.invalidateCache() presentations.values.forEach(::updatePresentationImages) } diff --git a/app/src/main/java/com/lhw/pdf/ui/gallery/GalleryViewModel.kt b/app/src/main/java/com/lhw/pdf/ui/gallery/GalleryViewModel.kt index 2c44217..32963fd 100644 --- a/app/src/main/java/com/lhw/pdf/ui/gallery/GalleryViewModel.kt +++ b/app/src/main/java/com/lhw/pdf/ui/gallery/GalleryViewModel.kt @@ -8,6 +8,7 @@ class GalleryViewModel : ViewModel() { val pageThumbnails = MutableLiveData>().apply { value = listOf() } val hiddenPageGroups = MutableLiveData>().apply { value = setOf() } val pageGroups = MutableLiveData>().apply { value = listOf() } + val enabledPageIds = MutableLiveData>().apply { value = listOf() } val thumbnailScrollProgress = MutableLiveData().apply { value = 0F } val textDisplays = MutableLiveData().apply { value = "" } val pagesPerLandscape = MutableLiveData().apply { value = 3F }