scroll the editor filters list horizontally when we reach an edge
This commit is contained in:
parent
1c89721292
commit
d848f0b305
6 changed files with 22 additions and 13 deletions
|
@ -9,6 +9,7 @@ import android.graphics.Point
|
|||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.provider.MediaStore
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.widget.RelativeLayout
|
||||
|
@ -353,8 +354,8 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
|||
|
||||
if (currPrimaryAction == PRIMARY_ACTION_FILTER && bottom_actions_filter_list.adapter == null) {
|
||||
Thread {
|
||||
val size = resources.getDimension(R.dimen.bottom_filters_thumbnail_height).toInt()
|
||||
val bitmap = Glide.with(this).asBitmap().load(uri).submit(size, size).get()
|
||||
val thumbnailSize = resources.getDimension(R.dimen.bottom_filters_thumbnail_size).toInt()
|
||||
val bitmap = Glide.with(this).asBitmap().load(uri).submit(thumbnailSize, thumbnailSize).get()
|
||||
runOnUiThread {
|
||||
val filterThumbnailsManager = FilterThumbnailsManager()
|
||||
filterThumbnailsManager.clearThumbs()
|
||||
|
@ -369,7 +370,14 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
|||
|
||||
val filterItems = filterThumbnailsManager.processThumbs()
|
||||
val adapter = FiltersAdapter(applicationContext, filterItems) {
|
||||
applyFilter(it)
|
||||
val layoutManager = bottom_actions_filter_list.layoutManager as LinearLayoutManager
|
||||
applyFilter(filterItems[it])
|
||||
|
||||
if (it == layoutManager.findLastCompletelyVisibleItemPosition() || it == layoutManager.findLastVisibleItemPosition()) {
|
||||
bottom_actions_filter_list.smoothScrollBy(thumbnailSize, 0)
|
||||
} else if (it == layoutManager.findFirstCompletelyVisibleItemPosition() || it == layoutManager.findFirstVisibleItemPosition()) {
|
||||
bottom_actions_filter_list.smoothScrollBy(-thumbnailSize, 0)
|
||||
}
|
||||
}
|
||||
|
||||
bottom_actions_filter_list.adapter = adapter
|
||||
|
|
|
@ -12,7 +12,7 @@ import com.simplemobiletools.gallery.models.FilterItem
|
|||
import kotlinx.android.synthetic.main.editor_filter_item.view.*
|
||||
import java.util.*
|
||||
|
||||
class FiltersAdapter(val context: Context, val filterItems: ArrayList<FilterItem>, val itemClick: (FilterItem) -> Unit) : RecyclerView.Adapter<FiltersAdapter.ViewHolder>(),
|
||||
class FiltersAdapter(val context: Context, val filterItems: ArrayList<FilterItem>, val itemClick: (Int) -> Unit) : RecyclerView.Adapter<FiltersAdapter.ViewHolder>(),
|
||||
FilterAdapterListener {
|
||||
|
||||
private var currentSelection = filterItems.first()
|
||||
|
@ -31,11 +31,12 @@ class FiltersAdapter(val context: Context, val filterItems: ArrayList<FilterItem
|
|||
|
||||
override fun getCurrentFilter() = currentSelection
|
||||
|
||||
override fun setCurrentFilter(filterItem: FilterItem) {
|
||||
override fun setCurrentFilter(position: Int) {
|
||||
val filterItem = filterItems.getOrNull(position) ?: return
|
||||
if (currentSelection != filterItem) {
|
||||
currentSelection = filterItem
|
||||
notifyDataSetChanged()
|
||||
itemClick.invoke(filterItem)
|
||||
itemClick.invoke(position)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,7 +52,7 @@ class FiltersAdapter(val context: Context, val filterItems: ArrayList<FilterItem
|
|||
}
|
||||
|
||||
setOnClickListener {
|
||||
filterAdapterListener.setCurrentFilter(filterItem)
|
||||
filterAdapterListener.setCurrentFilter(adapterPosition)
|
||||
}
|
||||
}
|
||||
return itemView
|
||||
|
|
|
@ -5,5 +5,5 @@ import com.simplemobiletools.gallery.models.FilterItem
|
|||
interface FilterAdapterListener {
|
||||
fun getCurrentFilter(): FilterItem
|
||||
|
||||
fun setCurrentFilter(filterItem: FilterItem)
|
||||
fun setCurrentFilter(position: Int)
|
||||
}
|
||||
|
|
|
@ -10,13 +10,13 @@
|
|||
android:id="@+id/default_image_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="@dimen/bottom_filters_thumbnail_height"/>
|
||||
android:layout_marginBottom="@dimen/bottom_filters_thumbnail_size"/>
|
||||
|
||||
<com.theartofdev.edmodo.cropper.CropImageView
|
||||
android:id="@+id/crop_image_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="@dimen/bottom_filters_thumbnail_height"
|
||||
android:layout_marginBottom="@dimen/bottom_filters_thumbnail_size"
|
||||
android:visibility="gone"
|
||||
app:cropBackgroundColor="@color/crop_image_view_background"
|
||||
app:cropInitialCropWindowPaddingRatio="0"/>
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
|
||||
<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_width="@dimen/bottom_filters_thumbnail_size"
|
||||
android:layout_height="@dimen/bottom_filters_thumbnail_size"
|
||||
android:layout_above="@+id/editor_filter_item_label"
|
||||
android:background="@drawable/stroke_background"
|
||||
android:padding="1dp"/>
|
||||
|
|
|
@ -11,6 +11,6 @@
|
|||
<dimen name="instant_change_bar_width">30dp</dimen>
|
||||
<dimen name="list_view_folder_thumbnail_size">72dp</dimen>
|
||||
<dimen name="bottom_actions_height">64dp</dimen>
|
||||
<dimen name="bottom_filters_thumbnail_height">76dp</dimen>
|
||||
<dimen name="bottom_filters_thumbnail_size">76dp</dimen>
|
||||
<dimen name="bottom_filters_height">90dp</dimen>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue