mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-11-01 15:23:54 +01:00
refactor: prevent app from crashing for SDKs >= 34
This commit is contained in:
parent
f8d164b6a2
commit
ad1074a84a
4 changed files with 16 additions and 8 deletions
|
|
@ -62,13 +62,15 @@ class FolderAdapter(
|
|||
folder.images.removeAll(toBeRemoved)
|
||||
val count = folder.images.size
|
||||
|
||||
if(count == 0) {
|
||||
if(count == 0 && folders.size > 0) {
|
||||
// Folder is empty, remove folder from the adapter.
|
||||
holder.itemView.post{
|
||||
val updatePosition = folders.indexOf(folder)
|
||||
folders.removeAt(updatePosition)
|
||||
notifyItemRemoved(updatePosition)
|
||||
notifyItemRangeChanged(updatePosition, folders.size)
|
||||
if(updatePosition != -1) {
|
||||
folders.removeAt(updatePosition)
|
||||
notifyItemRemoved(updatePosition)
|
||||
notifyItemRangeChanged(updatePosition, folders.size)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
val previewImage = folder.images[0]
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ class ImageAdapter(
|
|||
* Bind View holder, load image, selected view, click listeners.
|
||||
*/
|
||||
override fun onBindViewHolder(holder: ImageViewHolder, position: Int) {
|
||||
|
||||
if(images.size == 0) { return }
|
||||
var image=images[position]
|
||||
holder.image.setImageDrawable (null)
|
||||
if (context.contentResolver.getType(image.uri) == null) {
|
||||
|
|
|
|||
|
|
@ -116,11 +116,14 @@ class FolderFragment : CommonsDaggerSupportFragment() {
|
|||
private fun handleResult(result: Result) {
|
||||
if(result.status is CallbackStatus.SUCCESS){
|
||||
val images = result.images
|
||||
if(images.isNullOrEmpty())
|
||||
{
|
||||
if(images.isEmpty()){
|
||||
binding?.emptyText?.let {
|
||||
it.visibility = View.VISIBLE
|
||||
}
|
||||
} else {
|
||||
binding?.emptyText?.let {
|
||||
it.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
folders = ImageHelper.folderListFromImages(result.images)
|
||||
folderAdapter.init(folders)
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import fr.free.nrw.commons.upload.FileUtilsWrapper
|
|||
import io.reactivex.schedulers.Schedulers
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
/**
|
||||
* Custom Selector Image Fragment.
|
||||
|
|
@ -279,6 +280,8 @@ class ImageFragment : CommonsDaggerSupportFragment(), RefreshUIListener, PassDat
|
|||
}
|
||||
}
|
||||
} else {
|
||||
filteredImages = ArrayList()
|
||||
allImages = filteredImages
|
||||
binding?.emptyText?.let {
|
||||
it.visibility = View.VISIBLE
|
||||
}
|
||||
|
|
@ -324,7 +327,7 @@ class ImageFragment : CommonsDaggerSupportFragment(), RefreshUIListener, PassDat
|
|||
.findFirstVisibleItemPosition()
|
||||
|
||||
// Check for empty RecyclerView.
|
||||
if (position != -1) {
|
||||
if (position != -1 && filteredImages.size > 0) {
|
||||
context?.let { context ->
|
||||
context.getSharedPreferences(
|
||||
"CustomSelector",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue