Merge pull request #593 from nitehu/fix/album_list

Fixed album lists
This commit is contained in:
tzugen 2021-10-12 15:36:52 +02:00 committed by GitHub
commit 855f111cb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 27 deletions

View File

@ -5,14 +5,19 @@ import java.util.Calendar
data class Album( data class Album(
val id: String = "", val id: String = "",
val parent: String = "",
val album: String = "",
val title: String = "",
val name: String = "", val name: String = "",
val discNumber: Int = 0,
val coverArt: String = "", val coverArt: String = "",
val songCount: Int = 0,
val created: Calendar? = null,
val artist: String = "", val artist: String = "",
val artistId: String = "", val artistId: String = "",
val songCount: Int = 0,
val duration: Int = 0, val duration: Int = 0,
val created: Calendar? = null,
val year: Int = 0, val year: Int = 0,
val genre: String = "", val genre: String = "",
@JsonProperty("song") val songList: List<MusicDirectoryChild> = emptyList() @JsonProperty("song") val songList: List<MusicDirectoryChild> = emptyList(),
@JsonProperty("starred") val starredDate: String = ""
) )

View File

@ -16,7 +16,8 @@ fun Album.toDomainEntity(): MusicDirectory.Entry = MusicDirectory.Entry(
duration = this@toDomainEntity.duration, duration = this@toDomainEntity.duration,
created = this@toDomainEntity.created?.time, created = this@toDomainEntity.created?.time,
year = this@toDomainEntity.year, year = this@toDomainEntity.year,
genre = this@toDomainEntity.genre genre = this@toDomainEntity.genre,
starred = this@toDomainEntity.starredDate.isNotEmpty()
) )
fun Album.toMusicDirectoryDomainEntity(): MusicDirectory = MusicDirectory().apply { fun Album.toMusicDirectoryDomainEntity(): MusicDirectory = MusicDirectory().apply {

View File

@ -63,7 +63,8 @@ class AlbumListFragment : GenericListFragment<MusicDirectory.Entry, AlbumRowAdap
{ entry -> onItemClick(entry) }, { entry -> onItemClick(entry) },
{ menuItem, entry -> onContextMenuItemSelected(menuItem, entry) }, { menuItem, entry -> onContextMenuItemSelected(menuItem, entry) },
imageLoaderProvider.getImageLoader(), imageLoaderProvider.getImageLoader(),
onMusicFolderUpdate onMusicFolderUpdate,
requireContext()
) )
} }

View File

@ -7,15 +7,22 @@
package org.moire.ultrasonic.fragment package org.moire.ultrasonic.fragment
import android.content.Context
import android.graphics.drawable.Drawable
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.widget.ImageView import android.widget.ImageView
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import java.lang.Exception
import org.moire.ultrasonic.R import org.moire.ultrasonic.R
import org.moire.ultrasonic.domain.MusicDirectory import org.moire.ultrasonic.domain.MusicDirectory
import org.moire.ultrasonic.imageloader.ImageLoader import org.moire.ultrasonic.imageloader.ImageLoader
import org.moire.ultrasonic.service.MusicServiceFactory.getMusicService
import org.moire.ultrasonic.util.Settings.shouldUseId3Tags
import org.moire.ultrasonic.util.Util
import timber.log.Timber
/** /**
* Creates a Row in a RecyclerView which contains the details of an Album * Creates a Row in a RecyclerView which contains the details of an Album
@ -25,13 +32,19 @@ class AlbumRowAdapter(
onItemClick: (MusicDirectory.Entry) -> Unit, onItemClick: (MusicDirectory.Entry) -> Unit,
onContextMenuClick: (MenuItem, MusicDirectory.Entry) -> Boolean, onContextMenuClick: (MenuItem, MusicDirectory.Entry) -> Boolean,
private val imageLoader: ImageLoader, private val imageLoader: ImageLoader,
onMusicFolderUpdate: (String?) -> Unit onMusicFolderUpdate: (String?) -> Unit,
context: Context,
) : GenericRowAdapter<MusicDirectory.Entry>( ) : GenericRowAdapter<MusicDirectory.Entry>(
onItemClick, onItemClick,
onContextMenuClick, onContextMenuClick,
onMusicFolderUpdate onMusicFolderUpdate
) { ) {
private val starDrawable: Drawable =
Util.getDrawableFromAttribute(context, R.attr.star_full)
private val starHollowDrawable: Drawable =
Util.getDrawableFromAttribute(context, R.attr.star_hollow)
override var itemList = albumList override var itemList = albumList
// Set our layout files // Set our layout files
@ -53,6 +66,8 @@ class AlbumRowAdapter(
holder.details.setOnClickListener { onItemClick(entry) } holder.details.setOnClickListener { onItemClick(entry) }
holder.details.setOnLongClickListener { view -> createPopupMenu(view, listPosition) } holder.details.setOnLongClickListener { view -> createPopupMenu(view, listPosition) }
holder.coverArtId = entry.coverArt holder.coverArtId = entry.coverArt
holder.star.setImageDrawable(if (entry.starred) starDrawable else starHollowDrawable)
holder.star.setOnClickListener { onStarClick(entry, holder.star) }
imageLoader.loadImage( imageLoader.loadImage(
holder.coverArt, entry, holder.coverArt, entry,
@ -78,6 +93,7 @@ class AlbumRowAdapter(
var artist: TextView = view.findViewById(R.id.album_artist) var artist: TextView = view.findViewById(R.id.album_artist)
var details: LinearLayout = view.findViewById(R.id.row_album_details) var details: LinearLayout = view.findViewById(R.id.row_album_details)
var coverArt: ImageView = view.findViewById(R.id.album_coverart) var coverArt: ImageView = view.findViewById(R.id.album_coverart)
var star: ImageView = view.findViewById(R.id.album_star)
var coverArtId: String? = null var coverArtId: String? = null
} }
@ -87,4 +103,33 @@ class AlbumRowAdapter(
override fun newViewHolder(view: View): RecyclerView.ViewHolder { override fun newViewHolder(view: View): RecyclerView.ViewHolder {
return ViewHolder(view) return ViewHolder(view)
} }
/**
* Handles the star / unstar action for an album
*/
private fun onStarClick(entry: MusicDirectory.Entry, star: ImageView) {
entry.starred = !entry.starred
star.setImageDrawable(if (entry.starred) starDrawable else starHollowDrawable)
val musicService = getMusicService()
Thread {
val useId3 = shouldUseId3Tags
try {
if (entry.starred) {
musicService.star(
if (!useId3) entry.id else null,
if (useId3) entry.id else null,
null
)
} else {
musicService.unstar(
if (!useId3) entry.id else null,
if (useId3) entry.id else null,
null
)
}
} catch (all: Exception) {
Timber.e(all)
}
}.start()
}
} }

