From 8c116f6c16886ab46018ce649f4dea9b8d67edad Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 20 Jul 2018 11:07:25 +0200 Subject: [PATCH] apply the filters on thumbnail items --- .../gallery/activities/EditActivity.kt | 9 ++++++- .../helpers/FilterThumbnailsManager.kt | 26 +++++++++++++++++++ .../gallery/models/FilterItem.kt | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/helpers/FilterThumbnailsManager.kt 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 802adaedd..a438dd1a7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt @@ -23,6 +23,7 @@ import com.simplemobiletools.gallery.dialogs.ResizeDialog import com.simplemobiletools.gallery.dialogs.SaveAsDialog import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.openEditor +import com.simplemobiletools.gallery.helpers.FilterThumbnailsManager import com.simplemobiletools.gallery.models.FilterItem import com.theartofdev.edmodo.cropper.CropImageView import com.zomato.photofilters.FilterPack @@ -253,8 +254,14 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener val size = resources.getDimension(R.dimen.bottom_filters_thumbnail_height).toInt() val bitmap = Glide.with(this).asBitmap().load(uri).submit(size, size).get() runOnUiThread { - val filterItems = FilterPack.getFilterPack(this).map { FilterItem(bitmap, it) } as ArrayList + FilterThumbnailsManager.clearThumbs() + FilterPack.getFilterPack(this).forEach { + val filterItem = FilterItem(bitmap, it) + FilterThumbnailsManager.addThumb(filterItem) + } + + val filterItems = FilterThumbnailsManager.processThumbs() val adapter = FiltersAdapter(filterItems) { } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/FilterThumbnailsManager.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/FilterThumbnailsManager.kt new file mode 100644 index 000000000..f9d833280 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/FilterThumbnailsManager.kt @@ -0,0 +1,26 @@ +package com.simplemobiletools.gallery.helpers + +import com.simplemobiletools.gallery.models.FilterItem +import java.util.* + +object FilterThumbnailsManager { + private var filterThumbnails = ArrayList(10) + private var processedThumbnails = ArrayList(10) + + fun addThumb(filterItem: FilterItem) { + filterThumbnails.add(filterItem) + } + + fun processThumbs(): ArrayList { + for (filterItem in filterThumbnails) { + filterItem.bitmap = filterItem.filter.processFilter(filterItem.bitmap) + processedThumbnails.add(filterItem) + } + return processedThumbnails + } + + fun clearThumbs() { + filterThumbnails = ArrayList() + processedThumbnails = ArrayList() + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/FilterItem.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/FilterItem.kt index f998efa27..f2dd7f2d6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/FilterItem.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/FilterItem.kt @@ -3,4 +3,4 @@ package com.simplemobiletools.gallery.models import android.graphics.Bitmap import com.zomato.photofilters.imageprocessors.Filter -data class FilterItem(val bitmap: Bitmap, val filter: Filter) +data class FilterItem(var bitmap: Bitmap, val filter: Filter)