From 8a183230ac2d18fe20233ec41638a86fc672d49f Mon Sep 17 00:00:00 2001 From: easyhz Date: Thu, 14 Mar 2024 01:16:04 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=AC=B4=ED=95=9C=20=ED=81=B4=EB=A6=AD?= =?UTF-8?q?=20=EC=8B=9C=20bottom=20sheet=20=EC=A4=91=EB=B3=B5=EB=90=98?= =?UTF-8?q?=EC=96=B4=20=EB=82=98=EC=98=A4=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0=20(2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../picly/view/album/upload/UploadFragment.kt | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/easyhz/picly/view/album/upload/UploadFragment.kt b/app/src/main/java/com/easyhz/picly/view/album/upload/UploadFragment.kt index 260e88d..ed3a608 100644 --- a/app/src/main/java/com/easyhz/picly/view/album/upload/UploadFragment.kt +++ b/app/src/main/java/com/easyhz/picly/view/album/upload/UploadFragment.kt @@ -63,6 +63,8 @@ class UploadFragment: Fragment() { private val galleryPermissionLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted -> this.isGranted = isGranted } + private var bottomSheetFragment: GalleryBottomSheetFragment? = null + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -178,16 +180,26 @@ class UploadFragment: Fragment() { } private fun onClickAddImage() { - if (isGranted || ContextCompat.checkSelfPermission( - requireContext(), - Manifest.permission.READ_EXTERNAL_STORAGE - ) == PackageManager.PERMISSION_GRANTED) { - val bottomSheetFragment = GalleryBottomSheetFragment.getInstance() - bottomSheetFragment.show(requireActivity().supportFragmentManager, bottomSheetFragment.tag) + if (isStoragePermissionGranted()) { + showGalleryBottomSheet() } else { showGalleryPermissionDialog() } } + + + private fun isStoragePermissionGranted(): Boolean { + return isGranted || ContextCompat.checkSelfPermission( + requireContext(), + Manifest.permission.READ_EXTERNAL_STORAGE + ) == PackageManager.PERMISSION_GRANTED + } + + private fun showGalleryBottomSheet() { + if (bottomSheetFragment != null && bottomSheetFragment!!.isAdded) return + bottomSheetFragment = GalleryBottomSheetFragment() + bottomSheetFragment!!.show(requireActivity().supportFragmentManager, "Gallery_Bottom_Sheet") + } private fun observeGallerySelectedImageList() { galleryViewModel.selectedImageList.observe(viewLifecycleOwner) { uploadImageAdapter.setUploadImageList(it)