|
|
@ -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,8 +97,8 @@ 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 { |
|
|
|
override fun onQueryTextSubmit(rawQuery: String?): Boolean { |
|
|
|
binding.search.clearFocus() |
|
|
|
binding.search.clearFocus() |
|
|
|
|
|
|
|
|
|
|
@ -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) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|