mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor: Simplify code
This commit is contained in:
parent
712be76112
commit
5a99a0322b
2 changed files with 57 additions and 49 deletions
|
@ -24,12 +24,14 @@ import androidx.compose.ui.platform.LocalContext
|
|||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import dev.yokai.domain.ComposableAlertDialog
|
||||
import dev.yokai.presentation.AppBarType
|
||||
import dev.yokai.presentation.YokaiScaffold
|
||||
import dev.yokai.presentation.component.EmptyScreen
|
||||
import dev.yokai.presentation.extension.repo.component.ExtensionRepoItem
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.util.compose.LocalAlertDialog
|
||||
import eu.kanade.tachiyomi.util.compose.currentOrThrow
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
|
||||
|
@ -44,7 +46,7 @@ fun ExtensionRepoScreen(
|
|||
val repoState = viewModel.repoState.collectAsState()
|
||||
var inputText by remember { mutableStateOf("") }
|
||||
val listState = rememberLazyListState()
|
||||
val alertDialog = LocalAlertDialog.current ?: throw RuntimeException("LocalAlertDialog not yet provided")
|
||||
val alertDialog = LocalAlertDialog.currentOrThrow
|
||||
|
||||
YokaiScaffold(
|
||||
onNavigationIconClicked = onBackPress,
|
||||
|
@ -59,8 +61,7 @@ fun ExtensionRepoScreen(
|
|||
|
||||
val repos = (repoState.value as ExtensionRepoState.Success).repos
|
||||
|
||||
if (alertDialog.content != null)
|
||||
alertDialog.content?.let { it() }
|
||||
alertDialog.content?.let { it() }
|
||||
|
||||
LazyColumn(
|
||||
modifier = Modifier.padding(innerPadding),
|
||||
|
@ -93,52 +94,7 @@ fun ExtensionRepoScreen(
|
|||
ExtensionRepoItem(
|
||||
repoUrl = repo,
|
||||
onDeleteClick = { repoToDelete ->
|
||||
alertDialog.content =
|
||||
{
|
||||
AlertDialog(
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
title = {
|
||||
Text(
|
||||
text = stringResource(R.string.confirm_delete_repo_title),
|
||||
fontStyle = MaterialTheme.typography.titleMedium.fontStyle,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
fontSize = 24.sp,
|
||||
)
|
||||
},
|
||||
text = {
|
||||
Text(
|
||||
text = stringResource(R.string.confirm_delete_repo, repoToDelete),
|
||||
fontStyle = MaterialTheme.typography.bodyMedium.fontStyle,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
fontSize = 14.sp,
|
||||
)
|
||||
},
|
||||
onDismissRequest = { alertDialog.content = null },
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
viewModel.deleteRepo(repoToDelete)
|
||||
alertDialog.content = null
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.delete),
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
fontSize = 14.sp,
|
||||
)
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { alertDialog.content = null }) {
|
||||
Text(
|
||||
text = stringResource(R.string.cancel),
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
fontSize = 14.sp,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
alertDialog.content = { ExtensionRepoDeletePrompt(repoToDelete, alertDialog, viewModel) }
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -159,3 +115,50 @@ fun ExtensionRepoScreen(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ExtensionRepoDeletePrompt(repoToDelete: String, alertDialog: ComposableAlertDialog, viewModel: ExtensionRepoViewModel) {
|
||||
AlertDialog(
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
title = {
|
||||
Text(
|
||||
text = stringResource(R.string.confirm_delete_repo_title),
|
||||
fontStyle = MaterialTheme.typography.titleMedium.fontStyle,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
fontSize = 24.sp,
|
||||
)
|
||||
},
|
||||
text = {
|
||||
Text(
|
||||
text = stringResource(R.string.confirm_delete_repo, repoToDelete),
|
||||
fontStyle = MaterialTheme.typography.bodyMedium.fontStyle,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
fontSize = 14.sp,
|
||||
)
|
||||
},
|
||||
onDismissRequest = { alertDialog.content = null },
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
viewModel.deleteRepo(repoToDelete)
|
||||
alertDialog.content = null
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.delete),
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
fontSize = 14.sp,
|
||||
)
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { alertDialog.content = null }) {
|
||||
Text(
|
||||
text = stringResource(R.string.cancel),
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
fontSize = 14.sp,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
package eu.kanade.tachiyomi.util.compose
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.ProvidableCompositionLocal
|
||||
import androidx.compose.runtime.compositionLocalOf
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import dev.yokai.domain.ComposableAlertDialog
|
||||
|
||||
val <T> ProvidableCompositionLocal<T?>.currentOrThrow
|
||||
@Composable
|
||||
get(): T = this.current ?: throw RuntimeException("CompositionLocal is null")
|
||||
|
||||
val LocalBackPress: ProvidableCompositionLocal<(() -> Unit)?> = staticCompositionLocalOf { null }
|
||||
val LocalAlertDialog: ProvidableCompositionLocal<ComposableAlertDialog?> = compositionLocalOf { null }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue