Remember search mode

pull/128/head
Koitharu 4 years ago
parent 996f8f0f2e
commit 4913332444
No known key found for this signature in database
GPG Key ID: 8E861F8CE6E7CE27

@ -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) {

Loading…
Cancel
Save