mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
FIX : Custom picker detect images that is already in commons (#6288)
Some checks failed
Android CI / Run tests and generate APK (push) Has been cancelled
Some checks failed
Android CI / Run tests and generate APK (push) Has been cancelled
* Fix: Exclude specific text from being posted in WikidataFeedback * Add detection logic for images already on Commons in custom picker
This commit is contained in:
parent
1a13cb3383
commit
78d29bcf20
3 changed files with 36 additions and 41 deletions
|
|
@ -26,6 +26,7 @@ import kotlinx.coroutines.MainScope
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import java.util.TreeMap
|
import java.util.TreeMap
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
|
|
@ -342,45 +343,36 @@ class ImageAdapter(
|
||||||
numberOfSelectedImagesMarkedAsNotForUpload--
|
numberOfSelectedImagesMarkedAsNotForUpload--
|
||||||
}
|
}
|
||||||
notifyItemChanged(position, ImageUnselected())
|
notifyItemChanged(position, ImageUnselected())
|
||||||
|
|
||||||
// Getting index from all images index when switch is on
|
|
||||||
val indexes =
|
|
||||||
if (showAlreadyActionedImages) {
|
|
||||||
ImageHelper.getIndexList(selectedImages, images)
|
|
||||||
|
|
||||||
// Getting index from actionable images when switch is off
|
|
||||||
} else {
|
|
||||||
ImageHelper.getIndexList(selectedImages, ArrayList(actionableImagesMap.values))
|
|
||||||
}
|
|
||||||
for (index in indexes) {
|
|
||||||
notifyItemChanged(index, ImageSelectedOrUpdated())
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
|
val image = images[position]
|
||||||
|
scope.launch(ioDispatcher) {
|
||||||
|
val imageSHA1 = imageLoader.getSHA1(image, defaultDispatcher)
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
if (holder.isItemUploaded()) {
|
if (holder.isItemUploaded()) {
|
||||||
Toast.makeText(context, R.string.custom_selector_already_uploaded_image_text, Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, R.string.custom_selector_already_uploaded_image_text, Toast.LENGTH_SHORT).show()
|
||||||
} else {
|
return@withContext
|
||||||
if (holder.isItemNotForUpload()) {
|
|
||||||
numberOfSelectedImagesMarkedAsNotForUpload++
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getting index from all images index when switch is on
|
|
||||||
val indexes: ArrayList<Int> =
|
|
||||||
if (showAlreadyActionedImages) {
|
|
||||||
selectedImages.add(images[position])
|
|
||||||
ImageHelper.getIndexList(selectedImages, images)
|
|
||||||
|
|
||||||
// Getting index from actionable images when switch is off
|
|
||||||
} else {
|
|
||||||
selectedImages.add(ArrayList(actionableImagesMap.values)[position])
|
|
||||||
ImageHelper.getIndexList(selectedImages, ArrayList(actionableImagesMap.values))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (index in indexes) {
|
if (imageSHA1.isNotEmpty() && imageLoader.getFromUploaded(imageSHA1) != null) {
|
||||||
notifyItemChanged(index, ImageSelectedOrUpdated())
|
holder.itemUploaded()
|
||||||
|
Toast.makeText(context, R.string.custom_selector_already_uploaded_image_text, Toast.LENGTH_SHORT).show()
|
||||||
|
return@withContext
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!holder.isItemUploaded() && imageSHA1.isNotEmpty() && imageLoader.getFromUploaded(imageSHA1) != null) {
|
||||||
|
Toast.makeText(context, R.string.custom_selector_already_uploaded_image_text, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (holder.isItemNotForUpload()) {
|
||||||
|
numberOfSelectedImagesMarkedAsNotForUpload++
|
||||||
|
}
|
||||||
|
selectedImages.add(image)
|
||||||
|
notifyItemChanged(position, ImageSelectedOrUpdated())
|
||||||
|
|
||||||
|
imageSelectListener.onSelectedImagesChanged(selectedImages, numberOfSelectedImagesMarkedAsNotForUpload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
imageSelectListener.onSelectedImagesChanged(selectedImages, numberOfSelectedImagesMarkedAsNotForUpload)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -638,17 +638,20 @@ class CustomSelectorActivity :
|
||||||
finishPickImages(arrayListOf())
|
finishPickImages(arrayListOf())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var i = 0
|
scope.launch(ioDispatcher) {
|
||||||
while (i < selectedImages.size) {
|
val uniqueImages = selectedImages.distinctBy { image ->
|
||||||
val path = selectedImages[i].path
|
CustomSelectorUtils.getImageSHA1(
|
||||||
val file = File(path)
|
image.uri,
|
||||||
if (!file.exists()) {
|
ioDispatcher,
|
||||||
selectedImages.removeAt(i)
|
fileUtilsWrapper,
|
||||||
i--
|
contentResolver
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
finishPickImages(ArrayList(uniqueImages))
|
||||||
}
|
}
|
||||||
i++
|
|
||||||
}
|
}
|
||||||
finishPickImages(selectedImages)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue