mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Fix Custom image selector (#5576)
* Custom Image Selector Fix * Custom Image Selector Fix * code cleanup * fixes * Renamed yue-hant * added java docs * fix
This commit is contained in:
parent
f73c9dc4d3
commit
3e5424e18d
4 changed files with 68 additions and 17 deletions
|
|
@ -119,6 +119,7 @@ class ImageAdapter(
|
||||||
* Bind View holder, load image, selected view, click listeners.
|
* Bind View holder, load image, selected view, click listeners.
|
||||||
*/
|
*/
|
||||||
override fun onBindViewHolder(holder: ImageViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ImageViewHolder, position: Int) {
|
||||||
|
|
||||||
var image=images[position]
|
var image=images[position]
|
||||||
holder.image.setImageDrawable (null)
|
holder.image.setImageDrawable (null)
|
||||||
if (context.contentResolver.getType(image.uri) == null) {
|
if (context.contentResolver.getType(image.uri) == null) {
|
||||||
|
|
@ -174,10 +175,12 @@ class ImageAdapter(
|
||||||
// inside map, so it will fetch the image from the map and load in the holder
|
// inside map, so it will fetch the image from the map and load in the holder
|
||||||
} else {
|
} else {
|
||||||
val actionableImages: List<Image> = ArrayList(actionableImagesMap.values)
|
val actionableImages: List<Image> = ArrayList(actionableImagesMap.values)
|
||||||
|
if(actionableImages.size > position) {
|
||||||
image = actionableImages[position]
|
image = actionableImages[position]
|
||||||
Glide.with(holder.image).load(image.uri)
|
Glide.with(holder.image).load(image.uri)
|
||||||
.thumbnail(0.3f).into(holder.image)
|
.thumbnail(0.3f).into(holder.image)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If switch is turned off, it just fetches the image from all images without any
|
// If switch is turned off, it just fetches the image from all images without any
|
||||||
// further operations
|
// further operations
|
||||||
|
|
@ -364,6 +367,48 @@ class ImageAdapter(
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear selected images and empty the list.
|
||||||
|
*/
|
||||||
|
fun clearSelectedImages(){
|
||||||
|
numberOfSelectedImagesMarkedAsNotForUpload = 0
|
||||||
|
selectedImages.clear()
|
||||||
|
selectedImages = arrayListOf()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove image from actionable images map.
|
||||||
|
*/
|
||||||
|
fun removeImageFromActionableImageMap(image: Image) {
|
||||||
|
val sharedPreferences: SharedPreferences =
|
||||||
|
context.getSharedPreferences(CUSTOM_SELECTOR_PREFERENCE_KEY, 0)
|
||||||
|
val showAlreadyActionedImages =
|
||||||
|
sharedPreferences.getBoolean(SHOW_ALREADY_ACTIONED_IMAGES_PREFERENCE_KEY, true)
|
||||||
|
|
||||||
|
if(showAlreadyActionedImages) {
|
||||||
|
refresh(allImages, allImages)
|
||||||
|
} else {
|
||||||
|
val iterator = actionableImagesMap.entries.iterator()
|
||||||
|
var index = 0
|
||||||
|
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
val entry = iterator.next()
|
||||||
|
if (entry.value == image) {
|
||||||
|
imagePositionAsPerIncreasingOrder -= 2
|
||||||
|
iterator.remove()
|
||||||
|
alreadyAddedPositions.removeAt(alreadyAddedPositions.size - 1)
|
||||||
|
notifyItemRemoved(index)
|
||||||
|
notifyItemRangeChanged(index, itemCount )
|
||||||
|
break
|
||||||
|
}
|
||||||
|
index++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the total number of items in the data set held by the adapter.
|
* Returns the total number of items in the data set held by the adapter.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -276,8 +276,10 @@ class CustomSelectorActivity : BaseActivity(), FolderClickListener, ImageSelectL
|
||||||
imageSHA1
|
imageSHA1
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
imageFragment!!.removeImage(it)
|
||||||
|
|
||||||
|
}
|
||||||
|
imageFragment!!.clearSelectedImages()
|
||||||
// if all images is already marked as not for upload, delete all images from
|
// if all images is already marked as not for upload, delete all images from
|
||||||
// not for upload table
|
// not for upload table
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -290,9 +292,9 @@ class CustomSelectorActivity : BaseActivity(), FolderClickListener, ImageSelectL
|
||||||
)
|
)
|
||||||
notForUploadStatusDao.deleteNotForUploadWithImageSHA1(imageSHA1)
|
notForUploadStatusDao.deleteNotForUploadWithImageSHA1(imageSHA1)
|
||||||
}
|
}
|
||||||
|
imageFragment!!.refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
imageFragment!!.refresh()
|
|
||||||
imageFragment!!.dismissMarkUnmarkProgressDialog()
|
imageFragment!!.dismissMarkUnmarkProgressDialog()
|
||||||
|
|
||||||
val bottomLayout: ConstraintLayout = findViewById(R.id.bottom_layout)
|
val bottomLayout: ConstraintLayout = findViewById(R.id.bottom_layout)
|
||||||
|
|
|
||||||
|
|
@ -339,6 +339,19 @@ class ImageFragment : CommonsDaggerSupportFragment(), RefreshUIListener, PassDat
|
||||||
imageAdapter.refresh(filteredImages, allImages)
|
imageAdapter.refresh(filteredImages, allImages)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the image from the actionable image map
|
||||||
|
*/
|
||||||
|
fun removeImage(image : Image){
|
||||||
|
imageAdapter.removeImageFromActionableImageMap(image)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the selected images
|
||||||
|
*/
|
||||||
|
fun clearSelectedImages() {
|
||||||
|
imageAdapter.clearSelectedImages()
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Passes selected images and other information from Activity to Fragment and connects it with
|
* Passes selected images and other information from Activity to Fragment and connects it with
|
||||||
* the adapter
|
* the adapter
|
||||||
|
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- Authors:
|
|
||||||
* Winston Sung
|
|
||||||
-->
|
|
||||||
<resources>
|
|
||||||
<string name="crash_dialog_title">同享壞咗</string>
|
|
||||||
<string name="crash_dialog_text">哎呀。出咗錯!</string>
|
|
||||||
<string name="crash_dialog_ok_toast">多謝你!</string>
|
|
||||||
</resources>
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue