Do not close gallery picker once 0 items selected.

This change only takes effect if the user navigates directly to the gallery picker.
This commit is contained in:
Nicholas
2022-10-20 10:13:15 -04:00
committed by Alex Hart
parent 084e806c25
commit 371267a1d3
3 changed files with 11 additions and 7 deletions

View File

@@ -24,7 +24,8 @@ data class MediaSelectionState(
val editorStateMap: Map<Uri, Any> = mapOf(),
val cameraFirstCapture: Media? = null,
val isStory: Boolean,
val storySendRequirements: Stories.MediaTransform.SendRequirements = Stories.MediaTransform.SendRequirements.CAN_NOT_SEND
val storySendRequirements: Stories.MediaTransform.SendRequirements = Stories.MediaTransform.SendRequirements.CAN_NOT_SEND,
val suppressEmptyError: Boolean = true
) {
val maxSelection = if (sendType.usesSmsTransport) {

View File

@@ -140,6 +140,10 @@ class MediaSelectionViewModel(
store.update { it.copy(isTouchEnabled = isEnabled) }
}
fun setSuppressEmptyError(isSuppressed: Boolean) {
store.update { it.copy(suppressEmptyError = isSuppressed) }
}
fun addMedia(media: Media) {
addMedia(listOf(media))
}
@@ -230,10 +234,6 @@ class MediaSelectionViewModel(
}
fun removeMedia(media: Media) {
removeMedia(media, false)
}
private fun removeMedia(media: Media, suppressEmptyError: Boolean) {
val snapshot = store.state
val newMediaList = snapshot.selectedMedia - media
val oldFocusIndex = snapshot.selectedMedia.indexOf(media)
@@ -252,7 +252,7 @@ class MediaSelectionViewModel(
)
}
if (newMediaList.isEmpty() && !suppressEmptyError) {
if (newMediaList.isEmpty() && !store.state.suppressEmptyError) {
mediaErrors.onNext(MediaValidator.FilterError.NoItems())
}
@@ -272,7 +272,8 @@ class MediaSelectionViewModel(
fun removeCameraFirstCapture() {
val cameraFirstCapture: Media? = store.state.cameraFirstCapture
if (cameraFirstCapture != null) {
removeMedia(cameraFirstCapture, true)
setSuppressEmptyError(true)
removeMedia(cameraFirstCapture)
}
}

View File

@@ -37,6 +37,8 @@ class MediaSelectionGalleryFragment : Fragment(R.layout.fragment_container), Med
)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val isFirst = arguments?.getBoolean("first") ?: false
sharedViewModel.setSuppressEmptyError(isFirst)
mediaGalleryFragment = ensureMediaGalleryFragment()
mediaGalleryFragment.bindSelectedMediaItemDragHelper(ItemTouchHelper(MediaSelectionItemTouchHelper(sharedViewModel)))