Add song list to AlbumDetailFragment
Add a list of the albums songs to AlbumDetailFragment.
This commit is contained in:
parent
20047313fc
commit
ec45a020a5
10 changed files with 188 additions and 18 deletions
|
@ -8,8 +8,11 @@ import android.view.ViewGroup
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.navigation.fragment.navArgs
|
import androidx.navigation.fragment.navArgs
|
||||||
|
import org.oxycblt.auxio.ClickListener
|
||||||
import org.oxycblt.auxio.databinding.FragmentAlbumDetailBinding
|
import org.oxycblt.auxio.databinding.FragmentAlbumDetailBinding
|
||||||
|
import org.oxycblt.auxio.detail.adapters.DetailSongAdapter
|
||||||
import org.oxycblt.auxio.music.MusicViewModel
|
import org.oxycblt.auxio.music.MusicViewModel
|
||||||
|
import org.oxycblt.auxio.theme.applyDivider
|
||||||
|
|
||||||
class AlbumDetailFragment : Fragment() {
|
class AlbumDetailFragment : Fragment() {
|
||||||
|
|
||||||
|
@ -30,6 +33,15 @@ class AlbumDetailFragment : Fragment() {
|
||||||
binding.lifecycleOwner = this
|
binding.lifecycleOwner = this
|
||||||
binding.album = album
|
binding.album = album
|
||||||
|
|
||||||
|
binding.songRecycler.adapter = DetailSongAdapter(
|
||||||
|
album.songs,
|
||||||
|
ClickListener {
|
||||||
|
Log.d(this::class.simpleName, it.name)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
binding.songRecycler.applyDivider()
|
||||||
|
binding.songRecycler.setHasFixedSize(true)
|
||||||
|
|
||||||
Log.d(this::class.simpleName, "Fragment created.")
|
Log.d(this::class.simpleName, "Fragment created.")
|
||||||
|
|
||||||
return binding.root
|
return binding.root
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
package org.oxycblt.auxio.detail.adapters
|
||||||
|
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import org.oxycblt.auxio.ClickListener
|
||||||
|
import org.oxycblt.auxio.databinding.ItemAlbumSongBinding
|
||||||
|
import org.oxycblt.auxio.music.models.Song
|
||||||
|
|
||||||
|
class DetailSongAdapter(
|
||||||
|
private val data: List<Song>,
|
||||||
|
private val listener: ClickListener<Song>
|
||||||
|
) : RecyclerView.Adapter<DetailSongAdapter.ViewHolder>() {
|
||||||
|
|
||||||
|
override fun getItemCount(): Int = data.size
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
|
return ViewHolder(
|
||||||
|
ItemAlbumSongBinding.inflate(LayoutInflater.from(parent.context))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
|
holder.bind(data[position])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generic ViewHolder for an album
|
||||||
|
inner class ViewHolder(
|
||||||
|
private val binding: ItemAlbumSongBinding
|
||||||
|
) : RecyclerView.ViewHolder(binding.root) {
|
||||||
|
|
||||||
|
init {
|
||||||
|
// Force the viewholder to *actually* be the screen width so ellipsizing can work.
|
||||||
|
binding.root.layoutParams = RecyclerView.LayoutParams(
|
||||||
|
RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bind the view w/new data
|
||||||
|
fun bind(song: Song) {
|
||||||
|
binding.song = song
|
||||||
|
|
||||||
|
binding.root.setOnClickListener {
|
||||||
|
listener.onClick(song)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Force-update the layout so ellipsizing works.
|
||||||
|
binding.songName.requestLayout()
|
||||||
|
binding.executePendingBindings()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,7 +8,7 @@ data class Album(
|
||||||
var name: String = "",
|
var name: String = "",
|
||||||
val artistName: String = "", // only used for sorting. Use artist.name instead.
|
val artistName: String = "", // only used for sorting. Use artist.name instead.
|
||||||
val coverUri: Uri = Uri.EMPTY,
|
val coverUri: Uri = Uri.EMPTY,
|
||||||
val year: String = ""
|
val year: Int = 0
|
||||||
) {
|
) {
|
||||||
lateinit var artist: Artist
|
lateinit var artist: Artist
|
||||||
|
|
||||||
|
|
|
@ -191,7 +191,7 @@ class MusicLoader(private val resolver: ContentResolver) {
|
||||||
albums.add(
|
albums.add(
|
||||||
Album(
|
Album(
|
||||||
id, name, artist,
|
id, name, artist,
|
||||||
coverUri, year.toString()
|
coverUri, year
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,8 @@ class MusicSorter(
|
||||||
album.songs.add(song)
|
album.songs.add(song)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
album.finalize()
|
||||||
|
|
||||||
unknownSongs.removeAll(albumSongs)
|
unknownSongs.removeAll(albumSongs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
tools:src="@drawable/ic_album" />
|
tools:src="@drawable/ic_album" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
android:id="@+id/artist_name"
|
android:id="@+id/album_name"
|
||||||
style="@style/DetailHeader"
|
style="@style/DetailHeader"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -65,6 +65,18 @@
|
||||||
app:layout_constraintTop_toBottomOf="@+id/cover"
|
app:layout_constraintTop_toBottomOf="@+id/cover"
|
||||||
tools:text="Album Name" />
|
tools:text="Album Name" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/artist_name"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceListItem"
|
||||||
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
|
android:layout_marginStart="@dimen/margin_medium"
|
||||||
|
android:text="@{album.artist.name}"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/album_name"
|
||||||
|
tools:text="Artist Name" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/album_year"
|
android:id="@+id/album_year"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
@ -72,25 +84,44 @@
|
||||||
android:textAppearance="?android:attr/textAppearanceListItem"
|
android:textAppearance="?android:attr/textAppearanceListItem"
|
||||||
android:textColor="?android:attr/textColorSecondary"
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
android:layout_marginStart="@dimen/margin_medium"
|
android:layout_marginStart="@dimen/margin_medium"
|
||||||
android:text="@{album.year}"
|
android:text="@{String.valueOf(album.year)}"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/artist_name"
|
app:layout_constraintTop_toBottomOf="@+id/artist_name"
|
||||||
tools:text="2020" />
|
tools:text="2020" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/artist_counts"
|
android:id="@+id/header_songs"
|
||||||
android:layout_width="0dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:textAppearance="?android:attr/textAppearanceListItem"
|
android:text="@string/label_songs"
|
||||||
android:textColor="?android:attr/textColorSecondary"
|
android:textAppearance="@style/TextAppearance.MaterialComponents.Overline"
|
||||||
android:layout_marginStart="@dimen/margin_medium"
|
android:textSize="16sp"
|
||||||
app:songCount="@{album}"
|
android:fontFamily="@font/inter_bold"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
android:layout_marginTop="@dimen/padding_medium"
|
||||||
|
android:paddingStart="@dimen/padding_medium"
|
||||||
|
android:paddingEnd="@dimen/padding_small"
|
||||||
|
android:paddingTop="@dimen/padding_small"
|
||||||
|
android:paddingBottom="@dimen/padding_small"
|
||||||
|
android:background="@drawable/header_dividers"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/album_year"
|
app:layout_constraintTop_toBottomOf="@+id/album_year"
|
||||||
tools:text="20 Songs" />
|
tools:layout_editor_absoluteX="60dp" />
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/song_recycler"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:nestedScrollingEnabled="true"
|
||||||
|
android:overScrollMode="never"
|
||||||
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/header_songs"
|
||||||
|
app:layout_constraintVertical_bias="0.0"
|
||||||
|
tools:itemCount="4"
|
||||||
|
tools:layout_editor_absoluteX="0dp"
|
||||||
|
tools:listitem="@layout/item_album_song" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
</androidx.core.widget.NestedScrollView>
|
</androidx.core.widget.NestedScrollView>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</layout>
|
</layout>
|
|
@ -97,8 +97,6 @@
|
||||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Overline"
|
android:textAppearance="@style/TextAppearance.MaterialComponents.Overline"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
android:fontFamily="@font/inter_bold"
|
android:fontFamily="@font/inter_bold"
|
||||||
android:clickable="true"
|
|
||||||
android:focusable="true"
|
|
||||||
android:layout_marginTop="@dimen/padding_medium"
|
android:layout_marginTop="@dimen/padding_medium"
|
||||||
android:paddingStart="@dimen/padding_medium"
|
android:paddingStart="@dimen/padding_medium"
|
||||||
android:paddingEnd="@dimen/padding_small"
|
android:paddingEnd="@dimen/padding_small"
|
||||||
|
@ -118,9 +116,7 @@
|
||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/header_albums"
|
app:layout_constraintTop_toBottomOf="@+id/header_albums"
|
||||||
app:layout_constraintVertical_bias="0.0"
|
|
||||||
tools:itemCount="4"
|
tools:itemCount="4"
|
||||||
tools:layout_editor_absoluteX="0dp"
|
|
||||||
tools:listitem="@layout/item_album" />
|
tools:listitem="@layout/item_album" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
74
app/src/main/res/layout/item_album_song.xml
Normal file
74
app/src/main/res/layout/item_album_song.xml
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<variable
|
||||||
|
name="song"
|
||||||
|
type="org.oxycblt.auxio.music.models.Song" />
|
||||||
|
</data>
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/ripple"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:padding="@dimen/padding_medium">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/track_number"
|
||||||
|
android:layout_width="@dimen/track_number_size"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@{String.valueOf(song.track)}"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceListItem"
|
||||||
|
android:textColor="?android:attr/textColorTertiary"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:maxLines="1"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
tools:ignore="ContentDescription"
|
||||||
|
tools:src="@drawable/ic_song"
|
||||||
|
tools:text="1" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/song_name"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="@dimen/margin_medium"
|
||||||
|
android:layout_marginEnd="@dimen/margin_medium"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:text="@{song.name}"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceListItem"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/duration"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/track_number"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintVertical_chainStyle="packed"
|
||||||
|
tools:text="Song Name" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/duration"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="@dimen/margin_medium"
|
||||||
|
android:layout_marginEnd="@dimen/margin_medium"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||||
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
|
android:text="@{song.formattedDuration}"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/track_number"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/song_name"
|
||||||
|
tools:text="16:16" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
</layout>
|
|
@ -16,6 +16,8 @@
|
||||||
<dimen name="cover_size_large">80dp</dimen>
|
<dimen name="cover_size_large">80dp</dimen>
|
||||||
<dimen name="cover_size_huge">230dp</dimen>
|
<dimen name="cover_size_huge">230dp</dimen>
|
||||||
|
|
||||||
|
<dimen name="track_number_size">32dp</dimen>
|
||||||
|
|
||||||
<dimen name="detail_header_size_max">26sp</dimen>
|
<dimen name="detail_header_size_max">26sp</dimen>
|
||||||
<dimen name="detail_header_size_min">10sp</dimen>'
|
<dimen name="detail_header_size_min">10sp</dimen>'
|
||||||
<dimen name="detail_header_size_increment">2sp</dimen>
|
<dimen name="detail_header_size_increment">2sp</dimen>
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
<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_albums">Albums</string>
|
<string name="label_albums">Albums</string>
|
||||||
|
<string name="label_songs">Songs</string>
|
||||||
|
|
||||||
<string name="placeholder_unknown_genre">Unknown Genre</string>
|
<string name="placeholder_unknown_genre">Unknown Genre</string>
|
||||||
<string name="placeholder_unknown_artist">Unknown Artist</string>
|
<string name="placeholder_unknown_artist">Unknown Artist</string>
|
||||||
|
|
Loading…
Reference in a new issue