fix #171, change multiselector to use colored circle Check icons
This commit is contained in:
parent
15159de4e9
commit
9ee1273995
|
@ -129,8 +129,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
}
|
||||
|
||||
private fun checkIfColorChanged() {
|
||||
if (media_grid.adapter != null && getRecyclerAdapter().foregroundColor != config.primaryColor) {
|
||||
getRecyclerAdapter().updatePrimaryColor(config.primaryColor)
|
||||
if (media_grid.adapter != null && getRecyclerAdapter().primaryColor != config.primaryColor) {
|
||||
getRecyclerAdapter().primaryColor = config.primaryColor
|
||||
media_horizontal_fastscroller.updateHandleColor()
|
||||
media_vertical_fastscroller.updateHandleColor()
|
||||
}
|
||||
|
|
|
@ -109,8 +109,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
|
|||
override fun onDestroyActionMode(actionMode: ActionMode?) {
|
||||
super.onDestroyActionMode(actionMode)
|
||||
selectedPositions.forEach {
|
||||
if (itemViews[it] != null)
|
||||
itemViews[it].dir_check.beGone()
|
||||
itemViews[it]?.dir_check?.beGone()
|
||||
}
|
||||
selectedPositions.clear()
|
||||
actMode = null
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
package com.simplemobiletools.gallery.adapters
|
||||
|
||||
import android.os.Build
|
||||
import android.graphics.PorterDuff
|
||||
import android.support.v7.view.ActionMode
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.util.SparseArray
|
||||
import android.view.*
|
||||
import android.widget.FrameLayout
|
||||
import com.bignerdranch.android.multiselector.ModalMultiSelectorCallback
|
||||
import com.bignerdranch.android.multiselector.MultiSelector
|
||||
import com.bignerdranch.android.multiselector.SwappingHolder
|
||||
|
@ -13,13 +12,13 @@ import com.bumptech.glide.Glide
|
|||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
||||
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
||||
import com.simplemobiletools.commons.extensions.beGone
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||
import com.simplemobiletools.gallery.extensions.*
|
||||
import com.simplemobiletools.gallery.models.Medium
|
||||
import kotlinx.android.synthetic.main.photo_video_item.view.*
|
||||
import kotlinx.android.synthetic.main.photo_video_tmb.view.*
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
|
@ -32,19 +31,19 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
|||
var actMode: ActionMode? = null
|
||||
var itemViews = SparseArray<View>()
|
||||
val selectedPositions = HashSet<Int>()
|
||||
var foregroundColor = config.primaryColor
|
||||
var primaryColor = config.primaryColor
|
||||
var displayFilenames = config.displayFileNames
|
||||
var scrollVertically = !config.scrollHorizontally
|
||||
|
||||
fun toggleItemSelection(select: Boolean, pos: Int) {
|
||||
if (itemViews[pos] != null)
|
||||
getProperView(itemViews[pos]!!).isSelected = select
|
||||
|
||||
if (select)
|
||||
if (select) {
|
||||
itemViews[pos].medium_check.background.setColorFilter(primaryColor, PorterDuff.Mode.SRC_IN)
|
||||
selectedPositions.add(pos)
|
||||
else
|
||||
} else
|
||||
selectedPositions.remove(pos)
|
||||
|
||||
itemViews[pos]?.medium_check?.beVisibleIf(select)
|
||||
|
||||
if (selectedPositions.isEmpty()) {
|
||||
actMode?.finish()
|
||||
return
|
||||
|
@ -53,40 +52,16 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
|||
updateTitle(selectedPositions.size)
|
||||
}
|
||||
|
||||
fun getProperView(itemView: View): View {
|
||||
return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
|
||||
itemView.medium_thumbnail_holder
|
||||
else
|
||||
itemView.medium_thumbnail
|
||||
}
|
||||
|
||||
fun updateTitle(cnt: Int) {
|
||||
actMode?.title = "$cnt / ${media.size}"
|
||||
actMode?.invalidate()
|
||||
}
|
||||
|
||||
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) {
|
||||
setupItemViewForeground(itemView)
|
||||
}
|
||||
|
||||
override fun getSelectedPositions(): HashSet<Int> = selectedPositions
|
||||
}
|
||||
|
||||
|
@ -127,8 +102,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
|||
override fun onDestroyActionMode(actionMode: ActionMode?) {
|
||||
super.onDestroyActionMode(actionMode)
|
||||
selectedPositions.forEach {
|
||||
if (itemViews[it] != null)
|
||||
getProperView(itemViews[it]!!).isSelected = false
|
||||
itemViews[it]?.medium_check?.beGone()
|
||||
}
|
||||
selectedPositions.clear()
|
||||
actMode = null
|
||||
|
@ -348,8 +322,6 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
|||
|
||||
setOnClickListener { viewClicked(medium) }
|
||||
setOnLongClickListener { if (isPickIntent) viewClicked(medium) else viewLongClicked(); true }
|
||||
|
||||
adapterListener.setupItemForeground(this)
|
||||
}
|
||||
return itemView
|
||||
}
|
||||
|
@ -383,8 +355,6 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
|||
interface MyAdapterListener {
|
||||
fun toggleItemSelectionAdapter(select: Boolean, position: Int)
|
||||
|
||||
fun setupItemForeground(itemView: View)
|
||||
|
||||
fun getSelectedPositions(): HashSet<Int>
|
||||
}
|
||||
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
package com.simplemobiletools.gallery.extensions
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.RippleDrawable
|
||||
import android.graphics.drawable.StateListDrawable
|
||||
import android.os.Build
|
||||
import com.simplemobiletools.commons.extensions.adjustAlpha
|
||||
|
||||
fun Int.createSelector(): StateListDrawable {
|
||||
val statelist = StateListDrawable()
|
||||
val selectedDrawable = ColorDrawable(adjustAlpha(0.5f))
|
||||
statelist.addState(intArrayOf(android.R.attr.state_selected), selectedDrawable)
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
val pressedDrawable = ColorDrawable(adjustAlpha(0.2f))
|
||||
statelist.addState(intArrayOf(android.R.attr.state_pressed), pressedDrawable)
|
||||
} else {
|
||||
val pressedDrawable = RippleDrawable(ColorStateList.valueOf(adjustAlpha(0.2f)), null, ColorDrawable(Color.WHITE))
|
||||
statelist.addState(intArrayOf(), pressedDrawable)
|
||||
}
|
||||
return statelist
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.simplemobiletools.gallery.views.MySquareImageView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/medium_thumbnail"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
|
@ -6,14 +6,22 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:padding="1px">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/tmb_wrapper"
|
||||
<com.simplemobiletools.gallery.views.MySquareImageView
|
||||
android:id="@+id/medium_thumbnail"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<include layout="@layout/photo_video_tmb"/>
|
||||
|
||||
</FrameLayout>
|
||||
<ImageView
|
||||
android:id="@+id/medium_check"
|
||||
android:layout_width="@dimen/selection_check_size"
|
||||
android:layout_height="@dimen/selection_check_size"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_margin="@dimen/small_margin"
|
||||
android:background="@drawable/circle_background"
|
||||
android:padding="@dimen/tiny_margin"
|
||||
android:src="@drawable/ic_check"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/play_outline"
|
||||
|
@ -30,9 +38,9 @@
|
|||
android:id="@+id/photo_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignLeft="@+id/tmb_wrapper"
|
||||
android:layout_alignLeft="@+id/medium_thumbnail"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignRight="@+id/tmb_wrapper"
|
||||
android:layout_alignRight="@+id/medium_thumbnail"
|
||||
android:background="@drawable/gradient_background"
|
||||
android:gravity="bottom"
|
||||
android:maxLines="3"
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge>
|
||||
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/medium_thumbnail_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.simplemobiletools.gallery.views.MySquareImageView
|
||||
android:id="@+id/medium_thumbnail"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</FrameLayout>
|
||||
</merge>
|
Loading…
Reference in New Issue