From 87b722bac3e0ed2d90a4351d69f88f155782458a Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 14 May 2017 20:32:01 +0200 Subject: [PATCH] properly update some stuff if the primary color changes --- .../gallery/activities/MainActivity.kt | 2 +- .../gallery/activities/MediaActivity.kt | 8 ++++++++ .../gallery/adapters/DirectoryAdapter.kt | 18 ++++++++++++++---- .../gallery/adapters/MediaAdapter.kt | 18 ++++++++++++++---- 4 files changed, 37 insertions(+), 9 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 59f1c0c89..a57ec49e3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -195,7 +195,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private fun checkIfColorChanged() { if (getRecyclerAdapter().foregroundColor != config.primaryColor) { - getRecyclerAdapter().foregroundColor = config.primaryColor + getRecyclerAdapter().updatePrimaryColor(config.primaryColor) directories_fastscroller.updateHandleColor() } } 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 331b75b69..ec6529420 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -100,11 +100,19 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { title = if (mShowAll) resources.getString(R.string.all_folders) else dirName getMedia() handleZooming() + checkIfColorChanged() } else { finish() } } + private fun checkIfColorChanged() { + if (getRecyclerAdapter().foregroundColor != config.primaryColor) { + getRecyclerAdapter().updatePrimaryColor(config.primaryColor) + media_fastscroller.updateHandleColor() + } + } + private fun initializeGallery() { if (isDirEmpty()) return 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 698e109fe..4237638aa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -68,16 +68,26 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList = selectedPositions 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 fd1bb3873..1cd31ca23 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -64,16 +64,26 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, actMode?.title = "$cnt / ${media.size}" } + fun updatePrimaryColor(color: Int) { + foregroundColor = color + (0..itemViews.size() - 1).mapNotNull { itemViews[it] } + .forEach { setupItemViewForeground(it) } + } + + private fun setupItemViewForeground(itemView: View) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) + (getProperView(itemView) as FrameLayout).foreground = foregroundColor.createSelector() + else + getProperView(itemView).foreground = foregroundColor.createSelector() + } + val adapterListener = object : MyAdapterListener { override fun toggleItemSelectionAdapter(select: Boolean, position: Int) { toggleItemSelection(select, position) } override fun setupItemForeground(itemView: View) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) - (getProperView(itemView) as FrameLayout).foreground = foregroundColor.createSelector() - else - getProperView(itemView).foreground = foregroundColor.createSelector() + setupItemViewForeground(itemView) } override fun getSelectedPositions(): HashSet = selectedPositions