mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 13:08:00 +01:00
use a helper method for refreshing recyclerviews at delete
This commit is contained in:
parent
df86b5d9ae
commit
b5b3648602
5 changed files with 22 additions and 56 deletions
|
@ -47,7 +47,7 @@ ext {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
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.davemorrissey.labs:subsampling-scale-image-view:3.8.0'
|
||||||
implementation 'com.theartofdev.edmodo:android-image-cropper:2.4.0'
|
implementation 'com.theartofdev.edmodo:android-image-cropper:2.4.0'
|
||||||
implementation 'com.android.support:multidex:1.0.2'
|
implementation 'com.android.support:multidex:1.0.2'
|
||||||
|
|
|
@ -324,15 +324,13 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun tryDeleteFolders(folders: ArrayList<File>) {
|
override fun deleteFolders(folders: ArrayList<File>) {
|
||||||
for (file in folders) {
|
|
||||||
deleteFolders(folders) {
|
deleteFolders(folders) {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
refreshItems()
|
refreshItems()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun getRecyclerAdapter() = (directories_grid.adapter as DirectoryAdapter)
|
private fun getRecyclerAdapter() = (directories_grid.adapter as DirectoryAdapter)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.simplemobiletools.gallery.adapters
|
package com.simplemobiletools.gallery.adapters
|
||||||
|
|
||||||
import android.graphics.PorterDuff
|
import android.graphics.PorterDuff
|
||||||
import android.util.SparseArray
|
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
@ -233,42 +232,33 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deleteFiles() {
|
private fun deleteFiles() {
|
||||||
|
if (selectedPositions.isEmpty()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val folders = ArrayList<File>(selectedPositions.size)
|
val folders = ArrayList<File>(selectedPositions.size)
|
||||||
val removeFolders = ArrayList<Directory>(selectedPositions.size)
|
val removeFolders = ArrayList<Directory>(selectedPositions.size)
|
||||||
|
|
||||||
var needPermissionForPath = ""
|
var SAFPath = ""
|
||||||
selectedPositions.forEach {
|
selectedPositions.forEach {
|
||||||
if (dirs.size > it) {
|
if (dirs.size > it) {
|
||||||
val path = dirs[it].path
|
val path = dirs[it].path
|
||||||
if (activity.needsStupidWritePermissions(path) && config.treeUri.isEmpty()) {
|
if (activity.needsStupidWritePermissions(path) && config.treeUri.isEmpty()) {
|
||||||
needPermissionForPath = path
|
SAFPath = path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
activity.handleSAFDialog(File(needPermissionForPath)) {
|
activity.handleSAFDialog(File(SAFPath)) {
|
||||||
selectedPositions.sortedDescending().forEach {
|
selectedPositions.sortedDescending().forEach {
|
||||||
if (dirs.size > it) {
|
|
||||||
val directory = dirs[it]
|
val directory = dirs[it]
|
||||||
folders.add(File(directory.path))
|
folders.add(File(directory.path))
|
||||||
removeFolders.add(directory)
|
removeFolders.add(directory)
|
||||||
notifyItemRemoved(it)
|
|
||||||
itemViews.put(it, null)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dirs.removeAll(removeFolders)
|
dirs.removeAll(removeFolders)
|
||||||
selectedPositions.clear()
|
listener?.deleteFolders(folders)
|
||||||
listener?.tryDeleteFolders(folders)
|
removeSelectedItems()
|
||||||
|
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,7 +353,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
|
||||||
interface DirOperationsListener {
|
interface DirOperationsListener {
|
||||||
fun refreshItems()
|
fun refreshItems()
|
||||||
|
|
||||||
fun tryDeleteFolders(folders: ArrayList<File>)
|
fun deleteFolders(folders: ArrayList<File>)
|
||||||
|
|
||||||
fun recheckPinnedFolders()
|
fun recheckPinnedFolders()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.simplemobiletools.gallery.adapters
|
package com.simplemobiletools.gallery.adapters
|
||||||
|
|
||||||
import android.util.SparseArray
|
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
@ -72,8 +71,6 @@ class ManageFoldersAdapter(activity: BaseSimpleActivity, var folders: ArrayList<
|
||||||
selectedPositions.sortedDescending().forEach {
|
selectedPositions.sortedDescending().forEach {
|
||||||
val folder = folders[it]
|
val folder = folders[it]
|
||||||
removeFolders.add(folder)
|
removeFolders.add(folder)
|
||||||
notifyItemRemoved(it)
|
|
||||||
itemViews.put(it, null)
|
|
||||||
if (isShowingExcludedFolders) {
|
if (isShowingExcludedFolders) {
|
||||||
config.removeExcludedFolder(folder)
|
config.removeExcludedFolder(folder)
|
||||||
} else {
|
} else {
|
||||||
|
@ -82,16 +79,7 @@ class ManageFoldersAdapter(activity: BaseSimpleActivity, var folders: ArrayList<
|
||||||
}
|
}
|
||||||
|
|
||||||
folders.removeAll(removeFolders)
|
folders.removeAll(removeFolders)
|
||||||
selectedPositions.clear()
|
removeSelectedItems()
|
||||||
|
|
||||||
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()
|
|
||||||
if (folders.isEmpty()) {
|
if (folders.isEmpty()) {
|
||||||
listener?.refreshItems()
|
listener?.refreshItems()
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.simplemobiletools.gallery.adapters
|
||||||
|
|
||||||
import android.graphics.PorterDuff
|
import android.graphics.PorterDuff
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.util.SparseArray
|
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
@ -212,26 +211,17 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
activity.handleSAFDialog(File(media[selectedPositions.first()].path)) {
|
val SAFPath = media[selectedPositions.first()].path
|
||||||
|
activity.handleSAFDialog(File(SAFPath)) {
|
||||||
selectedPositions.sortedDescending().forEach {
|
selectedPositions.sortedDescending().forEach {
|
||||||
val medium = media[it]
|
val medium = media[it]
|
||||||
files.add(File(medium.path))
|
files.add(File(medium.path))
|
||||||
removeMedia.add(medium)
|
removeMedia.add(medium)
|
||||||
notifyItemRemoved(it)
|
|
||||||
itemViews.put(it, null)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
media.removeAll(removeMedia)
|
media.removeAll(removeMedia)
|
||||||
listener?.deleteFiles(files)
|
listener?.deleteFiles(files)
|
||||||
|
removeSelectedItems()
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue