Browse Source

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.
housekeeping/remove-warnings
Antoine POPINEAU 4 years ago
parent
commit
0facf09c94
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
  1. 26
      app/src/main/java/com/github/apognu/otter/adapters/ArtistsAdapter.kt

26
app/src/main/java/com/github/apognu/otter/adapters/ArtistsAdapter.kt

@ -15,13 +15,31 @@ import jp.wasabeef.picasso.transformations.RoundedCornersTransformation @@ -15,13 +15,31 @@ import jp.wasabeef.picasso.transformations.RoundedCornersTransformation
import kotlinx.android.synthetic.main.row_artist.view.*
class ArtistsAdapter(val context: Context?, private val listener: OnArtistClickListener) : FunkwhaleAdapter<Artist, ArtistsAdapter.ViewHolder>() {
private var active: List<Artist> = mutableListOf()
interface OnArtistClickListener {
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 }
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) = data[position].id.toLong()
override fun getItemId(position: Int) = active[position].id.toLong()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
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 @@ -32,7 +50,7 @@ class ArtistsAdapter(val context: Context?, private val listener: OnArtistClickL
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val artist = data[position]
val artist = active[position]
artist.albums?.let { albums ->
if (albums.isNotEmpty()) {
@ -59,7 +77,7 @@ class ArtistsAdapter(val context: Context?, private val listener: OnArtistClickL @@ -59,7 +77,7 @@ class ArtistsAdapter(val context: Context?, private val listener: OnArtistClickL
val albums = view.albums
override fun onClick(view: View?) {
listener.onClick(view, data[layoutPosition])
listener.onClick(view, active[layoutPosition])
}
}
}
Loading…
Cancel
Save