|
|
@ -3,9 +3,11 @@ package audio.funkwhale.ffa.activities |
|
|
|
import android.os.Bundle |
|
|
|
import android.os.Bundle |
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
import androidx.appcompat.app.AppCompatActivity |
|
|
|
import androidx.appcompat.app.AppCompatActivity |
|
|
|
|
|
|
|
import androidx.appcompat.widget.SearchView |
|
|
|
import androidx.lifecycle.Lifecycle |
|
|
|
import androidx.lifecycle.Lifecycle |
|
|
|
import androidx.lifecycle.lifecycleScope |
|
|
|
import androidx.lifecycle.lifecycleScope |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
|
|
|
|
import audio.funkwhale.ffa.adapters.FavoriteListener |
|
|
|
import audio.funkwhale.ffa.adapters.SearchAdapter |
|
|
|
import audio.funkwhale.ffa.adapters.SearchAdapter |
|
|
|
import audio.funkwhale.ffa.databinding.ActivitySearchBinding |
|
|
|
import audio.funkwhale.ffa.databinding.ActivitySearchBinding |
|
|
|
import audio.funkwhale.ffa.fragments.AddToPlaylistDialog |
|
|
|
import audio.funkwhale.ffa.fragments.AddToPlaylistDialog |
|
|
@ -51,7 +53,12 @@ class SearchActivity : AppCompatActivity() { |
|
|
|
setContentView(binding.root) |
|
|
|
setContentView(binding.root) |
|
|
|
|
|
|
|
|
|
|
|
adapter = |
|
|
|
adapter = |
|
|
|
SearchAdapter(layoutInflater, this, SearchResultClickListener(), FavoriteListener()).also { |
|
|
|
SearchAdapter( |
|
|
|
|
|
|
|
layoutInflater, |
|
|
|
|
|
|
|
this, |
|
|
|
|
|
|
|
SearchResultClickListener(), |
|
|
|
|
|
|
|
FavoriteListener(favoritesRepository) |
|
|
|
|
|
|
|
).also { |
|
|
|
binding.results.layoutManager = LinearLayoutManager(this) |
|
|
|
binding.results.layoutManager = LinearLayoutManager(this) |
|
|
|
binding.results.adapter = it |
|
|
|
binding.results.adapter = it |
|
|
|
} |
|
|
|
} |
|
|
@ -90,59 +97,59 @@ class SearchActivity : AppCompatActivity() { |
|
|
|
tracksRepository = TracksSearchRepository(this@SearchActivity, "") |
|
|
|
tracksRepository = TracksSearchRepository(this@SearchActivity, "") |
|
|
|
favoritesRepository = FavoritesRepository(this@SearchActivity) |
|
|
|
favoritesRepository = FavoritesRepository(this@SearchActivity) |
|
|
|
|
|
|
|
|
|
|
|
binding.search.setOnQueryTextListener(object : |
|
|
|
binding.search.setOnQueryTextListener(object : SearchView.OnQueryTextListener { |
|
|
|
androidx.appcompat.widget.SearchView.OnQueryTextListener { |
|
|
|
|
|
|
|
override fun onQueryTextSubmit(rawQuery: String?): Boolean { |
|
|
|
|
|
|
|
binding.search.clearFocus() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rawQuery?.let { |
|
|
|
override fun onQueryTextSubmit(rawQuery: String?): Boolean { |
|
|
|
done = 0 |
|
|
|
binding.search.clearFocus() |
|
|
|
|
|
|
|
|
|
|
|
val query = URLEncoder.encode(it, "UTF-8") |
|
|
|
rawQuery?.let { |
|
|
|
|
|
|
|
done = 0 |
|
|
|
|
|
|
|
|
|
|
|
artistsRepository.query = query.lowercase(Locale.ROOT) |
|
|
|
val query = URLEncoder.encode(it, "UTF-8") |
|
|
|
albumsRepository.query = query.lowercase(Locale.ROOT) |
|
|
|
|
|
|
|
tracksRepository.query = query.lowercase(Locale.ROOT) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binding.searchSpinner.visibility = View.VISIBLE |
|
|
|
artistsRepository.query = query.lowercase(Locale.ROOT) |
|
|
|
binding.searchEmpty.visibility = View.GONE |
|
|
|
albumsRepository.query = query.lowercase(Locale.ROOT) |
|
|
|
binding.searchNoResults.visibility = View.GONE |
|
|
|
tracksRepository.query = query.lowercase(Locale.ROOT) |
|
|
|
|
|
|
|
|
|
|
|
adapter.artists.clear() |
|
|
|
binding.searchSpinner.visibility = View.VISIBLE |
|
|
|
adapter.albums.clear() |
|
|
|
binding.searchEmpty.visibility = View.GONE |
|
|
|
adapter.tracks.clear() |
|
|
|
binding.searchNoResults.visibility = View.GONE |
|
|
|
adapter.notifyDataSetChanged() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
artistsRepository.fetch(Repository.Origin.Network.origin) |
|
|
|
adapter.artists.clear() |
|
|
|
.untilNetwork(lifecycleScope) { artists, _, _, _ -> |
|
|
|
adapter.albums.clear() |
|
|
|
done++ |
|
|
|
adapter.tracks.clear() |
|
|
|
|
|
|
|
adapter.notifyDataSetChanged() |
|
|
|
|
|
|
|
|
|
|
|
adapter.artists.addAll(artists) |
|
|
|
artistsRepository.fetch(Repository.Origin.Network.origin) |
|
|
|
refresh() |
|
|
|
.untilNetwork(lifecycleScope) { artists, _, _, _ -> |
|
|
|
} |
|
|
|
done++ |
|
|
|
|
|
|
|
|
|
|
|
albumsRepository.fetch(Repository.Origin.Network.origin) |
|
|
|
adapter.artists.addAll(artists) |
|
|
|
.untilNetwork(lifecycleScope) { albums, _, _, _ -> |
|
|
|
refresh() |
|
|
|
done++ |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
adapter.albums.addAll(albums) |
|
|
|
albumsRepository.fetch(Repository.Origin.Network.origin) |
|
|
|
refresh() |
|
|
|
.untilNetwork(lifecycleScope) { albums, _, _, _ -> |
|
|
|
} |
|
|
|
done++ |
|
|
|
|
|
|
|
|
|
|
|
tracksRepository.fetch(Repository.Origin.Network.origin) |
|
|
|
adapter.albums.addAll(albums) |
|
|
|
.untilNetwork(lifecycleScope) { tracks, _, _, _ -> |
|
|
|
refresh() |
|
|
|
done++ |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
adapter.tracks.addAll(tracks) |
|
|
|
tracksRepository.fetch(Repository.Origin.Network.origin) |
|
|
|
refresh() |
|
|
|
.untilNetwork(lifecycleScope) { tracks, _, _, _ -> |
|
|
|
} |
|
|
|
done++ |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true |
|
|
|
adapter.tracks.addAll(tracks) |
|
|
|
|
|
|
|
refresh() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onQueryTextChange(newText: String?) = true |
|
|
|
return true |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onQueryTextChange(newText: String?) = true |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun refresh() { |
|
|
|
private fun refresh() { |
|
|
@ -187,13 +194,4 @@ class SearchActivity : AppCompatActivity() { |
|
|
|
AlbumsFragment.openTracks(this@SearchActivity, album) |
|
|
|
AlbumsFragment.openTracks(this@SearchActivity, album) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
inner class FavoriteListener : SearchAdapter.OnFavoriteListener { |
|
|
|
|
|
|
|
override fun onToggleFavorite(id: Int, state: Boolean) { |
|
|
|
|
|
|
|
when (state) { |
|
|
|
|
|
|
|
true -> favoritesRepository.addFavorite(id) |
|
|
|
|
|
|
|
false -> favoritesRepository.deleteFavorite(id) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|