Skip to content

Commit

Permalink
library: add fast-scroller
Browse files Browse the repository at this point in the history
Add a fast-scroller to the library view. This makes long lists of
items such as albums easier to scroll through, but also requires
pre-sorting of artists to make sure that unintended behavior does
not occur. A future commit may improve the sort options here so that
this does not need to occur.
  • Loading branch information
OxygenCobalt committed Jun 19, 2021
1 parent 7adfb92 commit 5131db5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.oxycblt.auxio.music.Artist
import org.oxycblt.auxio.music.Genre
import org.oxycblt.auxio.music.Parent
import org.oxycblt.auxio.music.Song
import org.oxycblt.auxio.recycler.sliceArticle
import org.oxycblt.auxio.ui.getSpans
import org.oxycblt.auxio.ui.newMenu

Expand Down Expand Up @@ -67,6 +68,13 @@ class LibraryFragment : Fragment() {
}
}

binding.libraryFastScroll.setup(binding.libraryRecycler) { pos ->
val item = libraryModel.libraryData.value!![pos]
val char = item.displayName.sliceArticle().first().uppercaseChar()

if (char.isDigit()) '#' else char
}

// --- VIEWMODEL SETUP ---

libraryModel.libraryData.observe(viewLifecycleOwner) { data ->
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/org/oxycblt/auxio/music/MusicLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.core.database.getStringOrNull
import org.oxycblt.auxio.R
import org.oxycblt.auxio.database.BlacklistDatabase
import org.oxycblt.auxio.logD
import org.oxycblt.auxio.recycler.SortMode

/**
* Class that loads/constructs [Genre]s, [Artist]s, [Album]s, and [Song] objects from the filesystem
Expand Down Expand Up @@ -227,6 +228,9 @@ class MusicLoader(private val context: Context) {
)
}

// Make the artist view line up with the rest of the lists by sorting it.
artists = SortMode.ALPHA_DOWN.getSortedArtistList(artists).toMutableList()

logD("Albums successfully linked into ${artists.size} artists")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import kotlin.math.roundToInt
* fast-scrollers, this one displays indicators and a thumb instead of simply a scroll bar.
* This code is fundamentally an adaptation of Reddit's IndicatorFastScroll, albeit specialized
* towards Auxio. The original library is here: https://github.com/reddit/IndicatorFastScroll/
* TODO: Make this update with data.
* @author OxygenCobalt
*/
class FastScrollView @JvmOverloads constructor(
Expand Down
17 changes: 15 additions & 2 deletions app/src/main/res/layout/fragment_library.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
tools:context=".library.LibraryFragment">

<LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
Expand All @@ -13,6 +13,9 @@
<androidx.appcompat.widget.Toolbar
android:id="@+id/library_toolbar"
style="@style/Toolbar.Style"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:menu="@menu/menu_library"
app:title="@string/label_library" />

Expand All @@ -22,7 +25,17 @@
android:layout_height="0dp"
android:layout_weight="1"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/library_toolbar"
tools:listitem="@layout/item_artist" />

</LinearLayout>
<org.oxycblt.auxio.songs.FastScrollView
android:id="@+id/library_fast_scroll"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/library_toolbar" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

0 comments on commit 5131db5

Please sign in to comment.