From 4c911ca5e69adf04f110478dd7f2674b232f6498 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 22 Nov 2021 11:10:01 +0100 Subject: [PATCH] use the new fastscroller at the filepicker dialog --- .../adapters/FilepickerItemsAdapter.kt | 7 ++++- .../commons/dialogs/FilePickerDialog.kt | 10 ++----- .../src/main/res/layout/dialog_filepicker.xml | 27 +++++++++++-------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/adapters/FilepickerItemsAdapter.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/adapters/FilepickerItemsAdapter.kt index d9bd42682..4a203bf43 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/adapters/FilepickerItemsAdapter.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/adapters/FilepickerItemsAdapter.kt @@ -12,6 +12,7 @@ import com.bumptech.glide.load.resource.bitmap.CenterCrop import com.bumptech.glide.load.resource.bitmap.RoundedCorners import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade import com.bumptech.glide.request.RequestOptions +import com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller import com.simplemobiletools.commons.R import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.* @@ -24,7 +25,7 @@ import java.util.* class FilepickerItemsAdapter( activity: BaseSimpleActivity, val fileDirItems: List, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit -) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) { +) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick), RecyclerViewFastScroller.OnPopupTextUpdate { private lateinit var fileDrawable: Drawable private lateinit var folderDrawable: Drawable @@ -32,6 +33,8 @@ class FilepickerItemsAdapter( private val hasOTGConnected = activity.hasOTGConnected() private var fontSize = 0f private val cornerRadius = resources.getDimension(R.dimen.rounded_corner_radius_small).toInt() + private val dateFormat = activity.baseConfig.dateFormat + private val timeFormat = activity.getTimeFormat() init { initDrawables() @@ -144,4 +147,6 @@ class FilepickerItemsAdapter( fileDrawable = resources.getDrawable(R.drawable.ic_file_generic) fileDrawables = getFilePlaceholderDrawables(activity) } + + override fun onChange(position: Int) = fileDirItems.getOrNull(position)?.getBubbleText(activity, dateFormat, timeFormat) ?: "" } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FilePickerDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FilePickerDialog.kt index cd1a2197e..780a183fb 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FilePickerDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FilePickerDialog.kt @@ -43,8 +43,6 @@ class FilePickerDialog( private var mFirstUpdate = true private var mPrevPath = "" private var mScrollStates = HashMap() - private val mDateFormat = activity.baseConfig.dateFormat - private val mTimeFormat = activity.getTimeFormat() private lateinit var mDialog: AlertDialog private var mDialogView = activity.layoutInflater.inflate(R.layout.dialog_filepicker, null) @@ -103,6 +101,8 @@ class FilePickerDialog( (layoutParams as CoordinatorLayout.LayoutParams).bottomMargin = secondaryFabBottomMargin } + val adjustedPrimaryColor = activity.getAdjustedPrimaryColor() + mDialogView.filepicker_fastscroller.updateColors(adjustedPrimaryColor, adjustedPrimaryColor.getContrastColor()) mDialogView.filepicker_fab_show_hidden.apply { beVisibleIf(!showHidden && canAddShowHiddenButton) setOnClickListener { @@ -183,18 +183,12 @@ class FilePickerDialog( mDialogView.apply { filepicker_list.adapter = adapter filepicker_breadcrumbs.setBreadcrumb(currPath) - filepicker_fastscroller.setViews(filepicker_list) { - filepicker_fastscroller.updateBubbleText(sortedItems.getOrNull(it)?.getBubbleText(context, mDateFormat, mTimeFormat) ?: "") - } if (context.areSystemAnimationsEnabled) { filepicker_list.scheduleLayoutAnimation() } layoutManager.onRestoreInstanceState(mScrollStates[currPath.trimEnd('/')]) - filepicker_list.onGlobalLayout { - filepicker_fastscroller.setScrollToY(filepicker_list.computeVerticalScrollOffset()) - } } mFirstUpdate = false diff --git a/commons/src/main/res/layout/dialog_filepicker.xml b/commons/src/main/res/layout/dialog_filepicker.xml index 4ea511f02..2532c888c 100644 --- a/commons/src/main/res/layout/dialog_filepicker.xml +++ b/commons/src/main/res/layout/dialog_filepicker.xml @@ -25,27 +25,32 @@ android:paddingEnd="@dimen/small_margin" android:paddingBottom="@dimen/small_margin" /> - + android:layout_height="wrap_content" + android:layout_below="@+id/filepicker_breadcrumbs"> - + + + +