Browse Source

Optimized workflow between two searches.

housekeeping/remove-warnings
Antoine POPINEAU 4 years ago
parent
commit
b9e9272336
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
  1. 13
      app/src/main/java/com/github/apognu/otter/activities/SearchActivity.kt
  2. 15
      app/src/main/java/com/github/apognu/otter/repositories/SearchRepository.kt

13
app/src/main/java/com/github/apognu/otter/activities/SearchActivity.kt

@ -12,6 +12,7 @@ import com.github.apognu.otter.fragments.ArtistsFragment @@ -12,6 +12,7 @@ import com.github.apognu.otter.fragments.ArtistsFragment
import com.github.apognu.otter.repositories.*
import com.github.apognu.otter.utils.Album
import com.github.apognu.otter.utils.Artist
import com.github.apognu.otter.utils.log
import com.github.apognu.otter.utils.untilNetwork
import kotlinx.android.synthetic.main.activity_search.*
import java.net.URLEncoder
@ -42,6 +43,11 @@ class SearchActivity : AppCompatActivity() { @@ -42,6 +43,11 @@ class SearchActivity : AppCompatActivity() {
override fun onResume() {
super.onResume()
artistsRepository = ArtistsSearchRepository(this@SearchActivity, "")
albumsRepository = AlbumsSearchRepository(this@SearchActivity, "")
tracksRepository = TracksSearchRepository(this@SearchActivity, "")
favoritesRepository = FavoritesRepository(this@SearchActivity)
search.requestFocus()
search.setOnQueryTextListener(object : androidx.appcompat.widget.SearchView.OnQueryTextListener {
@ -53,10 +59,9 @@ class SearchActivity : AppCompatActivity() { @@ -53,10 +59,9 @@ class SearchActivity : AppCompatActivity() {
val query = URLEncoder.encode(it, "UTF-8")
tracksRepository = TracksSearchRepository(this@SearchActivity, query.toLowerCase(Locale.ROOT))
albumsRepository = AlbumsSearchRepository(this@SearchActivity, query.toLowerCase(Locale.ROOT))
artistsRepository = ArtistsSearchRepository(this@SearchActivity, query.toLowerCase(Locale.ROOT))
favoritesRepository = FavoritesRepository(this@SearchActivity)
artistsRepository.query = query.toLowerCase(Locale.ROOT)
albumsRepository.query = query.toLowerCase(Locale.ROOT)
tracksRepository.query = query.toLowerCase(Locale.ROOT)
search_spinner.visibility = View.VISIBLE
search_empty.visibility = View.GONE

15
app/src/main/java/com/github/apognu/otter/repositories/SearchRepository.kt

@ -10,9 +10,10 @@ import kotlinx.coroutines.flow.toList @@ -10,9 +10,10 @@ import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.runBlocking
import java.io.BufferedReader
class TracksSearchRepository(override val context: Context?, query: String) : Repository<Track, TracksCache>() {
class TracksSearchRepository(override val context: Context?, var query: String) : Repository<Track, TracksCache>() {
override val cacheId: String? = null
override val upstream = HttpUpstream<Track, OtterResponse<Track>>(HttpUpstream.Behavior.AtOnce, "/api/v1/tracks/?playable=true&q=$query", object : TypeToken<TracksResponse>() {}.type)
override val upstream: Upstream<Track>
get() = HttpUpstream(HttpUpstream.Behavior.AtOnce, "/api/v1/tracks/?playable=true&q=$query", object : TypeToken<TracksResponse>() {}.type)
override fun cache(data: List<Track>) = TracksCache(data)
override fun uncache(reader: BufferedReader) = gsonDeserializerOf(TracksCache::class.java).deserialize(reader)
@ -40,17 +41,19 @@ class TracksSearchRepository(override val context: Context?, query: String) : Re @@ -40,17 +41,19 @@ class TracksSearchRepository(override val context: Context?, query: String) : Re
}
}
class ArtistsSearchRepository(override val context: Context?, query: String) : Repository<Artist, ArtistsCache>() {
class ArtistsSearchRepository(override val context: Context?, var query: String) : Repository<Artist, ArtistsCache>() {
override val cacheId: String? = null
override val upstream = HttpUpstream<Artist, OtterResponse<Artist>>(HttpUpstream.Behavior.AtOnce, "/api/v1/artists/?playable=true&q=$query", object : TypeToken<ArtistsResponse>() {}.type)
override val upstream: Upstream<Artist>
get() = HttpUpstream(HttpUpstream.Behavior.AtOnce, "/api/v1/artists/?playable=true&q=$query", object : TypeToken<ArtistsResponse>() {}.type)
override fun cache(data: List<Artist>) = ArtistsCache(data)
override fun uncache(reader: BufferedReader) = gsonDeserializerOf(ArtistsCache::class.java).deserialize(reader)
}
class AlbumsSearchRepository(override val context: Context?, query: String) : Repository<Album, AlbumsCache>() {
class AlbumsSearchRepository(override val context: Context?, var query: String) : Repository<Album, AlbumsCache>() {
override val cacheId: String? = null
override val upstream = HttpUpstream<Album, OtterResponse<Album>>(HttpUpstream.Behavior.AtOnce, "/api/v1/albums/?playable=true&q=$query", object : TypeToken<AlbumsResponse>() {}.type)
override val upstream: Upstream<Album>
get() = HttpUpstream(HttpUpstream.Behavior.AtOnce, "/api/v1/albums/?playable=true&q=$query", object : TypeToken<AlbumsResponse>() {}.type)
override fun cache(data: List<Album>) = AlbumsCache(data)
override fun uncache(reader: BufferedReader) = gsonDeserializerOf(AlbumsCache::class.java).deserialize(reader)

Loading…
Cancel
Save