From 27e1952375eddaec78d7c95d3a431633ab4275c8 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sun, 26 Jan 2020 11:49:45 +0530 Subject: Add fastscroller with alphabetic hints (#616) * Setup basic fast scroll Work towards #558 * Implement PopupTextProvider Fixes #558 * Update changes * Hide system scrollbars * Port fastscroll to autofill preferences * Spotless Signed-off-by: Harsh Shandilya --- app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt | 3 +++ .../com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.kt | 2 ++ .../java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.kt | 7 ++++++- .../java/com/zeapo/pwdstore/ui/adapters/EntryRecyclerAdapter.kt | 8 +++++++- app/src/main/res/layout/autofill_recycler_view.xml | 9 ++++++--- app/src/main/res/layout/password_recycler_view.xml | 2 +- 6 files changed, 25 insertions(+), 6 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt index 279869bc..61437731 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt @@ -26,6 +26,7 @@ import com.zeapo.pwdstore.utils.PasswordRepository.PasswordSortOrder.Companion.g import java.io.File import java.util.Locale import java.util.Stack +import me.zhanghai.android.fastscroll.FastScrollerBuilder /** * A fragment representing a list of Items. @@ -67,6 +68,8 @@ class PasswordFragment : Fragment() { recyclerView.addItemDecoration(DividerItemDecoration(requireContext(), DividerItemDecoration.VERTICAL)) // Set the adapter recyclerView.adapter = recyclerAdapter + // Setup fast scroller + FastScrollerBuilder(recyclerView).build() val fab: FloatingActionButton = view.findViewById(R.id.fab) fab.setOnClickListener { (requireActivity() as PasswordStore).createPassword() } registerForContextMenu(recyclerView) diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.kt index 3fe5e9e7..5c49bf81 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.kt @@ -21,6 +21,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton import com.zeapo.pwdstore.R import java.lang.ref.WeakReference import java.util.ArrayList +import me.zhanghai.android.fastscroll.FastScrollerBuilder class AutofillPreferenceActivity : AppCompatActivity() { @@ -39,6 +40,7 @@ class AutofillPreferenceActivity : AppCompatActivity() { val layoutManager = LinearLayoutManager(this) recyclerView!!.layoutManager = layoutManager recyclerView!!.addItemDecoration(DividerItemDecoration(this, DividerItemDecoration.VERTICAL)) + FastScrollerBuilder(recyclerView!!).build() pm = packageManager diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.kt index 139f9582..47937a32 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.kt +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.kt @@ -20,11 +20,12 @@ import com.zeapo.pwdstore.R import com.zeapo.pwdstore.utils.splitLines import java.util.ArrayList import java.util.Locale +import me.zhanghai.android.fastscroll.PopupTextProvider internal class AutofillRecyclerAdapter( allApps: List, private val activity: AutofillPreferenceActivity -) : RecyclerView.Adapter() { +) : RecyclerView.Adapter(), PopupTextProvider { private val apps: SortedList private val allApps: ArrayList // for filtering, maintain a list of all @@ -56,6 +57,10 @@ internal class AutofillRecyclerAdapter( } } + override fun getPopupText(position: Int): String { + return allApps[position].appName[0].toString().toUpperCase(Locale.getDefault()) + } + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { val v = LayoutInflater.from(parent.context) .inflate(R.layout.autofill_row_layout, parent, false) diff --git a/app/src/main/java/com/zeapo/pwdstore/ui/adapters/EntryRecyclerAdapter.kt b/app/src/main/java/com/zeapo/pwdstore/ui/adapters/EntryRecyclerAdapter.kt index 6ddfa777..81aa4f05 100644 --- a/app/src/main/java/com/zeapo/pwdstore/ui/adapters/EntryRecyclerAdapter.kt +++ b/app/src/main/java/com/zeapo/pwdstore/ui/adapters/EntryRecyclerAdapter.kt @@ -19,9 +19,11 @@ import com.zeapo.pwdstore.utils.PasswordItem import com.zeapo.pwdstore.widget.MultiselectableConstraintLayout import java.io.File import java.util.ArrayList +import java.util.Locale import java.util.TreeSet +import me.zhanghai.android.fastscroll.PopupTextProvider -abstract class EntryRecyclerAdapter internal constructor(val values: ArrayList) : RecyclerView.Adapter() { +abstract class EntryRecyclerAdapter internal constructor(val values: ArrayList) : RecyclerView.Adapter(), PopupTextProvider { internal val selectedItems: MutableSet = TreeSet() internal var settings: SharedPreferences? = null @@ -30,6 +32,10 @@ abstract class EntryRecyclerAdapter internal constructor(val values: ArrayList

+ android:layout_height="match_parent"> + android:scrollbars="none" + tools:listitem="@layout/autofill_row_layout" + tools:itemCount="20"/>