diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/AlbumsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/AlbumsActivity.kt index 074bba31..e884cc7e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/AlbumsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/AlbumsActivity.kt @@ -12,6 +12,7 @@ import com.simplemobiletools.musicplayer.helpers.ALBUM import com.simplemobiletools.musicplayer.helpers.ARTIST import com.simplemobiletools.musicplayer.models.Album import com.simplemobiletools.musicplayer.models.Artist +import com.simplemobiletools.musicplayer.models.ListItem import com.simplemobiletools.musicplayer.models.Song import kotlinx.android.synthetic.main.activity_albums.* @@ -26,8 +27,9 @@ class AlbumsActivity : SimpleActivity() { title = artist.title getAlbums(artist) { albums -> + val items = albums.toMutableList() as ArrayList runOnUiThread { - AlbumsAdapter(this, albums, albums_list) { + AlbumsAdapter(this, items, albums_list) { Intent(this, SongsActivity::class.java).apply { putExtra(ALBUM, Gson().toJson(it as Album)) startActivity(this) diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/AlbumsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/AlbumsAdapter.kt index 4f66680f..3a9e6e8f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/AlbumsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/AlbumsAdapter.kt @@ -14,10 +14,12 @@ import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.musicplayer.R import com.simplemobiletools.musicplayer.activities.SimpleActivity import com.simplemobiletools.musicplayer.models.Album +import com.simplemobiletools.musicplayer.models.ListItem import kotlinx.android.synthetic.main.item_album.view.* import java.util.* -class AlbumsAdapter(activity: SimpleActivity, val albums: ArrayList, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : +// we show both albums and individual songs here +class AlbumsAdapter(activity: SimpleActivity, val items: ArrayList, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) { init { @@ -29,32 +31,32 @@ class AlbumsAdapter(activity: SimpleActivity, val albums: ArrayList, recy override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_album, parent) override fun onBindViewHolder(holder: ViewHolder, position: Int) { - val album = albums.getOrNull(position) ?: return + val album = items.getOrNull(position) ?: return holder.bindView(album, true, true) { itemView, layoutPosition -> - setupView(itemView, album) + setupView(itemView, album as Album) } bindViewHolder(holder) } - override fun getItemCount() = albums.size + override fun getItemCount() = items.size override fun prepareActionMode(menu: Menu) {} override fun actionItemPressed(id: Int) {} - override fun getSelectableItemCount() = albums.size + override fun getSelectableItemCount() = items.size override fun getIsItemSelectable(position: Int) = true - override fun getItemSelectionKey(position: Int) = albums.getOrNull(position)?.id + override fun getItemSelectionKey(position: Int) = (items.getOrNull(position) as? Album)?.id - override fun getItemKeyPosition(key: Int) = albums.indexOfFirst { it.id == key } + override fun getItemKeyPosition(key: Int) = items.indexOfFirst { (it as Album).id == key } override fun onActionModeCreated() {} override fun onActionModeDestroyed() {} - private fun getItemWithKey(key: Int): Album? = albums.firstOrNull { it.id == key } + private fun getItemWithKey(key: Int): ListItem? = items.firstOrNull { (it as Album).id == key } private fun setupView(view: View, album: Album) { view.apply { diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/models/Album.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/models/Album.kt index c94efb5b..d4f64532 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/models/Album.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/models/Album.kt @@ -1,3 +1,3 @@ package com.simplemobiletools.musicplayer.models -data class Album(val id: Int, val artist: String, val title: String) +data class Album(val id: Int, val artist: String, val title: String): ListItem() diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/models/ListItem.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/models/ListItem.kt new file mode 100644 index 00000000..99e81265 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/models/ListItem.kt @@ -0,0 +1,3 @@ +package com.simplemobiletools.musicplayer.models + +open class ListItem diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/models/Song.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/models/Song.kt index 901b2413..6d1ccd83 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/models/Song.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/models/Song.kt @@ -22,7 +22,7 @@ data class Song( @ColumnInfo(name = "duration") val duration: Int, @ColumnInfo(name = "album") val album: String, @ColumnInfo(name = "playlist_id") val playListId: Int, - @ColumnInfo(name = "track_id") val trackId: Int) : Serializable, Comparable { + @ColumnInfo(name = "track_id") val trackId: Int) : Serializable, Comparable, ListItem() { companion object { private const val serialVersionUID = 6717978793256852245L