add a fastscroller to the filepicker recyclerview

This commit is contained in:
tibbi 2017-03-18 19:41:38 +01:00
parent 8ea3e5f602
commit b4fdb838fb
3 changed files with 20 additions and 8 deletions

View file

@ -139,6 +139,7 @@ class FilePickerDialog(val activity: BaseSimpleActivity,
directory_picker_list.adapter = adapter
directory_picker_breadcrumbs.setBreadcrumb(currPath)
directory_fastscroller.setViews(directory_picker_list)
}
layoutManager.onRestoreInstanceState(mScrollStates[currPath.trimEnd('/')])

View file

@ -3,7 +3,7 @@ package com.simplemobiletools.commons.views
import android.content.Context
import android.graphics.PorterDuff
import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.util.AttributeSet
import android.view.LayoutInflater
@ -29,7 +29,7 @@ class FastScroller : LinearLayout {
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle)
fun setViews(recyclerView: RecyclerView, swipeRefreshLayout: SwipeRefreshLayout) {
fun setViews(recyclerView: RecyclerView, swipeRefreshLayout: SwipeRefreshLayout? = null) {
this.recyclerView = recyclerView
this.swipeRefreshLayout = swipeRefreshLayout
handle.background.setColorFilter(context.baseConfig.primaryColor, PorterDuff.Mode.SRC_IN)
@ -94,7 +94,7 @@ class FastScroller : LinearLayout {
val itemCount = recyclerView!!.adapter.itemCount
val proportion = y / currHeight
val targetPos = getValueInRange(0f, (itemCount - 1).toFloat(), proportion * itemCount).toInt()
(recyclerView!!.layoutManager as GridLayoutManager).scrollToPositionWithOffset(targetPos, 0)
(recyclerView!!.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(targetPos, 0)
}
}

View file

@ -6,9 +6,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<RelativeLayout
android:id="@+id/directory_picker_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -24,10 +22,22 @@
android:id="@+id/directory_picker_list"
android:layout_width="match_parent"
android:layout_height="1000dp"
android:scrollbars="vertical"
android:layout_below="@+id/directory_picker_breadcrumbs"
android:scrollbars="none"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
</LinearLayout>
<com.simplemobiletools.commons.views.FastScroller
android:id="@+id/directory_fastscroller"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignBottom="@+id/directory_picker_list"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/directory_picker_list"
android:paddingLeft="@dimen/normal_margin"
android:paddingStart="@dimen/normal_margin"/>
</RelativeLayout>
<com.simplemobiletools.commons.views.MyFloatingActionButton
android:id="@+id/directory_picker_fab"
@ -37,4 +47,5 @@
android:layout_margin="@dimen/activity_margin"
android:src="@drawable/ic_plus"
android:visibility="gone"/>
</android.support.design.widget.CoordinatorLayout>