mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
feat: Functional LocalAlertDialog
Probably unnecessary in this use-case, but it's the only place I can test it lol
This commit is contained in:
parent
1fb0e32868
commit
712be76112
4 changed files with 75 additions and 55 deletions
10
app/src/main/java/dev/yokai/domain/ComposableAlertDialog.kt
Normal file
10
app/src/main/java/dev/yokai/domain/ComposableAlertDialog.kt
Normal file
|
@ -0,0 +1,10 @@
|
|||
package dev.yokai.domain
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
|
||||
class ComposableAlertDialog(initial: (@Composable () -> Unit)?) {
|
||||
var content: (@Composable () -> Unit)? by mutableStateOf(initial)
|
||||
}
|
|
@ -1,7 +1,10 @@
|
|||
package dev.yokai.presentation.extension.repo
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import dev.yokai.domain.ComposableAlertDialog
|
||||
import eu.kanade.tachiyomi.ui.base.controller.BaseComposeController
|
||||
import eu.kanade.tachiyomi.util.compose.LocalAlertDialog
|
||||
|
||||
class ExtensionRepoController() :
|
||||
BaseComposeController() {
|
||||
|
@ -14,10 +17,12 @@ class ExtensionRepoController() :
|
|||
|
||||
@Composable
|
||||
override fun ScreenContent() {
|
||||
ExtensionRepoScreen(
|
||||
title = "Extension Repos",
|
||||
onBackPress = router::handleBack,
|
||||
repoUrl = repoUrl,
|
||||
)
|
||||
CompositionLocalProvider(LocalAlertDialog provides ComposableAlertDialog(null)) {
|
||||
ExtensionRepoScreen(
|
||||
title = "Extension Repos",
|
||||
onBackPress = router::handleBack,
|
||||
repoUrl = repoUrl,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ 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.system.toast
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
|
||||
|
@ -43,7 +44,7 @@ fun ExtensionRepoScreen(
|
|||
val repoState = viewModel.repoState.collectAsState()
|
||||
var inputText by remember { mutableStateOf("") }
|
||||
val listState = rememberLazyListState()
|
||||
var repoToDelete by remember { mutableStateOf<String?>(null) }
|
||||
val alertDialog = LocalAlertDialog.current ?: throw RuntimeException("LocalAlertDialog not yet provided")
|
||||
|
||||
YokaiScaffold(
|
||||
onNavigationIconClicked = onBackPress,
|
||||
|
@ -58,52 +59,8 @@ fun ExtensionRepoScreen(
|
|||
|
||||
val repos = (repoState.value as ExtensionRepoState.Success).repos
|
||||
|
||||
if (repoToDelete != null)
|
||||
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.orEmpty()),
|
||||
fontStyle = MaterialTheme.typography.bodyMedium.fontStyle,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
fontSize = 14.sp,
|
||||
)
|
||||
},
|
||||
onDismissRequest = { repoToDelete = null },
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
repoToDelete?.let {
|
||||
viewModel.deleteRepo(it)
|
||||
repoToDelete = null
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.delete),
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
fontSize = 14.sp,
|
||||
)
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { repoToDelete = null }) {
|
||||
Text(
|
||||
text = stringResource(R.string.cancel),
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
fontSize = 14.sp,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
if (alertDialog.content != null)
|
||||
alertDialog.content?.let { it() }
|
||||
|
||||
LazyColumn(
|
||||
modifier = Modifier.padding(innerPadding),
|
||||
|
@ -135,7 +92,54 @@ fun ExtensionRepoScreen(
|
|||
item {
|
||||
ExtensionRepoItem(
|
||||
repoUrl = repo,
|
||||
onDeleteClick = { repoToDelete = it },
|
||||
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,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
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 LocalBackPress: ProvidableCompositionLocal<(() -> Unit)?> = staticCompositionLocalOf { null }
|
||||
val LocalAlertDialog: ProvidableCompositionLocal<(@Composable () -> Unit)?> = staticCompositionLocalOf { null }
|
||||
val LocalAlertDialog: ProvidableCompositionLocal<ComposableAlertDialog?> = compositionLocalOf { null }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue