From f1b4391d939ea85f7ff89a422750edc347247654 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 16 Jun 2018 21:50:55 +0200 Subject: [PATCH] update Commons with the recyclerview adapter, fix some inconsistency glitches --- app/build.gradle | 2 +- .../gallery/adapters/DirectoryAdapter.kt | 26 ++++++++++++------- .../gallery/adapters/ManageFoldersAdapter.kt | 6 ++--- .../adapters/ManageHiddenFoldersAdapter.kt | 6 ++--- .../gallery/adapters/MediaAdapter.kt | 8 +++--- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4ff65d961..fb4e5d952 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:4.1.17' + implementation 'com.simplemobiletools:commons:4.2.1' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' 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 d20a65167..b85316f05 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -47,12 +47,12 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList() - (0 until itemViews.size()) - .filter { itemViews[it] != null } - .forEachIndexed { curIndex, i -> newItems.put(curIndex, itemViews[i]) } + val newViewHolders = SparseArray() + val cnt = viewHolders.size() + for (i in 0..cnt) { + if (affectedPositions.contains(i)) { + continue + } + val view = viewHolders.get(i, null) + val newIndex = i - selectedPositions.count { it <= i } + newViewHolders.put(newIndex, view) + } + viewHolders = newViewHolders currentDirectoriesHash = newDirs.hashCode() - itemViews = newItems dirs = newDirs + finishActMode() fastScroller?.measureRecyclerView() listener?.updateDirectories(newDirs) 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 e27d56887..c65112f01 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ManageFoldersAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ManageFoldersAdapter.kt @@ -25,10 +25,10 @@ class ManageFoldersAdapter(activity: BaseSimpleActivity, var folders: ArrayList< override fun prepareActionMode(menu: Menu) {} - override fun prepareItemSelection(view: View) {} + override fun prepareItemSelection(viewHolder: ViewHolder) {} - override fun markItemSelection(select: Boolean, view: View?) { - view?.manage_folder_holder?.isSelected = select + override fun markViewHolderSelection(select: Boolean, viewHolder: ViewHolder?) { + viewHolder?.itemView?.manage_folder_holder?.isSelected = select } override fun actionItemPressed(id: Int) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ManageHiddenFoldersAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ManageHiddenFoldersAdapter.kt index 931348420..31c35bb38 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ManageHiddenFoldersAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ManageHiddenFoldersAdapter.kt @@ -27,10 +27,10 @@ class ManageHiddenFoldersAdapter(activity: BaseSimpleActivity, var folders: Arra override fun prepareActionMode(menu: Menu) {} - override fun prepareItemSelection(view: View) {} + override fun prepareItemSelection(viewHolder: ViewHolder) {} - override fun markItemSelection(select: Boolean, view: View?) { - view?.manage_folder_holder?.isSelected = select + override fun markViewHolderSelection(select: Boolean, viewHolder: ViewHolder?) { + viewHolder?.itemView?.manage_folder_holder?.isSelected = select } override fun actionItemPressed(id: Int) { 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 d1ed183ec..2e2199529 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -49,12 +49,12 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, override fun getActionMenuId() = R.menu.cab_media - override fun prepareItemSelection(view: View) { - view.medium_check?.background?.applyColorFilter(primaryColor) + override fun prepareItemSelection(viewHolder: ViewHolder) { + viewHolder.itemView?.medium_check?.background?.applyColorFilter(primaryColor) } - override fun markItemSelection(select: Boolean, view: View?) { - view?.medium_check?.beVisibleIf(select) + override fun markViewHolderSelection(select: Boolean, viewHolder: ViewHolder?) { + viewHolder?.itemView?.medium_check?.beVisibleIf(select) } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {