all: remove databinding
Remove databinding entirely. Databinding was a terrible idea for Auxio. I rarely leveraged it, and when I did, it produced messy code and bloated build times. Dumpster it for just viewbinding, which is good. This reduces building times by nearly 2/3, and generally makes the codebase more coherent and usable.
This commit is contained in:
@@ -26,8 +26,6 @@ import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import org.oxycblt.auxio.databinding.ActivityMainBinding
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.playback.system.PlaybackService
|
||||
@@ -54,10 +52,9 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
setupTheme()
|
||||
|
||||
val binding =
|
||||
DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main)
|
||||
|
||||
applyEdgeToEdgeWindow(binding)
|
||||
val binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
applyEdgeToEdgeWindow(binding.root)
|
||||
|
||||
logD("Activity created")
|
||||
}
|
||||
@@ -114,7 +111,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun applyEdgeToEdgeWindow(binding: ViewBinding) {
|
||||
private fun applyEdgeToEdgeWindow(contentView: View) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
logD("Doing R+ edge-to-edge")
|
||||
|
||||
@@ -124,7 +121,7 @@ class MainActivity : AppCompatActivity() {
|
||||
// the R+ SDK decides to make you specify the insets yourself with a barely
|
||||
// documented API that isn't even mentioned in any of the edge-to-edge
|
||||
// tutorials. Thanks android, very cool!
|
||||
binding.root.setOnApplyWindowInsetsListener { _, insets ->
|
||||
contentView.setOnApplyWindowInsetsListener { view, insets ->
|
||||
WindowInsets.Builder()
|
||||
.setInsets(
|
||||
WindowInsets.Type.systemBars(),
|
||||
@@ -133,27 +130,25 @@ class MainActivity : AppCompatActivity() {
|
||||
WindowInsets.Type.systemGestures(),
|
||||
insets.getInsetsIgnoringVisibility(WindowInsets.Type.systemGestures()))
|
||||
.build()
|
||||
.applyLeftRightInsets(binding)
|
||||
.applyLeftRightInsets(view)
|
||||
}
|
||||
} else {
|
||||
// Do old edge-to-edge otherwise.
|
||||
logD("Doing legacy edge-to-edge")
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
binding.root.apply {
|
||||
contentView.apply {
|
||||
systemUiVisibility =
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
|
||||
setOnApplyWindowInsetsListener { _, insets -> insets.applyLeftRightInsets(binding) }
|
||||
setOnApplyWindowInsetsListener { view, insets -> insets.applyLeftRightInsets(view) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun WindowInsets.applyLeftRightInsets(binding: ViewBinding): WindowInsets {
|
||||
private fun WindowInsets.applyLeftRightInsets(contentView: View): WindowInsets {
|
||||
val bars = systemBarInsetsCompat
|
||||
|
||||
binding.root.updatePadding(left = bars.left, right = bars.right)
|
||||
|
||||
contentView.updatePadding(left = bars.left, right = bars.right)
|
||||
return replaceSystemBarInsetsCompat(0, bars.top, 0, bars.bottom)
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import android.widget.ImageView
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import androidx.databinding.BindingAdapter
|
||||
import coil.dispose
|
||||
import coil.imageLoader
|
||||
import coil.load
|
||||
@@ -39,28 +38,25 @@ import org.oxycblt.auxio.music.Song
|
||||
// --- BINDING ADAPTERS ---
|
||||
|
||||
/** Bind the album cover for a [song]. */
|
||||
@BindingAdapter("albumArt")
|
||||
fun ImageView.bindAlbumCover(song: Song?) =
|
||||
fun ImageView.applyAlbumCover(song: Song?) =
|
||||
load(song, R.drawable.ic_album, R.string.desc_album_cover)
|
||||
|
||||
/** Bind the album cover for an [album]. */
|
||||
@BindingAdapter("albumArt")
|
||||
fun ImageView.bindAlbumCover(album: Album?) =
|
||||
fun ImageView.applyAlbumCover(album: Album?) =
|
||||
load(album, R.drawable.ic_album, R.string.desc_album_cover)
|
||||
|
||||
/** Bind the image for an [artist] */
|
||||
@BindingAdapter("artistImage")
|
||||
fun ImageView.bindArtistImage(artist: Artist?) =
|
||||
fun ImageView.applyArtistImage(artist: Artist?) =
|
||||
load(artist, R.drawable.ic_artist, R.string.desc_artist_image)
|
||||
|
||||
/** Bind the image for a [genre] */
|
||||
@BindingAdapter("genreImage")
|
||||
fun ImageView.bindGenreImage(genre: Genre?) =
|
||||
fun ImageView.applyGenreImage(genre: Genre?) =
|
||||
load(genre, R.drawable.ic_genre, R.string.desc_genre_image)
|
||||
|
||||
fun <T : Music> ImageView.load(music: T?, @DrawableRes error: Int, @StringRes desc: Int) {
|
||||
contentDescription = context.getString(desc, music?.resolvedName)
|
||||
dispose()
|
||||
scaleType = ImageView.ScaleType.FIT_CENTER
|
||||
load(music) {
|
||||
error(error)
|
||||
transformations(SquareFrameTransform.INSTANCE)
|
||||
|
||||
@@ -24,7 +24,7 @@ import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.IntegerTable
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.coil.bindAlbumCover
|
||||
import org.oxycblt.auxio.coil.applyAlbumCover
|
||||
import org.oxycblt.auxio.databinding.ItemAlbumSongBinding
|
||||
import org.oxycblt.auxio.databinding.ItemDetailBinding
|
||||
import org.oxycblt.auxio.detail.DetailViewModel
|
||||
@@ -32,12 +32,14 @@ import org.oxycblt.auxio.music.ActionHeader
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Item
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.music.toDuration
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.ui.ActionHeaderViewHolder
|
||||
import org.oxycblt.auxio.ui.BaseViewHolder
|
||||
import org.oxycblt.auxio.ui.DiffCallback
|
||||
import org.oxycblt.auxio.util.getPluralSafe
|
||||
import org.oxycblt.auxio.util.inflater
|
||||
import org.oxycblt.auxio.util.textSafe
|
||||
|
||||
/**
|
||||
* An adapter for displaying the details and [Song]s of an [Album]
|
||||
@@ -127,14 +129,14 @@ class AlbumDetailAdapter(
|
||||
|
||||
override fun onBind(data: Album) {
|
||||
binding.detailCover.apply {
|
||||
bindAlbumCover(data)
|
||||
applyAlbumCover(data)
|
||||
contentDescription = context.getString(R.string.desc_album_cover, data.resolvedName)
|
||||
}
|
||||
|
||||
binding.detailName.text = data.resolvedName
|
||||
binding.detailName.textSafe = data.resolvedName
|
||||
|
||||
binding.detailSubhead.apply {
|
||||
text = data.artist.resolvedName
|
||||
textSafe = data.artist.resolvedName
|
||||
setOnClickListener { detailModel.navToItem(data.artist) }
|
||||
}
|
||||
|
||||
@@ -157,14 +159,25 @@ class AlbumDetailAdapter(
|
||||
private val binding: ItemAlbumSongBinding,
|
||||
) : BaseViewHolder<Song>(binding, doOnClick, doOnLongClick), Highlightable {
|
||||
override fun onBind(data: Song) {
|
||||
binding.song = data
|
||||
binding.songName.requestLayout()
|
||||
// Hide the track number view if the song does not have a track.
|
||||
if (data.track != null) {
|
||||
binding.songTrack.apply {
|
||||
textSafe = context.getString(R.string.fmt_number, data.track)
|
||||
isInvisible = false
|
||||
}
|
||||
|
||||
// Hide the track number view if the track is zero, as generally a track number of
|
||||
// zero implies that the song does not have a track number.
|
||||
val usePlaceholder = data.track == null
|
||||
binding.songTrack.isInvisible = usePlaceholder
|
||||
binding.songTrackPlaceholder.isInvisible = !usePlaceholder
|
||||
binding.songTrackPlaceholder.isInvisible = true
|
||||
} else {
|
||||
binding.songTrack.apply {
|
||||
textSafe = ""
|
||||
isInvisible = true
|
||||
}
|
||||
|
||||
binding.songTrackPlaceholder.isInvisible = false
|
||||
}
|
||||
|
||||
binding.songName.textSafe = data.resolvedName
|
||||
binding.songDuration.textSafe = data.seconds.toDuration(false)
|
||||
}
|
||||
|
||||
override fun setHighlighted(isHighlighted: Boolean) {
|
||||
|
||||
@@ -23,23 +23,26 @@ import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.IntegerTable
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.coil.bindArtistImage
|
||||
import org.oxycblt.auxio.databinding.ItemArtistAlbumBinding
|
||||
import org.oxycblt.auxio.databinding.ItemArtistSongBinding
|
||||
import org.oxycblt.auxio.coil.applyAlbumCover
|
||||
import org.oxycblt.auxio.coil.applyArtistImage
|
||||
import org.oxycblt.auxio.databinding.ItemDetailBinding
|
||||
import org.oxycblt.auxio.databinding.ItemParentBinding
|
||||
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.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
|
||||
import org.oxycblt.auxio.ui.ActionHeaderViewHolder
|
||||
import org.oxycblt.auxio.ui.BaseViewHolder
|
||||
import org.oxycblt.auxio.ui.DiffCallback
|
||||
import org.oxycblt.auxio.ui.HeaderViewHolder
|
||||
import org.oxycblt.auxio.util.context
|
||||
import org.oxycblt.auxio.util.getPluralSafe
|
||||
import org.oxycblt.auxio.util.inflater
|
||||
import org.oxycblt.auxio.util.textSafe
|
||||
|
||||
/**
|
||||
* An adapter for displaying the [Album]s and [Song]s of an artist.
|
||||
@@ -73,9 +76,9 @@ class ArtistDetailAdapter(
|
||||
IntegerTable.ITEM_TYPE_ARTIST_DETAIL ->
|
||||
ArtistDetailViewHolder(ItemDetailBinding.inflate(parent.context.inflater))
|
||||
IntegerTable.ITEM_TYPE_ARTIST_ALBUM ->
|
||||
ArtistAlbumViewHolder(ItemArtistAlbumBinding.inflate(parent.context.inflater))
|
||||
ArtistAlbumViewHolder(ItemParentBinding.inflate(parent.context.inflater))
|
||||
IntegerTable.ITEM_TYPE_ARTIST_SONG ->
|
||||
ArtistSongViewHolder(ItemArtistSongBinding.inflate(parent.context.inflater))
|
||||
ArtistSongViewHolder(ItemSongBinding.inflate(parent.context.inflater))
|
||||
IntegerTable.ITEM_TYPE_HEADER -> HeaderViewHolder.from(parent.context)
|
||||
IntegerTable.ITEM_TYPE_ACTION_HEADER -> ActionHeaderViewHolder.from(parent.context)
|
||||
else -> error("Invalid ViewHolder item type $viewType")
|
||||
@@ -173,16 +176,16 @@ class ArtistDetailAdapter(
|
||||
val context = binding.root.context
|
||||
|
||||
binding.detailCover.apply {
|
||||
bindArtistImage(data)
|
||||
applyArtistImage(data)
|
||||
contentDescription =
|
||||
context.getString(R.string.desc_artist_image, data.resolvedName)
|
||||
}
|
||||
|
||||
binding.detailName.text = data.resolvedName
|
||||
binding.detailName.textSafe = data.resolvedName
|
||||
|
||||
// Get the genre that corresponds to the most songs in this artist, which would be
|
||||
// the most "Prominent" genre.
|
||||
binding.detailSubhead.text =
|
||||
binding.detailSubhead.textSafe =
|
||||
data.songs
|
||||
.groupBy { it.genre.resolvedName }
|
||||
.entries
|
||||
@@ -190,7 +193,11 @@ class ArtistDetailAdapter(
|
||||
?.key
|
||||
?: context.getString(R.string.def_genre)
|
||||
|
||||
binding.detailInfo.bindArtistInfo(data)
|
||||
binding.detailInfo.textSafe =
|
||||
binding.context.getString(
|
||||
R.string.fmt_two,
|
||||
binding.context.getPluralSafe(R.plurals.fmt_album_count, data.albums.size),
|
||||
binding.context.getPluralSafe(R.plurals.fmt_song_count, data.songs.size))
|
||||
|
||||
binding.detailPlayButton.setOnClickListener { playbackModel.playArtist(data, false) }
|
||||
|
||||
@@ -199,24 +206,26 @@ class ArtistDetailAdapter(
|
||||
}
|
||||
|
||||
inner class ArtistAlbumViewHolder(
|
||||
private val binding: ItemArtistAlbumBinding,
|
||||
private val binding: ItemParentBinding,
|
||||
) : BaseViewHolder<Album>(binding, doOnClick, doOnLongClick), Highlightable {
|
||||
override fun onBind(data: Album) {
|
||||
binding.album = data
|
||||
binding.albumName.requestLayout()
|
||||
binding.parentImage.applyAlbumCover(data)
|
||||
binding.parentName.textSafe = data.resolvedName
|
||||
binding.parentInfo.textSafe = binding.context.getString(R.string.fmt_number, data.year)
|
||||
}
|
||||
|
||||
override fun setHighlighted(isHighlighted: Boolean) {
|
||||
binding.albumName.isActivated = isHighlighted
|
||||
binding.parentName.isActivated = isHighlighted
|
||||
}
|
||||
}
|
||||
|
||||
inner class ArtistSongViewHolder(
|
||||
private val binding: ItemArtistSongBinding,
|
||||
private val binding: ItemSongBinding,
|
||||
) : BaseViewHolder<Song>(binding, doOnSongClick, doOnLongClick), Highlightable {
|
||||
override fun onBind(data: Song) {
|
||||
binding.song = data
|
||||
binding.songName.requestLayout()
|
||||
binding.songAlbumCover.applyAlbumCover(data)
|
||||
binding.songName.textSafe = data.resolvedName
|
||||
binding.songInfo.textSafe = data.resolvedAlbumName
|
||||
}
|
||||
|
||||
override fun setHighlighted(isHighlighted: Boolean) {
|
||||
|
||||
@@ -23,19 +23,22 @@ import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.IntegerTable
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.coil.bindGenreImage
|
||||
import org.oxycblt.auxio.coil.applyAlbumCover
|
||||
import org.oxycblt.auxio.coil.applyGenreImage
|
||||
import org.oxycblt.auxio.databinding.ItemDetailBinding
|
||||
import org.oxycblt.auxio.databinding.ItemGenreSongBinding
|
||||
import org.oxycblt.auxio.databinding.ItemSongBinding
|
||||
import org.oxycblt.auxio.music.ActionHeader
|
||||
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
|
||||
import org.oxycblt.auxio.ui.ActionHeaderViewHolder
|
||||
import org.oxycblt.auxio.ui.BaseViewHolder
|
||||
import org.oxycblt.auxio.ui.DiffCallback
|
||||
import org.oxycblt.auxio.util.context
|
||||
import org.oxycblt.auxio.util.getPluralSafe
|
||||
import org.oxycblt.auxio.util.inflater
|
||||
import org.oxycblt.auxio.util.textSafe
|
||||
|
||||
/**
|
||||
* An adapter for displaying the [Song]s of a genre.
|
||||
@@ -64,9 +67,7 @@ class GenreDetailAdapter(
|
||||
GenreDetailViewHolder(ItemDetailBinding.inflate(parent.context.inflater))
|
||||
IntegerTable.ITEM_TYPE_ACTION_HEADER -> ActionHeaderViewHolder.from(parent.context)
|
||||
IntegerTable.ITEM_TYPE_GENRE_SONG ->
|
||||
GenreSongViewHolder(
|
||||
ItemGenreSongBinding.inflate(parent.context.inflater),
|
||||
)
|
||||
GenreSongViewHolder(ItemSongBinding.inflate(parent.context.inflater))
|
||||
else -> error("Bad ViewHolder item type $viewType")
|
||||
}
|
||||
}
|
||||
@@ -127,13 +128,14 @@ class GenreDetailAdapter(
|
||||
val context = binding.root.context
|
||||
|
||||
binding.detailCover.apply {
|
||||
bindGenreImage(data)
|
||||
applyGenreImage(data)
|
||||
contentDescription = context.getString(R.string.desc_genre_image, data.resolvedName)
|
||||
}
|
||||
|
||||
binding.detailName.text = data.resolvedName
|
||||
binding.detailSubhead.bindGenreInfo(data)
|
||||
binding.detailInfo.text = data.totalDuration
|
||||
binding.detailName.textSafe = data.resolvedName
|
||||
binding.detailSubhead.textSafe =
|
||||
binding.context.getPluralSafe(R.plurals.fmt_song_count, data.songs.size)
|
||||
binding.detailInfo.textSafe = data.totalDuration
|
||||
|
||||
binding.detailPlayButton.setOnClickListener { playbackModel.playGenre(data, false) }
|
||||
|
||||
@@ -141,14 +143,16 @@ class GenreDetailAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
inner class GenreSongViewHolder(
|
||||
private val binding: ItemGenreSongBinding,
|
||||
/** The Shared ViewHolder for a [Song]. Instantiation should be done with [from]. */
|
||||
inner class GenreSongViewHolder
|
||||
constructor(
|
||||
private val binding: ItemSongBinding,
|
||||
) : BaseViewHolder<Song>(binding, doOnClick, doOnLongClick), Highlightable {
|
||||
override fun onBind(data: Song) {
|
||||
binding.song = data
|
||||
|
||||
binding.songName.requestLayout()
|
||||
binding.songInfo.requestLayout()
|
||||
override fun onBind(data: Song) {
|
||||
binding.songAlbumCover.applyAlbumCover(data)
|
||||
binding.songName.textSafe = data.resolvedName
|
||||
binding.songInfo.textSafe = data.resolvedArtistName
|
||||
}
|
||||
|
||||
override fun setHighlighted(isHighlighted: Boolean) {
|
||||
|
||||
@@ -186,6 +186,8 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
||||
// --- RECYCLERVIEW EVENT MANAGEMENT ---
|
||||
|
||||
private fun onPreDraw() {
|
||||
// FIXME: Make the way we lay out views less of a hacky mess. Perhaps consider
|
||||
// overlaying views or turning this into a ViewGroup.
|
||||
updateScrollbarState()
|
||||
|
||||
thumbView.layoutDirection = layoutDirection
|
||||
|
||||
@@ -18,12 +18,7 @@
|
||||
package org.oxycblt.auxio.music
|
||||
|
||||
import android.text.format.DateUtils
|
||||
import android.widget.TextView
|
||||
import androidx.databinding.BindingAdapter
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.util.getPluralSafe
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.logW
|
||||
|
||||
// --- EXTENSION FUNCTIONS ---
|
||||
|
||||
@@ -47,53 +42,3 @@ fun Long.toDuration(isElapsed: Boolean): String {
|
||||
|
||||
return durationString
|
||||
}
|
||||
|
||||
// --- BINDING ADAPTERS ---
|
||||
|
||||
@BindingAdapter("songInfo")
|
||||
fun TextView.bindSongInfo(song: Song?) {
|
||||
if (song == null) {
|
||||
logW("Song was null, not applying info")
|
||||
return
|
||||
}
|
||||
|
||||
text = context.getString(R.string.fmt_two, song.resolvedArtistName, song.resolvedAlbumName)
|
||||
}
|
||||
|
||||
@BindingAdapter("albumInfo")
|
||||
fun TextView.bindAlbumInfo(album: Album?) {
|
||||
if (album == null) {
|
||||
logW("Album was null, not applying info")
|
||||
return
|
||||
}
|
||||
|
||||
text =
|
||||
context.getString(
|
||||
R.string.fmt_two,
|
||||
album.resolvedArtistName,
|
||||
context.getPluralSafe(R.plurals.fmt_song_count, album.songs.size))
|
||||
}
|
||||
|
||||
@BindingAdapter("artistInfo")
|
||||
fun TextView.bindArtistInfo(artist: Artist?) {
|
||||
if (artist == null) {
|
||||
logW("Artist was null, not applying info")
|
||||
return
|
||||
}
|
||||
|
||||
text =
|
||||
context.getString(
|
||||
R.string.fmt_two,
|
||||
context.getPluralSafe(R.plurals.fmt_album_count, artist.albums.size),
|
||||
context.getPluralSafe(R.plurals.fmt_song_count, artist.songs.size))
|
||||
}
|
||||
|
||||
@BindingAdapter("genreInfo")
|
||||
fun TextView.bindGenreInfo(genre: Genre?) {
|
||||
if (genre == null) {
|
||||
logW("Genre was null, not applying info")
|
||||
return
|
||||
}
|
||||
|
||||
text = context.getPluralSafe(R.plurals.fmt_song_count, genre.songs.size)
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.databinding.ItemExcludedDirBinding
|
||||
import org.oxycblt.auxio.util.inflater
|
||||
import org.oxycblt.auxio.util.textSafe
|
||||
|
||||
/**
|
||||
* Adapter that shows the excluded directories and their "Clear" button.
|
||||
@@ -56,8 +57,7 @@ class ExcludedEntryAdapter(private val onClear: (String) -> Unit) :
|
||||
}
|
||||
|
||||
fun bind(path: String) {
|
||||
binding.excludedPath.text = path
|
||||
binding.excludedPath.requestLayout()
|
||||
binding.excludedPath.textSafe = path
|
||||
binding.excludedClear.setOnClickListener { onClear(path) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,14 +25,14 @@ import androidx.core.view.updatePadding
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.google.android.material.color.MaterialColors
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.coil.bindAlbumCover
|
||||
import org.oxycblt.auxio.coil.applyAlbumCover
|
||||
import org.oxycblt.auxio.databinding.FragmentPlaybackBarBinding
|
||||
import org.oxycblt.auxio.detail.DetailViewModel
|
||||
import org.oxycblt.auxio.music.bindSongInfo
|
||||
import org.oxycblt.auxio.ui.BottomSheetLayout
|
||||
import org.oxycblt.auxio.ui.ViewBindingFragment
|
||||
import org.oxycblt.auxio.util.getAttrColorSafe
|
||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||
import org.oxycblt.auxio.util.textSafe
|
||||
|
||||
class PlaybackBarFragment : ViewBindingFragment<FragmentPlaybackBarBinding>() {
|
||||
private val playbackModel: PlaybackViewModel by activityViewModels()
|
||||
@@ -99,9 +99,10 @@ class PlaybackBarFragment : ViewBindingFragment<FragmentPlaybackBarBinding>() {
|
||||
|
||||
playbackModel.song.observe(viewLifecycleOwner) { song ->
|
||||
if (song != null) {
|
||||
binding.playbackCover.bindAlbumCover(song)
|
||||
binding.playbackSong.text = song.resolvedName
|
||||
binding.playbackInfo.bindSongInfo(song)
|
||||
binding.playbackCover.applyAlbumCover(song)
|
||||
binding.playbackSong.textSafe = song.resolvedName
|
||||
binding.playbackInfo.textSafe =
|
||||
getString(R.string.fmt_two, song.resolvedArtistName, song.resolvedAlbumName)
|
||||
binding.playbackProgressBar.max = song.seconds.toInt()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import com.google.android.material.slider.Slider
|
||||
import kotlin.math.max
|
||||
import org.oxycblt.auxio.MainFragmentDirections
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.coil.bindAlbumCover
|
||||
import org.oxycblt.auxio.coil.applyAlbumCover
|
||||
import org.oxycblt.auxio.databinding.FragmentPlaybackPanelBinding
|
||||
import org.oxycblt.auxio.detail.DetailViewModel
|
||||
import org.oxycblt.auxio.music.MusicParent
|
||||
@@ -42,6 +42,7 @@ import org.oxycblt.auxio.util.getAttrColorSafe
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.stateList
|
||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||
import org.oxycblt.auxio.util.textSafe
|
||||
|
||||
/**
|
||||
* A [Fragment] that displays more information about the song, along with more media controls.
|
||||
@@ -166,7 +167,7 @@ class PlaybackPanelFragment :
|
||||
|
||||
override fun onValueChange(slider: Slider, value: Float, fromUser: Boolean) {
|
||||
if (fromUser) {
|
||||
requireBinding().playbackPosition.text = value.toLong().toDuration(true)
|
||||
requireBinding().playbackPosition.textSafe = value.toLong().toDuration(true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,14 +175,14 @@ class PlaybackPanelFragment :
|
||||
if (song == null) return
|
||||
|
||||
val binding = requireBinding()
|
||||
binding.playbackCover.bindAlbumCover(song)
|
||||
binding.playbackSong.text = song.resolvedName
|
||||
binding.playbackArtist.text = song.resolvedArtistName
|
||||
binding.playbackAlbum.text = song.resolvedAlbumName
|
||||
binding.playbackCover.applyAlbumCover(song)
|
||||
binding.playbackSong.textSafe = song.resolvedName
|
||||
binding.playbackArtist.textSafe = song.resolvedArtistName
|
||||
binding.playbackAlbum.textSafe = song.resolvedAlbumName
|
||||
|
||||
// Normally if a song had a duration
|
||||
val seconds = song.seconds
|
||||
binding.playbackDuration.text = seconds.toDuration(false)
|
||||
binding.playbackDuration.textSafe = seconds.toDuration(false)
|
||||
binding.playbackSeekBar.apply {
|
||||
valueTo = max(seconds, 1L).toFloat()
|
||||
isEnabled = seconds > 0L
|
||||
@@ -199,7 +200,7 @@ class PlaybackPanelFragment :
|
||||
val binding = requireBinding()
|
||||
if (!binding.playbackPosition.isActivated) {
|
||||
binding.playbackSeekBar.value = position.toFloat()
|
||||
binding.playbackPosition.text = position.toDuration(true)
|
||||
binding.playbackPosition.textSafe = position.toDuration(true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
||||
private val mMode = MutableLiveData(PlaybackMode.ALL_SONGS)
|
||||
|
||||
// Other
|
||||
// TODO: Move URI management to PlaybackService (more capable of taking commands)
|
||||
private var mIntentUri: Uri? = null
|
||||
|
||||
/** The current song. */
|
||||
|
||||
@@ -28,6 +28,7 @@ import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.shape.MaterialShapeDrawable
|
||||
import org.oxycblt.auxio.IntegerTable
|
||||
import org.oxycblt.auxio.coil.applyAlbumCover
|
||||
import org.oxycblt.auxio.databinding.ItemQueueSongBinding
|
||||
import org.oxycblt.auxio.music.ActionHeader
|
||||
import org.oxycblt.auxio.music.Header
|
||||
@@ -41,6 +42,7 @@ import org.oxycblt.auxio.util.disableDropShadowCompat
|
||||
import org.oxycblt.auxio.util.inflater
|
||||
import org.oxycblt.auxio.util.logE
|
||||
import org.oxycblt.auxio.util.stateList
|
||||
import org.oxycblt.auxio.util.textSafe
|
||||
|
||||
/**
|
||||
* The single adapter for both the Next Queue and the User Queue.
|
||||
@@ -125,7 +127,9 @@ class QueueAdapter(private val touchHelper: ItemTouchHelper) :
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onBind(data: Song) {
|
||||
binding.song = data
|
||||
binding.songAlbumCover.applyAlbumCover(data)
|
||||
binding.songName.textSafe = data.resolvedName
|
||||
binding.songInfo.textSafe = data.resolvedArtistName
|
||||
|
||||
binding.background.isInvisible = true
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.oxycblt.auxio.ui.ViewBindingFragment
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.showToast
|
||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||
import org.oxycblt.auxio.util.textSafe
|
||||
|
||||
/**
|
||||
* A [BottomSheetDialogFragment] that shows Auxio's about screen.
|
||||
@@ -54,13 +55,13 @@ class AboutFragment : ViewBindingFragment<FragmentAboutBinding>() {
|
||||
|
||||
binding.aboutToolbar.setNavigationOnClickListener { findNavController().navigateUp() }
|
||||
|
||||
binding.aboutVersion.text = BuildConfig.VERSION_NAME
|
||||
binding.aboutVersion.textSafe = BuildConfig.VERSION_NAME
|
||||
binding.aboutCode.setOnClickListener { openLinkInBrowser(LINK_CODEBASE) }
|
||||
binding.aboutFaq.setOnClickListener { openLinkInBrowser(LINK_FAQ) }
|
||||
binding.aboutLicenses.setOnClickListener { openLinkInBrowser(LINK_LICENSES) }
|
||||
|
||||
homeModel.songs.observe(viewLifecycleOwner) { songs ->
|
||||
binding.aboutSongCount.text = getString(R.string.fmt_songs_loaded, songs.size)
|
||||
binding.aboutSongCount.textSafe = getString(R.string.fmt_songs_loaded, songs.size)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -249,11 +249,11 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) :
|
||||
barView = getChildAt(1) // Child 2 is assumed to be the bar used when collapsed
|
||||
panelView = getChildAt(2) // Child 3 is assumed to be the panel used when expanded
|
||||
|
||||
// We actually move the bar and panel views into a container so that they have consistent
|
||||
// behavior when be manipulate layouts later.
|
||||
removeView(barView)
|
||||
removeView(panelView)
|
||||
|
||||
// We actually move the bar and panel views into a container so that they have consistent
|
||||
// behavior when be manipulate layouts later.
|
||||
containerView.apply {
|
||||
addView(
|
||||
barView,
|
||||
|
||||
@@ -20,13 +20,15 @@ package org.oxycblt.auxio.ui
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import androidx.appcompat.widget.TooltipCompat
|
||||
import androidx.databinding.ViewDataBinding
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.coil.applyAlbumCover
|
||||
import org.oxycblt.auxio.coil.applyArtistImage
|
||||
import org.oxycblt.auxio.coil.applyGenreImage
|
||||
import org.oxycblt.auxio.databinding.ItemActionHeaderBinding
|
||||
import org.oxycblt.auxio.databinding.ItemAlbumBinding
|
||||
import org.oxycblt.auxio.databinding.ItemArtistBinding
|
||||
import org.oxycblt.auxio.databinding.ItemGenreBinding
|
||||
import org.oxycblt.auxio.databinding.ItemHeaderBinding
|
||||
import org.oxycblt.auxio.databinding.ItemParentBinding
|
||||
import org.oxycblt.auxio.databinding.ItemSongBinding
|
||||
import org.oxycblt.auxio.music.ActionHeader
|
||||
import org.oxycblt.auxio.music.Album
|
||||
@@ -35,7 +37,10 @@ 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.context
|
||||
import org.oxycblt.auxio.util.getPluralSafe
|
||||
import org.oxycblt.auxio.util.inflater
|
||||
import org.oxycblt.auxio.util.textSafe
|
||||
|
||||
/**
|
||||
* A [RecyclerView.ViewHolder] that streamlines a lot of the common things across all viewholders.
|
||||
@@ -46,7 +51,7 @@ import org.oxycblt.auxio.util.inflater
|
||||
* @author OxygenCobalt
|
||||
*/
|
||||
abstract class BaseViewHolder<T : Item>(
|
||||
private val binding: ViewDataBinding,
|
||||
private val binding: ViewBinding,
|
||||
private val doOnClick: ((data: T) -> Unit)? = null,
|
||||
private val doOnLongClick: ((view: View, data: T) -> Unit)? = null
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
@@ -73,8 +78,6 @@ abstract class BaseViewHolder<T : Item>(
|
||||
}
|
||||
|
||||
onBind(data)
|
||||
|
||||
binding.executePendingBindings()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,10 +96,9 @@ private constructor(
|
||||
) : BaseViewHolder<Song>(binding, doOnClick, doOnLongClick) {
|
||||
|
||||
override fun onBind(data: Song) {
|
||||
binding.song = data
|
||||
|
||||
binding.songName.requestLayout()
|
||||
binding.songInfo.requestLayout()
|
||||
binding.songAlbumCover.applyAlbumCover(data)
|
||||
binding.songName.textSafe = data.resolvedName
|
||||
binding.songInfo.textSafe = data.resolvedArtistName
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -115,14 +117,19 @@ private constructor(
|
||||
/** The Shared ViewHolder for a [Album]. Instantiation should be done with [from]. */
|
||||
class AlbumViewHolder
|
||||
private constructor(
|
||||
private val binding: ItemAlbumBinding,
|
||||
private val binding: ItemParentBinding,
|
||||
doOnClick: (data: Album) -> Unit,
|
||||
doOnLongClick: (view: View, data: Album) -> Unit
|
||||
) : BaseViewHolder<Album>(binding, doOnClick, doOnLongClick) {
|
||||
|
||||
override fun onBind(data: Album) {
|
||||
binding.album = data
|
||||
binding.albumName.requestLayout()
|
||||
binding.parentImage.applyAlbumCover(data)
|
||||
binding.parentName.textSafe = data.resolvedName
|
||||
binding.parentInfo.textSafe =
|
||||
binding.context.getString(
|
||||
R.string.fmt_two,
|
||||
data.resolvedArtistName,
|
||||
binding.context.getPluralSafe(R.plurals.fmt_song_count, data.songs.size))
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -133,7 +140,7 @@ private constructor(
|
||||
doOnLongClick: (view: View, data: Album) -> Unit
|
||||
): AlbumViewHolder {
|
||||
return AlbumViewHolder(
|
||||
ItemAlbumBinding.inflate(context.inflater), doOnClick, doOnLongClick)
|
||||
ItemParentBinding.inflate(context.inflater), doOnClick, doOnLongClick)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,14 +148,19 @@ private constructor(
|
||||
/** The Shared ViewHolder for a [Artist]. Instantiation should be done with [from]. */
|
||||
class ArtistViewHolder
|
||||
private constructor(
|
||||
private val binding: ItemArtistBinding,
|
||||
private val binding: ItemParentBinding,
|
||||
doOnClick: (Artist) -> Unit,
|
||||
doOnLongClick: (view: View, data: Artist) -> Unit
|
||||
) : BaseViewHolder<Artist>(binding, doOnClick, doOnLongClick) {
|
||||
|
||||
override fun onBind(data: Artist) {
|
||||
binding.artist = data
|
||||
binding.artistName.requestLayout()
|
||||
binding.parentImage.applyArtistImage(data)
|
||||
binding.parentName.textSafe = data.resolvedName
|
||||
binding.parentInfo.textSafe =
|
||||
binding.context.getString(
|
||||
R.string.fmt_two,
|
||||
binding.context.getPluralSafe(R.plurals.fmt_album_count, data.albums.size),
|
||||
binding.context.getPluralSafe(R.plurals.fmt_song_count, data.songs.size))
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -159,7 +171,7 @@ private constructor(
|
||||
doOnLongClick: (view: View, data: Artist) -> Unit
|
||||
): ArtistViewHolder {
|
||||
return ArtistViewHolder(
|
||||
ItemArtistBinding.inflate(context.inflater), doOnClick, doOnLongClick)
|
||||
ItemParentBinding.inflate(context.inflater), doOnClick, doOnLongClick)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,14 +179,16 @@ private constructor(
|
||||
/** The Shared ViewHolder for a [Genre]. Instantiation should be done with [from]. */
|
||||
class GenreViewHolder
|
||||
private constructor(
|
||||
private val binding: ItemGenreBinding,
|
||||
private val binding: ItemParentBinding,
|
||||
doOnClick: (Genre) -> Unit,
|
||||
doOnLongClick: (view: View, data: Genre) -> Unit
|
||||
) : BaseViewHolder<Genre>(binding, doOnClick, doOnLongClick) {
|
||||
|
||||
override fun onBind(data: Genre) {
|
||||
binding.genre = data
|
||||
binding.genreName.requestLayout()
|
||||
binding.parentImage.applyGenreImage(data)
|
||||
binding.parentName.textSafe = data.resolvedName
|
||||
binding.parentInfo.textSafe =
|
||||
binding.context.getPluralSafe(R.plurals.fmt_song_count, data.songs.size)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -185,7 +199,7 @@ private constructor(
|
||||
doOnLongClick: (view: View, data: Genre) -> Unit
|
||||
): GenreViewHolder {
|
||||
return GenreViewHolder(
|
||||
ItemGenreBinding.inflate(context.inflater), doOnClick, doOnLongClick)
|
||||
ItemParentBinding.inflate(context.inflater), doOnClick, doOnLongClick)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,7 +209,7 @@ class HeaderViewHolder private constructor(private val binding: ItemHeaderBindin
|
||||
BaseViewHolder<Header>(binding) {
|
||||
|
||||
override fun onBind(data: Header) {
|
||||
binding.header = data
|
||||
binding.title.textSafe = binding.context.getString(data.string)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -211,13 +225,11 @@ class ActionHeaderViewHolder private constructor(private val binding: ItemAction
|
||||
BaseViewHolder<ActionHeader>(binding) {
|
||||
|
||||
override fun onBind(data: ActionHeader) {
|
||||
binding.header = data
|
||||
|
||||
binding.executePendingBindings()
|
||||
|
||||
binding.headerTitle.textSafe = binding.context.getString(data.string)
|
||||
binding.headerButton.apply {
|
||||
setImageResource(data.icon)
|
||||
contentDescription = context.getString(data.desc)
|
||||
TooltipCompat.setTooltipText(this, contentDescription)
|
||||
|
||||
setOnClickListener(data.onClick)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package org.oxycblt.auxio.util
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Insets
|
||||
import android.graphics.Rect
|
||||
@@ -24,44 +25,14 @@ import android.graphics.drawable.Drawable
|
||||
import android.os.Build
|
||||
import android.view.View
|
||||
import android.view.WindowInsets
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.ColorRes
|
||||
import androidx.core.graphics.drawable.DrawableCompat
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import org.oxycblt.auxio.R
|
||||
|
||||
/** Converts this color to a single-color [ColorStateList]. */
|
||||
val @receiver:ColorRes Int.stateList
|
||||
get() = ColorStateList.valueOf(this)
|
||||
|
||||
/**
|
||||
* Apply the recommended spans for a [RecyclerView].
|
||||
*
|
||||
* @param shouldBeFullWidth Optional callback for determining whether an item should be full-width,
|
||||
* regardless of spans
|
||||
*/
|
||||
fun RecyclerView.applySpans(shouldBeFullWidth: ((Int) -> Boolean)? = null) {
|
||||
val spans = resources.getInteger(R.integer.recycler_spans)
|
||||
|
||||
if (spans > 1) {
|
||||
val mgr = GridLayoutManager(context, spans)
|
||||
|
||||
if (shouldBeFullWidth != null) {
|
||||
mgr.spanSizeLookup =
|
||||
object : GridLayoutManager.SpanSizeLookup() {
|
||||
override fun getSpanSize(position: Int): Int {
|
||||
return if (shouldBeFullWidth(position)) spans else 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
layoutManager = mgr
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns whether a recyclerview can scroll. */
|
||||
fun RecyclerView.canScroll(): Boolean = computeVerticalScrollRange() > height
|
||||
|
||||
/**
|
||||
* Disables drop shadows on a view programmatically in a version-compatible manner. This only works
|
||||
* on Android 9 and above. Below that version, shadows will remain visible.
|
||||
@@ -113,9 +84,52 @@ private fun isUnderImpl(
|
||||
|
||||
val View.isRtl: Boolean
|
||||
get() = layoutDirection == View.LAYOUT_DIRECTION_RTL
|
||||
|
||||
val Drawable.isRtl: Boolean
|
||||
get() = DrawableCompat.getLayoutDirection(this) == View.LAYOUT_DIRECTION_RTL
|
||||
|
||||
val ViewBinding.context: Context
|
||||
get() = root.context
|
||||
|
||||
var TextView.textSafe
|
||||
get() = text
|
||||
set(value) {
|
||||
text = value
|
||||
requestLayout()
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the recommended spans for a [RecyclerView].
|
||||
*
|
||||
* @param shouldBeFullWidth Optional callback for determining whether an item should be full-width,
|
||||
* regardless of spans
|
||||
*/
|
||||
fun RecyclerView.applySpans(shouldBeFullWidth: ((Int) -> Boolean)? = null) {
|
||||
val spans = resources.getInteger(R.integer.recycler_spans)
|
||||
|
||||
if (spans > 1) {
|
||||
val mgr = GridLayoutManager(context, spans)
|
||||
|
||||
if (shouldBeFullWidth != null) {
|
||||
mgr.spanSizeLookup =
|
||||
object : GridLayoutManager.SpanSizeLookup() {
|
||||
override fun getSpanSize(position: Int): Int {
|
||||
return if (shouldBeFullWidth(position)) spans else 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
layoutManager = mgr
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns whether a recyclerview can scroll. */
|
||||
fun RecyclerView.canScroll(): Boolean = computeVerticalScrollRange() > height
|
||||
|
||||
/** Converts this color to a single-color [ColorStateList]. */
|
||||
val @receiver:ColorRes Int.stateList
|
||||
get() = ColorStateList.valueOf(this)
|
||||
|
||||
/**
|
||||
* Resolve system bar insets in a version-aware manner. This can be used to apply padding to a view
|
||||
* that properly follows all the frustrating changes that were made between 8-11.
|
||||
|
||||
Reference in New Issue
Block a user