Skip to content

Commit

Permalink
make app visible on android auto need to be tested and fix search in …
Browse files Browse the repository at this point in the history
…offline ext
  • Loading branch information
brahmkshatriya committed Jan 6, 2025
1 parent 83a46fb commit e0a9425
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>

<meta-data android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ object MediaStoreUtils {

fun <E> List<E>.searchBy(query: String, block: (E) -> List<String?>) = map { item ->
val titles = block(item).mapNotNull { it }.ifEmpty { return@map 0 to item }
val distance = titles.map { it to wagnerFischer(it, query) }.minBy { it.second }
val distance = titles.map { it to wagnerFischer(it, query) }.maxBy { it.second }
val bonus = if (distance.first.contains(query, true)) -20 else 0
distance.second + bonus to item
}.filter { it.first <= 0 }.sortedBy { it.first }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,15 @@ class OfflineExtension(
context.saveToCache("search_history", history, "offline")
}

override suspend fun searchTabs(query: String) =
listOf("All", "Tracks", "Albums", "Artists").map { Tab(it, it) }
override suspend fun searchTabs(query: String) = if (query.isBlank()) listOf()
else listOf("All", "Tracks", "Albums", "Artists").map { Tab(it, it) }

override fun searchFeed(query: String, tab: Tab?) = run {
query.ifBlank { return@run emptyList() }
query.ifBlank {
return@run library.songList.sortedByDescending {
it.extras["addDate"]?.toLongOrNull()
}.map { it.toMediaItem().toShelf() }
}
saveInHistory(query)
val tracks = library.songList.map { it }.searchBy(query) {
listOf(it.title, it.album?.title) + it.artists.map { artist -> artist.name }
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/xml/automotive_app_desc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<automotiveApp xmlns:tools="http://schemas.android.com/tools">
<uses name="media"/>
<uses name="video" tools:ignore="InvalidUsesTagAttribute" />
</automotiveApp>

0 comments on commit e0a9425

Please sign in to comment.