Refactor hidden page tracking
This commit is contained in:
parent
b67da818c2
commit
033629bb11
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ class GalleryViewModel : ViewModel() {
|
|||
val pageThumbnails = MutableLiveData<List<Bitmap>>().apply { value = listOf() }
|
||||
val hiddenPageGroups = MutableLiveData<Set<Int>>().apply { value = setOf() }
|
||||
val pageGroups = MutableLiveData<List<Int>>().apply { value = listOf() }
|
||||
val enabledPageIds = MutableLiveData<List<Int>>().apply { value = listOf() }
|
||||
val thumbnailScrollProgress = MutableLiveData<Float>().apply { value = 0F }
|
||||
val textDisplays = MutableLiveData<String>().apply { value = "" }
|
||||
val pagesPerLandscape = MutableLiveData<Float>().apply { value = 3F }
|
||||
|
|
Loading…
Reference in New Issue