in FileProvider/app/src/main/java/com/example/graygallery/ui/GalleryFragment.kt [40:74]
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
super.onCreate(savedInstanceState)
binding = FragmentGalleryBinding.inflate(inflater, container, false)
viewModel.loadImages()
val galleryAdapter =
GalleryAdapter { image ->
viewImageUsingExternalApp(image)
}
binding.gallery.also { view ->
view.layoutManager = GridLayoutManager(
activity,
GALLERY_COLUMNS
)
view.adapter = galleryAdapter
}
viewModel.images.observe(viewLifecycleOwner, Observer { images ->
galleryAdapter.submitList(images)
})
viewModel.notification.observe(viewLifecycleOwner, Observer {
Snackbar.make(binding.root, it, Snackbar.LENGTH_SHORT).show()
})
// TODO: Add popup menu https://material.io/develop/android/components/menu/
// https://www.techotopia.com/index.php/Working_with_the_Android_GridLayout_in_XML_Layout_Resources
return binding.root
}