|
@@ -4,28 +4,24 @@ import androidx.compose.foundation.layout.PaddingValues
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
import androidx.compose.foundation.lazy.items
|
|
|
import androidx.compose.runtime.Composable
|
|
|
-import androidx.compose.runtime.LaunchedEffect
|
|
|
import androidx.compose.ui.Modifier
|
|
|
import androidx.compose.ui.platform.LocalContext
|
|
|
import androidx.compose.ui.res.stringResource
|
|
|
import eu.kanade.presentation.components.AppBar
|
|
|
import eu.kanade.presentation.components.EmptyScreen
|
|
|
import eu.kanade.presentation.components.FastScrollLazyColumn
|
|
|
-import eu.kanade.presentation.components.LoadingScreen
|
|
|
import eu.kanade.presentation.components.Scaffold
|
|
|
import eu.kanade.presentation.more.settings.widget.SwitchPreferenceWidget
|
|
|
import eu.kanade.tachiyomi.R
|
|
|
-import eu.kanade.tachiyomi.ui.browse.extension.ExtensionFilterPresenter
|
|
|
+import eu.kanade.tachiyomi.ui.browse.extension.ExtensionFilterState
|
|
|
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
|
|
-import eu.kanade.tachiyomi.util.system.toast
|
|
|
-import kotlinx.coroutines.flow.collectLatest
|
|
|
|
|
|
@Composable
|
|
|
fun ExtensionFilterScreen(
|
|
|
navigateUp: () -> Unit,
|
|
|
- presenter: ExtensionFilterPresenter,
|
|
|
+ state: ExtensionFilterState.Success,
|
|
|
+ onClickToggle: (String) -> Unit,
|
|
|
) {
|
|
|
- val context = LocalContext.current
|
|
|
Scaffold(
|
|
|
topBar = { scrollBehavior ->
|
|
|
AppBar(
|
|
@@ -35,50 +31,37 @@ fun ExtensionFilterScreen(
|
|
|
)
|
|
|
},
|
|
|
) { contentPadding ->
|
|
|
- when {
|
|
|
- presenter.isLoading -> LoadingScreen()
|
|
|
- presenter.isEmpty -> EmptyScreen(
|
|
|
+ if (state.isEmpty) {
|
|
|
+ EmptyScreen(
|
|
|
textResource = R.string.empty_screen,
|
|
|
modifier = Modifier.padding(contentPadding),
|
|
|
)
|
|
|
- else -> ExtensionFilterContent(
|
|
|
- contentPadding = contentPadding,
|
|
|
- state = presenter,
|
|
|
- onClickLang = {
|
|
|
- presenter.toggleLanguage(it)
|
|
|
- },
|
|
|
- )
|
|
|
- }
|
|
|
- }
|
|
|
- LaunchedEffect(Unit) {
|
|
|
- presenter.events.collectLatest {
|
|
|
- when (it) {
|
|
|
- ExtensionFilterPresenter.Event.FailedFetchingLanguages -> {
|
|
|
- context.toast(R.string.internal_error)
|
|
|
- }
|
|
|
- }
|
|
|
+ return@Scaffold
|
|
|
}
|
|
|
+ ExtensionFilterContent(
|
|
|
+ contentPadding = contentPadding,
|
|
|
+ state = state,
|
|
|
+ onClickLang = onClickToggle,
|
|
|
+ )
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
|
private fun ExtensionFilterContent(
|
|
|
contentPadding: PaddingValues,
|
|
|
- state: ExtensionFilterState,
|
|
|
+ state: ExtensionFilterState.Success,
|
|
|
onClickLang: (String) -> Unit,
|
|
|
) {
|
|
|
+ val context = LocalContext.current
|
|
|
FastScrollLazyColumn(
|
|
|
contentPadding = contentPadding,
|
|
|
) {
|
|
|
- items(
|
|
|
- items = state.items,
|
|
|
- ) { model ->
|
|
|
- val lang = model.lang
|
|
|
+ items(state.languages) { language ->
|
|
|
SwitchPreferenceWidget(
|
|
|
modifier = Modifier.animateItemPlacement(),
|
|
|
- title = LocaleHelper.getSourceDisplayName(lang, LocalContext.current),
|
|
|
- checked = model.enabled,
|
|
|
- onCheckedChanged = { onClickLang(lang) },
|
|
|
+ title = LocaleHelper.getSourceDisplayName(language, context),
|
|
|
+ checked = language in state.enabledLanguages,
|
|
|
+ onCheckedChanged = { onClickLang(language) },
|
|
|
)
|
|
|
}
|
|
|
}
|