adding some sections at the albums view
This commit is contained in:
parent
f0c44f3f18
commit
48cf2dcc15
6 changed files with 58 additions and 26 deletions
|
@ -58,7 +58,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:5.30.25'
|
||||
implementation 'com.simplemobiletools:commons:5.30.26'
|
||||
implementation 'org.greenrobot:eventbus:3.2.0'
|
||||
implementation 'com.squareup.picasso:picasso:2.71828'
|
||||
implementation 'androidx.media:media:1.2.0'
|
||||
|
|
|
@ -4,15 +4,14 @@ import android.content.Intent
|
|||
import android.os.Bundle
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.simplemobiletools.commons.extensions.getFormattedDuration
|
||||
import com.simplemobiletools.musicplayer.R
|
||||
import com.simplemobiletools.musicplayer.adapters.AlbumsAdapter
|
||||
import com.simplemobiletools.musicplayer.extensions.getAlbums
|
||||
import com.simplemobiletools.musicplayer.extensions.getSongsSync
|
||||
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.*
|
||||
import kotlinx.android.synthetic.main.activity_albums.*
|
||||
|
||||
// Artists -> Albums -> Songs
|
||||
|
@ -26,15 +25,26 @@ class AlbumsActivity : SimpleActivity() {
|
|||
title = artist.title
|
||||
|
||||
getAlbums(artist) { albums ->
|
||||
val items = albums.toMutableList() as ArrayList<ListItem>
|
||||
val listItems = ArrayList<ListItem>()
|
||||
val albumsSectionLabel = resources.getQuantityString(R.plurals.albums, albums.size, albums.size)
|
||||
listItems.add(AlbumSection(albumsSectionLabel))
|
||||
listItems.addAll(albums)
|
||||
|
||||
var trackFullDuration = 0
|
||||
val tracksToAdd = ArrayList<Song>()
|
||||
albums.forEach {
|
||||
val tracks = getSongsSync(it.id)
|
||||
items.addAll(tracks)
|
||||
trackFullDuration += tracks.sumBy { it.duration }
|
||||
tracksToAdd.addAll(tracks)
|
||||
}
|
||||
|
||||
var tracksSectionLabel = resources.getQuantityString(R.plurals.tracks, tracksToAdd.size, tracksToAdd.size)
|
||||
tracksSectionLabel += " • ${trackFullDuration.getFormattedDuration(true)}"
|
||||
listItems.add(AlbumSection(tracksSectionLabel))
|
||||
|
||||
listItems.addAll(tracksToAdd)
|
||||
runOnUiThread {
|
||||
AlbumsAdapter(this, items, albums_list) {
|
||||
AlbumsAdapter(this, listItems, albums_list) {
|
||||
if (it is Album) {
|
||||
Intent(this, SongsActivity::class.java).apply {
|
||||
putExtra(ALBUM, Gson().toJson(it))
|
||||
|
|
|
@ -16,9 +16,11 @@ 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.AlbumSection
|
||||
import com.simplemobiletools.musicplayer.models.ListItem
|
||||
import com.simplemobiletools.musicplayer.models.Song
|
||||
import kotlinx.android.synthetic.main.item_album.view.*
|
||||
import kotlinx.android.synthetic.main.item_section.view.*
|
||||
import kotlinx.android.synthetic.main.item_song.view.*
|
||||
import java.util.*
|
||||
|
||||
|
@ -26,8 +28,9 @@ import java.util.*
|
|||
class AlbumsAdapter(activity: SimpleActivity, val items: ArrayList<ListItem>, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) :
|
||||
MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
|
||||
|
||||
private val ITEM_ALBUM = 0
|
||||
private val ITEM_TRACK = 1
|
||||
private val ITEM_SECTION = 0
|
||||
private val ITEM_ALBUM = 1
|
||||
private val ITEM_TRACK = 2
|
||||
|
||||
init {
|
||||
setupDragListener(true)
|
||||
|
@ -36,10 +39,10 @@ class AlbumsAdapter(activity: SimpleActivity, val items: ArrayList<ListItem>, re
|
|||
override fun getActionMenuId() = R.menu.cab_albums
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val layout = if (viewType == ITEM_ALBUM) {
|
||||
R.layout.item_album
|
||||
} else {
|
||||
R.layout.item_song
|
||||
val layout = when (viewType) {
|
||||
ITEM_SECTION -> R.layout.item_section
|
||||
ITEM_ALBUM -> R.layout.item_album
|
||||
else -> R.layout.item_song
|
||||
}
|
||||
|
||||
return createViewHolder(layout, parent)
|
||||
|
@ -48,10 +51,10 @@ class AlbumsAdapter(activity: SimpleActivity, val items: ArrayList<ListItem>, re
|
|||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val item = items.getOrNull(position) ?: return
|
||||
holder.bindView(item, true, true) { itemView, layoutPosition ->
|
||||
if (item is Album) {
|
||||
setupAlbum(itemView, item)
|
||||
} else {
|
||||
setupTrack(itemView, item as Song)
|
||||
when (item) {
|
||||
is AlbumSection -> setupSection(itemView, item)
|
||||
is Album -> setupAlbum(itemView, item)
|
||||
else -> setupTrack(itemView, item as Song)
|
||||
}
|
||||
}
|
||||
bindViewHolder(holder)
|
||||
|
@ -60,11 +63,10 @@ class AlbumsAdapter(activity: SimpleActivity, val items: ArrayList<ListItem>, re
|
|||
override fun getItemCount() = items.size
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
val item = items[position]
|
||||
return if (item is Album) {
|
||||
ITEM_ALBUM
|
||||
} else {
|
||||
ITEM_TRACK
|
||||
return when (items[position]) {
|
||||
is AlbumSection -> ITEM_SECTION
|
||||
is Album -> ITEM_ALBUM
|
||||
else -> ITEM_TRACK
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,4 +118,11 @@ class AlbumsAdapter(activity: SimpleActivity, val items: ArrayList<ListItem>, re
|
|||
song_duration.setTextColor(textColor)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupSection(view: View, section: AlbumSection) {
|
||||
view.apply {
|
||||
item_section.text = section.title
|
||||
item_section.setTextColor(textColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
package com.simplemobiletools.musicplayer.models
|
||||
|
||||
data class AlbumSection(val title: String) : ListItem()
|
10
app/src/main/res/layout/item_section.xml
Normal file
10
app/src/main/res/layout/item_section.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.simplemobiletools.commons.views.MyTextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/item_section"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:textSize="@dimen/bigger_text_size"
|
||||
tools:text="3 Albums" />
|
|
@ -49,13 +49,13 @@
|
|||
<!-- Artists -->
|
||||
<string name="artists">Artists</string>
|
||||
<plurals name="albums">
|
||||
<item quantity="one">%d album</item>
|
||||
<item quantity="other">%d albums</item>
|
||||
<item quantity="one">%d Album</item>
|
||||
<item quantity="other">%d Albums</item>
|
||||
</plurals>
|
||||
|
||||
<plurals name="tracks">
|
||||
<item quantity="one">%d track</item>
|
||||
<item quantity="other">%d tracks</item>
|
||||
<item quantity="one">%d Track</item>
|
||||
<item quantity="other">%d Tracks</item>
|
||||
</plurals>
|
||||
|
||||
<!-- Settings -->
|
||||
|
|
Loading…
Reference in a new issue