Skip to content

Commit

Permalink
feat: fast scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
butzist committed Feb 17, 2024
1 parent 6cc68d2 commit 6581c19
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.LinearLayoutManager
import dagger.hilt.android.AndroidEntryPoint
import de.szalkowski.activitylauncher.databinding.FragmentActivityListBinding
import javax.inject.Inject
Expand Down Expand Up @@ -48,7 +47,7 @@ class ActivityListFragment : Fragment() {
}

binding.rvActivities.adapter = activityListAdapter
binding.rvActivities.layoutManager = LinearLayoutManager(requireContext())
binding.rvActivities.isNestedScrollingEnabled = false
}

override fun onDestroyView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import dagger.hilt.android.AndroidEntryPoint
import de.szalkowski.activitylauncher.databinding.FragmentPackageListBinding
import javax.inject.Inject
Expand Down Expand Up @@ -37,7 +36,6 @@ class PackageListFragment : Fragment() {
findNavController().navigate(action)
}
binding.rvPackages.adapter = packageListAdapter
binding.rvPackages.layoutManager = LinearLayoutManager(requireContext())
binding.rvPackages.isNestedScrollingEnabled = false
}

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/fast_scroll_thumb.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- CC BY-SA 4.0 https://stackoverflow.com/a/46026362 -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/shape_thumb"/>

<item
android:drawable="@drawable/shape_thumb"/>
</selector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/fast_scroll_track.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- CC BY-SA 4.0 https://stackoverflow.com/a/46026362 -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/shape_track"/>

<item
android:drawable="@drawable/shape_track"/>
</selector>
16 changes: 16 additions & 0 deletions app/src/main/res/drawable/shape_thumb.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- CC BY-SA 4.0 https://stackoverflow.com/a/46026362 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<corners
android:topLeftRadius="44dp"
android:topRightRadius="44dp"
android:bottomLeftRadius="44dp" />

<padding
android:paddingLeft="22dp"
android:paddingRight="22dp" />

<solid android:color="@color/material_dynamic_primary20" />
</shape>
13 changes: 13 additions & 0 deletions app/src/main/res/drawable/shape_track.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- CC BY-SA 4.0 https://stackoverflow.com/a/46026362 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<solid android:color="@android:color/darker_gray" />

<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
</shape>
7 changes: 7 additions & 0 deletions app/src/main/res/layout/fragment_activity_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
android:padding="16dp"
tools:context=".ui.ActivityListFragment">

<!-- CC BY-SA 4.0 https://stackoverflow.com/a/46026362 -->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvActivities"
android:layout_width="0dp"
android:layout_height="0dp"
app:fastScrollEnabled="true"
app:fastScrollHorizontalThumbDrawable="@drawable/fast_scroll_thumb"
app:fastScrollHorizontalTrackDrawable="@drawable/fast_scroll_track"
app:fastScrollVerticalThumbDrawable="@drawable/fast_scroll_thumb"
app:fastScrollVerticalTrackDrawable="@drawable/fast_scroll_track"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/layout/fragment_package_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
android:padding="16dp"
tools:context=".ui.PackageListFragment">

<!-- CC BY-SA 4.0 https://stackoverflow.com/a/46026362 -->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvPackages"
android:layout_width="0dp"
android:layout_height="0dp"
app:fastScrollEnabled="true"
app:fastScrollHorizontalThumbDrawable="@drawable/fast_scroll_thumb"
app:fastScrollHorizontalTrackDrawable="@drawable/fast_scroll_track"
app:fastScrollVerticalThumbDrawable="@drawable/fast_scroll_thumb"
app:fastScrollVerticalTrackDrawable="@drawable/fast_scroll_track"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down

0 comments on commit 6581c19

Please sign in to comment.