From b5b3648602ae9585c7b8df4bb7ddb0e91ad35d46 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 30 Nov 2017 16:37:06 +0100 Subject: [PATCH] use a helper method for refreshing recyclerviews at delete --- app/build.gradle | 2 +- .../gallery/activities/MainActivity.kt | 10 +++--- .../gallery/adapters/DirectoryAdapter.kt | 36 +++++++------------ .../gallery/adapters/ManageFoldersAdapter.kt | 14 +------- .../gallery/adapters/MediaAdapter.kt | 16 ++------- 5 files changed, 22 insertions(+), 56 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 91b49f6dd..93b11d6c2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index a3883847d..1337bf98e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -324,12 +324,10 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } } - override fun tryDeleteFolders(folders: ArrayList) { - for (file in folders) { - deleteFolders(folders) { - runOnUiThread { - refreshItems() - } + override fun deleteFolders(folders: ArrayList) { + deleteFolders(folders) { + runOnUiThread { + refreshItems() } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 92b09d15d..8a13d5c40 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -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(selectedPositions.size) val removeFolders = ArrayList(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() - (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) + fun deleteFolders(folders: ArrayList) fun recheckPinnedFolders() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ManageFoldersAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ManageFoldersAdapter.kt index 5d671bc29..98c2cb4a5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ManageFoldersAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ManageFoldersAdapter.kt @@ -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() - (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() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index 116858a5f..4ea65d63a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -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, 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() - (0 until itemViews.size()) - .filter { itemViews[it] != null } - .forEachIndexed { curIndex, i -> newItems.put(curIndex, itemViews[i]) } - - itemViews = newItems - selectableItemCount = media.size - finishActMode() + removeSelectedItems() } }