Handle the case where selectedImages is null

This commit is contained in:
sonalyadav 2024-12-19 19:20:41 +05:30 committed by Sonal Yadav
parent ad34160105
commit 6b7d484768

View file

@ -1,5 +1,7 @@
package fr.free.nrw.commons.customselector.ui.selector
import timber.log.Timber
import android.Manifest
import android.app.Activity
import android.app.Dialog
@ -158,9 +160,7 @@ class CustomSelectorActivity :
/**
* Waits for confirmation of delete folder
*/
private val startForFolderDeletionResult = registerForActivityResult(ActivityResultContracts.StartIntentSenderForResult()){
result -> onDeleteFolderResultReceived(result)
}
private val startForFolderDeletionResult = registerForActivityResult(ActivityResultContracts.StartIntentSenderForResult()) { result -> onDeleteFolderResultReceived(result) }
private val startForResult = registerForActivityResult(StartActivityForResult()) { result ->
onFullScreenDataReceived(result)
@ -247,10 +247,14 @@ class CustomSelectorActivity :
*/
private fun onFullScreenDataReceived(result: ActivityResult) {
if (result.resultCode == Activity.RESULT_OK) {
val selectedImages: ArrayList<Image> =
result.data!!
.getParcelableArrayListExtra(CustomSelectorConstants.NEW_SELECTED_IMAGES)!!
result.data?.getParcelableArrayListExtra<Image>(CustomSelectorConstants.NEW_SELECTED_IMAGES)
?.let { selectedImages ->
// Check if viewModel is not null before updating selectedImages
viewModel?.selectedImages?.value = selectedImages
} ?: run {
// Handle the case where selectedImages is null
Timber.e("No images selected or data is null")
}
}
}
@ -262,7 +266,6 @@ class CustomSelectorActivity :
}
/**
* Show Custom Selector Welcome Dialog.
*/
@ -426,7 +429,8 @@ class CustomSelectorActivity :
R.plurals.custom_picker_images_selected_title_appendix,
selectedImageCount,
selectedImageCount,
)})"
)
})"
}
if (titleText != null) {
titleText.text = titleWithAppendedImageCount
@ -500,7 +504,6 @@ class CustomSelectorActivity :
}
/**
* Navigates back to the main `FolderFragment`, refreshes the MediaStore, resets UI states,
* and reloads folder data.