View File

@ -36,14 +36,14 @@
a:paddingLeft="3dip" a:paddingLeft="3dip"
a:paddingRight="3dip" a:paddingRight="3dip"
a:textAppearance="?android:attr/textAppearanceMedium" a:textAppearance="?android:attr/textAppearanceMedium"
app:layout_constraintEnd_toStartOf="@+id/guideline2" app:layout_constraintEnd_toStartOf="@+id/album_star"
app:layout_constraintLeft_toRightOf="@+id/album_coverart" app:layout_constraintLeft_toRightOf="@+id/album_coverart"
app:layout_constraintStart_toEndOf="@+id/album_coverart" app:layout_constraintStart_toEndOf="@+id/album_coverart"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
<TextView <TextView
a:id="@+id/album_title" a:id="@+id/album_title"
a:layout_width="wrap_content" a:layout_width="match_parent"
a:layout_height="wrap_content" a:layout_height="wrap_content"
a:ellipsize="marquee" a:ellipsize="marquee"
a:singleLine="true" a:singleLine="true"
@ -52,7 +52,7 @@
<TextView <TextView
a:id="@+id/album_artist" a:id="@+id/album_artist"
a:layout_width="wrap_content" a:layout_width="match_parent"
a:layout_height="wrap_content" a:layout_height="wrap_content"
a:singleLine="true" a:singleLine="true"
a:textAppearance="?android:attr/textAppearanceSmall" a:textAppearance="?android:attr/textAppearanceSmall"
@ -67,29 +67,15 @@
a:layout_marginStart="16dp" a:layout_marginStart="16dp"
a:layout_marginLeft="16dp" a:layout_marginLeft="16dp"
a:layout_marginTop="16dp" a:layout_marginTop="16dp"
a:layout_marginEnd="20dp"
a:layout_marginRight="20dp"
a:background="@android:color/transparent" a:background="@android:color/transparent"
a:focusable="false"
a:gravity="center_horizontal" a:gravity="center_horizontal"
a:paddingRight="3dip"
a:src="?attr/star_hollow" a:src="?attr/star_hollow"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="@+id/row_album_details" app:layout_constraintLeft_toRightOf="@+id/row_album_details"
app:layout_constraintStart_toEndOf="@+id/row_album_details" app:layout_constraintStart_toEndOf="@+id/row_album_details"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/ic_star_hollow_dark" tools:src="@drawable/ic_star_hollow_dark" />
a:paddingEnd="3dip" />
<androidx.constraintlayout.widget.Guideline
a:id="@+id/guideline"
a:layout_width="wrap_content"
a:layout_height="wrap_content"
a:orientation="vertical"
app:layout_constraintGuide_begin="76dp" />
<androidx.constraintlayout.widget.Guideline
a:id="@+id/guideline2"
a:layout_width="wrap_content"
a:layout_height="wrap_content"
a:orientation="vertical"
app:layout_constraintGuide_begin="346dp" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>