Skip to content

Commit

Permalink
Merge pull request #76 from tindy2013/master
Browse files Browse the repository at this point in the history
Use different tag for ImagePickerFragment and MediaPickerFragment
  • Loading branch information
Alex009 authored Apr 11, 2024
2 parents e899ae1 + 4ae33c1 commit cdb8271
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ actual interface MediaPickerController {
companion object {
operator fun invoke(
permissionsController: PermissionsController,
pickerFragmentTag: String = "MediaControllerPicker",
mediaPickerFragmentTag: String = "MediaControllerMediaPicker",
imagePickerFragmentTag: String = "MediaControllerImagePicker",
filePickerFragmentTag: String = "FileMediaControllerPicker"
): MediaPickerController {
return MediaPickerControllerImpl(
permissionsController = permissionsController,
pickerFragmentTag = pickerFragmentTag,
mediaPickerFragmentTag = mediaPickerFragmentTag,
imagePickerFragmentTag = imagePickerFragmentTag,
filePickerFragmentTag = filePickerFragmentTag
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import kotlin.coroutines.suspendCoroutine

internal class MediaPickerControllerImpl(
override val permissionsController: PermissionsController,
private val pickerFragmentTag: String,
private val mediaPickerFragmentTag: String,
private val imagePickerFragmentTag: String,
private val filePickerFragmentTag: String
) : MediaPickerController {
var fragmentManager: FragmentManager? = null
Expand Down Expand Up @@ -57,14 +58,14 @@ internal class MediaPickerControllerImpl(
permissionsController.providePermission(permission)
}

val currentFragment: Fragment? = fragmentManager.findFragmentByTag(pickerFragmentTag)
val currentFragment: Fragment? = fragmentManager.findFragmentByTag(imagePickerFragmentTag)
val imagePickerFragment: ImagePickerFragment = if (currentFragment != null) {
currentFragment as ImagePickerFragment
} else {
ImagePickerFragment.newInstance(maxWidth, maxHeight).also {
fragmentManager
.beginTransaction()
.add(it, pickerFragmentTag)
.add(it, imagePickerFragmentTag)
.commitNow()
}
}
Expand All @@ -86,14 +87,14 @@ internal class MediaPickerControllerImpl(

permissionsController.providePermission(Permission.GALLERY)

val currentFragment: Fragment? = fragmentManager.findFragmentByTag(pickerFragmentTag)
val currentFragment: Fragment? = fragmentManager.findFragmentByTag(mediaPickerFragmentTag)
val pickerFragment: MediaPickerFragment = if (currentFragment != null) {
currentFragment as MediaPickerFragment
} else {
MediaPickerFragment().apply {
fragmentManager
.beginTransaction()
.add(this, pickerFragmentTag)
.add(this, mediaPickerFragmentTag)
.commitNow()
}
}
Expand All @@ -117,7 +118,7 @@ internal class MediaPickerControllerImpl(
FilePickerFragment().apply {
fragmentManager
.beginTransaction()
.add(this, pickerFragmentTag)
.add(this, filePickerFragmentTag)
.commitNow()
}
}
Expand Down

0 comments on commit cdb8271

Please sign in to comment.