mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Fix - Custom picker sometimes crashing when marking many pictures as "not for upload" towards the bottom (#5639)
* fix crash * fix crash
This commit is contained in:
parent
7e5789d539
commit
e5c4230f97
1 changed files with 33 additions and 35 deletions
|
|
@ -206,15 +206,15 @@ class CustomSelectorActivity : BaseActivity(), FolderClickListener, ImageSelectL
|
||||||
markAsNotForUpload(arrayListOf())
|
markAsNotForUpload(arrayListOf())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var i = 0
|
|
||||||
while (i < selectedImages.size) {
|
val iterator = selectedImages.iterator()
|
||||||
val path = selectedImages[i].path
|
while (iterator.hasNext()) {
|
||||||
|
val image = iterator.next()
|
||||||
|
val path = image.path
|
||||||
val file = File(path)
|
val file = File(path)
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
selectedImages.removeAt(i)
|
iterator.remove()
|
||||||
i--
|
|
||||||
}
|
}
|
||||||
i++
|
|
||||||
}
|
}
|
||||||
markAsNotForUpload(selectedImages)
|
markAsNotForUpload(selectedImages)
|
||||||
toolbarBinding.imageLimitError.visibility = View.INVISIBLE
|
toolbarBinding.imageLimitError.visibility = View.INVISIBLE
|
||||||
|
|
@ -241,66 +241,64 @@ class CustomSelectorActivity : BaseActivity(), FolderClickListener, ImageSelectL
|
||||||
*/
|
*/
|
||||||
private fun insertIntoNotForUpload(images: ArrayList<Image>) {
|
private fun insertIntoNotForUpload(images: ArrayList<Image>) {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
imageFragment!!.showMarkUnmarkProgressDialog(
|
withContext(Dispatchers.Main) {
|
||||||
text= progressDialogText
|
imageFragment?.showMarkUnmarkProgressDialog(text = progressDialogText)
|
||||||
)
|
}
|
||||||
|
|
||||||
var allImagesAlreadyNotForUpload = true
|
var allImagesAlreadyNotForUpload = true
|
||||||
images.forEach {
|
images.forEach { image ->
|
||||||
val imageSHA1 = CustomSelectorUtils.getImageSHA1(
|
val imageSHA1 = CustomSelectorUtils.getImageSHA1(
|
||||||
it.uri,
|
image.uri,
|
||||||
ioDispatcher,
|
ioDispatcher,
|
||||||
fileUtilsWrapper,
|
fileUtilsWrapper,
|
||||||
contentResolver
|
contentResolver
|
||||||
)
|
)
|
||||||
val exists = notForUploadStatusDao.find(imageSHA1)
|
val exists = notForUploadStatusDao.find(imageSHA1)
|
||||||
|
|
||||||
// If image exists in not for upload table make allImagesAlreadyNotForUpload false
|
|
||||||
if (exists < 1) {
|
if (exists < 1) {
|
||||||
allImagesAlreadyNotForUpload = false
|
allImagesAlreadyNotForUpload = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if all images is not already marked as not for upload, insert all images in
|
|
||||||
// not for upload table
|
|
||||||
if (!allImagesAlreadyNotForUpload) {
|
if (!allImagesAlreadyNotForUpload) {
|
||||||
images.forEach {
|
// Insert or delete images as necessary, but the UI updates should be posted back to the main thread
|
||||||
|
images.forEach { image ->
|
||||||
val imageSHA1 = CustomSelectorUtils.getImageSHA1(
|
val imageSHA1 = CustomSelectorUtils.getImageSHA1(
|
||||||
it.uri,
|
image.uri,
|
||||||
ioDispatcher,
|
ioDispatcher,
|
||||||
fileUtilsWrapper,
|
fileUtilsWrapper,
|
||||||
contentResolver
|
contentResolver
|
||||||
)
|
)
|
||||||
notForUploadStatusDao.insert(
|
notForUploadStatusDao.insert(NotForUploadStatus(imageSHA1))
|
||||||
NotForUploadStatus(
|
}
|
||||||
imageSHA1
|
withContext(Dispatchers.Main) {
|
||||||
)
|
images.forEach { image ->
|
||||||
)
|
imageFragment?.removeImage(image)
|
||||||
imageFragment!!.removeImage(it)
|
}
|
||||||
|
imageFragment?.clearSelectedImages()
|
||||||
}
|
}
|
||||||
imageFragment!!.clearSelectedImages()
|
|
||||||
// if all images is already marked as not for upload, delete all images from
|
|
||||||
// not for upload table
|
|
||||||
} else {
|
} else {
|
||||||
images.forEach {
|
images.forEach { image ->
|
||||||
val imageSHA1 = CustomSelectorUtils.getImageSHA1(
|
val imageSHA1 = CustomSelectorUtils.getImageSHA1(
|
||||||
it.uri,
|
image.uri,
|
||||||
ioDispatcher,
|
ioDispatcher,
|
||||||
fileUtilsWrapper,
|
fileUtilsWrapper,
|
||||||
contentResolver
|
contentResolver
|
||||||
)
|
)
|
||||||
notForUploadStatusDao.deleteNotForUploadWithImageSHA1(imageSHA1)
|
notForUploadStatusDao.deleteNotForUploadWithImageSHA1(imageSHA1)
|
||||||
}
|
}
|
||||||
imageFragment!!.refresh()
|
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
imageFragment?.refresh()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
imageFragment!!.dismissMarkUnmarkProgressDialog()
|
withContext(Dispatchers.Main) {
|
||||||
|
imageFragment?.dismissMarkUnmarkProgressDialog()
|
||||||
val bottomLayout: ConstraintLayout = findViewById(R.id.bottom_layout)
|
val bottomLayout: ConstraintLayout = findViewById(R.id.bottom_layout)
|
||||||
bottomLayout.visibility = View.GONE
|
bottomLayout.visibility = View.GONE
|
||||||
|
changeTitle(bucketName, 0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
changeTitle(bucketName, 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue