mark the currently selected filter with a white stroke

This commit is contained in:
tibbi 2018-07-22 22:17:30 +02:00
parent 1112d5f19b
commit e17aa8b4b8
5 changed files with 50 additions and 12 deletions

View File

@ -286,7 +286,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
}
val filterItems = filterThumbnailsManager.processThumbs()
val adapter = FiltersAdapter(filterItems) {
val adapter = FiltersAdapter(applicationContext, filterItems) {
val newBitmap = Bitmap.createBitmap(shownBitmap)
default_image_view.setImageBitmap(it.filter.processFilter(newBitmap))
}

View File

@ -1,35 +1,57 @@
package com.simplemobiletools.gallery.adapters
import android.content.Context
import android.graphics.drawable.Drawable
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.interfaces.FilterAdapterListener
import com.simplemobiletools.gallery.models.FilterItem
import kotlinx.android.synthetic.main.editor_filter_item.view.*
import java.util.*
class FiltersAdapter(val filterItems: ArrayList<FilterItem>, val itemClick: (FilterItem) -> Unit) : RecyclerView.Adapter<FiltersAdapter.ViewHolder>() {
class FiltersAdapter(val context: Context, val filterItems: ArrayList<FilterItem>, val itemClick: (FilterItem) -> Unit) : RecyclerView.Adapter<FiltersAdapter.ViewHolder>(),
FilterAdapterListener {
private var currentSelection = filterItems.first()
private var strokeBackground = context.resources.getDrawable(R.drawable.stroke_background)
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bindView(filterItems[position], itemClick)
holder.bindView(filterItems[position], strokeBackground)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.editor_filter_item, parent, false)
return ViewHolder(view)
return ViewHolder(view, this)
}
override fun getItemCount() = filterItems.size
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bindView(filterItem: FilterItem, itemClick: (FilterItem) -> Unit): View {
override fun getCurrentFilter() = currentSelection
override fun setCurrentFilter(filterItem: FilterItem) {
if (currentSelection != filterItem) {
currentSelection = filterItem
notifyDataSetChanged()
itemClick.invoke(filterItem)
}
}
class ViewHolder(view: View, val filterAdapterListener: FilterAdapterListener) : RecyclerView.ViewHolder(view) {
fun bindView(filterItem: FilterItem, strokeBackground: Drawable): View {
itemView.apply {
editor_filter_item_label.text = filterItem.filter.name
editor_filter_item_thumbnail.setImageBitmap(filterItem.bitmap)
editor_filter_item_thumbnail.background = if (filterAdapterListener.getCurrentFilter() == filterItem) {
strokeBackground
} else {
null
}
setOnClickListener {
itemClick.invoke(filterItem)
filterAdapterListener.setCurrentFilter(filterItem)
}
}
return itemView

View File

@ -0,0 +1,9 @@
package com.simplemobiletools.gallery.interfaces
import com.simplemobiletools.gallery.models.FilterItem
interface FilterAdapterListener {
fun getCurrentFilter(): FilterItem
fun setCurrentFilter(filterItem: FilterItem)
}

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<stroke android:width="1dp" android:color="#FFFFFFFF"/>
</shape>
</item>
</selector>

View File

@ -4,16 +4,15 @@
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/editor_filter_item_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/tiny_margin"
android:paddingRight="@dimen/tiny_margin"
android:paddingTop="@dimen/tiny_margin">
android:layout_height="wrap_content">
<ImageView
android:id="@+id/editor_filter_item_thumbnail"
android:layout_width="@dimen/bottom_filters_thumbnail_height"
android:layout_height="@dimen/bottom_filters_thumbnail_height"
android:layout_above="@+id/editor_filter_item_label"/>
android:layout_above="@+id/editor_filter_item_label"
android:background="@drawable/stroke_background"
android:padding="1dp"/>
<TextView
android:id="@+id/editor_filter_item_label"