From 3acb283fa3d5b4a5fc45bb45d1ba9d5a3dea5ebf Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 14 Oct 2018 18:50:06 +0200 Subject: [PATCH] use integers for storing selected recyclerview item keys --- app/build.gradle | 2 +- .../filemanager/adapters/ItemsAdapter.kt | 12 ++++++------ .../adapters/ManageFavoritesAdapter.kt | 18 ++++++++++++------ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0261994a..1f7efcff 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -42,7 +42,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:5.0.16' + implementation 'com.simplemobiletools:commons:5.0.18' implementation files('../libs/RootTools.jar') } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt index cbb89dcd..ff917450 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt @@ -99,9 +99,9 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList(selectedKeys.size) val positions = ArrayList() selectedKeys.forEach { - activity.config.removeFavorite(it) + activity.config.removeFavorite(getItemWithKey(it)?.path ?: "") val key = it - val position = fileDirItems.indexOfFirst { it.path == key } + val position = fileDirItems.indexOfFirst { it.path.hashCode() == key } if (position != -1) { positions.add(position) files.add(fileDirItems[position]) @@ -545,7 +545,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList - setupView(itemView, favorite, isKeySelected(favorite)) + setupView(itemView, favorite, isKeySelected(favorite.hashCode())) } bindViewHolder(holder) } @@ -67,11 +67,15 @@ class ManageFavoritesAdapter(activity: BaseSimpleActivity, var favorites: ArrayL val positions = java.util.ArrayList() selectedKeys.forEach { val key = it - val position = favorites.indexOfFirst { it == key } + val position = favorites.indexOfFirst { it.hashCode() == key } if (position != -1) { positions.add(position) - removeFavorites.add(key) - config.removeFavorite(key) + + val favorite = getItemWithKey(key) + if (favorite != null) { + removeFavorites.add(favorite) + config.removeFavorite(favorite) + } } } @@ -83,4 +87,6 @@ class ManageFavoritesAdapter(activity: BaseSimpleActivity, var favorites: ArrayL listener?.refreshItems() } } + + private fun getItemWithKey(key: Int): String? = favorites.firstOrNull { it.hashCode() == key } }