Skip to content

Commit

Permalink
fix: 무한 클릭 시 bottom sheet 중복되어 나오는 문제 해결 (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
easyhz committed Mar 13, 2024
1 parent 3fb392d commit 8a18323
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8a18323

Please sign in to comment.