Remember search mode
This commit is contained in:
@@ -150,6 +150,10 @@ class AppSettings(context: Context) {
|
||||
val isSuggestionsExcludeNsfw: Boolean
|
||||
get() = prefs.getBoolean(KEY_SUGGESTIONS_EXCLUDE_NSFW, false)
|
||||
|
||||
var isSearchSingleSource: Boolean
|
||||
get() = prefs.getBoolean(KEY_SEARCH_SINGLE_SOURCE, false)
|
||||
set(value) = prefs.edit { putBoolean(KEY_SEARCH_SINGLE_SOURCE, value) }
|
||||
|
||||
fun isPagesPreloadAllowed(cm: ConnectivityManager): Boolean {
|
||||
return when (prefs.getString(KEY_PAGES_PRELOAD, null)?.toIntOrNull()) {
|
||||
NETWORK_ALWAYS -> true
|
||||
@@ -247,6 +251,7 @@ class AppSettings(context: Context) {
|
||||
const val KEY_PAGES_PRELOAD = "pages_preload"
|
||||
const val KEY_SUGGESTIONS = "suggestions"
|
||||
const val KEY_SUGGESTIONS_EXCLUDE_NSFW = "suggestions_exclude_nsfw"
|
||||
const val KEY_SEARCH_SINGLE_SOURCE = "search_single_source"
|
||||
|
||||
// About
|
||||
const val KEY_APP_UPDATE = "app_update"
|
||||
|
||||
@@ -23,5 +23,5 @@ val searchModule
|
||||
viewModel { query ->
|
||||
GlobalSearchViewModel(query.get(), get(), get())
|
||||
}
|
||||
viewModel { SearchSuggestionViewModel(get()) }
|
||||
viewModel { SearchSuggestionViewModel(get(), get()) }
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.*
|
||||
import org.koitharu.kotatsu.base.ui.BaseViewModel
|
||||
import org.koitharu.kotatsu.base.ui.widgets.ChipsView
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||
import org.koitharu.kotatsu.search.domain.MangaSearchRepository
|
||||
@@ -18,17 +19,21 @@ private const val MAX_TAGS_ITEMS = 8
|
||||
|
||||
class SearchSuggestionViewModel(
|
||||
private val repository: MangaSearchRepository,
|
||||
private val settings: AppSettings,
|
||||
) : BaseViewModel() {
|
||||
|
||||
private val query = MutableStateFlow("")
|
||||
private val source = MutableStateFlow<MangaSource?>(null)
|
||||
private val isLocalSearch = MutableStateFlow(false)
|
||||
private val isLocalSearch = MutableStateFlow(settings.isSearchSingleSource)
|
||||
private var suggestionJob: Job? = null
|
||||
|
||||
val suggestion = MutableLiveData<List<SearchSuggestionItem>>()
|
||||
|
||||
init {
|
||||
setupSuggestion()
|
||||
isLocalSearch.onEach {
|
||||
settings.isSearchSingleSource = it
|
||||
}.launchIn(viewModelScope)
|
||||
}
|
||||
|
||||
fun onQueryChanged(newQuery: String) {
|
||||
|
||||
Reference in New Issue
Block a user