use a helper method for refreshing recyclerviews at delete

This commit is contained in:
tibbi 2017-11-30 16:37:06 +01:00
parent df86b5d9ae
commit b5b3648602
5 changed files with 22 additions and 56 deletions

View file

@ -47,7 +47,7 @@ ext {
}
dependencies {
implementation 'com.simplemobiletools:commons:3.0.5'
implementation 'com.simplemobiletools:commons:3.0.6'
implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.8.0'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.4.0'
implementation 'com.android.support:multidex:1.0.2'

View file

@ -324,12 +324,10 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
}
}
override fun tryDeleteFolders(folders: ArrayList<File>) {
for (file in folders) {
deleteFolders(folders) {
runOnUiThread {
refreshItems()
}
override fun deleteFolders(folders: ArrayList<File>) {
deleteFolders(folders) {
runOnUiThread {
refreshItems()
}
}
}

View file

@ -1,7 +1,6 @@
package com.simplemobiletools.gallery.adapters
import android.graphics.PorterDuff
import android.util.SparseArray
import android.view.Menu
import android.view.View
import android.view.ViewGroup
@ -233,42 +232,33 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
}
private fun deleteFiles() {
if (selectedPositions.isEmpty()) {
return
}
val folders = ArrayList<File>(selectedPositions.size)
val removeFolders = ArrayList<Directory>(selectedPositions.size)
var needPermissionForPath = ""
var SAFPath = ""
selectedPositions.forEach {
if (dirs.size > it) {
val path = dirs[it].path
if (activity.needsStupidWritePermissions(path) && config.treeUri.isEmpty()) {
needPermissionForPath = path
SAFPath = path
}
}
}
activity.handleSAFDialog(File(needPermissionForPath)) {
activity.handleSAFDialog(File(SAFPath)) {
selectedPositions.sortedDescending().forEach {
if (dirs.size > it) {
val directory = dirs[it]
folders.add(File(directory.path))
removeFolders.add(directory)
notifyItemRemoved(it)
itemViews.put(it, null)
}
val directory = dirs[it]
folders.add(File(directory.path))
removeFolders.add(directory)
}
dirs.removeAll(removeFolders)
selectedPositions.clear()
listener?.tryDeleteFolders(folders)
val newItems = SparseArray<View>()
(0 until itemViews.size())
.filter { itemViews[it] != null }
.forEachIndexed { curIndex, i -> newItems.put(curIndex, itemViews[i]) }
itemViews = newItems
selectableItemCount = dirs.size
finishActMode()
listener?.deleteFolders(folders)
removeSelectedItems()
}
}
@ -363,7 +353,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
interface DirOperationsListener {
fun refreshItems()
fun tryDeleteFolders(folders: ArrayList<File>)
fun deleteFolders(folders: ArrayList<File>)
fun recheckPinnedFolders()
}

View file

@ -1,6 +1,5 @@
package com.simplemobiletools.gallery.adapters
import android.util.SparseArray
import android.view.Menu
import android.view.View
import android.view.ViewGroup
@ -72,8 +71,6 @@ class ManageFoldersAdapter(activity: BaseSimpleActivity, var folders: ArrayList<
selectedPositions.sortedDescending().forEach {
val folder = folders[it]
removeFolders.add(folder)
notifyItemRemoved(it)
itemViews.put(it, null)
if (isShowingExcludedFolders) {
config.removeExcludedFolder(folder)
} else {
@ -82,16 +79,7 @@ class ManageFoldersAdapter(activity: BaseSimpleActivity, var folders: ArrayList<
}
folders.removeAll(removeFolders)
selectedPositions.clear()
val newItems = SparseArray<View>()
(0 until itemViews.size())
.filter { itemViews[it] != null }
.forEachIndexed { curIndex, i -> newItems.put(curIndex, itemViews[i]) }
itemViews = newItems
selectableItemCount = folders.size
finishActMode()
removeSelectedItems()
if (folders.isEmpty()) {
listener?.refreshItems()
}

View file

@ -2,7 +2,6 @@ package com.simplemobiletools.gallery.adapters
import android.graphics.PorterDuff
import android.net.Uri
import android.util.SparseArray
import android.view.Menu
import android.view.View
import android.view.ViewGroup
@ -212,26 +211,17 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
return
}
activity.handleSAFDialog(File(media[selectedPositions.first()].path)) {
val SAFPath = media[selectedPositions.first()].path
activity.handleSAFDialog(File(SAFPath)) {
selectedPositions.sortedDescending().forEach {
val medium = media[it]
files.add(File(medium.path))
removeMedia.add(medium)
notifyItemRemoved(it)
itemViews.put(it, null)
}
media.removeAll(removeMedia)
listener?.deleteFiles(files)
val newItems = SparseArray<View>()
(0 until itemViews.size())
.filter { itemViews[it] != null }
.forEachIndexed { curIndex, i -> newItems.put(curIndex, itemViews[i]) }
itemViews = newItems
selectableItemCount = media.size
finishActMode()
removeSelectedItems()
}
}