Make global search "Has result" sticky
Closes #133 (cherry picked from commit 5a61ca5535fe0d9e8e7bcb9e665ba2f9cb0cf649) # Conflicts: # app/src/main/java/eu/kanade/domain/source/service/SourcePreferences.kt
This commit is contained in:
parent
2f23ad6bfd
commit
3db4bccebc
@ -49,6 +49,11 @@ class SourcePreferences(
|
||||
emptySet(),
|
||||
)
|
||||
|
||||
fun globalSearchFilterState() = preferenceStore.getBoolean(
|
||||
Preference.appStateKey("has_filters_toggle_state"),
|
||||
false,
|
||||
)
|
||||
|
||||
// SY -->
|
||||
fun enableSourceBlacklist() = preferenceStore.getBoolean("eh_enable_source_blacklist", true)
|
||||
|
||||
|
@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.compose.runtime.produceState
|
||||
import cafe.adriel.voyager.core.model.StateScreenModel
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import eu.kanade.domain.manga.model.toDomainManga
|
||||
import eu.kanade.domain.source.service.SourcePreferences
|
||||
import eu.kanade.presentation.util.ioCoroutineScope
|
||||
@ -24,6 +25,7 @@ import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.isActive
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import tachiyomi.core.common.preference.toggle
|
||||
import tachiyomi.domain.manga.interactor.GetManga
|
||||
import tachiyomi.domain.manga.interactor.NetworkToLocalManga
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
@ -39,6 +41,7 @@ abstract class SearchScreenModel(
|
||||
private val extensionManager: ExtensionManager = Injekt.get(),
|
||||
private val networkToLocalManga: NetworkToLocalManga = Injekt.get(),
|
||||
private val getManga: GetManga = Injekt.get(),
|
||||
private val preferences: SourcePreferences = Injekt.get(),
|
||||
) : StateScreenModel<SearchScreenModel.State>(initialState) {
|
||||
|
||||
private val coroutineDispatcher = Executors.newFixedThreadPool(5).asCoroutineDispatcher()
|
||||
@ -61,6 +64,14 @@ abstract class SearchScreenModel(
|
||||
)
|
||||
}
|
||||
|
||||
init {
|
||||
screenModelScope.launch {
|
||||
preferences.globalSearchFilterState().changes().collectLatest { state ->
|
||||
mutableState.update { it.copy(onlyShowHasResults = state) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun getManga(initialManga: Manga): androidx.compose.runtime.State<Manga> {
|
||||
return produceState(initialValue = initialManga) {
|
||||
@ -111,7 +122,7 @@ abstract class SearchScreenModel(
|
||||
}
|
||||
|
||||
fun toggleFilterResults() {
|
||||
mutableState.update { it.copy(onlyShowHasResults = !it.onlyShowHasResults) }
|
||||
preferences.globalSearchFilterState().toggle()
|
||||
}
|
||||
|
||||
fun search() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user