From 37f4b1da9ed9182e6fbbc38198231f13816487ae Mon Sep 17 00:00:00 2001 From: Antoine POPINEAU Date: Wed, 8 Jul 2020 13:19:03 +0200 Subject: [PATCH] Sort artists and global albums by name/title. Sort an artist's albums by release date. Display the release year in the albums view (#54). --- .../com/github/apognu/otter/adapters/AlbumsAdapter.kt | 9 +++++++++ .../com/github/apognu/otter/adapters/DownloadsAdapter.kt | 2 +- .../github/apognu/otter/repositories/AlbumsRepository.kt | 4 ++-- .../apognu/otter/repositories/ArtistsRepository.kt | 2 +- .../main/java/com/github/apognu/otter/utils/Models.kt | 3 ++- app/src/main/res/drawable/pill.xml | 9 +++++++++ app/src/main/res/layout/row_album.xml | 8 ++++++++ 7 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 app/src/main/res/drawable/pill.xml diff --git a/app/src/main/java/com/github/apognu/otter/adapters/AlbumsAdapter.kt b/app/src/main/java/com/github/apognu/otter/adapters/AlbumsAdapter.kt index 7ef50e1..a4d2703 100644 --- a/app/src/main/java/com/github/apognu/otter/adapters/AlbumsAdapter.kt +++ b/app/src/main/java/com/github/apognu/otter/adapters/AlbumsAdapter.kt @@ -41,12 +41,21 @@ class AlbumsAdapter(val context: Context?, private val listener: OnAlbumClickLis holder.title.text = album.title holder.artist.text = album.artist.name + holder.release_date.visibility = View.GONE + + album.release_date.split('-').getOrNull(0)?.let { year -> + if (year.isNotEmpty()) { + holder.release_date.visibility = View.VISIBLE + holder.release_date.text = year + } + } } inner class ViewHolder(view: View, private val listener: OnAlbumClickListener) : RecyclerView.ViewHolder(view), View.OnClickListener { val art = view.art val title = view.title val artist = view.artist + val release_date = view.release_date override fun onClick(view: View?) { listener.onClick(view, data[layoutPosition]) diff --git a/app/src/main/java/com/github/apognu/otter/adapters/DownloadsAdapter.kt b/app/src/main/java/com/github/apognu/otter/adapters/DownloadsAdapter.kt index b4e3af6..b3ed5c4 100644 --- a/app/src/main/java/com/github/apognu/otter/adapters/DownloadsAdapter.kt +++ b/app/src/main/java/com/github/apognu/otter/adapters/DownloadsAdapter.kt @@ -79,7 +79,7 @@ class DownloadsAdapter(private val context: Context, private val listener: OnDow Download.STATE_QUEUED, Download.STATE_DOWNLOADING -> DownloadService.sendSetStopReason(context, PinService::class.java, download.contentId, 1, false) Download.STATE_FAILED -> { - Track(download.id, download.title, Artist(0, download.artist, listOf()), Album(0, Album.Artist(""), "", Covers("")), 0, listOf(Track.Upload(download.contentId, 0, 0))).also { + Track(download.id, download.title, Artist(0, download.artist, listOf()), Album(0, Album.Artist(""), "", Covers(""), ""), 0, listOf(Track.Upload(download.contentId, 0, 0))).also { PinService.download(context, it) } } diff --git a/app/src/main/java/com/github/apognu/otter/repositories/AlbumsRepository.kt b/app/src/main/java/com/github/apognu/otter/repositories/AlbumsRepository.kt index efb6920..38af962 100644 --- a/app/src/main/java/com/github/apognu/otter/repositories/AlbumsRepository.kt +++ b/app/src/main/java/com/github/apognu/otter/repositories/AlbumsRepository.kt @@ -17,8 +17,8 @@ class AlbumsRepository(override val context: Context?, artistId: Int? = null) : override val upstream: Upstream by lazy { val url = - if (artistId == null) "/api/v1/albums/?playable=true" - else "/api/v1/albums/?playable=true&artist=$artistId" + if (artistId == null) "/api/v1/albums/?playable=true&ordering=title" + else "/api/v1/albums/?playable=true&artist=$artistId&ordering=release_date" HttpUpstream>( HttpUpstream.Behavior.Progressive, diff --git a/app/src/main/java/com/github/apognu/otter/repositories/ArtistsRepository.kt b/app/src/main/java/com/github/apognu/otter/repositories/ArtistsRepository.kt index c01b0e0..fc797c7 100644 --- a/app/src/main/java/com/github/apognu/otter/repositories/ArtistsRepository.kt +++ b/app/src/main/java/com/github/apognu/otter/repositories/ArtistsRepository.kt @@ -11,7 +11,7 @@ import java.io.BufferedReader class ArtistsRepository(override val context: Context?) : Repository() { override val cacheId = "artists" - override val upstream = HttpUpstream>(HttpUpstream.Behavior.Progressive, "/api/v1/artists/?playable=true", object : TypeToken() {}.type) + override val upstream = HttpUpstream>(HttpUpstream.Behavior.Progressive, "/api/v1/artists/?playable=true&ordering=name", object : TypeToken() {}.type) override fun cache(data: List) = ArtistsCache(data) override fun uncache(reader: BufferedReader) = gsonDeserializerOf(ArtistsCache::class.java).deserialize(reader) diff --git a/app/src/main/java/com/github/apognu/otter/utils/Models.kt b/app/src/main/java/com/github/apognu/otter/utils/Models.kt index 1dab613..fa1ebed 100644 --- a/app/src/main/java/com/github/apognu/otter/utils/Models.kt +++ b/app/src/main/java/com/github/apognu/otter/utils/Models.kt @@ -70,7 +70,8 @@ data class Album( val id: Int, val artist: Artist, val title: String, - val cover: Covers + val cover: Covers, + val release_date: String ) : SearchResult { data class Artist(val name: String) diff --git a/app/src/main/res/drawable/pill.xml b/app/src/main/res/drawable/pill.xml new file mode 100644 index 0000000..adde417 --- /dev/null +++ b/app/src/main/res/drawable/pill.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/row_album.xml b/app/src/main/res/layout/row_album.xml index a7c6464..b03cc1c 100644 --- a/app/src/main/res/layout/row_album.xml +++ b/app/src/main/res/layout/row_album.xml @@ -22,6 +22,7 @@ + + \ No newline at end of file