mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 08:18:00 +01:00
set proper long press selector colors to media screen too
This commit is contained in:
parent
b02fa1c409
commit
a118990170
10 changed files with 47 additions and 69 deletions
|
@ -1,10 +1,5 @@
|
||||||
package com.simplemobiletools.gallery.adapters
|
package com.simplemobiletools.gallery.adapters
|
||||||
|
|
||||||
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 android.os.Build
|
||||||
import android.support.v7.view.ActionMode
|
import android.support.v7.view.ActionMode
|
||||||
import android.support.v7.widget.RecyclerView
|
import android.support.v7.widget.RecyclerView
|
||||||
|
@ -18,7 +13,6 @@ import com.bumptech.glide.load.DecodeFormat
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
import com.bumptech.glide.signature.StringSignature
|
import com.bumptech.glide.signature.StringSignature
|
||||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||||
import com.simplemobiletools.commons.extensions.adjustAlpha
|
|
||||||
import com.simplemobiletools.filepicker.asynctasks.CopyMoveTask
|
import com.simplemobiletools.filepicker.asynctasks.CopyMoveTask
|
||||||
import com.simplemobiletools.filepicker.extensions.isAStorageRootFolder
|
import com.simplemobiletools.filepicker.extensions.isAStorageRootFolder
|
||||||
import com.simplemobiletools.filepicker.extensions.isImageVideoGif
|
import com.simplemobiletools.filepicker.extensions.isImageVideoGif
|
||||||
|
@ -29,6 +23,7 @@ import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.activities.SimpleActivity
|
import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||||
import com.simplemobiletools.gallery.dialogs.CopyDialog
|
import com.simplemobiletools.gallery.dialogs.CopyDialog
|
||||||
import com.simplemobiletools.gallery.dialogs.RenameDirectoryDialog
|
import com.simplemobiletools.gallery.dialogs.RenameDirectoryDialog
|
||||||
|
import com.simplemobiletools.gallery.extensions.createSelector
|
||||||
import com.simplemobiletools.gallery.helpers.Config
|
import com.simplemobiletools.gallery.helpers.Config
|
||||||
import com.simplemobiletools.gallery.models.Directory
|
import com.simplemobiletools.gallery.models.Directory
|
||||||
import kotlinx.android.synthetic.main.directory_item.view.*
|
import kotlinx.android.synthetic.main.directory_item.view.*
|
||||||
|
@ -47,7 +42,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
||||||
companion object {
|
companion object {
|
||||||
var actMode: ActionMode? = null
|
var actMode: ActionMode? = null
|
||||||
val markedItems = HashSet<Int>()
|
val markedItems = HashSet<Int>()
|
||||||
var selectorDrawableColor = 0
|
var foregroundColor = 0
|
||||||
|
|
||||||
fun toggleItemSelection(itemView: View, select: Boolean, pos: Int = -1) {
|
fun toggleItemSelection(itemView: View, select: Boolean, pos: Int = -1) {
|
||||||
getProperView(itemView).isSelected = select
|
getProperView(itemView).isSelected = select
|
||||||
|
@ -67,25 +62,10 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
||||||
else
|
else
|
||||||
itemView.dir_thumbnail
|
itemView.dir_thumbnail
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createSelector(color: Int): StateListDrawable {
|
|
||||||
val statelist = StateListDrawable()
|
|
||||||
val selectedDrawable = ColorDrawable(color.adjustAlpha(0.5f))
|
|
||||||
statelist.addState(intArrayOf(android.R.attr.state_selected), selectedDrawable)
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
val pressedDrawable = ColorDrawable(color.adjustAlpha(0.4f))
|
|
||||||
statelist.addState(intArrayOf(android.R.attr.state_pressed), pressedDrawable)
|
|
||||||
} else {
|
|
||||||
val pressedDrawable = RippleDrawable(ColorStateList.valueOf(color.adjustAlpha(0.4f)), null, ColorDrawable(Color.WHITE))
|
|
||||||
statelist.addState(intArrayOf(), pressedDrawable)
|
|
||||||
}
|
|
||||||
return statelist
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
selectorDrawableColor = Config.newInstance(activity).primaryColor
|
foregroundColor = Config.newInstance(activity).primaryColor
|
||||||
}
|
}
|
||||||
|
|
||||||
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
|
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
|
||||||
|
@ -279,7 +259,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
|
||||||
val view = LayoutInflater.from(parent?.context).inflate(R.layout.directory_item, parent, false)
|
val view = LayoutInflater.from(parent?.context).inflate(R.layout.directory_item, parent, false)
|
||||||
return ViewHolder(view, selectorDrawableColor, itemClick)
|
return ViewHolder(view, foregroundColor, itemClick)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
|
@ -323,9 +303,9 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
|
||||||
(getProperView(itemView) as FrameLayout).foreground = createSelector(foregroundColor)
|
(getProperView(itemView) as FrameLayout).foreground = foregroundColor.createSelector()
|
||||||
else
|
else
|
||||||
getProperView(itemView).foreground = createSelector(foregroundColor)
|
getProperView(itemView).foreground = foregroundColor.createSelector()
|
||||||
return itemView
|
return itemView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.os.Build
|
||||||
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.view.*
|
import android.view.*
|
||||||
|
import android.widget.FrameLayout
|
||||||
import com.bignerdranch.android.multiselector.ModalMultiSelectorCallback
|
import com.bignerdranch.android.multiselector.ModalMultiSelectorCallback
|
||||||
import com.bignerdranch.android.multiselector.MultiSelector
|
import com.bignerdranch.android.multiselector.MultiSelector
|
||||||
import com.bignerdranch.android.multiselector.SwappingHolder
|
import com.bignerdranch.android.multiselector.SwappingHolder
|
||||||
|
@ -19,10 +20,7 @@ import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.activities.SimpleActivity
|
import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||||
import com.simplemobiletools.gallery.dialogs.CopyDialog
|
import com.simplemobiletools.gallery.dialogs.CopyDialog
|
||||||
import com.simplemobiletools.gallery.dialogs.RenameFileDialog
|
import com.simplemobiletools.gallery.dialogs.RenameFileDialog
|
||||||
import com.simplemobiletools.gallery.extensions.beVisibleIf
|
import com.simplemobiletools.gallery.extensions.*
|
||||||
import com.simplemobiletools.gallery.extensions.openEditor
|
|
||||||
import com.simplemobiletools.gallery.extensions.shareMedia
|
|
||||||
import com.simplemobiletools.gallery.extensions.shareMedium
|
|
||||||
import com.simplemobiletools.gallery.helpers.Config
|
import com.simplemobiletools.gallery.helpers.Config
|
||||||
import com.simplemobiletools.gallery.models.Medium
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
import kotlinx.android.synthetic.main.photo_video_item.view.*
|
import kotlinx.android.synthetic.main.photo_video_item.view.*
|
||||||
|
@ -40,6 +38,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
||||||
var actMode: ActionMode? = null
|
var actMode: ActionMode? = null
|
||||||
var displayFilenames = false
|
var displayFilenames = false
|
||||||
val markedItems = HashSet<Int>()
|
val markedItems = HashSet<Int>()
|
||||||
|
var foregroundColor = 0
|
||||||
|
|
||||||
fun toggleItemSelection(itemView: View, select: Boolean, pos: Int = -1) {
|
fun toggleItemSelection(itemView: View, select: Boolean, pos: Int = -1) {
|
||||||
getProperView(itemView).isSelected = select
|
getProperView(itemView).isSelected = select
|
||||||
|
@ -61,6 +60,10 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
foregroundColor = Config.newInstance(activity).primaryColor
|
||||||
|
}
|
||||||
|
|
||||||
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
|
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
|
||||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
|
@ -198,7 +201,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
|
||||||
val view = LayoutInflater.from(parent?.context).inflate(R.layout.photo_video_item, parent, false)
|
val view = LayoutInflater.from(parent?.context).inflate(R.layout.photo_video_item, parent, false)
|
||||||
return ViewHolder(view, itemClick)
|
return ViewHolder(view, foregroundColor, itemClick)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
|
@ -217,7 +220,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
class ViewHolder(view: View, val itemClick: (Medium) -> (Unit)) : SwappingHolder(view, MultiSelector()) {
|
class ViewHolder(view: View, val foregroundColor: Int, val itemClick: (Medium) -> (Unit)) : SwappingHolder(view, MultiSelector()) {
|
||||||
fun bindView(activity: SimpleActivity, multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, medium: Medium, pos: Int): View {
|
fun bindView(activity: SimpleActivity, multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, medium: Medium, pos: Int): View {
|
||||||
itemView.play_outline.visibility = if (medium.isVideo) View.VISIBLE else View.GONE
|
itemView.play_outline.visibility = if (medium.isVideo) View.VISIBLE else View.GONE
|
||||||
itemView.file_name.beVisibleIf(displayFilenames)
|
itemView.file_name.beVisibleIf(displayFilenames)
|
||||||
|
@ -248,6 +251,11 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
|
||||||
|
(getProperView(itemView) as FrameLayout).foreground = foregroundColor.createSelector()
|
||||||
|
else
|
||||||
|
getProperView(itemView).foreground = foregroundColor.createSelector()
|
||||||
|
|
||||||
return itemView
|
return itemView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
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,17 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<item>
|
|
||||||
<selector>
|
|
||||||
<item
|
|
||||||
android:drawable="@color/activated_item_foreground"
|
|
||||||
android:state_selected="true"/>
|
|
||||||
</selector>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<ripple android:color="@color/pressed_item_foreground">
|
|
||||||
<item android:id="@android:id/mask">
|
|
||||||
<color android:color="@android:color/white"/>
|
|
||||||
</item>
|
|
||||||
</ripple>
|
|
||||||
</item>
|
|
||||||
</layer-list>
|
|
|
@ -1,4 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<item android:drawable="@color/activated_item_foreground"/>
|
|
||||||
</selector>
|
|
|
@ -1,4 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<item android:drawable="@color/pressed_item_foreground"/>
|
|
||||||
</selector>
|
|
|
@ -1,5 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<item android:drawable="@drawable/selected_pressed_mask" android:state_pressed="true"/>
|
|
||||||
<item android:drawable="@drawable/selected_mask" android:state_selected="true"/>
|
|
||||||
</selector>
|
|
|
@ -1,7 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<com.simplemobiletools.gallery.views.MyImageView
|
<com.simplemobiletools.gallery.views.MyImageView
|
||||||
android:id="@+id/medium_thumbnail"
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/medium_thumbnail"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"/>
|
||||||
android:foreground="@drawable/selector"/>
|
|
||||||
|
|
|
@ -5,8 +5,7 @@
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/medium_thumbnail_holder"
|
android:id="@+id/medium_thumbnail_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent">
|
||||||
android:foreground="@drawable/selector">
|
|
||||||
|
|
||||||
<com.simplemobiletools.gallery.views.MyImageView
|
<com.simplemobiletools.gallery.views.MyImageView
|
||||||
android:id="@+id/medium_thumbnail"
|
android:id="@+id/medium_thumbnail"
|
||||||
|
|
|
@ -3,8 +3,6 @@
|
||||||
<color name="colorPrimary">#fff68630</color>
|
<color name="colorPrimary">#fff68630</color>
|
||||||
<color name="colorPrimaryDark">#ffe27725</color>
|
<color name="colorPrimaryDark">#ffe27725</color>
|
||||||
<color name="colorAccent">@color/colorPrimary</color>
|
<color name="colorAccent">@color/colorPrimary</color>
|
||||||
<color name="pressed_item_foreground">#33ff6f00</color>
|
|
||||||
<color name="activated_item_foreground">#99ff6f00</color>
|
|
||||||
<color name="tmb_background">#ff222222</color>
|
<color name="tmb_background">#ff222222</color>
|
||||||
<color name="actionbar_grey">#AA000000</color>
|
<color name="actionbar_grey">#AA000000</color>
|
||||||
<color name="light_grey">#aa888888</color>
|
<color name="light_grey">#aa888888</color>
|
||||||
|
|
Loading…
Reference in a new issue