properly update some stuff if the primary color changes

This commit is contained in:
tibbi 2017-05-14 20:32:01 +02:00
parent 1c96f5ced7
commit 87b722bac3
4 changed files with 37 additions and 9 deletions

View file

@ -195,7 +195,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
private fun checkIfColorChanged() { private fun checkIfColorChanged() {
if (getRecyclerAdapter().foregroundColor != config.primaryColor) { if (getRecyclerAdapter().foregroundColor != config.primaryColor) {
getRecyclerAdapter().foregroundColor = config.primaryColor getRecyclerAdapter().updatePrimaryColor(config.primaryColor)
directories_fastscroller.updateHandleColor() directories_fastscroller.updateHandleColor()
} }
} }

View file

@ -100,11 +100,19 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
title = if (mShowAll) resources.getString(R.string.all_folders) else dirName title = if (mShowAll) resources.getString(R.string.all_folders) else dirName
getMedia() getMedia()
handleZooming() handleZooming()
checkIfColorChanged()
} else { } else {
finish() finish()
} }
} }
private fun checkIfColorChanged() {
if (getRecyclerAdapter().foregroundColor != config.primaryColor) {
getRecyclerAdapter().updatePrimaryColor(config.primaryColor)
media_fastscroller.updateHandleColor()
}
}
private fun initializeGallery() { private fun initializeGallery() {
if (isDirEmpty()) if (isDirEmpty())
return return

View file

@ -68,16 +68,26 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
actMode?.title = "$cnt / ${dirs.size}" actMode?.title = "$cnt / ${dirs.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 { val adapterListener = object : MyAdapterListener {
override fun toggleItemSelectionAdapter(select: Boolean, position: Int) { override fun toggleItemSelectionAdapter(select: Boolean, position: Int) {
toggleItemSelection(select, position) toggleItemSelection(select, position)
} }
override fun setupItemForeground(itemView: View) { override fun setupItemForeground(itemView: View) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) setupItemViewForeground(itemView)
(getProperView(itemView) as FrameLayout).foreground = foregroundColor.createSelector()
else
getProperView(itemView).foreground = foregroundColor.createSelector()
} }
override fun getSelectedPositions(): HashSet<Int> = selectedPositions override fun getSelectedPositions(): HashSet<Int> = selectedPositions

View file

@ -64,16 +64,26 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
actMode?.title = "$cnt / ${media.size}" 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 { val adapterListener = object : MyAdapterListener {
override fun toggleItemSelectionAdapter(select: Boolean, position: Int) { override fun toggleItemSelectionAdapter(select: Boolean, position: Int) {
toggleItemSelection(select, position) toggleItemSelection(select, position)
} }
override fun setupItemForeground(itemView: View) { override fun setupItemForeground(itemView: View) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) setupItemViewForeground(itemView)
(getProperView(itemView) as FrameLayout).foreground = foregroundColor.createSelector()
else
getProperView(itemView).foreground = foregroundColor.createSelector()
} }
override fun getSelectedPositions(): HashSet<Int> = selectedPositions override fun getSelectedPositions(): HashSet<Int> = selectedPositions