search: cleanup new filter impl
This commit is contained in:
@@ -154,8 +154,8 @@ class SearchFragment : ListFragment<Music, FragmentSearchBinding>() {
|
|||||||
binding.searchFilterGenres.isChecked = MusicType.GENRES in filters
|
binding.searchFilterGenres.isChecked = MusicType.GENRES in filters
|
||||||
binding.searchFilterPlaylists.isChecked = MusicType.PLAYLISTS in filters
|
binding.searchFilterPlaylists.isChecked = MusicType.PLAYLISTS in filters
|
||||||
binding.searchFilters.apply {
|
binding.searchFilters.apply {
|
||||||
setOnCheckedStateChangeListener { group, ids ->
|
setOnCheckedStateChangeListener { _, ids ->
|
||||||
val types =
|
val filters =
|
||||||
ids.mapNotNullTo(mutableSetOf()) {
|
ids.mapNotNullTo(mutableSetOf()) {
|
||||||
when (it) {
|
when (it) {
|
||||||
R.id.search_filter_songs -> MusicType.SONGS
|
R.id.search_filter_songs -> MusicType.SONGS
|
||||||
@@ -166,7 +166,7 @@ class SearchFragment : ListFragment<Music, FragmentSearchBinding>() {
|
|||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
searchModel.filters = types
|
searchModel.updateFilters(filters)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ package org.oxycblt.auxio.search
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import javax.inject.Inject
|
|
||||||
import org.oxycblt.auxio.R
|
import org.oxycblt.auxio.R
|
||||||
import org.oxycblt.auxio.music.MusicType
|
import org.oxycblt.auxio.music.MusicType
|
||||||
import org.oxycblt.auxio.settings.Settings
|
import org.oxycblt.auxio.settings.Settings
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User configuration specific to the search UI.
|
* User configuration specific to the search UI.
|
||||||
@@ -39,17 +39,47 @@ interface SearchSettings : Settings<Nothing> {
|
|||||||
class SearchSettingsImpl @Inject constructor(@ApplicationContext context: Context) :
|
class SearchSettingsImpl @Inject constructor(@ApplicationContext context: Context) :
|
||||||
Settings.Impl<Nothing>(context), SearchSettings {
|
Settings.Impl<Nothing>(context), SearchSettings {
|
||||||
override var filters: Set<MusicType>
|
override var filters: Set<MusicType>
|
||||||
get() =
|
get() = buildSet {
|
||||||
sharedPreferences
|
val intCode = sharedPreferences.getInt(getString(R.string.set_key_search_filters), 0)
|
||||||
.getStringSet(getString(R.string.set_key_search_filters), null)
|
if (intCode and BIT_SONGS == BIT_SONGS) add(MusicType.SONGS)
|
||||||
?.mapNotNull { it.toIntOrNull()?.let(MusicType::fromIntCode) }
|
if (intCode and BIT_ALBUMS == BIT_ALBUMS) add(MusicType.ALBUMS)
|
||||||
?.toSet() ?: setOf()
|
if (intCode and BIT_ARTISTS == BIT_ARTISTS) add(MusicType.ARTISTS)
|
||||||
|
if (intCode and BIT_GENRES == BIT_GENRES) add(MusicType.GENRES)
|
||||||
|
if (intCode and BIT_PLAYLISTS == BIT_PLAYLISTS) add(MusicType.PLAYLISTS)
|
||||||
|
}
|
||||||
set(value) {
|
set(value) {
|
||||||
|
var intCode = 0;
|
||||||
|
if (MusicType.SONGS in value) intCode = intCode or BIT_SONGS
|
||||||
|
if (MusicType.ALBUMS in value) intCode = intCode or BIT_ALBUMS
|
||||||
|
if (MusicType.ARTISTS in value) intCode = intCode or BIT_ARTISTS
|
||||||
|
if (MusicType.GENRES in value) intCode = intCode or BIT_GENRES
|
||||||
|
if (MusicType.PLAYLISTS in value) intCode = intCode or BIT_PLAYLISTS
|
||||||
sharedPreferences.edit {
|
sharedPreferences.edit {
|
||||||
putStringSet(
|
putInt(getString(R.string.set_key_search_filters), intCode)
|
||||||
getString(R.string.set_key_search_filters),
|
|
||||||
value.map { it.intCode.toString() }.toSet(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun migrate() {
|
||||||
|
val filter = MusicType.fromIntCode(sharedPreferences.getInt(OLD_KEY_SEARCH_FILTER, 0))
|
||||||
|
val intCode = when (filter) {
|
||||||
|
MusicType.SONGS -> BIT_SONGS
|
||||||
|
MusicType.ALBUMS -> BIT_ALBUMS
|
||||||
|
MusicType.ARTISTS -> BIT_ARTISTS
|
||||||
|
MusicType.GENRES -> BIT_GENRES
|
||||||
|
MusicType.PLAYLISTS -> BIT_PLAYLISTS
|
||||||
|
else -> 0
|
||||||
|
}
|
||||||
|
sharedPreferences.edit {
|
||||||
|
putInt(getString(R.string.set_key_search_filters), intCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
private companion object {
|
||||||
|
const val OLD_KEY_SEARCH_FILTER = "KEY_SEARCH_FILTER"
|
||||||
|
const val BIT_SONGS = 0b00001
|
||||||
|
const val BIT_ALBUMS = 0b00010
|
||||||
|
const val BIT_ARTISTS = 0b00100
|
||||||
|
const val BIT_GENRES = 0b01000
|
||||||
|
const val BIT_PLAYLISTS = 0b10000
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,13 +182,20 @@ constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var filters: Set<MusicType>
|
/**
|
||||||
|
* The current filters used for search.
|
||||||
|
*/
|
||||||
|
val filters: Set<MusicType>
|
||||||
get() = searchSettings.filters
|
get() = searchSettings.filters
|
||||||
set(value) {
|
|
||||||
// TODO: make this consistent in convention
|
/**
|
||||||
searchSettings.filters = value
|
* Update the filters used by search. Will trigger a research.
|
||||||
search(lastQuery)
|
* @param filters The new filters to use.
|
||||||
}
|
*/
|
||||||
|
fun updateFilters(filters: Set<MusicType>) {
|
||||||
|
searchSettings.filters = filters
|
||||||
|
search(lastQuery)
|
||||||
|
}
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
val SORT = Sort(Sort.Mode.ByName, Sort.Direction.ASCENDING)
|
val SORT = Sort(Sort.Mode.ByName, Sort.Direction.ASCENDING)
|
||||||
|
|||||||
@@ -47,8 +47,7 @@
|
|||||||
<string name="set_key_round_mode" translatable="false">auxio_round_covers</string>
|
<string name="set_key_round_mode" translatable="false">auxio_round_covers</string>
|
||||||
<string name="set_key_bar_action" translatable="false">auxio_bar_action</string>
|
<string name="set_key_bar_action" translatable="false">auxio_bar_action</string>
|
||||||
|
|
||||||
<string name="set_key_search_filter_to" translatable="false">KEY_SEARCH_FILTER</string>
|
<string name="set_key_search_filters" translatable="false">auxio_search_filters</string>
|
||||||
<string name="set_key_search_filters" translatable="false">auxio_search_filters_TEMP_DEV_TAG_TODO_REMOVE</string>
|
|
||||||
|
|
||||||
<string name="set_key_task_exit" translatable="false">auxio_task_exit</string>
|
<string name="set_key_task_exit" translatable="false">auxio_task_exit</string>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user