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 f8ab5ad18..82f8e7c81 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -1,10 +1,5 @@ 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.support.v7.view.ActionMode 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.signature.StringSignature import com.simplemobiletools.commons.dialogs.ConfirmationDialog -import com.simplemobiletools.commons.extensions.adjustAlpha import com.simplemobiletools.filepicker.asynctasks.CopyMoveTask import com.simplemobiletools.filepicker.extensions.isAStorageRootFolder 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.dialogs.CopyDialog import com.simplemobiletools.gallery.dialogs.RenameDirectoryDialog +import com.simplemobiletools.gallery.extensions.createSelector import com.simplemobiletools.gallery.helpers.Config import com.simplemobiletools.gallery.models.Directory import kotlinx.android.synthetic.main.directory_item.view.* @@ -47,7 +42,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList() - var selectorDrawableColor = 0 + var foregroundColor = 0 fun toggleItemSelection(itemView: View, select: Boolean, pos: Int = -1) { getProperView(itemView).isSelected = select @@ -67,25 +62,10 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList, var actMode: ActionMode? = null var displayFilenames = false val markedItems = HashSet() + var foregroundColor = 0 fun toggleItemSelection(itemView: View, select: Boolean, pos: Int = -1) { getProperView(itemView).isSelected = select @@ -61,6 +60,10 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, } } + init { + foregroundColor = Config.newInstance(activity).primaryColor + } + val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) { override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { when (item.itemId) { @@ -198,7 +201,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder { 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) { @@ -217,7 +220,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, 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 { itemView.play_outline.visibility = if (medium.isVideo) View.VISIBLE else View.GONE itemView.file_name.beVisibleIf(displayFilenames) @@ -248,6 +251,11 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, 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 } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Int.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Int.kt new file mode 100644 index 000000000..064c348b6 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Int.kt @@ -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 +} diff --git a/app/src/main/res/drawable-v21/selector.xml b/app/src/main/res/drawable-v21/selector.xml deleted file mode 100644 index a24cfe2b1..000000000 --- a/app/src/main/res/drawable-v21/selector.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/app/src/main/res/drawable/selected_mask.xml b/app/src/main/res/drawable/selected_mask.xml deleted file mode 100644 index 50e6a28e4..000000000 --- a/app/src/main/res/drawable/selected_mask.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/app/src/main/res/drawable/selected_pressed_mask.xml b/app/src/main/res/drawable/selected_pressed_mask.xml deleted file mode 100644 index aa5443835..000000000 --- a/app/src/main/res/drawable/selected_pressed_mask.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/app/src/main/res/drawable/selector.xml b/app/src/main/res/drawable/selector.xml deleted file mode 100644 index c0b842372..000000000 --- a/app/src/main/res/drawable/selector.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/app/src/main/res/layout-v23/photo_video_tmb.xml b/app/src/main/res/layout-v23/photo_video_tmb.xml index a84e18bd8..a01dc5c30 100644 --- a/app/src/main/res/layout-v23/photo_video_tmb.xml +++ b/app/src/main/res/layout-v23/photo_video_tmb.xml @@ -1,7 +1,6 @@ + android:layout_height="match_parent"/> diff --git a/app/src/main/res/layout/photo_video_tmb.xml b/app/src/main/res/layout/photo_video_tmb.xml index c14d9fce1..ceef0cc74 100644 --- a/app/src/main/res/layout/photo_video_tmb.xml +++ b/app/src/main/res/layout/photo_video_tmb.xml @@ -5,8 +5,7 @@ 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" - android:foreground="@drawable/selector"> + android:layout_height="match_parent"> #fff68630 #ffe27725 @color/colorPrimary - #33ff6f00 - #99ff6f00 #ff222222 #AA000000 #aa888888