add some extra sorting on some places

This commit is contained in:
tibbi 2020-10-18 11:50:08 +02:00
parent 1d0ad94425
commit 890d4381e0
5 changed files with 21 additions and 5 deletions

View file

@ -8,8 +8,8 @@ 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.getAlbumTracksSync
import com.simplemobiletools.musicplayer.extensions.getAlbums
import com.simplemobiletools.musicplayer.extensions.resetQueueItems
import com.simplemobiletools.musicplayer.helpers.ALBUM
import com.simplemobiletools.musicplayer.helpers.ARTIST
@ -48,6 +48,7 @@ class AlbumsActivity : SimpleActivity() {
val tracksToAdd = ArrayList<Track>()
albums.forEach {
val tracks = getAlbumTracksSync(it.id)
tracks.sortWith(compareBy({ it.trackId }, { it.title.toLowerCase() }))
trackFullDuration += tracks.sumBy { it.duration }
tracksToAdd.addAll(tracks)
}

View file

@ -6,6 +6,7 @@ import android.os.Bundle
import android.view.Menu
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.simplemobiletools.commons.helpers.AlphanumericComparator
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.musicplayer.R
import com.simplemobiletools.musicplayer.adapters.SongsAdapter
@ -44,10 +45,15 @@ class TracksActivity : SimpleActivity() {
val tracks = ArrayList<Track>()
val listItems = ArrayList<ListItem>()
if (playlist != null) {
tracks.addAll(getPlaylistSongs(playlist.id))
val playlistTracks = getPlaylistSongs(playlist.id)
playlistTracks.sortWith { o1, o2 -> AlphanumericComparator().compare(o1.title.toLowerCase(), o2.title.toLowerCase()) }
tracks.addAll(playlistTracks)
listItems.addAll(tracks)
} else {
tracks.addAll(getAlbumTracksSync(album.id))
val albumTracks = getAlbumTracksSync(album.id)
albumTracks.sortWith(compareBy({ it.trackId }, { it.title.toLowerCase() }))
tracks.addAll(albumTracks)
val coverArt = ContentUris.withAppendedId(artworkUri, album.id.toLong()).toString()
val header = AlbumHeader(album.title, coverArt, album.year, tracks.size, tracks.sumBy { it.duration }, album.artist)
listItems.add(header)

View file

@ -10,6 +10,7 @@ import com.simplemobiletools.commons.extensions.getIntValue
import com.simplemobiletools.commons.extensions.getLongValue
import com.simplemobiletools.commons.extensions.getStringValue
import com.simplemobiletools.commons.extensions.showErrorToast
import com.simplemobiletools.commons.helpers.AlphanumericComparator
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.isOreoPlus
import com.simplemobiletools.commons.helpers.isQPlus
@ -162,6 +163,7 @@ fun Context.getAlbumsSync(artist: Artist): ArrayList<Album> {
showErrorToast(e)
}
albums.sortWith { o1, o2 -> AlphanumericComparator().compare(o1.title.toLowerCase(), o2.title.toLowerCase()) }
return albums
}

View file

@ -12,6 +12,7 @@ import com.simplemobiletools.commons.extensions.getIntValue
import com.simplemobiletools.commons.extensions.getLongValue
import com.simplemobiletools.commons.extensions.getStringValue
import com.simplemobiletools.commons.extensions.showErrorToast
import com.simplemobiletools.commons.helpers.AlphanumericComparator
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.musicplayer.activities.AlbumsActivity
import com.simplemobiletools.musicplayer.activities.SimpleActivity
@ -69,6 +70,8 @@ class ArtistsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
activity.showErrorToast(e)
}
artists.sortWith { o1, o2 -> AlphanumericComparator().compare(o1.title.toLowerCase(), o2.title.toLowerCase()) }
// move <unknown> at the bottom
val unknown = artists.firstOrNull { it.title == MediaStore.UNKNOWN_STRING }
if (unknown != null) {

View file

@ -1,4 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/cab_add_to_playlist"
android:title="@string/add_to_playlist"
app:showAsAction="never" />
</menu>