Add architecture document
Add a document describing the high-level auxio architecture.
This commit is contained in:
@@ -15,11 +15,6 @@ import org.oxycblt.auxio.music.Genre
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.settings.SettingsManager
|
||||
|
||||
// SettingsManager is lazy-initted to prevent it from being used before its initialized.
|
||||
private val settingsManager: SettingsManager by lazy {
|
||||
SettingsManager.getInstance()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a bitmap for a song. onDone will be called when the bitmap is loaded.
|
||||
* **Do not use this on the UI elements, instead use the Binding Adapters.**
|
||||
@@ -28,7 +23,7 @@ private val settingsManager: SettingsManager by lazy {
|
||||
* @param onDone What to do with the bitmap when the loading is finished. Bitmap will be null if loading failed/shouldn't occur.
|
||||
*/
|
||||
fun getBitmap(context: Context, song: Song, onDone: (Bitmap?) -> Unit) {
|
||||
if (!settingsManager.showCovers) {
|
||||
if (!SettingsManager.getInstance().showCovers) {
|
||||
onDone(null)
|
||||
|
||||
return
|
||||
@@ -49,12 +44,12 @@ fun getBitmap(context: Context, song: Song, onDone: (Bitmap?) -> Unit) {
|
||||
*/
|
||||
@BindingAdapter("coverArt")
|
||||
fun ImageView.bindCoverArt(song: Song) {
|
||||
if (!settingsManager.showCovers) {
|
||||
if (!SettingsManager.getInstance().showCovers) {
|
||||
setImageResource(R.drawable.ic_song)
|
||||
return
|
||||
}
|
||||
|
||||
val request = getDefaultRequest()
|
||||
val request = newRequest()
|
||||
.doCoverSetup(context, song)
|
||||
.error(R.drawable.ic_song)
|
||||
.build()
|
||||
@@ -67,12 +62,12 @@ fun ImageView.bindCoverArt(song: Song) {
|
||||
*/
|
||||
@BindingAdapter("coverArt")
|
||||
fun ImageView.bindCoverArt(album: Album) {
|
||||
if (!settingsManager.showCovers) {
|
||||
if (!SettingsManager.getInstance().showCovers) {
|
||||
setImageResource(R.drawable.ic_album)
|
||||
return
|
||||
}
|
||||
|
||||
val request = getDefaultRequest()
|
||||
val request = newRequest()
|
||||
.doCoverSetup(context, album)
|
||||
.error(R.drawable.ic_album)
|
||||
.build()
|
||||
@@ -85,10 +80,11 @@ fun ImageView.bindCoverArt(album: Album) {
|
||||
*/
|
||||
@BindingAdapter("artistImage")
|
||||
fun ImageView.bindArtistImage(artist: Artist) {
|
||||
if (!settingsManager.showCovers) {
|
||||
if (!SettingsManager.getInstance().showCovers) {
|
||||
setImageResource(R.drawable.ic_artist)
|
||||
return
|
||||
}
|
||||
|
||||
val request: ImageRequest
|
||||
|
||||
// If there is more than one album, then create a mosaic of them.
|
||||
@@ -101,7 +97,7 @@ fun ImageView.bindArtistImage(artist: Artist) {
|
||||
|
||||
val fetcher = MosaicFetcher(context)
|
||||
|
||||
request = getDefaultRequest()
|
||||
request = newRequest()
|
||||
.data(uris)
|
||||
.fetcher(fetcher)
|
||||
.error(R.drawable.ic_artist)
|
||||
@@ -110,7 +106,7 @@ fun ImageView.bindArtistImage(artist: Artist) {
|
||||
// Otherwise, just get the first cover and use that
|
||||
// If the artist doesn't have any albums [Which happens], then don't even bother with that.
|
||||
if (artist.albums.isNotEmpty()) {
|
||||
request = getDefaultRequest()
|
||||
request = newRequest()
|
||||
.doCoverSetup(context, artist.albums[0])
|
||||
.error(R.drawable.ic_artist)
|
||||
.build()
|
||||
@@ -129,7 +125,7 @@ fun ImageView.bindArtistImage(artist: Artist) {
|
||||
*/
|
||||
@BindingAdapter("genreImage")
|
||||
fun ImageView.bindGenreImage(genre: Genre) {
|
||||
if (!settingsManager.showCovers) {
|
||||
if (!SettingsManager.getInstance().showCovers) {
|
||||
setImageResource(R.drawable.ic_genre)
|
||||
return
|
||||
}
|
||||
@@ -137,21 +133,20 @@ fun ImageView.bindGenreImage(genre: Genre) {
|
||||
val request: ImageRequest
|
||||
val genreCovers = mutableListOf<Uri>()
|
||||
|
||||
genre.songs.groupBy { it.album }.forEach {
|
||||
genreCovers.add(it.key.coverUri)
|
||||
}
|
||||
// Group the genre's songs by their album's cover and add them
|
||||
genre.songs.groupBy { it.album.coverUri }.forEach { genreCovers.add(it.key) }
|
||||
|
||||
if (genreCovers.size >= 4) {
|
||||
val fetcher = MosaicFetcher(context)
|
||||
|
||||
request = getDefaultRequest()
|
||||
request = newRequest()
|
||||
.data(genreCovers.slice(0..3))
|
||||
.fetcher(fetcher)
|
||||
.error(R.drawable.ic_genre)
|
||||
.build()
|
||||
} else {
|
||||
if (genreCovers.isNotEmpty()) {
|
||||
request = getDefaultRequest()
|
||||
request = newRequest()
|
||||
.doCoverSetup(context, genre.songs[0])
|
||||
.error(R.drawable.ic_genre)
|
||||
.build()
|
||||
@@ -170,7 +165,7 @@ fun ImageView.bindGenreImage(genre: Genre) {
|
||||
* @return The same builder that this is applied to
|
||||
*/
|
||||
private fun ImageRequest.Builder.doCoverSetup(context: Context, data: Album): ImageRequest.Builder {
|
||||
if (settingsManager.useQualityCovers) {
|
||||
if (SettingsManager.getInstance().useQualityCovers) {
|
||||
fetcher(QualityCoverFetcher(context))
|
||||
data(data.songs[0])
|
||||
} else {
|
||||
@@ -185,7 +180,7 @@ private fun ImageRequest.Builder.doCoverSetup(context: Context, data: Album): Im
|
||||
* @return The same builder that this is applied to
|
||||
*/
|
||||
private fun ImageRequest.Builder.doCoverSetup(context: Context, data: Song): ImageRequest.Builder {
|
||||
if (settingsManager.useQualityCovers) {
|
||||
if (SettingsManager.getInstance().useQualityCovers) {
|
||||
fetcher(QualityCoverFetcher(context))
|
||||
data(data)
|
||||
} else {
|
||||
@@ -199,6 +194,6 @@ private fun ImageRequest.Builder.doCoverSetup(context: Context, data: Song): Ima
|
||||
* Get the base request used by the above functions
|
||||
* @return The base request
|
||||
*/
|
||||
private fun ImageView.getDefaultRequest(): ImageRequest.Builder {
|
||||
private fun ImageView.newRequest(): ImageRequest.Builder {
|
||||
return ImageRequest.Builder(context).target(this)
|
||||
}
|
||||
|
||||
@@ -24,10 +24,12 @@ class PlaybackStateDatabase(context: Context) :
|
||||
}
|
||||
|
||||
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
db.execSQL("DROP TABLE IF EXISTS $TABLE_NAME_STATE")
|
||||
db.execSQL("DROP TABLE IF EXISTS $TABLE_NAME_QUEUE")
|
||||
db.apply {
|
||||
execSQL("DROP TABLE IF EXISTS $TABLE_NAME_STATE")
|
||||
execSQL("DROP TABLE IF EXISTS $TABLE_NAME_QUEUE")
|
||||
|
||||
onCreate(db)
|
||||
onCreate(this)
|
||||
}
|
||||
}
|
||||
|
||||
// --- DATABASE CONSTRUCTION FUNCTIONS ---
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.oxycblt.auxio.playback.queue
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MotionEvent
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.AsyncListDiffer
|
||||
@@ -19,6 +17,7 @@ import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.recycler.DiffCallback
|
||||
import org.oxycblt.auxio.recycler.viewholders.BaseHolder
|
||||
import org.oxycblt.auxio.recycler.viewholders.HeaderViewHolder
|
||||
import org.oxycblt.auxio.ui.inflater
|
||||
|
||||
/**
|
||||
* The single adapter for both the Next Queue and the User Queue.
|
||||
@@ -52,11 +51,11 @@ class QueueAdapter(
|
||||
HeaderViewHolder.ITEM_TYPE -> HeaderViewHolder.from(parent.context)
|
||||
|
||||
USER_QUEUE_HEADER_ITEM_TYPE -> UserQueueHeaderViewHolder(
|
||||
parent.context, ItemActionHeaderBinding.inflate(LayoutInflater.from(parent.context))
|
||||
ItemActionHeaderBinding.inflate(parent.context.inflater)
|
||||
)
|
||||
|
||||
QUEUE_SONG_ITEM_TYPE -> QueueSongViewHolder(
|
||||
ItemQueueSongBinding.inflate(LayoutInflater.from(parent.context))
|
||||
ItemQueueSongBinding.inflate(parent.context.inflater)
|
||||
)
|
||||
|
||||
else -> error("Someone messed with the ViewHolder item types.")
|
||||
@@ -159,11 +158,11 @@ class QueueAdapter(
|
||||
* ViewHolder for the **user queue header**. Has the clear queue button.
|
||||
*/
|
||||
inner class UserQueueHeaderViewHolder(
|
||||
context: Context, private val binding: ItemActionHeaderBinding
|
||||
private val binding: ItemActionHeaderBinding
|
||||
) : BaseHolder<Header>(binding) {
|
||||
|
||||
init {
|
||||
binding.headerButton.contentDescription = context.getString(
|
||||
binding.headerButton.contentDescription = binding.headerButton.context.getString(
|
||||
R.string.description_clear_user_queue
|
||||
)
|
||||
}
|
||||
|
||||
@@ -352,15 +352,15 @@ class PlaybackStateManager private constructor() {
|
||||
* @param to The destination index.
|
||||
*/
|
||||
fun moveQueueItems(from: Int, to: Int): Boolean {
|
||||
try {
|
||||
val item = mQueue.removeAt(from)
|
||||
mQueue.add(to, item)
|
||||
} catch (exception: IndexOutOfBoundsException) {
|
||||
if (from > mUserQueue.size || from < 0 || to > mUserQueue.size || to < 0) {
|
||||
logE("Indices were out of bounds, did not move queue item")
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
val item = mQueue.removeAt(from)
|
||||
mQueue.add(to, item)
|
||||
|
||||
forceQueueUpdate()
|
||||
|
||||
return true
|
||||
@@ -411,15 +411,15 @@ class PlaybackStateManager private constructor() {
|
||||
* @param to The destination index.
|
||||
*/
|
||||
fun moveUserQueueItems(from: Int, to: Int) {
|
||||
try {
|
||||
val item = mUserQueue.removeAt(from)
|
||||
mUserQueue.add(to, item)
|
||||
} catch (exception: IndexOutOfBoundsException) {
|
||||
if (from > mUserQueue.size || from < 0 || to > mUserQueue.size || to < 0) {
|
||||
logE("Indices were out of bounds, did not move queue item")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
val item = mUserQueue.removeAt(from)
|
||||
mUserQueue.add(to, item)
|
||||
|
||||
forceUserQueueUpdate()
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import android.content.res.ColorStateList
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.os.Build
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -23,6 +22,7 @@ import com.reddit.indicatorfastscroll.FastScrollItemIndicator
|
||||
import com.reddit.indicatorfastscroll.FastScrollerView
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.ui.Accent
|
||||
import org.oxycblt.auxio.ui.inflater
|
||||
import org.oxycblt.auxio.ui.toColor
|
||||
|
||||
/**
|
||||
@@ -56,9 +56,7 @@ class NoLeakThumbView @JvmOverloads constructor(
|
||||
|
||||
init {
|
||||
// --- VIEW SETUP ---
|
||||
LayoutInflater.from(context).inflate(
|
||||
R.layout.fast_scroller_thumb_view, this, true
|
||||
)
|
||||
context.inflater.inflate(R.layout.fast_scroller_thumb_view, this, true)
|
||||
|
||||
thumbView = findViewById(R.id.fast_scroller_thumb)
|
||||
textView = thumbView.findViewById(R.id.fast_scroller_thumb_text)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.oxycblt.auxio.recycler.viewholders
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import org.oxycblt.auxio.databinding.ItemAlbumBinding
|
||||
import org.oxycblt.auxio.databinding.ItemArtistBinding
|
||||
@@ -13,6 +12,7 @@ import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.Genre
|
||||
import org.oxycblt.auxio.music.Header
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.ui.inflater
|
||||
|
||||
/*
|
||||
* A table of all ViewHolder codes. Please add to these so that all viewholder codes are unique.
|
||||
@@ -59,7 +59,7 @@ class SongViewHolder private constructor(
|
||||
doOnLongClick: (view: View, data: Song) -> Unit
|
||||
): SongViewHolder {
|
||||
return SongViewHolder(
|
||||
ItemSongBinding.inflate(LayoutInflater.from(context)),
|
||||
ItemSongBinding.inflate(context.inflater),
|
||||
doOnClick, doOnLongClick
|
||||
)
|
||||
}
|
||||
@@ -92,7 +92,7 @@ class AlbumViewHolder private constructor(
|
||||
doOnLongClick: (view: View, data: Album) -> Unit
|
||||
): AlbumViewHolder {
|
||||
return AlbumViewHolder(
|
||||
ItemAlbumBinding.inflate(LayoutInflater.from(context)),
|
||||
ItemAlbumBinding.inflate(context.inflater),
|
||||
doOnClick, doOnLongClick
|
||||
)
|
||||
}
|
||||
@@ -125,7 +125,7 @@ class ArtistViewHolder private constructor(
|
||||
doOnLongClick: (view: View, data: Artist) -> Unit
|
||||
): ArtistViewHolder {
|
||||
return ArtistViewHolder(
|
||||
ItemArtistBinding.inflate(LayoutInflater.from(context)),
|
||||
ItemArtistBinding.inflate(context.inflater),
|
||||
doOnClick, doOnLongClick
|
||||
)
|
||||
}
|
||||
@@ -158,7 +158,7 @@ class GenreViewHolder private constructor(
|
||||
doOnLongClick: (view: View, data: Genre) -> Unit
|
||||
): GenreViewHolder {
|
||||
return GenreViewHolder(
|
||||
ItemGenreBinding.inflate(LayoutInflater.from(context)),
|
||||
ItemGenreBinding.inflate(context.inflater),
|
||||
doOnClick, doOnLongClick
|
||||
)
|
||||
}
|
||||
@@ -182,7 +182,7 @@ class HeaderViewHolder(private val binding: ItemHeaderBinding) : BaseHolder<Head
|
||||
*/
|
||||
fun from(context: Context): HeaderViewHolder {
|
||||
return HeaderViewHolder(
|
||||
ItemHeaderBinding.inflate(LayoutInflater.from(context))
|
||||
ItemHeaderBinding.inflate(context.inflater)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package org.oxycblt.auxio.settings.ui
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.ItemAccentBinding
|
||||
import org.oxycblt.auxio.ui.ACCENTS
|
||||
import org.oxycblt.auxio.ui.Accent
|
||||
import org.oxycblt.auxio.ui.inflater
|
||||
import org.oxycblt.auxio.ui.toStateList
|
||||
|
||||
/**
|
||||
@@ -20,7 +20,7 @@ class AccentAdapter(
|
||||
override fun getItemCount(): Int = ACCENTS.size
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return ViewHolder(ItemAccentBinding.inflate(LayoutInflater.from(parent.context)))
|
||||
return ViewHolder(ItemAccentBinding.inflate(parent.context.inflater))
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
|
||||
@@ -45,11 +45,7 @@ val ACCENTS = arrayOf(
|
||||
* @property theme The theme resource for this accent
|
||||
* @property name The name of this accent
|
||||
*/
|
||||
data class Accent(
|
||||
@ColorRes val color: Int,
|
||||
@StyleRes val theme: Int,
|
||||
@StringRes val name: Int
|
||||
) {
|
||||
data class Accent(@ColorRes val color: Int, @StyleRes val theme: Int, @StringRes val name: Int) {
|
||||
/**
|
||||
* Get a [ColorStateList] of the accent
|
||||
*/
|
||||
|
||||
@@ -78,7 +78,6 @@ fun Context.getPlural(@PluralsRes pluralsRes: Int, value: Int): String {
|
||||
*/
|
||||
val Context.inflater: LayoutInflater get() = LayoutInflater.from(this)
|
||||
|
||||
|
||||
/**
|
||||
* Create a [Toast] from a [String]
|
||||
* @param context [Context] required to create the toast
|
||||
|
||||
@@ -59,7 +59,7 @@ class MemberBinder<T : ViewDataBinding>(
|
||||
}
|
||||
|
||||
// Otherwise create the binding and return that.
|
||||
return inflate(LayoutInflater.from(thisRef.requireContext())).also {
|
||||
return inflate(thisRef.requireContext().inflater).also {
|
||||
fragmentBinding = it
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user