Native Android client for Spotify, built with Jetpack Compose
Kotlin ad-freeadblockandroidjetpack-composekotlinlyricsmusic-playermusic-videomyspotispotifyspotify-adblockerspotify-clientspotify-connectspotui
Android Auto: Home, Library and Downloads tabs with grids and artwork, search with playlists, albums and artists, Start radio on lists and artists, downloaded songs played from their files and browsable offline
kota-zo5fea9903508d
diff --git a/base/app/src/main/java/com/music/spotui/di/AutoBrowser.kt b/base/app/src/main/java/com/music/spotui/di/AutoBrowser.ktindex 21bf77bb..640546d8 100644--- a/base/app/src/main/java/com/music/spotui/di/AutoBrowser.kt+++ b/base/app/src/main/java/com/music/spotui/di/AutoBrowser.kt@@ -9,8 +9,19 @@ import app.myspoti.engine.Rimport app.myspoti.host.android.MyspotiRuntimeimport com.music.spotui.data.api.Responseimport com.music.spotui.data.entity.ContextPageModel+import com.music.spotui.data.entity.HomeItemimport com.music.spotui.data.entity.SongsModel+import com.music.spotui.data.offline.LocalPlayPlan+import com.music.spotui.data.offline.OfflineCollections+import com.music.spotui.data.offline.OfflineStore+import com.music.spotui.data.offline.OfflineTrack+import app.myspoti.api.MediaKind+import app.myspoti.api.best+import app.myspoti.api.groupRecents+import com.music.spotui.data.DataSaver+import kotlinx.coroutines.asyncimport kotlinx.coroutines.flow.first+import kotlinx.coroutines.launchimport kotlinx.coroutines.withTimeoutOrNull/**@@ -20,12 +31,18 @@ import kotlinx.coroutines.withTimeoutOrNullclass AudioNotReady(what: String) : IllegalStateException("player not ready: $what")/**- * Android Auto / media browser tree, built from the app's own data (not the web page):- * Liked Songs, playlists, albums, followed artists, and search. Tapping a track plays it- * in its context, the same way the album / playlist screens do.+ * Android Auto / media browser tree, built from the app's own data (not the web page).*- * Media ids: "liked", "playlists", "albums", "artists" (lists); "pl:<id>", "al:<id>",- * "ar:<id>" (contexts); "t|<context uri>|<play key>" (a track to play).+ * Root tabs (Auto allows four): Home (recently played, then the home feed's shelves, each a titled+ * group), Library (Liked Songs, playlists, albums, artists), Downloads (served from the files,+ * no network needed). Search answers songs, playlists, albums and artists as titled groups.+ * Tapping a song plays it in its context, the way the album / playlist screens do: a downloaded+ * song plays the local copy (see [playTrack]). "Start radio" items start Spotify's radio.+ *+ * Media ids: "home", "library", "downloads" (tabs); "liked", "playlists", "albums", "artists",+ * "dsongs" (lists); "pl:<id>", "al:<id>", "ar:<id>|<name>", "dl:<list uri>" (contexts);+ * "t|<context uri>|<play key>" (a song), "d|<list uri or empty>|<track id>" (a downloaded song),+ * "radio|<seed uri>|<fallback song uri>" (start a radio).*/object AutoBrowser {const val ROOT = "root"@@ -38,53 +55,202 @@ object AutoBrowser {private const val MAX_ITEMS = 300/** Cold start: the car binds before the hidden Web Player is up; browse waits this long. */private const val READY_WAIT_MS = 25_000L+ /** Home: how many recents, shelves and items per shelf (the car pages through a long tab slowly). */+ private const val HOME_RECENTS = 8+ private const val HOME_SHELVES = 6+ private const val HOME_PER_SHELF = 10++ private const val STYLE_LIST = 1+ private const val STYLE_GRID = 2+ private const val KEY_BROWSABLE = "android.media.browse.CONTENT_STYLE_BROWSABLE_HINT"+ private const val KEY_PLAYABLE = "android.media.browse.CONTENT_STYLE_PLAYABLE_HINT"+ private const val KEY_GROUP = "android.media.browse.CONTENT_STYLE_GROUP_TITLE_HINT"// Contexts recently listed, so a tap plays with the right queue.private val pages = java.util.concurrent.ConcurrentHashMap<String, ContextPageModel>()+ private val scope = kotlinx.coroutines.CoroutineScope(kotlinx.coroutines.SupervisorJob() + kotlinx.coroutines.Dispatchers.IO)/**- * Browse for [parentId]. The root is static and answers at once, so the car draws its- * four folders while the page loads; every other node needs the session, and waits for- * it instead of returning an empty list, which Android Auto keeps as the folder's- * content until it unsubscribes (issue #41, cold start).+ * Browse for [parentId]. The tabs, the Library list and the Downloads answer at once (no+ * session, no network); every other node needs the session, and waits for it instead of+ * returning an empty list, which Android Auto keeps as the folder's content until it+ * unsubscribes (issue #41, cold start).*/suspend fun children(context: Context, parentId: String): List<MediaItem> {- if (parentId == ROOT) return listOf(- browsable("liked", context.getString(R.string.collection_liked_songs_title), null, grid = false),- browsable("playlists", context.getString(R.string.aa_playlists), null, grid = false),- browsable("albums", context.getString(R.string.aa_albums), null, grid = false),- browsable("artists", context.getString(R.string.aa_artists), null, grid = false),- )+ when {+ parentId == ROOT -> return listOf(+ tab(context, "home", R.string.aa_home, "aa_ic_home", STYLE_GRID),+ tab(context, "library", R.string.aa_library, "aa_ic_library", STYLE_LIST),+ tab(context, "downloads", R.string.aa_downloads, "aa_ic_downloads", STYLE_LIST),+ )+ parentId == "library" -> return libraryTab(context)+ parentId == "downloads" -> return downloadsTab(context)+ parentId == "dsongs" -> return downloadedSongs("")+ parentId.startsWith("dl:") -> return downloadedSongs(parentId.removePrefix("dl:"))+ }+ // No connection: a downloaded list opens from its files, the web page is not needed.+ if (!OfflineStore.isOnline(context)) offlineContext(parentId)?.let { return it }if (!awaitPlayer()) throw AudioNotReady("browse $parentId")return when {+ parentId == "home" -> homeTab(context)parentId == "playlists" || parentId == "albums" -> {val wantPlaylists = parentId == "playlists"val entries = (firstResult { Graph.api.getLibrary() } ?: emptyList()).filter { it.isPlaylist == wantPlaylists && it.spotifyId != com.music.spotui.data.api.Api.HomeCache.LIKED_SONGS_ID }entries.take(MAX_ITEMS).map { e ->- browsable(if (wantPlaylists) "pl:${e.spotifyId}" else "al:${e.spotifyId}", e.name, e.coverUri, subtitle = e.subtitle)+ browsable(if (wantPlaylists) "pl:${e.spotifyId}" else "al:${e.spotifyId}", e.name, art(e.coverUri), subtitle = e.subtitle)}}parentId == "artists" -> Graph.api.getFollowedArtists().filter { it.id.isNotBlank() }.take(MAX_ITEMS).map { a ->- browsable("ar:${a.id}|${a.name}", a.name, a.coverUri)+ browsable("ar:${a.id}|${a.name}", a.name, art(a.coverUri))}- parentId == "liked" -> tracksOf(firstResult { Graph.api.getLikedPage() })- parentId.startsWith("pl:") -> tracksOf(firstResult { Graph.api.getPlaylistPage(parentId.removePrefix("pl:")) })- parentId.startsWith("al:") -> tracksOf(firstResult { Graph.api.getAlbumPage(parentId.removePrefix("al:")) })+ parentId == "liked" -> tracksOf(context, firstResult { Graph.api.getLikedPage() })+ parentId.startsWith("pl:") -> tracksOf(context, firstResult { Graph.api.getPlaylistPage(parentId.removePrefix("pl:")) })+ parentId.startsWith("al:") -> tracksOf(context, firstResult { Graph.api.getAlbumPage(parentId.removePrefix("al:")) })parentId.startsWith("ar:") -> {val (id, name) = parentId.removePrefix("ar:").split("|", limit = 2).let { it[0] to it.getOrElse(1) { "" } }- val overview = firstResult { Graph.api.getArtistOverview(name, id) }- overview?.topTracks?.map { playable("spotify:artist:$id", it.song) }.orEmpty()+ val overview = firstResult { Graph.api.getArtistOverview(name, id) } ?: return emptyList()+ val songs = context.getString(R.string.aa_songs)+ listOf(radioItem(context, "spotify:artist:$id", "", name)) ++ overview.topTracks.map { playable("spotify:artist:$id", it.song, songs) } ++ overview.popularReleases.filter { it.spotifyId.isNotBlank() }.take(12).map {+ browsable("al:${it.spotifyId}", it.name, art(it.coverUri), subtitle = it.year, group = context.getString(R.string.aa_albums))+ }}else -> emptyList()}}+ // ── Tabs ──++ private fun tab(context: Context, id: String, title: Int, icon: String, style: Int): MediaItem {+ val d = MediaDescriptionCompat.Builder().setMediaId(id).setTitle(context.getString(title))+ .setIconUri(Uri.parse("android.resource://${context.packageName}/drawable/$icon"))+ .setExtras(hints(style, null)).build()+ return MediaItem(d, MediaItem.FLAG_BROWSABLE)+ }++ private fun libraryTab(context: Context): List<MediaItem> = listOf(+ browsable("liked", context.getString(R.string.collection_liked_songs_title), resource(context, "aa_ic_liked"), grid = false),+ browsable("playlists", context.getString(R.string.aa_playlists), resource(context, "aa_ic_playlists"), grid = false),+ browsable("albums", context.getString(R.string.aa_albums), resource(context, "aa_ic_albums"), grid = false),+ browsable("artists", context.getString(R.string.aa_artists), resource(context, "aa_ic_artists"), grid = false),+ )++ /** Recently played, then the home feed's shelves (mixes, jump back in, …), each a titled group. */+ private suspend fun homeTab(context: Context): List<MediaItem> = kotlinx.coroutines.coroutineScope {+ val recents = async { runCatching { recentItems(context) }.getOrDefault(emptyList()) }+ val feed = async { runCatching { firstResult { Graph.api.getHomeFeed() } }.getOrNull() }+ val out = ArrayList<MediaItem>(recents.await())+ feed.await()?.sections?.take(HOME_SHELVES)?.forEach { section ->+ val title = section.title.ifBlank { context.getString(R.string.aa_home) }+ section.items.mapNotNull { homeItem(it, title) }.take(HOME_PER_SHELF).let(out::addAll)+ }+ out+ }++ private fun homeItem(item: HomeItem, group: String): MediaItem? = when (item) {+ is HomeItem.Playlist -> browsable(+ if (item.id == com.music.spotui.data.api.Api.HomeCache.LIKED_SONGS_ID) "liked" else "pl:${item.id}",+ item.name, art(item.imageUrl), group = group,+ ).takeIf { item.id.isNotBlank() }+ is HomeItem.Album -> browsable("al:${item.id}", item.name, art(item.imageUrl), subtitle = item.artists, group = group).takeIf { item.id.isNotBlank() }+ is HomeItem.Artist -> browsable("ar:${item.id}|${item.name}", item.name, art(item.imageUrl), group = group).takeIf { item.id.isNotBlank() }+ else -> null+ }++ /** The account's recents (all devices): playlists, albums, artists and Liked Songs, as a group. */+ private suspend fun recentItems(context: Context): List<MediaItem> {+ val entries = withTimeoutOrNull(TIMEOUT_MS) { MyspotiRuntime.api.recents.recentEntries(0, 50).items } ?: return emptyList()+ val title = context.getString(R.string.aa_recent)+ val seen = HashSet<String>()+ return groupRecents(entries).flatMap { it.groups }.filter { it.music }.mapNotNull { g ->+ val c = g.context+ val id = c.uri.substringAfterLast(':')+ val mediaId = when {+ c.kind == MediaKind.PLAYLIST -> "pl:$id"+ c.kind == MediaKind.ALBUM -> "al:$id"+ c.kind == MediaKind.ARTIST -> "ar:$id|${c.title}"+ c.kind == MediaKind.COLLECTION && c.uri == "spotify:collection:tracks" -> "liked"+ else -> return@mapNotNull null+ }+ if (id.isBlank() || !seen.add(mediaId)) return@mapNotNull null+ browsable(mediaId, c.title, art(c.images.best(300)?.url), subtitle = c.subtitle.orEmpty(), group = title)+ }.take(HOME_RECENTS)+ }++ // ── Downloads (from the files, no session) ──++ private fun downloadsTab(context: Context): List<MediaItem> {+ val out = ArrayList<MediaItem>()+ val songs = OfflineStore.list()+ if (songs.isNotEmpty()) out += browsable(+ "dsongs", context.getString(R.string.aa_downloaded_songs), downloadedCover(context, songs.first()),+ subtitle = songs.size.toString(), grid = false,+ )+ val lists = context.getString(R.string.aa_downloaded_lists)+ OfflineCollections.collections.values.sortedBy { it.name.lowercase() }.take(MAX_ITEMS).forEach { c ->+ val first = c.trackIds.firstNotNullOfOrNull { OfflineStore.tracks[it] }+ out += browsable("dl:${c.uri}", c.name, first?.let { downloadedCover(context, it) }, group = lists)+ }+ return out+ }++ /** The downloaded songs of the list at [listUri] (all of them when empty), as local-play items. */+ private fun downloadedSongs(listUri: String): List<MediaItem> =+ downloadedIds(listUri).take(MAX_ITEMS).mapNotNull { OfflineStore.tracks[it] }.map { t ->+ val d = MediaDescriptionCompat.Builder().setMediaId("d|$listUri|${t.trackId}")+ .setTitle(t.title).setSubtitle(t.artist).setIconUri(ArtworkProvider.uriForDownloaded(t))+ .setExtras(hints(STYLE_LIST, null)).build()+ MediaItem(d, MediaItem.FLAG_PLAYABLE)+ }++ /** Track ids of the downloaded songs of a list in its order, or of every download (newest first). */+ private fun downloadedIds(listUri: String): List<String> {+ if (listUri.isBlank()) return OfflineStore.list().map { it.trackId }+ val c = OfflineCollections.collections[listUri] ?: return emptyList()+ val ordered = OfflineCollections.offlinePage(listUri)?.tracks?.map { it.spotifyTrackId.ifBlank { it.url } }.orEmpty()+ return (ordered + c.trackIds).distinct().filter(OfflineStore::isDownloaded)+ }++ private fun downloadedCover(context: Context, t: OfflineTrack): Uri? = ArtworkProvider.uriForDownloaded(t)++ /** Offline, a downloaded list (or Liked Songs) opens from its stored page; null when it was never downloaded. */+ private fun offlineContext(parentId: String): List<MediaItem>? {+ val uri = when {+ parentId == "liked" -> "spotify:collection:tracks"+ parentId.startsWith("pl:") -> "spotify:playlist:${parentId.removePrefix("pl:")}"+ parentId.startsWith("al:") -> "spotify:album:${parentId.removePrefix("al:")}"+ else -> return null+ }+ if (!OfflineCollections.isDownloaded(uri)) return null+ return downloadedSongs(uri)+ }++ // ── Search ──+suspend fun search(query: String): List<MediaItem> {if (!awaitPlayer()) throw AudioNotReady("search")val r = firstResult { Graph.api.searchEverything(query) } ?: return emptyList()- return r.songs.take(20).map { playable("", it) } +- r.albums.filter { it.spotifyId.isNotBlank() }.take(8).map { browsable("al:${it.spotifyId}", it.name, it.coverUri, subtitle = it.artists) }+ val context = Graph.app+ val songs = r.songs.take(10)+ val out = ArrayList<MediaItem>()+ songs.firstOrNull()?.let { out += radioItem(context, it.url, it.url, it.title) }+ val songsTitle = context.getString(R.string.aa_songs)+ songs.forEach { out += playable("", it, songsTitle) }+ val playlists = context.getString(R.string.aa_playlists)+ r.playlists.filter { it.spotifyId.isNotBlank() && !it.isFolder }.take(8).forEach {+ out += browsable("pl:${it.spotifyId}", it.name, art(it.coverUri), subtitle = it.subtitle, group = playlists)+ }+ val albums = context.getString(R.string.aa_albums)+ r.albums.filter { it.spotifyId.isNotBlank() }.take(8).forEach {+ out += browsable("al:${it.spotifyId}", it.name, art(it.coverUri), subtitle = it.artists, group = albums)+ }+ val artists = context.getString(R.string.aa_artists)+ r.artists.filter { it.id.isNotBlank() }.take(8).forEach {+ out += browsable("ar:${it.id}|${it.name}", it.name, art(it.coverUri), group = artists)+ }+ return out}/** Voice search ("play X on Myspoti"): the best matching track. */@@ -105,13 +271,40 @@ object AutoBrowser {MyspotiRuntime.api.ready.value ||withTimeoutOrNull(READY_WAIT_MS) { MyspotiRuntime.api.ready.first { it } } != null+ // ── Playing ──+fun play(mediaId: String) {val parts = mediaId.split("|", limit = 3)- if (parts.size < 3 || parts[0] != "t") return- val contextUri = parts[1].ifBlank { null }- val key = parts[2]+ if (parts.size < 3) return+ when (parts[0]) {+ "t" -> playTrack(parts[1].ifBlank { null }, parts[2])+ "d" -> playDownloaded(parts[1], parts[2])+ "radio" -> startRadio(parts[1], parts[2])+ }+ }++ private fun onMain(block: () -> Unit) { android.os.Handler(android.os.Looper.getMainLooper()).post(block) }++ private fun playTrack(contextUri: String?, key: String) {val page = contextUri?.let { pages[it] }val song = page?.tracks?.firstOrNull { it.url == key }+ // A downloaded song plays its file, not the stream (the phone's rule, see LocalPlayPlan):+ // offline or on the data saver the list's downloaded songs, online the whole list when it+ // is all downloaded; a lone downloaded song (search) always.+ val store = OfflineStore+ val id = song?.spotifyTrackId?.ifBlank { null } ?: key.removePrefix("spotify:track:")+ val ids = if (page != null) LocalPlayPlan.localIds(+ page.tracks.map { it.spotifyTrackId.ifBlank { it.url } }, id, page.complete,+ offline = !store.isOnline(Graph.app), dataSaver = DataSaver.active, isDownloaded = store::isDownloaded,+ ) else if (store.isDownloaded(id)) listOf(id) else null+ if (ids != null) {+ val local = ids.mapNotNull { store.tracks[it] }+ val at = local.indexOfFirst { it.trackId == id }+ if (at >= 0) {+ onMain { LocalPlayer.play(local.map(store::toLocalTrack), at, shuffle = Graph.currentSongState.shuffle.value, context = page?.name ?: local[at].title, contextUri = page?.uri.orEmpty()) }+ return+ }+ }if (page != null) {Graph.currentSongState.updateQueue(page.tracks)if (page.type == "liked") SongPlayer.registerLikedSongs(page.tracks.map { it.url })@@ -120,10 +313,41 @@ object AutoBrowser {song?.let { Graph.currentSongState.updateSongState(it.coverUri, it.title, it.singer, true, it.id, 0, it.album) }}- private fun tracksOf(page: ContextPageModel?): List<MediaItem> {+ /** The Downloads tab: always the files, from the tapped song on. */+ private fun playDownloaded(listUri: String, trackId: String) {+ val store = OfflineStore+ val local = downloadedIds(listUri).mapNotNull { store.tracks[it] }+ val at = local.indexOfFirst { it.trackId == trackId }+ if (at < 0) return+ val name = OfflineCollections.collections[listUri]?.name ?: Graph.app.getString(R.string.aa_downloaded_songs)+ onMain { LocalPlayer.play(local.map(store::toLocalTrack), at, shuffle = Graph.currentSongState.shuffle.value, context = name, contextUri = listUri) }+ }++ /**+ * "Start radio": Spotify's radio playlist for the song / artist / list (the phone's "Go to song+ * radio" opens the same playlist), played from its first song. A list that has no radio of its+ * own falls back to the radio of [fallbackSong].+ */+ private fun startRadio(seed: String, fallbackSong: String) {+ scope.launch {+ val id = Graph.api.radioPlaylistId(seed)+ ?: fallbackSong.takeIf { it.startsWith("spotify:track:") }?.let { Graph.api.radioPlaylistId(it) }+ ?: return@launch+ val page = firstResult { Graph.api.getPlaylistPage(id) }?.takeIf { it.tracks.isNotEmpty() } ?: return@launch+ pages[page.uri] = page+ play("t|${page.uri}|${page.tracks.first().url}")+ }+ }++ // ── Items ──++ private fun tracksOf(context: Context, page: ContextPageModel?): List<MediaItem> {page ?: return emptyList()pages[page.uri] = page- return page.tracks.take(MAX_ITEMS).map { playable(page.uri, it) }+ val first = page.tracks.firstOrNull()+ val songs = context.getString(R.string.aa_songs)+ val radio = if (first == null) emptyList() else listOf(radioItem(context, page.uri.takeIf { page.type != "liked" } ?: first.url, first.url, page.name))+ return radio + page.tracks.take(MAX_ITEMS).map { playable(page.uri, it, songs) }}private suspend fun <T> firstResult(load: suspend () -> kotlinx.coroutines.flow.Flow<Response<T>>): T? =@@ -131,19 +355,32 @@ object AutoBrowser {(load().first { it !is Response.Loading } as? Response.Success)?.data}- private fun browsable(id: String, title: String, cover: String?, subtitle: String = "", grid: Boolean = true): MediaItem {- val extras = Bundle().apply {- putInt("android.media.browse.CONTENT_STYLE_BROWSABLE_HINT", if (grid) 2 else 1)- putInt("android.media.browse.CONTENT_STYLE_PLAYABLE_HINT", 1)- }+ private fun art(url: String?): Uri? = ArtworkProvider.uriFor(url)++ private fun resource(context: Context, name: String): Uri = Uri.parse("android.resource://${context.packageName}/drawable/$name")++ private fun hints(style: Int, group: String?) = Bundle().apply {+ putInt(KEY_BROWSABLE, style)+ putInt(KEY_PLAYABLE, STYLE_LIST)+ if (group != null) putString(KEY_GROUP, group)+ }++ private fun browsable(id: String, title: String, icon: Uri?, subtitle: String = "", grid: Boolean = true, group: String? = null): MediaItem {val d = MediaDescriptionCompat.Builder().setMediaId(id).setTitle(title).setSubtitle(subtitle)- .setIconUri(ArtworkProvider.uriFor(cover)).setExtras(extras).build()+ .setIconUri(icon).setExtras(hints(if (grid) STYLE_GRID else STYLE_LIST, group)).build()return MediaItem(d, MediaItem.FLAG_BROWSABLE)}- private fun playable(contextUri: String, s: SongsModel): MediaItem {+ private fun playable(contextUri: String, s: SongsModel, group: String? = null): MediaItem {val d = MediaDescriptionCompat.Builder().setMediaId("t|$contextUri|${s.url}")- .setTitle(s.title).setSubtitle(s.singer).setIconUri(ArtworkProvider.uriFor(s.coverUri)).build()+ .setTitle(s.title).setSubtitle(s.singer).setIconUri(art(s.coverUri)).setExtras(hints(STYLE_LIST, group)).build()+ return MediaItem(d, MediaItem.FLAG_PLAYABLE)+ }++ private fun radioItem(context: Context, seed: String, fallbackSong: String, name: String): MediaItem {+ val d = MediaDescriptionCompat.Builder().setMediaId("radio|$seed|$fallbackSong")+ .setTitle(context.getString(R.string.aa_start_radio)).setSubtitle(name)+ .setIconUri(resource(context, "aa_ic_radio")).setExtras(hints(STYLE_LIST, null)).build()return MediaItem(d, MediaItem.FLAG_PLAYABLE)}}@@ -157,6 +394,13 @@ class ArtworkProvider : android.content.ContentProvider() {private val AUTHORITY = app.myspoti.engine.BuildConfig.APPLICATION_ID + ".artwork"private val allowedHosts = setOf("i.scdn.co", "mosaic.scdn.co", "image-cdn-ak.spotifycdn.com", "image-cdn-fa.spotifycdn.com", "thisis-images.spotifycdn.com", "seeded-session-images.scdn.co", "pickasso.spotifycdn.com")+ /** A downloaded song's cover: its file (the car is offline), else the CDN image. */+ fun uriForDownloaded(t: com.music.spotui.data.offline.OfflineTrack): Uri? {+ if (t.cover.isNotBlank() && java.io.File(com.music.spotui.data.offline.OfflineStore.coverDir, t.cover).isFile)+ return Uri.Builder().scheme("content").authority(AUTHORITY).appendPath("cover").appendQueryParameter("f", t.cover).build()+ return uriFor(t.coverUrl)+ }+fun uriFor(url: String?): Uri? {if (url.isNullOrBlank() || !allowed(url)) return nullreturn Uri.Builder().scheme("content").authority(AUTHORITY).appendPath("img").appendQueryParameter("u", url).build()@@ -175,6 +419,12 @@ class ArtworkProvider : android.content.ContentProvider() {}override fun openFile(uri: Uri, mode: String): android.os.ParcelFileDescriptor? {+ // A downloaded song's cover: only a file that a download of the store names, never a path.+ uri.getQueryParameter("f")?.let { name ->+ val file = com.music.spotui.data.offline.OfflineStore.tracks.values.firstOrNull { it.cover == name }+ ?.let(com.music.spotui.data.offline.OfflineStore::coverFile) ?: return null+ return android.os.ParcelFileDescriptor.open(file, android.os.ParcelFileDescriptor.MODE_READ_ONLY)+ }val url = uri.getQueryParameter("u") ?: return nullif (!allowed(url)) return null// Bounded: a binder thread must not wait on the network forever.diff --git a/base/app/src/main/res/drawable/aa_ic_albums.xml b/base/app/src/main/res/drawable/aa_ic_albums.xmlnew file mode 100644index 00000000..3dbbd839--- /dev/null+++ b/base/app/src/main/res/drawable/aa_ic_albums.xml@@ -0,0 +1,7 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- Android Auto icon: Material Icons "album" (Google, Apache License 2.0). Tinted by the car on tabs. -->+<vector xmlns:android="http://schemas.android.com/apk/res/android"+ android:width="24dp" android:height="24dp"+ android:viewportWidth="24" android:viewportHeight="24">+ <path android:fillColor="#FFFFFFFF" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,16c-2.21,0 -4,-1.79 -4,-4s1.79,-4 4,-4 4,1.79 4,4 -1.79,4 -4,4zM12,11c-0.55,0 -1,0.45 -1,1s0.45,1 1,1 1,-0.45 1,-1 -0.45,-1 -1,-1z" />+</vector>diff --git a/base/app/src/main/res/drawable/aa_ic_artists.xml b/base/app/src/main/res/drawable/aa_ic_artists.xmlnew file mode 100644index 00000000..30b35c58--- /dev/null+++ b/base/app/src/main/res/drawable/aa_ic_artists.xml@@ -0,0 +1,7 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- Android Auto icon: Material Icons "person" (Google, Apache License 2.0). Tinted by the car on tabs. -->+<vector xmlns:android="http://schemas.android.com/apk/res/android"+ android:width="24dp" android:height="24dp"+ android:viewportWidth="24" android:viewportHeight="24">+ <path android:fillColor="#FFFFFFFF" android:pathData="M12,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM12,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z" />+</vector>diff --git a/base/app/src/main/res/drawable/aa_ic_downloads.xml b/base/app/src/main/res/drawable/aa_ic_downloads.xmlnew file mode 100644index 00000000..8945fb0b--- /dev/null+++ b/base/app/src/main/res/drawable/aa_ic_downloads.xml@@ -0,0 +1,7 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- Android Auto tab: Material Icons "file_download" (Google, Apache License 2.0). Tinted by the car. -->+<vector xmlns:android="http://schemas.android.com/apk/res/android"+ android:width="24dp" android:height="24dp"+ android:viewportWidth="24" android:viewportHeight="24">+ <path android:fillColor="#FFFFFFFF" android:pathData="M19,9h-4V3H9v6H5l7,7 7,-7zM5,18v2h14v-2H5z" />+</vector>diff --git a/base/app/src/main/res/drawable/aa_ic_home.xml b/base/app/src/main/res/drawable/aa_ic_home.xmlnew file mode 100644index 00000000..76b0984d--- /dev/null+++ b/base/app/src/main/res/drawable/aa_ic_home.xml@@ -0,0 +1,7 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- Android Auto icon: Material Icons "home" (Google, Apache License 2.0). Tinted by the car on tabs. -->+<vector xmlns:android="http://schemas.android.com/apk/res/android"+ android:width="24dp" android:height="24dp"+ android:viewportWidth="24" android:viewportHeight="24">+ <path android:fillColor="#FFFFFFFF" android:pathData="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z" />+</vector>diff --git a/base/app/src/main/res/drawable/aa_ic_library.xml b/base/app/src/main/res/drawable/aa_ic_library.xmlnew file mode 100644index 00000000..58d554d9--- /dev/null+++ b/base/app/src/main/res/drawable/aa_ic_library.xml@@ -0,0 +1,7 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- Android Auto icon: Material Icons "library_music" (Google, Apache License 2.0). Tinted by the car on tabs. -->+<vector xmlns:android="http://schemas.android.com/apk/res/android"+ android:width="24dp" android:height="24dp"+ android:viewportWidth="24" android:viewportHeight="24">+ <path android:fillColor="#FFFFFFFF" android:pathData="M20,2L8,2c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM18,7h-3v5.5c0,1.38 -1.12,2.5 -2.5,2.5S10,13.88 10,12.5s1.12,-2.5 2.5,-2.5c0.57,0 1.08,0.19 1.5,0.51L14,5h4v2zM4,6L2,6v14c0,1.1 0.9,2 2,2h14v-2L4,20L4,6z" />+</vector>diff --git a/base/app/src/main/res/drawable/aa_ic_liked.xml b/base/app/src/main/res/drawable/aa_ic_liked.xmlnew file mode 100644index 00000000..1fa23c84--- /dev/null+++ b/base/app/src/main/res/drawable/aa_ic_liked.xml@@ -0,0 +1,7 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- Android Auto icon: Material Icons "favorite" (Google, Apache License 2.0). Tinted by the car on tabs. -->+<vector xmlns:android="http://schemas.android.com/apk/res/android"+ android:width="24dp" android:height="24dp"+ android:viewportWidth="24" android:viewportHeight="24">+ <path android:fillColor="#FFFFFFFF" android:pathData="M12,21.35l-1.45,-1.32C5.4,15.36 2,12.28 2,8.5 2,5.42 4.42,3 7.5,3c1.74,0 3.41,0.81 4.5,2.09C13.09,3.81 14.76,3 16.5,3 19.58,3 22,5.42 22,8.5c0,3.78 -3.4,6.86 -8.55,11.54L12,21.35z" />+</vector>diff --git a/base/app/src/main/res/drawable/aa_ic_playlists.xml b/base/app/src/main/res/drawable/aa_ic_playlists.xmlnew file mode 100644index 00000000..bae1e919--- /dev/null+++ b/base/app/src/main/res/drawable/aa_ic_playlists.xml@@ -0,0 +1,7 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- Android Auto icon: Material Icons "queue_music" (Google, Apache License 2.0). Tinted by the car on tabs. -->+<vector xmlns:android="http://schemas.android.com/apk/res/android"+ android:width="24dp" android:height="24dp"+ android:viewportWidth="24" android:viewportHeight="24">+ <path android:fillColor="#FFFFFFFF" android:pathData="M15,6H3v2h12V6zM15,10H3v2h12v-2zM3,16h8v-2H3v2zM17,6v8.18c-0.31,-0.11 -0.65,-0.18 -1,-0.18 -1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3V8h3V6h-5z" />+</vector>diff --git a/base/app/src/main/res/drawable/aa_ic_radio.xml b/base/app/src/main/res/drawable/aa_ic_radio.xmlnew file mode 100644index 00000000..07e60352--- /dev/null+++ b/base/app/src/main/res/drawable/aa_ic_radio.xml@@ -0,0 +1,7 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- Android Auto icon: Material Icons "radio" (Google, Apache License 2.0). Tinted by the car on tabs. -->+<vector xmlns:android="http://schemas.android.com/apk/res/android"+ android:width="24dp" android:height="24dp"+ android:viewportWidth="24" android:viewportHeight="24">+ <path android:fillColor="#FFFFFFFF" android:pathData="M3.24,6.15C2.51,6.43 2,7.17 2,8v12c0,1.1 0.89,2 2,2h16c1.11,0 2,-0.9 2,-2L22,8c0,-1.1 -0.89,-2 -2,-2L8.3,6l8.26,-3.34L15.88,1 3.24,6.15zM7,20c-1.66,0 -3,-1.34 -3,-3s1.34,-3 3,-3 3,1.34 3,3 -1.34,3 -3,3zM20,12h-2v-2h-2v2L4,12L4,8h16v4z" />+</vector>