Skip to content

Commit

Permalink
Make global search "Has result" sticky
Browse files Browse the repository at this point in the history
Closes #133
  • Loading branch information
AntsyLich committed Jul 3, 2024
1 parent ddba71d commit 5a61ca5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ class SourcePreferences(
Preference.appStateKey("trusted_extensions"),
emptySet(),
)

fun globalSearchFilterState() = preferenceStore.getBoolean(
Preference.appStateKey("has_filters_toggle_state"),
false,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,6 +24,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
Expand All @@ -38,6 +40,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()
Expand All @@ -60,6 +63,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) {
Expand Down Expand Up @@ -107,7 +118,7 @@ abstract class SearchScreenModel(
}

fun toggleFilterResults() {
mutableState.update { it.copy(onlyShowHasResults = !it.onlyShowHasResults) }
preferences.globalSearchFilterState().toggle()
}

fun search() {
Expand Down

0 comments on commit 5a61ca5

Please sign in to comment.