music: rename BaseModel to Item
Rename BaseModel to Item to make the meaning of it clearer.
This commit is contained in:
parent
3aaa2ab0e0
commit
35b75b5f81
13 changed files with 60 additions and 55 deletions
|
@ -11,6 +11,7 @@
|
|||
#### Dev/Meta
|
||||
- Enabled elevation drop shadows below Android P for consistency
|
||||
- Reworked dynamic color usage
|
||||
- Reworked logging
|
||||
|
||||
## v2.2.1
|
||||
#### What's Improved
|
||||
|
|
|
@ -26,9 +26,9 @@ import org.oxycblt.auxio.R
|
|||
import org.oxycblt.auxio.music.ActionHeader
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.BaseModel
|
||||
import org.oxycblt.auxio.music.Genre
|
||||
import org.oxycblt.auxio.music.Header
|
||||
import org.oxycblt.auxio.music.Item
|
||||
import org.oxycblt.auxio.music.MusicStore
|
||||
import org.oxycblt.auxio.settings.SettingsManager
|
||||
import org.oxycblt.auxio.ui.DisplayMode
|
||||
|
@ -49,30 +49,30 @@ class DetailViewModel : ViewModel() {
|
|||
private val mCurGenre = MutableLiveData<Genre?>()
|
||||
val curGenre: LiveData<Genre?> get() = mCurGenre
|
||||
|
||||
private val mGenreData = MutableLiveData(listOf<BaseModel>())
|
||||
val genreData: LiveData<List<BaseModel>> = mGenreData
|
||||
private val mGenreData = MutableLiveData(listOf<Item>())
|
||||
val genreData: LiveData<List<Item>> = mGenreData
|
||||
|
||||
private val mCurArtist = MutableLiveData<Artist?>()
|
||||
val curArtist: LiveData<Artist?> get() = mCurArtist
|
||||
|
||||
private val mArtistData = MutableLiveData(listOf<BaseModel>())
|
||||
val artistData: LiveData<List<BaseModel>> = mArtistData
|
||||
private val mArtistData = MutableLiveData(listOf<Item>())
|
||||
val artistData: LiveData<List<Item>> = mArtistData
|
||||
|
||||
private val mCurAlbum = MutableLiveData<Album?>()
|
||||
val curAlbum: LiveData<Album?> get() = mCurAlbum
|
||||
|
||||
private val mAlbumData = MutableLiveData(listOf<BaseModel>())
|
||||
val albumData: LiveData<List<BaseModel>> get() = mAlbumData
|
||||
private val mAlbumData = MutableLiveData(listOf<Item>())
|
||||
val albumData: LiveData<List<Item>> get() = mAlbumData
|
||||
|
||||
data class MenuConfig(val anchor: View, val sortMode: Sort)
|
||||
|
||||
private val mShowMenu = MutableLiveData<MenuConfig?>(null)
|
||||
val showMenu: LiveData<MenuConfig?> = mShowMenu
|
||||
|
||||
private val mNavToItem = MutableLiveData<BaseModel?>()
|
||||
private val mNavToItem = MutableLiveData<Item?>()
|
||||
|
||||
/** Flag for unified navigation. Observe this to coordinate navigation to an item's UI. */
|
||||
val navToItem: LiveData<BaseModel?> get() = mNavToItem
|
||||
val navToItem: LiveData<Item?> get() = mNavToItem
|
||||
|
||||
var isNavigating = false
|
||||
private set
|
||||
|
@ -133,7 +133,7 @@ class DetailViewModel : ViewModel() {
|
|||
/**
|
||||
* Navigate to an item, whether a song/album/artist
|
||||
*/
|
||||
fun navToItem(item: BaseModel) {
|
||||
fun navToItem(item: Item) {
|
||||
mNavToItem.value = item
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,7 @@ class DetailViewModel : ViewModel() {
|
|||
private fun refreshGenreData() {
|
||||
logD("Refreshing genre data")
|
||||
val genre = requireNotNull(curGenre.value)
|
||||
val data = mutableListOf<BaseModel>(genre)
|
||||
val data = mutableListOf<Item>(genre)
|
||||
|
||||
data.add(
|
||||
ActionHeader(
|
||||
|
@ -177,7 +177,7 @@ class DetailViewModel : ViewModel() {
|
|||
private fun refreshArtistData() {
|
||||
logD("Refreshing artist data")
|
||||
val artist = requireNotNull(curArtist.value)
|
||||
val data = mutableListOf<BaseModel>(artist)
|
||||
val data = mutableListOf<Item>(artist)
|
||||
|
||||
data.add(
|
||||
Header(
|
||||
|
@ -209,7 +209,7 @@ class DetailViewModel : ViewModel() {
|
|||
private fun refreshAlbumData() {
|
||||
logD("Refreshing album data")
|
||||
val album = requireNotNull(curAlbum.value)
|
||||
val data = mutableListOf<BaseModel>(album)
|
||||
val data = mutableListOf<Item>(album)
|
||||
|
||||
data.add(
|
||||
ActionHeader(
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.oxycblt.auxio.databinding.ItemDetailBinding
|
|||
import org.oxycblt.auxio.detail.DetailViewModel
|
||||
import org.oxycblt.auxio.music.ActionHeader
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.BaseModel
|
||||
import org.oxycblt.auxio.music.Item
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.music.toDate
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
|
@ -49,7 +49,7 @@ class AlbumDetailAdapter(
|
|||
private val detailModel: DetailViewModel,
|
||||
private val doOnClick: (data: Song) -> Unit,
|
||||
private val doOnLongClick: (view: View, data: Song) -> Unit
|
||||
) : ListAdapter<BaseModel, RecyclerView.ViewHolder>(DiffCallback()) {
|
||||
) : ListAdapter<Item, RecyclerView.ViewHolder>(DiffCallback()) {
|
||||
private var currentSong: Song? = null
|
||||
private var currentHolder: Highlightable? = null
|
||||
|
||||
|
|
|
@ -30,8 +30,8 @@ import org.oxycblt.auxio.databinding.ItemDetailBinding
|
|||
import org.oxycblt.auxio.music.ActionHeader
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.BaseModel
|
||||
import org.oxycblt.auxio.music.Header
|
||||
import org.oxycblt.auxio.music.Item
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.music.bindArtistInfo
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
|
@ -49,8 +49,8 @@ class ArtistDetailAdapter(
|
|||
private val playbackModel: PlaybackViewModel,
|
||||
private val doOnClick: (data: Album) -> Unit,
|
||||
private val doOnSongClick: (data: Song) -> Unit,
|
||||
private val doOnLongClick: (view: View, data: BaseModel) -> Unit,
|
||||
) : ListAdapter<BaseModel, RecyclerView.ViewHolder>(DiffCallback()) {
|
||||
private val doOnLongClick: (view: View, data: Item) -> Unit,
|
||||
) : ListAdapter<Item, RecyclerView.ViewHolder>(DiffCallback()) {
|
||||
private var currentAlbum: Album? = null
|
||||
private var currentAlbumHolder: Highlightable? = null
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ import org.oxycblt.auxio.coil.bindGenreImage
|
|||
import org.oxycblt.auxio.databinding.ItemDetailBinding
|
||||
import org.oxycblt.auxio.databinding.ItemGenreSongBinding
|
||||
import org.oxycblt.auxio.music.ActionHeader
|
||||
import org.oxycblt.auxio.music.BaseModel
|
||||
import org.oxycblt.auxio.music.Genre
|
||||
import org.oxycblt.auxio.music.Item
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.music.bindGenreInfo
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
|
@ -45,7 +45,7 @@ class GenreDetailAdapter(
|
|||
private val playbackModel: PlaybackViewModel,
|
||||
private val doOnClick: (data: Song) -> Unit,
|
||||
private val doOnLongClick: (view: View, data: Song) -> Unit
|
||||
) : ListAdapter<BaseModel, RecyclerView.ViewHolder>(DiffCallback()) {
|
||||
) : ListAdapter<Item, RecyclerView.ViewHolder>(DiffCallback()) {
|
||||
private var currentSong: Song? = null
|
||||
private var currentHolder: Highlightable? = null
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import androidx.lifecycle.LiveData
|
|||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.databinding.FragmentHomeListBinding
|
||||
import org.oxycblt.auxio.home.HomeViewModel
|
||||
import org.oxycblt.auxio.music.BaseModel
|
||||
import org.oxycblt.auxio.music.Item
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.ui.memberBinding
|
||||
import org.oxycblt.auxio.util.applySpans
|
||||
|
@ -48,7 +48,7 @@ abstract class HomeListFragment : Fragment() {
|
|||
*/
|
||||
abstract val listPopupProvider: (Int) -> String
|
||||
|
||||
protected fun <T : BaseModel, VH : RecyclerView.ViewHolder> setupRecycler(
|
||||
protected fun <T : Item, VH : RecyclerView.ViewHolder> setupRecycler(
|
||||
@IdRes uniqueId: Int,
|
||||
homeAdapter: HomeAdapter<T, VH>,
|
||||
homeData: LiveData<List<T>>,
|
||||
|
@ -71,7 +71,7 @@ abstract class HomeListFragment : Fragment() {
|
|||
}
|
||||
}
|
||||
|
||||
abstract class HomeAdapter<T : BaseModel, VH : RecyclerView.ViewHolder> : RecyclerView.Adapter<VH>() {
|
||||
abstract class HomeAdapter<T : Item, VH : RecyclerView.ViewHolder> : RecyclerView.Adapter<VH>() {
|
||||
protected var data = listOf<T>()
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
|
|
|
@ -28,33 +28,37 @@ import androidx.annotation.StringRes
|
|||
// --- MUSIC MODELS ---
|
||||
|
||||
/**
|
||||
* The base data object for all music.
|
||||
* @property id A unique ID for this object. ***THIS IS NOT A MEDIASTORE ID!**
|
||||
* The template for all items in Auxio.
|
||||
*/
|
||||
sealed class BaseModel {
|
||||
sealed class Item {
|
||||
/** A unique ID for this item. ***THIS IS NOT A MEDIASTORE ID!** */
|
||||
abstract val id: Long
|
||||
}
|
||||
|
||||
/**
|
||||
* A [BaseModel] variant that represents a music item.
|
||||
* @property name The raw name of this track
|
||||
* A [Item] variant that represents a music item.
|
||||
* @property name
|
||||
*/
|
||||
sealed class Music : BaseModel() {
|
||||
sealed class Music : Item() {
|
||||
/** The raw name of this item. */
|
||||
abstract val name: String
|
||||
}
|
||||
|
||||
/**
|
||||
* [Music] variant that denotes that this object is a parent of other data objects, such
|
||||
* as an [Album] or [Artist]
|
||||
* @property resolvedName A name resolved from it's raw form to a form suitable to be shown in
|
||||
* a ui. Ex. "unknown" would become Unknown Artist, (124) would become its proper genre name, etc.
|
||||
* @property resolvedName
|
||||
*/
|
||||
sealed class MusicParent : Music() {
|
||||
/**
|
||||
* A name resolved from it's raw form to a form suitable to be shown in a ui.
|
||||
* Ex. "unknown" would become Unknown Artist, (124) would become its proper genre name, etc.
|
||||
*/
|
||||
abstract val resolvedName: String
|
||||
}
|
||||
|
||||
/**
|
||||
* The data object for a song. Inherits [BaseModel].
|
||||
* The data object for a song. Inherits [Item].
|
||||
*/
|
||||
data class Song(
|
||||
override val name: String,
|
||||
|
@ -243,7 +247,7 @@ data class Header(
|
|||
override val id: Long,
|
||||
/** The string resource used for the header. */
|
||||
@StringRes val string: Int
|
||||
) : BaseModel()
|
||||
) : Item()
|
||||
|
||||
/**
|
||||
* A data object used for an action header. Like [Header], but with a button.
|
||||
|
@ -259,7 +263,7 @@ data class ActionHeader(
|
|||
@StringRes val desc: Int,
|
||||
/** A callback for when this item is clicked. */
|
||||
val onClick: (View) -> Unit,
|
||||
) : BaseModel() {
|
||||
) : Item() {
|
||||
// All lambdas are not equal to each-other, so we override equals/hashCode and exclude them.
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
|
|
|
@ -30,8 +30,8 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import com.google.android.material.shape.MaterialShapeDrawable
|
||||
import org.oxycblt.auxio.databinding.ItemQueueSongBinding
|
||||
import org.oxycblt.auxio.music.ActionHeader
|
||||
import org.oxycblt.auxio.music.BaseModel
|
||||
import org.oxycblt.auxio.music.Header
|
||||
import org.oxycblt.auxio.music.Item
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.ui.ActionHeaderViewHolder
|
||||
import org.oxycblt.auxio.ui.BaseViewHolder
|
||||
|
@ -50,7 +50,7 @@ import org.oxycblt.auxio.util.stateList
|
|||
class QueueAdapter(
|
||||
private val touchHelper: ItemTouchHelper
|
||||
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
private var data = mutableListOf<BaseModel>()
|
||||
private var data = mutableListOf<Item>()
|
||||
private var listDiffer = AsyncListDiffer(this, DiffCallback())
|
||||
|
||||
override fun getItemCount(): Int = data.size
|
||||
|
@ -89,7 +89,7 @@ class QueueAdapter(
|
|||
* Submit data using [AsyncListDiffer].
|
||||
* **Only use this if you have no idea what changes occurred to the data**
|
||||
*/
|
||||
fun submitList(newData: MutableList<BaseModel>) {
|
||||
fun submitList(newData: MutableList<Item>) {
|
||||
if (data != newData) {
|
||||
data = newData
|
||||
listDiffer.submitList(newData)
|
||||
|
|
|
@ -24,9 +24,9 @@ import androidx.recyclerview.widget.ListAdapter
|
|||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.BaseModel
|
||||
import org.oxycblt.auxio.music.Genre
|
||||
import org.oxycblt.auxio.music.Header
|
||||
import org.oxycblt.auxio.music.Item
|
||||
import org.oxycblt.auxio.music.Music
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.ui.AlbumViewHolder
|
||||
|
@ -43,7 +43,7 @@ import org.oxycblt.auxio.ui.SongViewHolder
|
|||
class SearchAdapter(
|
||||
private val doOnClick: (data: Music) -> Unit,
|
||||
private val doOnLongClick: (view: View, data: Music) -> Unit
|
||||
) : ListAdapter<BaseModel, RecyclerView.ViewHolder>(DiffCallback<BaseModel>()) {
|
||||
) : ListAdapter<Item, RecyclerView.ViewHolder>(DiffCallback<Item>()) {
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return when (getItem(position)) {
|
||||
|
|
|
@ -25,8 +25,8 @@ import androidx.lifecycle.ViewModel
|
|||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.launch
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.music.BaseModel
|
||||
import org.oxycblt.auxio.music.Header
|
||||
import org.oxycblt.auxio.music.Item
|
||||
import org.oxycblt.auxio.music.Music
|
||||
import org.oxycblt.auxio.music.MusicParent
|
||||
import org.oxycblt.auxio.music.MusicStore
|
||||
|
@ -41,13 +41,13 @@ import java.text.Normalizer
|
|||
* @author OxygenCobalt
|
||||
*/
|
||||
class SearchViewModel : ViewModel() {
|
||||
private val mSearchResults = MutableLiveData(listOf<BaseModel>())
|
||||
private val mSearchResults = MutableLiveData(listOf<Item>())
|
||||
private var mIsNavigating = false
|
||||
private var mFilterMode: DisplayMode? = null
|
||||
private var mLastQuery = ""
|
||||
|
||||
/** Current search results from the last [search] call. */
|
||||
val searchResults: LiveData<List<BaseModel>> get() = mSearchResults
|
||||
val searchResults: LiveData<List<Item>> get() = mSearchResults
|
||||
val isNavigating: Boolean get() = mIsNavigating
|
||||
val filterMode: DisplayMode? get() = mFilterMode
|
||||
|
||||
|
@ -81,7 +81,7 @@ class SearchViewModel : ViewModel() {
|
|||
// Searching can be quite expensive, so get on a co-routine
|
||||
viewModelScope.launch {
|
||||
val sort = Sort.ByName(true)
|
||||
val results = mutableListOf<BaseModel>()
|
||||
val results = mutableListOf<Item>()
|
||||
|
||||
// Note: a filter mode of null means to not filter at all.
|
||||
|
||||
|
|
|
@ -30,8 +30,8 @@ import org.oxycblt.auxio.R
|
|||
import org.oxycblt.auxio.detail.DetailViewModel
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.BaseModel
|
||||
import org.oxycblt.auxio.music.Genre
|
||||
import org.oxycblt.auxio.music.Item
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.util.showToast
|
||||
|
@ -39,11 +39,11 @@ import org.oxycblt.auxio.util.showToast
|
|||
/**
|
||||
* Extension method for creating and showing a new [ActionMenu].
|
||||
* @param anchor [View] This should be centered around
|
||||
* @param data [BaseModel] this menu corresponds to
|
||||
* @param data [Item] this menu corresponds to
|
||||
* @param flag (Optional, defaults to [ActionMenu.FLAG_NONE]) Any extra flags to accompany the data.
|
||||
* @see ActionMenu
|
||||
*/
|
||||
fun Fragment.newMenu(anchor: View, data: BaseModel, flag: Int = ActionMenu.FLAG_NONE) {
|
||||
fun Fragment.newMenu(anchor: View, data: Item, flag: Int = ActionMenu.FLAG_NONE) {
|
||||
ActionMenu(requireActivity() as AppCompatActivity, anchor, data, flag).show()
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ fun Fragment.newMenu(anchor: View, data: BaseModel, flag: Int = ActionMenu.FLAG_
|
|||
* A wrapper around [PopupMenu] that automates the menu creation for nearly every datatype in Auxio.
|
||||
* @param activity [AppCompatActivity] required as both a context and ViewModelStore owner.
|
||||
* @param anchor [View] This should be centered around
|
||||
* @param data [BaseModel] this menu corresponds to
|
||||
* @param data [Item] this menu corresponds to
|
||||
* @param flag Any extra flags to accompany the data. See [FLAG_NONE], [FLAG_IN_ALBUM], [FLAG_IN_ARTIST], [FLAG_IN_GENRE] for more details.
|
||||
* @throws IllegalStateException When there is no menu for this specific datatype/flag
|
||||
* @author OxygenCobalt
|
||||
|
@ -59,7 +59,7 @@ fun Fragment.newMenu(anchor: View, data: BaseModel, flag: Int = ActionMenu.FLAG_
|
|||
class ActionMenu(
|
||||
activity: AppCompatActivity,
|
||||
anchor: View,
|
||||
private val data: BaseModel,
|
||||
private val data: Item,
|
||||
private val flag: Int
|
||||
) : PopupMenu(activity, anchor) {
|
||||
private val context = activity.applicationContext
|
||||
|
|
|
@ -19,14 +19,14 @@
|
|||
package org.oxycblt.auxio.ui
|
||||
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import org.oxycblt.auxio.music.BaseModel
|
||||
import org.oxycblt.auxio.music.Item
|
||||
|
||||
/**
|
||||
* A re-usable diff callback for all [BaseModel] implementations.
|
||||
* A re-usable diff callback for all [Item] implementations.
|
||||
* **Use this instead of creating a DiffCallback for each adapter.**
|
||||
* @author OxygenCobalt
|
||||
*/
|
||||
class DiffCallback<T : BaseModel> : DiffUtil.ItemCallback<T>() {
|
||||
class DiffCallback<T : Item> : DiffUtil.ItemCallback<T>() {
|
||||
override fun areContentsTheSame(oldItem: T, newItem: T): Boolean {
|
||||
return oldItem.hashCode() == newItem.hashCode()
|
||||
}
|
||||
|
|
|
@ -32,21 +32,21 @@ import org.oxycblt.auxio.databinding.ItemSongBinding
|
|||
import org.oxycblt.auxio.music.ActionHeader
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.BaseModel
|
||||
import org.oxycblt.auxio.music.Genre
|
||||
import org.oxycblt.auxio.music.Header
|
||||
import org.oxycblt.auxio.music.Item
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.util.inflater
|
||||
|
||||
/**
|
||||
* A [RecyclerView.ViewHolder] that streamlines a lot of the common things across all viewholders.
|
||||
* @param T The datatype, inheriting [BaseModel] for this ViewHolder.
|
||||
* @param T The datatype, inheriting [Item] for this ViewHolder.
|
||||
* @param binding Basic [ViewDataBinding] required to set up click listeners & sizing.
|
||||
* @param doOnClick (Optional) Function that calls on a click.
|
||||
* @param doOnLongClick (Optional) Functions that calls on a long-click.
|
||||
* @author OxygenCobalt
|
||||
*/
|
||||
abstract class BaseViewHolder<T : BaseModel>(
|
||||
abstract class BaseViewHolder<T : Item>(
|
||||
private val binding: ViewDataBinding,
|
||||
private val doOnClick: ((data: T) -> Unit)? = null,
|
||||
private val doOnLongClick: ((view: View, data: T) -> Unit)? = null
|
||||
|
@ -59,7 +59,7 @@ abstract class BaseViewHolder<T : BaseModel>(
|
|||
}
|
||||
|
||||
/**
|
||||
* Bind the viewholder with whatever [BaseModel] instance that has been specified.
|
||||
* Bind the viewholder with whatever [Item] instance that has been specified.
|
||||
* Will call [onBind] on the inheriting ViewHolder.
|
||||
* @param data Data that the viewholder should be bound with
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue