Change show constants to dedicated enum
Move the ShowMode constants to a dedicated ShowMode enum in /recycler/.
This commit is contained in:
parent
7abb888108
commit
127f700700
11 changed files with 55 additions and 63 deletions
|
@ -33,6 +33,9 @@ TODOs surrounded with !s are things I tried to do, but failed for reasons includ
|
||||||
/bugs/
|
/bugs/
|
||||||
- Fix issue where fast navigations will cause the app to not display anything
|
- Fix issue where fast navigations will cause the app to not display anything
|
||||||
|
|
||||||
|
/other/
|
||||||
|
- Collapse show constants into ShowMode enum
|
||||||
|
|
||||||
To be added:
|
To be added:
|
||||||
/prefs/
|
/prefs/
|
||||||
/playback/
|
/playback/
|
|
@ -24,9 +24,7 @@ import org.oxycblt.auxio.music.Artist
|
||||||
import org.oxycblt.auxio.music.BaseModel
|
import org.oxycblt.auxio.music.BaseModel
|
||||||
import org.oxycblt.auxio.music.Genre
|
import org.oxycblt.auxio.music.Genre
|
||||||
import org.oxycblt.auxio.music.MusicViewModel
|
import org.oxycblt.auxio.music.MusicViewModel
|
||||||
import org.oxycblt.auxio.theme.SHOW_ALBUMS
|
import org.oxycblt.auxio.recycler.ShowMode
|
||||||
import org.oxycblt.auxio.theme.SHOW_ARTISTS
|
|
||||||
import org.oxycblt.auxio.theme.SHOW_GENRES
|
|
||||||
import org.oxycblt.auxio.theme.applyColor
|
import org.oxycblt.auxio.theme.applyColor
|
||||||
import org.oxycblt.auxio.theme.applyDivider
|
import org.oxycblt.auxio.theme.applyDivider
|
||||||
import org.oxycblt.auxio.theme.resolveAttr
|
import org.oxycblt.auxio.theme.resolveAttr
|
||||||
|
@ -70,8 +68,11 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
||||||
|
|
||||||
item.setOnActionExpandListener(object : MenuItem.OnActionExpandListener {
|
item.setOnActionExpandListener(object : MenuItem.OnActionExpandListener {
|
||||||
override fun onMenuItemActionExpand(item: MenuItem): Boolean {
|
override fun onMenuItemActionExpand(item: MenuItem): Boolean {
|
||||||
// When opened, update the adapter to the SearchAdapter
|
// When opened, update the adapter to the SearchAdapter, and make the sorting
|
||||||
// And remove the sorting group
|
// group invisible. The query is also reset, as if the Auxio process is
|
||||||
|
// killed in the background while still on the search adapter, then the
|
||||||
|
// search query will stick around if its opened again
|
||||||
|
// TODO: Couldn't you just try to restore the search state on restart?
|
||||||
binding.libraryRecycler.adapter = searchAdapter
|
binding.libraryRecycler.adapter = searchAdapter
|
||||||
setGroupVisible(R.id.group_sorting, false)
|
setGroupVisible(R.id.group_sorting, false)
|
||||||
libraryModel.resetQuery()
|
libraryModel.resetQuery()
|
||||||
|
@ -80,11 +81,11 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMenuItemActionCollapse(item: MenuItem): Boolean {
|
override fun onMenuItemActionCollapse(item: MenuItem): Boolean {
|
||||||
// When closed, switch back to LibraryAdapter, make the sorting
|
// When closed, make the sorting icon visible again, change back to
|
||||||
// visible again, and reset the query so that the old results wont show
|
// LibraryAdapter, and reset the query.
|
||||||
// up if the search is opened again.
|
|
||||||
binding.libraryRecycler.adapter = libraryAdapter
|
binding.libraryRecycler.adapter = libraryAdapter
|
||||||
setGroupVisible(R.id.group_sorting, true)
|
setGroupVisible(R.id.group_sorting, true)
|
||||||
|
libraryModel.resetQuery()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -118,9 +119,9 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
||||||
// Update the adapter with the new data
|
// Update the adapter with the new data
|
||||||
libraryAdapter.updateData(
|
libraryAdapter.updateData(
|
||||||
when (libraryModel.showMode.value) {
|
when (libraryModel.showMode.value) {
|
||||||
SHOW_GENRES -> mode.getSortedGenreList(musicModel.genres.value!!)
|
ShowMode.SHOW_GENRES -> mode.getSortedGenreList(musicModel.genres.value!!)
|
||||||
SHOW_ARTISTS -> mode.getSortedArtistList(musicModel.artists.value!!)
|
ShowMode.SHOW_ARTISTS -> mode.getSortedArtistList(musicModel.artists.value!!)
|
||||||
SHOW_ALBUMS -> mode.getSortedAlbumList(musicModel.albums.value!!)
|
ShowMode.SHOW_ALBUMS -> mode.getSortedAlbumList(musicModel.albums.value!!)
|
||||||
|
|
||||||
else -> mode.getSortedArtistList(musicModel.artists.value!!)
|
else -> mode.getSortedArtistList(musicModel.artists.value!!)
|
||||||
}
|
}
|
||||||
|
@ -162,18 +163,23 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun navToItem(baseModel: BaseModel) {
|
private fun navToItem(baseModel: BaseModel) {
|
||||||
Log.d(this::class.simpleName, "Navigating to the detail fragment for ${baseModel.name}")
|
|
||||||
|
|
||||||
if (!libraryModel.isNavigating) {
|
if (!libraryModel.isNavigating) {
|
||||||
libraryModel.updateNavigationStatus(true)
|
libraryModel.updateNavigationStatus(true)
|
||||||
|
|
||||||
|
Log.d(this::class.simpleName, "Navigating to the detail fragment for ${baseModel.name}")
|
||||||
|
|
||||||
findNavController().navigate(
|
findNavController().navigate(
|
||||||
when (baseModel) {
|
when (baseModel) {
|
||||||
is Genre -> MainFragmentDirections.actionShowGenre(baseModel.id)
|
is Genre -> MainFragmentDirections.actionShowGenre(baseModel.id)
|
||||||
is Artist -> MainFragmentDirections.actionShowArtist(baseModel.id)
|
is Artist -> MainFragmentDirections.actionShowArtist(baseModel.id)
|
||||||
is Album -> MainFragmentDirections.actionShowAlbum(baseModel.id, true)
|
is Album -> MainFragmentDirections.actionShowAlbum(baseModel.id, true)
|
||||||
|
|
||||||
else -> return
|
// If given model wasn't valid, then reset the navigation status
|
||||||
|
// and abort the navigation.
|
||||||
|
else -> {
|
||||||
|
libraryModel.updateNavigationStatus(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,8 @@ import org.oxycblt.auxio.R
|
||||||
import org.oxycblt.auxio.music.BaseModel
|
import org.oxycblt.auxio.music.BaseModel
|
||||||
import org.oxycblt.auxio.music.Header
|
import org.oxycblt.auxio.music.Header
|
||||||
import org.oxycblt.auxio.music.MusicViewModel
|
import org.oxycblt.auxio.music.MusicViewModel
|
||||||
|
import org.oxycblt.auxio.recycler.ShowMode
|
||||||
import org.oxycblt.auxio.recycler.SortMode
|
import org.oxycblt.auxio.recycler.SortMode
|
||||||
import org.oxycblt.auxio.theme.SHOW_ALBUMS
|
|
||||||
import org.oxycblt.auxio.theme.SHOW_ARTISTS
|
|
||||||
import org.oxycblt.auxio.theme.SHOW_SONGS
|
|
||||||
|
|
||||||
class LibraryViewModel : ViewModel() {
|
class LibraryViewModel : ViewModel() {
|
||||||
private var mIsNavigating = false
|
private var mIsNavigating = false
|
||||||
|
@ -23,8 +21,8 @@ class LibraryViewModel : ViewModel() {
|
||||||
val searchHasFocus: Boolean get() = mSearchHasFocus
|
val searchHasFocus: Boolean get() = mSearchHasFocus
|
||||||
|
|
||||||
// TODO: Move these to prefs when they're added
|
// TODO: Move these to prefs when they're added
|
||||||
private val mShowMode = MutableLiveData(SHOW_ARTISTS)
|
private val mShowMode = MutableLiveData(ShowMode.SHOW_ARTISTS)
|
||||||
val showMode: LiveData<Int> get() = mShowMode
|
val showMode: LiveData<ShowMode> get() = mShowMode
|
||||||
|
|
||||||
private val mSortMode = MutableLiveData(SortMode.ALPHA_DOWN)
|
private val mSortMode = MutableLiveData(SortMode.ALPHA_DOWN)
|
||||||
val sortMode: LiveData<SortMode> get() = mSortMode
|
val sortMode: LiveData<SortMode> get() = mSortMode
|
||||||
|
@ -62,21 +60,21 @@ class LibraryViewModel : ViewModel() {
|
||||||
val artists = musicModel.artists.value!!.filter { it.name.contains(query, true) }
|
val artists = musicModel.artists.value!!.filter { it.name.contains(query, true) }
|
||||||
|
|
||||||
if (artists.isNotEmpty()) {
|
if (artists.isNotEmpty()) {
|
||||||
combined.add(Header(id = SHOW_ARTISTS.toLong()))
|
combined.add(Header(id = ShowMode.SHOW_ARTISTS.constant))
|
||||||
combined.addAll(artists)
|
combined.addAll(artists)
|
||||||
}
|
}
|
||||||
|
|
||||||
val albums = musicModel.albums.value!!.filter { it.name.contains(query, true) }
|
val albums = musicModel.albums.value!!.filter { it.name.contains(query, true) }
|
||||||
|
|
||||||
if (albums.isNotEmpty()) {
|
if (albums.isNotEmpty()) {
|
||||||
combined.add(Header(id = SHOW_ALBUMS.toLong()))
|
combined.add(Header(id = ShowMode.SHOW_ALBUMS.constant))
|
||||||
combined.addAll(albums)
|
combined.addAll(albums)
|
||||||
}
|
}
|
||||||
|
|
||||||
val songs = musicModel.songs.value!!.filter { it.name.contains(query, true) }
|
val songs = musicModel.songs.value!!.filter { it.name.contains(query, true) }
|
||||||
|
|
||||||
if (songs.isNotEmpty()) {
|
if (songs.isNotEmpty()) {
|
||||||
combined.add(Header(id = SHOW_SONGS.toLong()))
|
combined.add(Header(id = ShowMode.SHOW_SONGS.constant))
|
||||||
combined.addAll(songs)
|
combined.addAll(songs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,17 +7,15 @@ import org.oxycblt.auxio.music.Artist
|
||||||
import org.oxycblt.auxio.music.BaseModel
|
import org.oxycblt.auxio.music.BaseModel
|
||||||
import org.oxycblt.auxio.music.Genre
|
import org.oxycblt.auxio.music.Genre
|
||||||
import org.oxycblt.auxio.recycler.ClickListener
|
import org.oxycblt.auxio.recycler.ClickListener
|
||||||
|
import org.oxycblt.auxio.recycler.ShowMode
|
||||||
import org.oxycblt.auxio.recycler.viewholders.AlbumViewHolder
|
import org.oxycblt.auxio.recycler.viewholders.AlbumViewHolder
|
||||||
import org.oxycblt.auxio.recycler.viewholders.ArtistViewHolder
|
import org.oxycblt.auxio.recycler.viewholders.ArtistViewHolder
|
||||||
import org.oxycblt.auxio.recycler.viewholders.GenreViewHolder
|
import org.oxycblt.auxio.recycler.viewholders.GenreViewHolder
|
||||||
import org.oxycblt.auxio.theme.SHOW_ALBUMS
|
|
||||||
import org.oxycblt.auxio.theme.SHOW_ARTISTS
|
|
||||||
import org.oxycblt.auxio.theme.SHOW_GENRES
|
|
||||||
|
|
||||||
// A ListAdapter that can contain three different types of ViewHolders depending
|
// A ListAdapter that can contain three different types of ViewHolders depending
|
||||||
// the showmode given. It cannot display multiple types of viewholders *at once*.
|
// the showmode given. It cannot display multiple types of viewholders *at once*.
|
||||||
class LibraryAdapter(
|
class LibraryAdapter(
|
||||||
private val showMode: Int,
|
private val showMode: ShowMode,
|
||||||
private val doOnClick: (BaseModel) -> Unit
|
private val doOnClick: (BaseModel) -> Unit
|
||||||
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||||
|
|
||||||
|
@ -32,9 +30,9 @@ class LibraryAdapter(
|
||||||
init {
|
init {
|
||||||
// Assign the data on startup depending on the type
|
// Assign the data on startup depending on the type
|
||||||
data = when (showMode) {
|
data = when (showMode) {
|
||||||
SHOW_GENRES -> listOf<Genre>()
|
ShowMode.SHOW_GENRES -> listOf<Genre>()
|
||||||
SHOW_ALBUMS -> listOf<Album>()
|
ShowMode.SHOW_ARTISTS -> listOf<Artist>()
|
||||||
SHOW_ARTISTS -> listOf<Artist>()
|
ShowMode.SHOW_ALBUMS -> listOf<Album>()
|
||||||
|
|
||||||
else -> listOf<Artist>()
|
else -> listOf<Artist>()
|
||||||
}
|
}
|
||||||
|
@ -45,18 +43,18 @@ class LibraryAdapter(
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||||
// Return a different View Holder depending on the show type
|
// Return a different View Holder depending on the show type
|
||||||
return when (showMode) {
|
return when (showMode) {
|
||||||
SHOW_GENRES -> GenreViewHolder.from(parent.context, genreListener)
|
ShowMode.SHOW_GENRES -> GenreViewHolder.from(parent.context, genreListener)
|
||||||
SHOW_ARTISTS -> ArtistViewHolder.from(parent.context, artistListener)
|
ShowMode.SHOW_ARTISTS -> ArtistViewHolder.from(parent.context, artistListener)
|
||||||
SHOW_ALBUMS -> AlbumViewHolder.from(parent.context, albumListener)
|
ShowMode.SHOW_ALBUMS -> AlbumViewHolder.from(parent.context, albumListener)
|
||||||
else -> ArtistViewHolder.from(parent.context, artistListener)
|
else -> ArtistViewHolder.from(parent.context, artistListener)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||||
when (showMode) {
|
when (showMode) {
|
||||||
SHOW_GENRES -> (holder as GenreViewHolder).bind(data[position] as Genre)
|
ShowMode.SHOW_GENRES -> (holder as GenreViewHolder).bind(data[position] as Genre)
|
||||||
SHOW_ARTISTS -> (holder as ArtistViewHolder).bind(data[position] as Artist)
|
ShowMode.SHOW_ARTISTS -> (holder as ArtistViewHolder).bind(data[position] as Artist)
|
||||||
SHOW_ALBUMS -> (holder as AlbumViewHolder).bind(data[position] as Album)
|
ShowMode.SHOW_ALBUMS -> (holder as AlbumViewHolder).bind(data[position] as Album)
|
||||||
|
|
||||||
else -> return
|
else -> return
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ class SearchAdapter(
|
||||||
|
|
||||||
// Create separate listeners for each type, as a BaseModel ClickListener cant be
|
// Create separate listeners for each type, as a BaseModel ClickListener cant be
|
||||||
// casted to a ClickListener of a class that inherits BaseModel.
|
// casted to a ClickListener of a class that inherits BaseModel.
|
||||||
// FIXME: Maybe theres a way for this to be improved?
|
// FIXME: Maybe there's a way for this to be improved?
|
||||||
private val genreListener = ClickListener<Genre> { doOnClick(it) }
|
private val genreListener = ClickListener<Genre> { doOnClick(it) }
|
||||||
private val artistListener = ClickListener<Artist> { doOnClick(it) }
|
private val artistListener = ClickListener<Artist> { doOnClick(it) }
|
||||||
private val albumListener = ClickListener<Album> { doOnClick(it) }
|
private val albumListener = ClickListener<Album> { doOnClick(it) }
|
||||||
|
|
|
@ -8,9 +8,7 @@ import android.text.format.DateUtils
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.databinding.BindingAdapter
|
import androidx.databinding.BindingAdapter
|
||||||
import org.oxycblt.auxio.R
|
import org.oxycblt.auxio.R
|
||||||
import org.oxycblt.auxio.theme.SHOW_ALBUMS
|
import org.oxycblt.auxio.recycler.ShowMode
|
||||||
import org.oxycblt.auxio.theme.SHOW_ARTISTS
|
|
||||||
import org.oxycblt.auxio.theme.SHOW_SONGS
|
|
||||||
|
|
||||||
// List of ID3 genres + Winamp extensions, each index corresponds to their int value.
|
// List of ID3 genres + Winamp extensions, each index corresponds to their int value.
|
||||||
// There are a lot more int-genre extensions as far as Im aware, but this works for most cases.
|
// There are a lot more int-genre extensions as far as Im aware, but this works for most cases.
|
||||||
|
@ -143,6 +141,7 @@ fun TextView.bindAllAlbumDetails(album: Album) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get *less* miscellaneous album information. Please don't confuse this with the above.
|
||||||
@BindingAdapter("albumInfo")
|
@BindingAdapter("albumInfo")
|
||||||
fun TextView.bindAlbumInfo(album: Album) {
|
fun TextView.bindAlbumInfo(album: Album) {
|
||||||
text = context.getString(
|
text = context.getString(
|
||||||
|
@ -160,21 +159,15 @@ fun TextView.bindAlbumDate(album: Album) {
|
||||||
text = album.year.toYear(context)
|
text = album.year.toYear(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
@BindingAdapter("albumSongCount")
|
// Bind the text used by the header item
|
||||||
// Format the amount of songs in an album
|
|
||||||
fun TextView.bindAlbumSongs(album: Album) {
|
|
||||||
text = context.resources.getQuantityString(
|
|
||||||
R.plurals.format_song_count, album.numSongs, album.numSongs
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@BindingAdapter("headerText")
|
@BindingAdapter("headerText")
|
||||||
fun TextView.bindHeaderText(header: Header) {
|
fun TextView.bindHeaderText(header: Header) {
|
||||||
text = context.getString(
|
text = context.getString(
|
||||||
when (header.id.toInt()) {
|
when (header.id) {
|
||||||
SHOW_ARTISTS -> R.string.label_artists
|
ShowMode.SHOW_GENRES.constant -> R.string.label_genres
|
||||||
SHOW_ALBUMS -> R.string.label_albums
|
ShowMode.SHOW_ARTISTS.constant -> R.string.label_artists
|
||||||
SHOW_SONGS -> R.string.label_songs
|
ShowMode.SHOW_ALBUMS.constant -> R.string.label_albums
|
||||||
|
ShowMode.SHOW_SONGS.constant -> R.string.label_songs
|
||||||
|
|
||||||
else -> R.string.label_artists
|
else -> R.string.label_artists
|
||||||
}
|
}
|
||||||
|
|
5
app/src/main/java/org/oxycblt/auxio/recycler/ShowMode.kt
Normal file
5
app/src/main/java/org/oxycblt/auxio/recycler/ShowMode.kt
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
package org.oxycblt.auxio.recycler
|
||||||
|
|
||||||
|
enum class ShowMode(val constant: Long) {
|
||||||
|
SHOW_GENRES(10), SHOW_ARTISTS(11), SHOW_ALBUMS(12), SHOW_SONGS(13);
|
||||||
|
}
|
|
@ -15,7 +15,6 @@ import org.oxycblt.auxio.music.Song
|
||||||
import org.oxycblt.auxio.recycler.ClickListener
|
import org.oxycblt.auxio.recycler.ClickListener
|
||||||
|
|
||||||
// Basic ViewHolders for each music model.
|
// Basic ViewHolders for each music model.
|
||||||
// FIXME: Mode these type signaturs to something sensible.
|
|
||||||
|
|
||||||
class GenreViewHolder private constructor(
|
class GenreViewHolder private constructor(
|
||||||
listener: ClickListener<Genre>,
|
listener: ClickListener<Genre>,
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
package org.oxycblt.auxio.songs
|
package org.oxycblt.auxio.songs
|
||||||
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import org.oxycblt.auxio.databinding.ItemSongBinding
|
|
||||||
import org.oxycblt.auxio.music.Song
|
import org.oxycblt.auxio.music.Song
|
||||||
import org.oxycblt.auxio.recycler.ClickListener
|
import org.oxycblt.auxio.recycler.ClickListener
|
||||||
import org.oxycblt.auxio.recycler.viewholders.BaseViewHolder
|
|
||||||
import org.oxycblt.auxio.recycler.viewholders.SongViewHolder
|
import org.oxycblt.auxio.recycler.viewholders.SongViewHolder
|
||||||
|
|
||||||
class SongAdapter(
|
class SongAdapter(
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
package org.oxycblt.auxio.theme
|
|
||||||
|
|
||||||
// Preference Constants
|
|
||||||
// TODO: Move these to dedicated enum class.
|
|
||||||
const val SHOW_ARTISTS = 0
|
|
||||||
const val SHOW_ALBUMS = 1
|
|
||||||
const val SHOW_GENRES = 2
|
|
||||||
const val SHOW_SONGS = 3
|
|
|
@ -14,6 +14,7 @@
|
||||||
<!-- Label Namespace | Static Labels -->
|
<!-- Label Namespace | Static Labels -->
|
||||||
<string name="label_retry">Retry</string>
|
<string name="label_retry">Retry</string>
|
||||||
<string name="label_grant">Grant</string>
|
<string name="label_grant">Grant</string>
|
||||||
|
<string name="label_genres">Genres</string>
|
||||||
<string name="label_artists">Artists</string>
|
<string name="label_artists">Artists</string>
|
||||||
<string name="label_albums">Albums</string>
|
<string name="label_albums">Albums</string>
|
||||||
<string name="label_songs">Songs</string>
|
<string name="label_songs">Songs</string>
|
||||||
|
|
Loading…
Reference in a new issue