diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt index d7c4403d4..986bb3f71 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt @@ -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)) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/FiltersAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/FiltersAdapter.kt index 9d02845bc..e8dfd83ef 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/FiltersAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/FiltersAdapter.kt @@ -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, val itemClick: (FilterItem) -> Unit) : RecyclerView.Adapter() { +class FiltersAdapter(val context: Context, val filterItems: ArrayList, val itemClick: (FilterItem) -> Unit) : RecyclerView.Adapter(), + 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 diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/FilterAdapterListener.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/FilterAdapterListener.kt new file mode 100644 index 000000000..3a5814721 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/FilterAdapterListener.kt @@ -0,0 +1,9 @@ +package com.simplemobiletools.gallery.interfaces + +import com.simplemobiletools.gallery.models.FilterItem + +interface FilterAdapterListener { + fun getCurrentFilter(): FilterItem + + fun setCurrentFilter(filterItem: FilterItem) +} diff --git a/app/src/main/res/drawable/stroke_background.xml b/app/src/main/res/drawable/stroke_background.xml new file mode 100644 index 000000000..6d274b7d2 --- /dev/null +++ b/app/src/main/res/drawable/stroke_background.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/app/src/main/res/layout/editor_filter_item.xml b/app/src/main/res/layout/editor_filter_item.xml index 28d915ef2..ff20581f1 100644 --- a/app/src/main/res/layout/editor_filter_item.xml +++ b/app/src/main/res/layout/editor_filter_item.xml @@ -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"> + android:layout_above="@+id/editor_filter_item_label" + android:background="@drawable/stroke_background" + android:padding="1dp"/>