diff --git a/app/src/main/java/org/koitharu/kotatsu/core/prefs/AppSettings.kt b/app/src/main/java/org/koitharu/kotatsu/core/prefs/AppSettings.kt index 4283df21a..427392484 100644 --- a/app/src/main/java/org/koitharu/kotatsu/core/prefs/AppSettings.kt +++ b/app/src/main/java/org/koitharu/kotatsu/core/prefs/AppSettings.kt @@ -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" diff --git a/app/src/main/java/org/koitharu/kotatsu/search/SearchModule.kt b/app/src/main/java/org/koitharu/kotatsu/search/SearchModule.kt index cdb1ee75a..1f14c6ee3 100644 --- a/app/src/main/java/org/koitharu/kotatsu/search/SearchModule.kt +++ b/app/src/main/java/org/koitharu/kotatsu/search/SearchModule.kt @@ -23,5 +23,5 @@ val searchModule viewModel { query -> GlobalSearchViewModel(query.get(), get(), get()) } - viewModel { SearchSuggestionViewModel(get()) } + viewModel { SearchSuggestionViewModel(get(), get()) } } \ No newline at end of file diff --git a/app/src/main/java/org/koitharu/kotatsu/search/ui/suggestion/SearchSuggestionViewModel.kt b/app/src/main/java/org/koitharu/kotatsu/search/ui/suggestion/SearchSuggestionViewModel.kt index 109b7bf00..605f3a231 100644 --- a/app/src/main/java/org/koitharu/kotatsu/search/ui/suggestion/SearchSuggestionViewModel.kt +++ b/app/src/main/java/org/koitharu/kotatsu/search/ui/suggestion/SearchSuggestionViewModel.kt @@ -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(null) - private val isLocalSearch = MutableStateFlow(false) + private val isLocalSearch = MutableStateFlow(settings.isSearchSingleSource) private var suggestionJob: Job? = null val suggestion = MutableLiveData>() init { setupSuggestion() + isLocalSearch.onEach { + settings.isSearchSingleSource = it + }.launchIn(viewModelScope) } fun onQueryChanged(newQuery: String) {