From dbaacd596e35858aa38f307fe57bef19e331294d Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 19 Jul 2018 23:36:46 +0200 Subject: [PATCH] show a list of thumbnails at the editor, for applying filters --- app/build.gradle | 1 + app/src/main/AndroidManifest.xml | 3 +- .../gallery/activities/EditActivity.kt | 29 ++++++++++++++ .../gallery/adapters/FiltersAdapter.kt | 38 +++++++++++++++++++ .../gallery/models/FilterItem.kt | 6 +++ .../layout/bottom_editor_actions_filter.xml | 9 +++-- .../main/res/layout/editor_filter_item.xml | 29 ++++++++++++++ app/src/main/res/values/dimens.xml | 2 + 8 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/adapters/FiltersAdapter.kt create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/models/FilterItem.kt create mode 100644 app/src/main/res/layout/editor_filter_item.xml diff --git a/app/build.gradle b/app/build.gradle index 3b21595ad..14e86567d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,6 +57,7 @@ dependencies { implementation 'com.google.android.exoplayer:exoplayer-core:2.8.2' implementation 'com.google.vr:sdk-panowidget:1.150.0' implementation 'org.apache.sanselan:sanselan:0.97-incubator' + implementation 'info.androidhive:imagefilters:1.0.7' kapt "android.arch.persistence.room:compiler:1.1.1" implementation "android.arch.persistence.room:runtime:1.1.1" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d6c4a88c9..e58d5e3a1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -21,7 +21,8 @@ android:label="@string/app_launcher_name" android:roundIcon="@mipmap/ic_launcher" android:supportsRtl="true" - android:theme="@style/AppTheme"> + android:theme="@style/AppTheme" + tools:replace="android:label"> + + val adapter = FiltersAdapter(filterItems) { + + } + + bottom_actions_filter_list.adapter = adapter + adapter.notifyDataSetChanged() + } + }.start() + } + if (currPrimaryAction != PRIMARY_ACTION_CROP_ROTATE) { bottom_aspect_ratios.beGone() currCropRotateAction = CROP_ROTATE_NONE + updateCropRotateActionButtons() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/FiltersAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/FiltersAdapter.kt new file mode 100644 index 000000000..9d02845bc --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/FiltersAdapter.kt @@ -0,0 +1,38 @@ +package com.simplemobiletools.gallery.adapters + +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.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() { + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + holder.bindView(filterItems[position], itemClick) + } + + 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) + } + + override fun getItemCount() = filterItems.size + + class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { + fun bindView(filterItem: FilterItem, itemClick: (FilterItem) -> Unit): View { + itemView.apply { + editor_filter_item_label.text = filterItem.filter.name + editor_filter_item_thumbnail.setImageBitmap(filterItem.bitmap) + + setOnClickListener { + itemClick.invoke(filterItem) + } + } + return itemView + } + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/FilterItem.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/FilterItem.kt new file mode 100644 index 000000000..f998efa27 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/FilterItem.kt @@ -0,0 +1,6 @@ +package com.simplemobiletools.gallery.models + +import android.graphics.Bitmap +import com.zomato.photofilters.imageprocessors.Filter + +data class FilterItem(val bitmap: Bitmap, val filter: Filter) diff --git a/app/src/main/res/layout/bottom_editor_actions_filter.xml b/app/src/main/res/layout/bottom_editor_actions_filter.xml index 51b5ffa3e..689e81f2e 100644 --- a/app/src/main/res/layout/bottom_editor_actions_filter.xml +++ b/app/src/main/res/layout/bottom_editor_actions_filter.xml @@ -1,15 +1,18 @@ + android:layout_height="@dimen/bottom_filters_height" + android:background="@color/crop_image_view_background" + android:orientation="horizontal" + app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager"/> diff --git a/app/src/main/res/layout/editor_filter_item.xml b/app/src/main/res/layout/editor_filter_item.xml new file mode 100644 index 000000000..28d915ef2 --- /dev/null +++ b/app/src/main/res/layout/editor_filter_item.xml @@ -0,0 +1,29 @@ + + + + + + + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 81fefce87..14367ad1f 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -11,4 +11,6 @@ 30dp 72dp 64dp + 76dp + 90dp