Update naming
Update naming on layout files & other code.
This commit is contained in:
@@ -35,7 +35,7 @@ class MainFragment : Fragment() {
|
||||
|
||||
binding.lifecycleOwner = viewLifecycleOwner
|
||||
|
||||
binding.viewPager.adapter = PagerAdapter()
|
||||
binding.mainViewPager.adapter = PagerAdapter()
|
||||
|
||||
val colorActive = accent.first.toColor(requireContext())
|
||||
val colorInactive = getTransparentAccent(
|
||||
@@ -45,7 +45,7 @@ class MainFragment : Fragment() {
|
||||
)
|
||||
|
||||
// Link the ViewPager & Tab View
|
||||
TabLayoutMediator(binding.tabs, binding.viewPager) { tab, position ->
|
||||
TabLayoutMediator(binding.mainTabs, binding.mainViewPager) { tab, position ->
|
||||
tab.icon = ContextCompat.getDrawable(requireContext(), tabIcons[position])
|
||||
|
||||
// Set the icon tint to deselected if its not the default tab
|
||||
@@ -55,7 +55,7 @@ class MainFragment : Fragment() {
|
||||
}.attach()
|
||||
|
||||
// Set up the selected/deselected colors
|
||||
binding.tabs.addOnTabSelectedListener(
|
||||
binding.mainTabs.addOnTabSelectedListener(
|
||||
object : TabLayout.OnTabSelectedListener {
|
||||
|
||||
override fun onTabSelected(tab: TabLayout.Tab) {
|
||||
|
||||
@@ -51,11 +51,13 @@ class AlbumDetailFragment : Fragment() {
|
||||
binding.detailModel = detailModel
|
||||
binding.album = detailModel.currentAlbum
|
||||
|
||||
binding.songRecycler.adapter = songAdapter
|
||||
binding.songRecycler.applyDivider()
|
||||
binding.songRecycler.setHasFixedSize(true)
|
||||
binding.albumSongRecycler.apply {
|
||||
adapter = songAdapter
|
||||
applyDivider()
|
||||
setHasFixedSize(true)
|
||||
}
|
||||
|
||||
binding.toolbar.setNavigationOnClickListener {
|
||||
binding.albumToolbar.setNavigationOnClickListener {
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
|
||||
@@ -76,12 +78,12 @@ class AlbumDetailFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
binding.artistName.setBackgroundResource(R.drawable.ripple)
|
||||
binding.albumArtist.setBackgroundResource(R.drawable.ripple)
|
||||
}
|
||||
|
||||
detailModel.albumSortMode.observe(viewLifecycleOwner) { mode ->
|
||||
// Update the current sort icon
|
||||
binding.sortButton.setImageResource(mode.iconRes)
|
||||
binding.albumSortButton.setImageResource(mode.iconRes)
|
||||
|
||||
// Then update the sort mode of the album adapter.
|
||||
songAdapter.submitList(
|
||||
@@ -98,11 +100,11 @@ class AlbumDetailFragment : Fragment() {
|
||||
|
||||
// Don't enable the sort button if there's only one song [or less]
|
||||
if (detailModel.currentAlbum!!.numSongs < 2) {
|
||||
binding.sortButton.imageTintList = ColorStateList.valueOf(
|
||||
binding.albumSortButton.imageTintList = ColorStateList.valueOf(
|
||||
R.color.inactive_color.toColor(requireContext())
|
||||
)
|
||||
|
||||
binding.sortButton.isEnabled = false
|
||||
binding.albumSortButton.isEnabled = false
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment created.")
|
||||
|
||||
@@ -51,17 +51,19 @@ class ArtistDetailFragment : Fragment() {
|
||||
binding.detailModel = detailModel
|
||||
binding.artist = detailModel.currentArtist!!
|
||||
|
||||
binding.albumRecycler.adapter = albumAdapter
|
||||
binding.albumRecycler.applyDivider()
|
||||
binding.albumRecycler.setHasFixedSize(true)
|
||||
binding.artistAlbumRecycler.apply {
|
||||
adapter = albumAdapter
|
||||
applyDivider()
|
||||
setHasFixedSize(true)
|
||||
}
|
||||
|
||||
binding.toolbar.setNavigationOnClickListener {
|
||||
binding.artistToolbar.setNavigationOnClickListener {
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
|
||||
detailModel.artistSortMode.observe(viewLifecycleOwner) { mode ->
|
||||
// Update the current sort icon
|
||||
binding.sortButton.setImageResource(mode.iconRes)
|
||||
binding.artistSortButton.setImageResource(mode.iconRes)
|
||||
|
||||
// Then update the sort mode of the album adapter.
|
||||
albumAdapter.submitList(
|
||||
@@ -78,11 +80,11 @@ class ArtistDetailFragment : Fragment() {
|
||||
|
||||
// Don't enable the sort button if there is only one album [Or less]
|
||||
if (detailModel.currentArtist!!.numAlbums < 2) {
|
||||
binding.sortButton.imageTintList = ColorStateList.valueOf(
|
||||
binding.artistSortButton.imageTintList = ColorStateList.valueOf(
|
||||
R.color.inactive_color.toColor(requireContext())
|
||||
)
|
||||
|
||||
binding.sortButton.isEnabled = false
|
||||
binding.artistSortButton.isEnabled = false
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment created.")
|
||||
|
||||
@@ -51,17 +51,17 @@ class GenreDetailFragment : Fragment() {
|
||||
binding.detailModel = detailModel
|
||||
binding.genre = detailModel.currentGenre!!
|
||||
|
||||
binding.albumRecycler.adapter = albumAdapter
|
||||
binding.albumRecycler.applyDivider()
|
||||
binding.albumRecycler.setHasFixedSize(true)
|
||||
binding.genreArtistRecycler.adapter = albumAdapter
|
||||
binding.genreArtistRecycler.applyDivider()
|
||||
binding.genreArtistRecycler.setHasFixedSize(true)
|
||||
|
||||
binding.toolbar.setNavigationOnClickListener {
|
||||
binding.genreToolbar.setNavigationOnClickListener {
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
|
||||
detailModel.genreSortMode.observe(viewLifecycleOwner) { mode ->
|
||||
// Update the current sort icon
|
||||
binding.sortButton.setImageResource(mode.iconRes)
|
||||
binding.genreSortButton.setImageResource(mode.iconRes)
|
||||
|
||||
// Then update the sort mode of the album adapter.
|
||||
albumAdapter.submitList(
|
||||
@@ -78,11 +78,11 @@ class GenreDetailFragment : Fragment() {
|
||||
|
||||
// Don't enable the sort button if there is only one artist [Or less]
|
||||
if (detailModel.currentGenre!!.numArtists < 2) {
|
||||
binding.sortButton.imageTintList = ColorStateList.valueOf(
|
||||
binding.genreSortButton.imageTintList = ColorStateList.valueOf(
|
||||
R.color.inactive_color.toColor(requireContext())
|
||||
)
|
||||
|
||||
binding.sortButton.isEnabled = false
|
||||
binding.genreSortButton.isEnabled = false
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment created.")
|
||||
|
||||
@@ -3,7 +3,9 @@ package org.oxycblt.auxio.detail.adapters
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import org.oxycblt.auxio.databinding.ItemAlbumBinding
|
||||
import org.oxycblt.auxio.databinding.ItemArtistAlbumBinding
|
||||
import org.oxycblt.auxio.databinding.ItemArtistBinding
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.recycler.BaseViewHolder
|
||||
import org.oxycblt.auxio.recycler.ClickListener
|
||||
@@ -30,6 +32,7 @@ class DetailAlbumAdapter(
|
||||
|
||||
override fun onBind(model: Album) {
|
||||
binding.album = model
|
||||
|
||||
binding.albumName.requestLayout()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ package org.oxycblt.auxio.detail.adapters
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import org.oxycblt.auxio.databinding.ItemArtistBinding
|
||||
import org.oxycblt.auxio.databinding.ItemGenreArtistBinding
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.bindArtistCounts
|
||||
import org.oxycblt.auxio.recycler.BaseViewHolder
|
||||
import org.oxycblt.auxio.recycler.ClickListener
|
||||
import org.oxycblt.auxio.recycler.DiffCallback
|
||||
@@ -30,6 +32,7 @@ class DetailArtistAdapter(
|
||||
|
||||
override fun onBind(model: Artist) {
|
||||
binding.artist = model
|
||||
|
||||
binding.artistName.requestLayout()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.databinding.ItemAlbumBinding
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.bindAlbumSongs
|
||||
import org.oxycblt.auxio.recycler.BaseViewHolder
|
||||
import org.oxycblt.auxio.recycler.ClickListener
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.databinding.ItemArtistBinding
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.bindArtistCounts
|
||||
import org.oxycblt.auxio.recycler.BaseViewHolder
|
||||
import org.oxycblt.auxio.recycler.ClickListener
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class GenreAdapter(
|
||||
|
||||
override fun onBind(model: Genre) {
|
||||
binding.genre = model
|
||||
binding.artistName.requestLayout()
|
||||
binding.genreName.requestLayout()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ class LoadingFragment : Fragment(R.layout.fragment_loading) {
|
||||
)
|
||||
} else {
|
||||
binding.let { binding ->
|
||||
binding.errorText.text =
|
||||
binding.loadingErrorText.text =
|
||||
if (response == MusicLoaderResponse.NO_MUSIC)
|
||||
getString(R.string.error_no_music)
|
||||
else
|
||||
@@ -113,9 +113,9 @@ class LoadingFragment : Fragment(R.layout.fragment_loading) {
|
||||
// depending on which error response was given, along with a retry button
|
||||
binding.loadingBar.visibility = View.GONE
|
||||
|
||||
binding.errorText.visibility = View.VISIBLE
|
||||
binding.statusIcon.visibility = View.VISIBLE
|
||||
binding.retryButton.visibility = View.VISIBLE
|
||||
binding.loadingErrorText.visibility = View.VISIBLE
|
||||
binding.loadingErrorIcon.visibility = View.VISIBLE
|
||||
binding.loadingRetryButton.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,11 +126,11 @@ class LoadingFragment : Fragment(R.layout.fragment_loading) {
|
||||
// along with a GRANT button
|
||||
|
||||
binding.loadingBar.visibility = View.GONE
|
||||
binding.statusIcon.visibility = View.VISIBLE
|
||||
binding.grantButton.visibility = View.VISIBLE
|
||||
binding.errorText.visibility = View.VISIBLE
|
||||
binding.loadingErrorIcon.visibility = View.VISIBLE
|
||||
binding.loadingGrantButton.visibility = View.VISIBLE
|
||||
binding.loadingErrorText.visibility = View.VISIBLE
|
||||
|
||||
binding.errorText.text = getString(R.string.error_no_perms)
|
||||
binding.loadingErrorText.text = getString(R.string.error_no_perms)
|
||||
}
|
||||
|
||||
private fun onRetry(retry: Boolean) {
|
||||
@@ -149,12 +149,12 @@ class LoadingFragment : Fragment(R.layout.fragment_loading) {
|
||||
}
|
||||
}
|
||||
|
||||
// Wipe views and switch back to the plain LoadingBar
|
||||
// Wipe views and switch back to the plain ProgressBar
|
||||
private fun wipeViews() {
|
||||
binding.loadingBar.visibility = View.VISIBLE
|
||||
binding.errorText.visibility = View.GONE
|
||||
binding.statusIcon.visibility = View.GONE
|
||||
binding.retryButton.visibility = View.GONE
|
||||
binding.grantButton.visibility = View.GONE
|
||||
binding.loadingErrorText.visibility = View.GONE
|
||||
binding.loadingErrorIcon.visibility = View.GONE
|
||||
binding.loadingRetryButton.visibility = View.GONE
|
||||
binding.loadingGrantButton.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
+22
-19
@@ -15,7 +15,7 @@ data class Song(
|
||||
override var name: String,
|
||||
val albumId: Long,
|
||||
val track: Int,
|
||||
val duration: Long
|
||||
val duration: Long,
|
||||
) : BaseModel() {
|
||||
lateinit var album: Album
|
||||
|
||||
@@ -35,13 +35,14 @@ data class Album(
|
||||
|
||||
val songs = mutableListOf<Song>()
|
||||
val numSongs: Int get() = songs.size
|
||||
val totalDuration: String get() {
|
||||
var seconds: Long = 0
|
||||
songs.forEach {
|
||||
seconds += it.seconds
|
||||
val totalDuration: String
|
||||
get() {
|
||||
var seconds: Long = 0
|
||||
songs.forEach {
|
||||
seconds += it.seconds
|
||||
}
|
||||
return seconds.toDuration()
|
||||
}
|
||||
return seconds.toDuration()
|
||||
}
|
||||
}
|
||||
|
||||
// Artist
|
||||
@@ -72,18 +73,20 @@ data class Genre(
|
||||
val artists = mutableListOf<Artist>()
|
||||
|
||||
val numArtists: Int get() = artists.size
|
||||
val numAlbums: Int get() {
|
||||
var num = 0
|
||||
artists.forEach {
|
||||
num += it.numAlbums
|
||||
val numAlbums: Int
|
||||
get() {
|
||||
var num = 0
|
||||
artists.forEach {
|
||||
num += it.numAlbums
|
||||
}
|
||||
return num
|
||||
}
|
||||
return num
|
||||
}
|
||||
val numSongs: Int get() {
|
||||
var num = 0
|
||||
artists.forEach {
|
||||
num += it.numSongs
|
||||
val numSongs: Int
|
||||
get() {
|
||||
var num = 0
|
||||
artists.forEach {
|
||||
num += it.numSongs
|
||||
}
|
||||
return num
|
||||
}
|
||||
return num
|
||||
}
|
||||
}
|
||||
@@ -70,39 +70,23 @@ fun Long.toAlbumArtURI(): Uri {
|
||||
|
||||
// Convert seconds into its string duration
|
||||
fun Long.toDuration(): String {
|
||||
val durationString = DateUtils.formatElapsedTime(this)
|
||||
var durationString = DateUtils.formatElapsedTime(this)
|
||||
|
||||
val durationSplit = durationString.chunked(1).toMutableList()
|
||||
|
||||
// Iterate through the string and remove the first zero found
|
||||
// If anything else is found, exit the loop.
|
||||
for (i in 0 until durationSplit.size) {
|
||||
if (durationSplit[i] == "0") {
|
||||
durationSplit.removeAt(i)
|
||||
|
||||
break
|
||||
} else {
|
||||
break
|
||||
}
|
||||
// If the duration begins with a excess zero [e.g 01:42], then cut it off.
|
||||
if (durationString[0] == '0') {
|
||||
durationString = durationString.slice(1 until durationString.length)
|
||||
}
|
||||
|
||||
return durationSplit.joinToString("")
|
||||
return durationString
|
||||
}
|
||||
|
||||
// --- BINDING ADAPTERS ---
|
||||
|
||||
fun getAlbumSongCount(album: Album, context: Context): String {
|
||||
return context.resources.getQuantityString(
|
||||
R.plurals.format_song_count, album.numSongs, album.numSongs
|
||||
)
|
||||
}
|
||||
|
||||
@BindingAdapter("genreCounts")
|
||||
fun TextView.bindGenreCounts(genre: Genre) {
|
||||
val artists = context.resources.getQuantityString(
|
||||
R.plurals.format_artist_count, genre.numArtists, genre.numArtists
|
||||
)
|
||||
|
||||
val albums = context.resources.getQuantityString(
|
||||
R.plurals.format_album_count, genre.numAlbums, genre.numAlbums
|
||||
)
|
||||
@@ -117,6 +101,7 @@ fun TextView.bindArtistGenre(artist: Artist) {
|
||||
text = artist.genres[0].name
|
||||
}
|
||||
|
||||
// Get the artist counts
|
||||
@BindingAdapter("artistCounts")
|
||||
fun TextView.bindArtistCounts(artist: Artist) {
|
||||
val albums = context.resources.getQuantityString(
|
||||
@@ -135,13 +120,18 @@ fun TextView.bindAlbumDetails(album: Album) {
|
||||
text = context.getString(
|
||||
R.string.format_double_info,
|
||||
album.year.toString(),
|
||||
getAlbumSongCount(album, context),
|
||||
context.resources.getQuantityString(
|
||||
R.plurals.format_song_count,
|
||||
album.numSongs, album.numSongs
|
||||
),
|
||||
album.totalDuration
|
||||
)
|
||||
}
|
||||
|
||||
@BindingAdapter("albumSongs")
|
||||
// Format the amount of songs in an album
|
||||
@BindingAdapter("songCount")
|
||||
fun TextView.bindAlbumSongs(album: Album) {
|
||||
text = getAlbumSongCount(album, context)
|
||||
text = context.resources.getQuantityString(
|
||||
R.plurals.format_song_count, album.numSongs, album.numSongs
|
||||
)
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.oxycblt.auxio.music.Song
|
||||
|
||||
// Get the cover art for a song or album
|
||||
@BindingAdapter("coverArt")
|
||||
fun ImageView.getCoverArt(song: Song) {
|
||||
fun ImageView.bindCoverArt(song: Song) {
|
||||
val request = getDefaultRequest(context, this)
|
||||
.data(song.album.coverUri)
|
||||
.error(R.drawable.ic_song)
|
||||
@@ -24,7 +24,7 @@ fun ImageView.getCoverArt(song: Song) {
|
||||
}
|
||||
|
||||
@BindingAdapter("coverArt")
|
||||
fun ImageView.getCoverArt(album: Album) {
|
||||
fun ImageView.bindCoverArt(album: Album) {
|
||||
val request = getDefaultRequest(context, this)
|
||||
.data(album.coverUri)
|
||||
.error(R.drawable.ic_album)
|
||||
@@ -35,7 +35,7 @@ fun ImageView.getCoverArt(album: Album) {
|
||||
|
||||
// Get the artist image
|
||||
@BindingAdapter("artistImage")
|
||||
fun ImageView.getArtistImage(artist: Artist) {
|
||||
fun ImageView.bindArtistImage(artist: Artist) {
|
||||
val request: ImageRequest
|
||||
|
||||
// If there are more than one albums, then create a mosaic of them.
|
||||
@@ -72,7 +72,7 @@ fun ImageView.getArtistImage(artist: Artist) {
|
||||
}
|
||||
|
||||
@BindingAdapter("genreImage")
|
||||
fun ImageView.getGenreImage(genre: Genre) {
|
||||
fun ImageView.bindGenreImage(genre: Genre) {
|
||||
val request: ImageRequest
|
||||
|
||||
if (genre.numArtists >= 4) {
|
||||
|
||||
@@ -144,7 +144,7 @@ class MusicSorter(
|
||||
)
|
||||
|
||||
for (artist in unknownArtists) {
|
||||
artist.givenGenres.add(unknownGenre)
|
||||
artist.genres.add(unknownGenre)
|
||||
unknownGenre.artists.add(artist)
|
||||
}
|
||||
genres.add(unknownGenre)
|
||||
|
||||
Reference in New Issue
Block a user