Do not list artists without albums.

As of now, Otter cannot list albumless tracks (for example, tracks in
compilation, appearing under the original artist, but not part of an
album published by this artist). This created a lot of "empty" artists
(with no albums) in the Artists section of the app.

This may be rolled back if we are some day able to list "orphan"
tracks.
This commit is contained in:
Antoine POPINEAU 2020-07-08 14:09:48 +02:00
parent 2c4f8a4329
commit 0facf09c94
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
1 changed files with 22 additions and 4 deletions

View File

@ -15,13 +15,31 @@ import jp.wasabeef.picasso.transformations.RoundedCornersTransformation
import kotlinx.android.synthetic.main.row_artist.view.* import kotlinx.android.synthetic.main.row_artist.view.*
class ArtistsAdapter(val context: Context?, private val listener: OnArtistClickListener) : FunkwhaleAdapter<Artist, ArtistsAdapter.ViewHolder>() { class ArtistsAdapter(val context: Context?, private val listener: OnArtistClickListener) : FunkwhaleAdapter<Artist, ArtistsAdapter.ViewHolder>() {
private var active: List<Artist> = mutableListOf()
interface OnArtistClickListener { interface OnArtistClickListener {
fun onClick(holder: View?, artist: Artist) fun onClick(holder: View?, artist: Artist)
} }
override fun getItemCount() = data.size init {
registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
override fun onChanged() {
active = data.filter { it.albums?.isNotEmpty() ?: false }
override fun getItemId(position: Int) = data[position].id.toLong() super.onChanged()
}
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
active = data.filter { it.albums?.isNotEmpty() ?: false }
super.onItemRangeInserted(positionStart, itemCount)
}
})
}
override fun getItemCount() = active.size
override fun getItemId(position: Int) = active[position].id.toLong()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(context).inflate(R.layout.row_artist, parent, false) val view = LayoutInflater.from(context).inflate(R.layout.row_artist, parent, false)
@ -32,7 +50,7 @@ class ArtistsAdapter(val context: Context?, private val listener: OnArtistClickL
} }
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val artist = data[position] val artist = active[position]
artist.albums?.let { albums -> artist.albums?.let { albums ->
if (albums.isNotEmpty()) { if (albums.isNotEmpty()) {
@ -59,7 +77,7 @@ class ArtistsAdapter(val context: Context?, private val listener: OnArtistClickL
val albums = view.albums val albums = view.albums
override fun onClick(view: View?) { override fun onClick(view: View?) {
listener.onClick(view, data[layoutPosition]) listener.onClick(view, active[layoutPosition])
} }
} }
} }