Page Groups are toggled hidden instead of Pages
This commit is contained in:
parent
34fda4ed34
commit
5c980880c6
|
@ -8,7 +8,8 @@ Minimum Viable Goals:
|
||||||
- - [x] Accept intents to load a single PDF
|
- - [x] Accept intents to load a single PDF
|
||||||
- - [ ] Built-in file browser with requisite permissions
|
- - [ ] Built-in file browser with requisite permissions
|
||||||
- [ ] Delete+Reorder Pages - doesn't have to save the source file, but does need to save a change journal
|
- [ ] Delete+Reorder Pages - doesn't have to save the source file, but does need to save a change journal
|
||||||
- - [x] Tap thumbnails to hide/show pages
|
- - [x] Tap thumbnails in Home fragment to (un)group with previous
|
||||||
|
- - [x] Tap thumbnails in Gallery fragment to (un)hide page groups
|
||||||
- - [ ] Drag thumbnails to rearrange pages
|
- - [ ] Drag thumbnails to rearrange pages
|
||||||
- - [ ] Save metadata of these actions between sessions
|
- - [ ] Save metadata of these actions between sessions
|
||||||
- [ ] Text Annotations - as above
|
- [ ] Text Annotations - as above
|
||||||
|
|
|
@ -48,7 +48,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
private var usePdfBox = false
|
private var usePdfBox = false
|
||||||
private val presentations = mutableMapOf<Int, MyPresentation>()
|
private val presentations = mutableMapOf<Int, MyPresentation>()
|
||||||
private lateinit var pdfDocument: PdfDocument
|
private lateinit var pdfDocument: PdfDocument
|
||||||
private val showPages = mutableListOf<Boolean>()
|
private val hiddenPageGroups = mutableSetOf<Int>()
|
||||||
private val pageGroups = mutableListOf<Int>()
|
private val pageGroups = mutableListOf<Int>()
|
||||||
private val defaultCachedFileName = "cached.pdf"
|
private val defaultCachedFileName = "cached.pdf"
|
||||||
|
|
||||||
|
@ -101,8 +101,9 @@ class MainActivity : AppCompatActivity() {
|
||||||
val maxWidth: Int = (p.displayMetrics.widthPixels / pagesPerLandscape).toInt() //in(maxHeight * 5 / 7, (p.displayMetrics.widthPixels / pagesPerLandscape).toInt())
|
val maxWidth: Int = (p.displayMetrics.widthPixels / pagesPerLandscape).toInt() //in(maxHeight * 5 / 7, (p.displayMetrics.widthPixels / pagesPerLandscape).toInt())
|
||||||
updateBitmaps(maxWidth, maxHeight)
|
updateBitmaps(maxWidth, maxHeight)
|
||||||
val key = Pair(maxWidth, maxHeight)
|
val key = Pair(maxWidth, maxHeight)
|
||||||
val bitmaps = showPages.withIndex()
|
val bitmapPages = pdfDocument.bitmapPages[key]
|
||||||
.mapNotNull { (i, show) -> if (show) pdfDocument.bitmapPages[key]?.get(i) else null }
|
val bitmaps = pageGroups.withIndex()
|
||||||
|
.mapNotNull { (i, group) -> if (group in hiddenPageGroups) null else bitmapPages?.get(i) }
|
||||||
.toList()
|
.toList()
|
||||||
p.updateImages(bitmaps)
|
p.updateImages(bitmaps)
|
||||||
}
|
}
|
||||||
|
@ -143,7 +144,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
outState.putString("fileName", "TODO")
|
outState.putString("fileName", "TODO")
|
||||||
outState.putBoolean("renderAutoCrop", renderAutoCrop)
|
outState.putBoolean("renderAutoCrop", renderAutoCrop)
|
||||||
outState.putFloat("pagesPerLandscape", pagesPerLandscape)
|
outState.putFloat("pagesPerLandscape", pagesPerLandscape)
|
||||||
outState.putBooleanArray("showPages", showPages.toBooleanArray())
|
outState.putIntArray("hiddenPageGroups", hiddenPageGroups.toIntArray())
|
||||||
outState.putIntArray("pageGroups", pageGroups.toIntArray())
|
outState.putIntArray("pageGroups", pageGroups.toIntArray())
|
||||||
outState.putFloat("thumbnailScrollProgress", thumbnailScrollProgress)
|
outState.putFloat("thumbnailScrollProgress", thumbnailScrollProgress)
|
||||||
}
|
}
|
||||||
|
@ -183,15 +184,14 @@ class MainActivity : AppCompatActivity() {
|
||||||
pdfDocument.renderThumbnails(thumbnailWidth, thumbnailHeight)
|
pdfDocument.renderThumbnails(thumbnailWidth, thumbnailHeight)
|
||||||
displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION).forEach(::makePresentationView)
|
displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION).forEach(::makePresentationView)
|
||||||
|
|
||||||
showPages.clear()
|
hiddenPageGroups.clear()
|
||||||
pageGroups.clear()
|
pageGroups.clear()
|
||||||
(0..<pdfDocument.numPages).forEach {
|
(0..<pdfDocument.numPages).forEach { pageGroups.add(it) }
|
||||||
showPages.add(true)
|
savedInstanceState?.getIntArray("hiddenPageGroups")?.forEach { hiddenPageGroups += it }
|
||||||
pageGroups.add(it)
|
|
||||||
}
|
|
||||||
savedInstanceState?.getBooleanArray("showPages")?.forEachIndexed { i, show -> showPages[i] = show }
|
|
||||||
savedInstanceState?.getIntArray("pageGroups")?.forEachIndexed { i, groupIdx -> pageGroups[i] = groupIdx }
|
savedInstanceState?.getIntArray("pageGroups")?.forEachIndexed { i, groupIdx -> pageGroups[i] = groupIdx }
|
||||||
viewModel.showPages.value = showPages.toList()
|
println("Bundle debug: hiddenPageGroups = $hiddenPageGroups")
|
||||||
|
println("Bundle debug: pageGroups = $pageGroups")
|
||||||
|
viewModel.hiddenPageGroups.value = hiddenPageGroups.toSet()
|
||||||
viewModel.pageGroups.value = pageGroups.toList()
|
viewModel.pageGroups.value = pageGroups.toList()
|
||||||
viewModel.pageThumbnails.value = pdfDocument.bitmapThumbnails.toSortedMap().values.toList()
|
viewModel.pageThumbnails.value = pdfDocument.bitmapThumbnails.toSortedMap().values.toList()
|
||||||
|
|
||||||
|
@ -208,8 +208,14 @@ class MainActivity : AppCompatActivity() {
|
||||||
pdfDocument.usePdfBox = usePdfBox
|
pdfDocument.usePdfBox = usePdfBox
|
||||||
updatePresentations()
|
updatePresentations()
|
||||||
}
|
}
|
||||||
viewModel.showPages.observe(this) {
|
viewModel.pageGroups.observe(this) {
|
||||||
it.forEachIndexed() {i, shown -> showPages[i] = shown}
|
pageGroups.clear()
|
||||||
|
pageGroups += it
|
||||||
|
updatePresentations(false)
|
||||||
|
}
|
||||||
|
viewModel.hiddenPageGroups.observe(this) {
|
||||||
|
hiddenPageGroups.clear()
|
||||||
|
hiddenPageGroups += it
|
||||||
updatePresentations(false)
|
updatePresentations(false)
|
||||||
}
|
}
|
||||||
viewModel.thumbnailScrollProgress.observe(this) { thumbnailScrollProgress ->
|
viewModel.thumbnailScrollProgress.observe(this) { thumbnailScrollProgress ->
|
||||||
|
|
|
@ -51,6 +51,7 @@ class GalleryFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
galleryViewModel.pageThumbnails.observe(viewLifecycleOwner, ::populateThumbnails)
|
galleryViewModel.pageThumbnails.observe(viewLifecycleOwner, ::populateThumbnails)
|
||||||
|
galleryViewModel.pageGroups.observe(viewLifecycleOwner) { reLayoutThumbnails() }
|
||||||
|
|
||||||
val container = binding.thumbnailsLayout
|
val container = binding.thumbnailsLayout
|
||||||
val containerScroll = binding.thumbnailsScroll
|
val containerScroll = binding.thumbnailsScroll
|
||||||
|
@ -69,11 +70,14 @@ class GalleryFragment : Fragment() {
|
||||||
private fun reLayoutThumbnails() {
|
private fun reLayoutThumbnails() {
|
||||||
val container = binding.thumbnailsLayout
|
val container = binding.thumbnailsLayout
|
||||||
val disabledContainer = binding.thumbnailsDisabledLayout
|
val disabledContainer = binding.thumbnailsDisabledLayout
|
||||||
|
val hiddenPageGroups = galleryViewModel.hiddenPageGroups.value!!
|
||||||
container.removeAllViewsInLayout()
|
container.removeAllViewsInLayout()
|
||||||
disabledContainer.removeAllViewsInLayout()
|
disabledContainer.removeAllViewsInLayout()
|
||||||
galleryViewModel.showPages.value
|
thumbnailImageViews.forEach { (it.parent as? ViewGroup)?.removeView(it) }
|
||||||
?.map { if (it) container else disabledContainer }
|
galleryViewModel.pageGroups.value
|
||||||
?.zip(thumbnailImageViews)?.forEach { (cont, img) ->
|
?.map { group -> if (group in hiddenPageGroups) disabledContainer else container }
|
||||||
|
?.zip(thumbnailImageViews)
|
||||||
|
?.forEach { (cont, img) ->
|
||||||
cont.addView(img)
|
cont.addView(img)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,9 +87,14 @@ class GalleryFragment : Fragment() {
|
||||||
val img = ImageView(context)
|
val img = ImageView(context)
|
||||||
img.setImageBitmap(bitmap)
|
img.setImageBitmap(bitmap)
|
||||||
img.setOnClickListener {
|
img.setOnClickListener {
|
||||||
val showPages = galleryViewModel.showPages.value!!.toMutableList()
|
val hiddenPageGroups = galleryViewModel.hiddenPageGroups.value!!.toMutableSet()
|
||||||
showPages[index] = !showPages[index]
|
val group = galleryViewModel.pageGroups.value!![index]
|
||||||
galleryViewModel.showPages.value = showPages.toList()
|
if (group in hiddenPageGroups) {
|
||||||
|
hiddenPageGroups -= group
|
||||||
|
} else {
|
||||||
|
hiddenPageGroups += group
|
||||||
|
}
|
||||||
|
galleryViewModel.hiddenPageGroups.value = hiddenPageGroups.toSet()
|
||||||
reLayoutThumbnails()
|
reLayoutThumbnails()
|
||||||
}
|
}
|
||||||
thumbnailImageViews.add(img)
|
thumbnailImageViews.add(img)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import androidx.lifecycle.ViewModel
|
||||||
|
|
||||||
class GalleryViewModel : ViewModel() {
|
class GalleryViewModel : ViewModel() {
|
||||||
val pageThumbnails = MutableLiveData<List<Bitmap>>().apply { value = listOf() }
|
val pageThumbnails = MutableLiveData<List<Bitmap>>().apply { value = listOf() }
|
||||||
val showPages = MutableLiveData<List<Boolean>>().apply { value = listOf() }
|
val hiddenPageGroups = MutableLiveData<Set<Int>>().apply { value = setOf() }
|
||||||
val pageGroups = MutableLiveData<List<Int>>().apply { value = listOf() }
|
val pageGroups = MutableLiveData<List<Int>>().apply { value = listOf() }
|
||||||
val thumbnailScrollProgress = MutableLiveData<Float>().apply { value = 0F }
|
val thumbnailScrollProgress = MutableLiveData<Float>().apply { value = 0F }
|
||||||
val textDisplays = MutableLiveData<String>().apply { value = "" }
|
val textDisplays = MutableLiveData<String>().apply { value = "" }
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.lhw.pdf.ui.home
|
package com.lhw.pdf.ui.home
|
||||||
|
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.Color
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
@ -34,6 +35,8 @@ class HomeFragment : Fragment() {
|
||||||
val root: View = binding.root
|
val root: View = binding.root
|
||||||
|
|
||||||
galleryViewModel.pageThumbnails.observe(viewLifecycleOwner, ::populateThumbnails)
|
galleryViewModel.pageThumbnails.observe(viewLifecycleOwner, ::populateThumbnails)
|
||||||
|
galleryViewModel.pageGroups.observe(viewLifecycleOwner) { reLayoutThumbnails() }
|
||||||
|
galleryViewModel.hiddenPageGroups.observe(viewLifecycleOwner) { reLayoutThumbnails() }
|
||||||
|
|
||||||
return root
|
return root
|
||||||
}
|
}
|
||||||
|
@ -43,14 +46,22 @@ class HomeFragment : Fragment() {
|
||||||
_binding = null
|
_binding = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val groupContainers = mutableMapOf<Int, LinearLayout>()
|
||||||
private fun reLayoutThumbnails() {
|
private fun reLayoutThumbnails() {
|
||||||
val container = binding.thumbnailsLayout
|
val container = binding.thumbnailsLayout
|
||||||
container.children.forEach { (it as LinearLayout).removeAllViewsInLayout() }
|
thumbnailImageViews.forEach { (it.parent as? ViewGroup)?.removeView(it) }
|
||||||
|
groupContainers.values.forEach { it.removeAllViewsInLayout() }
|
||||||
container.removeAllViewsInLayout()
|
container.removeAllViewsInLayout()
|
||||||
val groupContainers = mutableMapOf<Int, LinearLayout>()
|
groupContainers.clear()
|
||||||
galleryViewModel.pageGroups.value?.forEachIndexed {i, groupIdx ->
|
galleryViewModel.pageGroups.value?.forEachIndexed {i, groupIdx ->
|
||||||
if (groupIdx !in groupContainers) {
|
if (groupIdx !in groupContainers) {
|
||||||
val c = LinearLayout(context)
|
val c = LinearLayout(context)
|
||||||
|
c.setPadding(2, 4, 2, 4)
|
||||||
|
galleryViewModel.hiddenPageGroups.value?.let {
|
||||||
|
if (groupIdx in it) {
|
||||||
|
c.setBackgroundColor(Color.RED)
|
||||||
|
}
|
||||||
|
}
|
||||||
groupContainers[groupIdx] = c
|
groupContainers[groupIdx] = c
|
||||||
container.addView(c)
|
container.addView(c)
|
||||||
}
|
}
|
||||||
|
@ -62,6 +73,7 @@ class HomeFragment : Fragment() {
|
||||||
bitmaps.forEachIndexed() { index, bitmap ->
|
bitmaps.forEachIndexed() { index, bitmap ->
|
||||||
val img = ImageView(context)
|
val img = ImageView(context)
|
||||||
img.setImageBitmap(bitmap)
|
img.setImageBitmap(bitmap)
|
||||||
|
img.setPadding(2, 0, 2, 0)
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
img.setOnClickListener {
|
img.setOnClickListener {
|
||||||
val pageGroups = galleryViewModel.pageGroups.value!!.toMutableList()
|
val pageGroups = galleryViewModel.pageGroups.value!!.toMutableList()
|
||||||
|
@ -79,7 +91,6 @@ class HomeFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
galleryViewModel.pageGroups.value = pageGroups.toList()
|
galleryViewModel.pageGroups.value = pageGroups.toList()
|
||||||
reLayoutThumbnails()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
thumbnailImageViews.add(img)
|
thumbnailImageViews.add(img)
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/thumbnails_layout"
|
android:id="@+id/thumbnails_layout"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:showIn="@layout/content_main" />
|
tools:showIn="@layout/content_main" />
|
||||||
|
|
Loading…
Reference in New Issue