add colored background to the currently selected directory thumbnail

This commit is contained in:
tibbi 2017-08-05 16:55:12 +02:00
parent fa775e35e3
commit 15159de4e9
6 changed files with 26 additions and 18 deletions

View file

@ -227,8 +227,8 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
} }
private fun checkIfColorChanged() { private fun checkIfColorChanged() {
if (directories_grid.adapter != null && getRecyclerAdapter().foregroundColor != config.primaryColor) { if (directories_grid.adapter != null && getRecyclerAdapter().primaryColor != config.primaryColor) {
getRecyclerAdapter().updatePrimaryColor(config.primaryColor) getRecyclerAdapter().primaryColor = config.primaryColor
directories_vertical_fastscroller.updateHandleColor() directories_vertical_fastscroller.updateHandleColor()
directories_horizontal_fastscroller.updateHandleColor() directories_horizontal_fastscroller.updateHandleColor()
} }

View file

@ -1,5 +1,6 @@
package com.simplemobiletools.gallery.adapters package com.simplemobiletools.gallery.adapters
import android.graphics.PorterDuff
import android.support.v7.view.ActionMode import android.support.v7.view.ActionMode
import android.support.v7.widget.RecyclerView import android.support.v7.widget.RecyclerView
import android.util.SparseArray import android.util.SparseArray
@ -33,19 +34,19 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
var actMode: ActionMode? = null var actMode: ActionMode? = null
var itemViews = SparseArray<View>() var itemViews = SparseArray<View>()
val selectedPositions = HashSet<Int>() val selectedPositions = HashSet<Int>()
var foregroundColor = config.primaryColor var primaryColor = config.primaryColor
var pinnedFolders = config.pinnedFolders var pinnedFolders = config.pinnedFolders
var scrollVertically = !config.scrollHorizontally var scrollVertically = !config.scrollHorizontally
fun toggleItemSelection(select: Boolean, pos: Int) { fun toggleItemSelection(select: Boolean, pos: Int) {
if (itemViews[pos] != null) if (select) {
itemViews[pos].dir_check.beVisibleIf(select) itemViews[pos].dir_check.background.setColorFilter(primaryColor, PorterDuff.Mode.SRC_IN)
if (select)
selectedPositions.add(pos) selectedPositions.add(pos)
else } else
selectedPositions.remove(pos) selectedPositions.remove(pos)
itemViews[pos]?.dir_check?.beVisibleIf(select)
if (selectedPositions.isEmpty()) { if (selectedPositions.isEmpty()) {
actMode?.finish() actMode?.finish()
return return
@ -59,14 +60,6 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
actMode?.invalidate() actMode?.invalidate()
} }
fun updatePrimaryColor(color: Int) {
foregroundColor = color
(0..itemViews.size() - 1).mapNotNull { itemViews[it] }
.forEach {
}
}
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)
@ -411,6 +404,8 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
setOnClickListener { viewClicked(directory) } setOnClickListener { viewClicked(directory) }
setOnLongClickListener { if (isPickIntent) viewClicked(directory) else viewLongClicked(); true } setOnLongClickListener { if (isPickIntent) viewClicked(directory) else viewLongClicked(); true }
} }
return itemView return itemView
} }

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="@color/color_primary"/>
</shape>

View file

@ -13,12 +13,14 @@
<ImageView <ImageView
android:id="@+id/dir_check" android:id="@+id/dir_check"
android:layout_width="@dimen/pin_size" android:layout_width="@dimen/selection_check_size"
android:layout_height="@dimen/pin_size" android:layout_height="@dimen/selection_check_size"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_margin="@dimen/small_margin" android:layout_margin="@dimen/small_margin"
android:background="@drawable/circle_background"
android:padding="@dimen/tiny_margin"
android:src="@drawable/ic_check"/> android:src="@drawable/ic_check"/>
<ImageView <ImageView

View file

@ -2,6 +2,7 @@
<dimen name="dir_tmb_size">150dp</dimen> <dimen name="dir_tmb_size">150dp</dimen>
<dimen name="medium_tmb_size">120dp</dimen> <dimen name="medium_tmb_size">120dp</dimen>
<dimen name="pin_size">30dp</dimen> <dimen name="pin_size">30dp</dimen>
<dimen name="selection_check_size">38dp</dimen>
<dimen name="play_outline_size">60dp</dimen> <dimen name="play_outline_size">60dp</dimen>
<dimen name="play_outline_size_big">230dp</dimen> <dimen name="play_outline_size_big">230dp</dimen>
<dimen name="timer_padding">32dp</dimen> <dimen name="timer_padding">32dp</dimen>

View file

@ -3,6 +3,7 @@
<dimen name="dir_tmb_size">150dp</dimen> <dimen name="dir_tmb_size">150dp</dimen>
<dimen name="medium_tmb_size">100dp</dimen> <dimen name="medium_tmb_size">100dp</dimen>
<dimen name="pin_size">20dp</dimen> <dimen name="pin_size">20dp</dimen>
<dimen name="selection_check_size">26dp</dimen>
<dimen name="play_outline_size">40dp</dimen> <dimen name="play_outline_size">40dp</dimen>
<dimen name="play_outline_size_big">150dp</dimen> <dimen name="play_outline_size_big">150dp</dimen>
<dimen name="timer_padding">24dp</dimen> <dimen name="timer_padding">24dp</dimen>