From 642e3e4c5032ec61f9b25305e34ef56de6664577 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 16 Jul 2018 15:00:07 +0200 Subject: [PATCH] always pass an arraylist clone to adapters, so the actual items arent updated --- .../simplemobiletools/gallery/activities/MainActivity.kt | 7 +++---- .../simplemobiletools/gallery/activities/MediaActivity.kt | 5 +++-- .../simplemobiletools/gallery/adapters/DirectoryAdapter.kt | 7 ++++--- .../com/simplemobiletools/gallery/adapters/MediaAdapter.kt | 7 ++++--- .../gallery/dialogs/PickDirectoryDialog.kt | 2 +- .../simplemobiletools/gallery/dialogs/PickMediumDialog.kt | 2 +- 6 files changed, 16 insertions(+), 14 deletions(-) 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 1360fe14a..d2bb50de1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -809,7 +809,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { } private fun showSortedDirs(dirs: ArrayList) { - var sortedDirs = getSortedDirectories(dirs).clone() as ArrayList + var sortedDirs = getSortedDirectories(dirs) sortedDirs = sortedDirs.distinctBy { it.path.getDistinctPath() } as ArrayList runOnUiThread { @@ -847,11 +847,10 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { private fun setupAdapter(dirs: ArrayList) { val currAdapter = directories_grid.adapter - val directories = dirs.clone() as ArrayList if (currAdapter == null) { initZoomListener() val fastscroller = if (config.scrollHorizontally) directories_horizontal_fastscroller else directories_vertical_fastscroller - DirectoryAdapter(this, directories, this, directories_grid, isPickIntent(intent) || isGetAnyContentIntent(intent), fastscroller) { + DirectoryAdapter(this, dirs.clone() as ArrayList, this, directories_grid, isPickIntent(intent) || isGetAnyContentIntent(intent), fastscroller) { val path = (it as Directory).path if (path != config.tempFolderPath) { itemClicked(path) @@ -861,7 +860,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { directories_grid.adapter = this } } else { - (currAdapter as DirectoryAdapter).updateDirs(directories) + (currAdapter as DirectoryAdapter).updateDirs(dirs) } getRecyclerAdapter()?.dirs?.apply { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 2532c05ed..8f86aaa43 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -338,7 +338,8 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { if (currAdapter == null) { initZoomListener() val fastscroller = if (config.scrollHorizontally) media_horizontal_fastscroller else media_vertical_fastscroller - MediaAdapter(this, mMedia, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple, media_grid, fastscroller) { + MediaAdapter(this, mMedia.clone() as ArrayList, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, + mAllowPickingMultiple, media_grid, fastscroller) { if (it is Medium) { itemClicked(it.path) } @@ -806,7 +807,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { mLatestMediaId = getLatestMediaId() mLatestMediaDateId = getLatestMediaByDateId() if (!isFromCache) { - val mediaToInsert = (mMedia.clone() as ArrayList).filter { it is Medium && it.deletedTS == 0L }.map { it as Medium } + val mediaToInsert = (mMedia).filter { it is Medium && it.deletedTS == 0L }.map { it as Medium } galleryDB.MediumDao().insertAll(mediaToInsert) } } 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 912ef06ac..fa5bf7dc2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -474,9 +474,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList) { - if (newDirs.hashCode() != currentDirectoriesHash) { - currentDirectoriesHash = newDirs.hashCode() - dirs = newDirs + val directories = newDirs.clone() as ArrayList + if (directories.hashCode() != currentDirectoriesHash) { + currentDirectoriesHash = directories.hashCode() + dirs = directories notifyDataSetChanged() finishActMode() } 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 9438fc4b3..01928ec04 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -342,10 +342,11 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList fun updateMedia(newMedia: ArrayList) { - if (newMedia.hashCode() != currentMediaHash) { - currentMediaHash = newMedia.hashCode() + val thumbnailItems = newMedia.clone() as ArrayList + if (thumbnailItems.hashCode() != currentMediaHash) { + currentMediaHash = thumbnailItems.hashCode() Handler().postDelayed({ - media = newMedia + media = thumbnailItems enableInstantLoad() notifyDataSetChanged() finishActMode() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt index 80a0a53f7..653041574 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt @@ -61,7 +61,7 @@ class PickDirectoryDialog(val activity: BaseSimpleActivity, val sourcePath: Stri return shownDirectories = dirs - val adapter = DirectoryAdapter(activity, dirs, null, view.directories_grid, true) { + val adapter = DirectoryAdapter(activity, dirs.clone() as ArrayList, null, view.directories_grid, true) { if ((it as Directory).path.trimEnd('/') == sourcePath) { activity.toast(R.string.source_and_destination_same) return@DirectoryAdapter diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt index 65cb91e25..1ccef0923 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt @@ -64,7 +64,7 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c return shownMedia = media - val adapter = MediaAdapter(activity, shownMedia, null, true, false, view.media_grid, null) { + val adapter = MediaAdapter(activity, shownMedia.clone() as ArrayList, null, true, false, view.media_grid, null) { if (it is Medium) { callback(it.path) dialog.dismiss()