diff --git a/app/build.gradle.kts b/app/build.gradle.kts index cb90666..586bf68 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -34,6 +34,7 @@ android { jvmTarget = "1.8" } buildFeatures { + dataBinding = true viewBinding = true } } diff --git a/app/src/main/java/com/lhw/pdf/ui/gallery/GalleryFragment.kt b/app/src/main/java/com/lhw/pdf/ui/gallery/GalleryFragment.kt index 32ac285..75b3d9e 100644 --- a/app/src/main/java/com/lhw/pdf/ui/gallery/GalleryFragment.kt +++ b/app/src/main/java/com/lhw/pdf/ui/gallery/GalleryFragment.kt @@ -33,6 +33,7 @@ class GalleryFragment : Fragment() { // val galleryViewModel = ViewModelProvider(this)[GalleryViewModel::class.java] _binding = FragmentGalleryBinding.inflate(inflater, container, false) + binding.viewModel = galleryViewModel val root: View = binding.root val chipGroupPages = binding.chipGroupPages @@ -45,19 +46,12 @@ class GalleryFragment : Fragment() { pageZoomLevelChips[pages] = chip } pageZoomLevelChips[galleryViewModel.pagesPerLandscape.value]?.isChecked = true - binding.chipAutoCrop.isChecked = galleryViewModel.renderAutoCrop.value!! - binding.chipUsePdfBox.isChecked = galleryViewModel.usePdfBox.value!! - galleryViewModel.textDisplays.observe(viewLifecycleOwner) { binding.textDisplays.text = it } - galleryViewModel.usePdfBox.observe(viewLifecycleOwner) { binding.chipUsePdfBox.isChecked = it } - galleryViewModel.renderAutoCrop.observe(viewLifecycleOwner) { binding.chipAutoCrop.isChecked = it } + galleryViewModel.textDisplays.observe(viewLifecycleOwner) { binding.textDisplays.text = it } // TODO: Investigate why the binding, even when set @=, in the XML is insufficient for live updates galleryViewModel.pagesPerLandscape.observe(viewLifecycleOwner) { pageZoomLevelChips[it]?.isChecked = true } - binding.chipAutoCrop.setOnCheckedChangeListener { _, checked -> galleryViewModel.renderAutoCrop.value = checked } - binding.chipUsePdfBox.setOnCheckedChangeListener { _, checked -> galleryViewModel.usePdfBox.value = checked } - galleryViewModel.pageThumbnails.observe(viewLifecycleOwner, ::populateThumbnails) val container = binding.thumbnailsLayout diff --git a/app/src/main/res/layout/fragment_gallery.xml b/app/src/main/res/layout/fragment_gallery.xml index bce669c..5a3f055 100644 --- a/app/src/main/res/layout/fragment_gallery.xml +++ b/app/src/main/res/layout/fragment_gallery.xml @@ -1,4 +1,8 @@ + + + + @@ -66,7 +71,7 @@ @@ -74,10 +79,12 @@ - \ No newline at end of file + + \ No newline at end of file