mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
feat: Confirm dialog for delete repo
This commit is contained in:
parent
4f2aa8c8f5
commit
ed2224d762
2 changed files with 58 additions and 2 deletions
|
@ -4,10 +4,15 @@ import androidx.compose.foundation.layout.Arrangement
|
|||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ExtensionOff
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.rememberTopAppBarState
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
|
@ -18,6 +23,8 @@ import androidx.compose.runtime.setValue
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import dev.yokai.presentation.AppBarType
|
||||
import dev.yokai.presentation.YokaiScaffold
|
||||
|
@ -38,6 +45,7 @@ fun ExtensionRepoScreen(
|
|||
val repoState = viewModel.repoState.collectAsState()
|
||||
var inputText by remember { mutableStateOf("") }
|
||||
val listState = rememberLazyListState()
|
||||
var repoToDelete by remember { mutableStateOf<String?>(null) }
|
||||
|
||||
YokaiScaffold(
|
||||
onNavigationIconClicked = onBackPress,
|
||||
|
@ -52,6 +60,53 @@ fun ExtensionRepoScreen(
|
|||
|
||||
val repos = (repoState.value as ExtensionRepoState.Success).repos
|
||||
|
||||
if (repoToDelete != null)
|
||||
AlertDialog(
|
||||
containerColor = MaterialTheme.colorScheme.onPrimary,
|
||||
title = {
|
||||
Text(
|
||||
text = stringResource(R.string.notice_delete_repo_title),
|
||||
fontStyle = MaterialTheme.typography.titleMedium.fontStyle,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
fontSize = 24.sp,
|
||||
)
|
||||
},
|
||||
text = {
|
||||
Text(
|
||||
text = stringResource(R.string.notice_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,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
LazyColumn(
|
||||
modifier = Modifier.padding(innerPadding),
|
||||
userScrollEnabled = true,
|
||||
|
@ -82,8 +137,7 @@ fun ExtensionRepoScreen(
|
|||
item {
|
||||
ExtensionRepoItem(
|
||||
repoUrl = repo,
|
||||
// TODO: Confirmation dialog
|
||||
onDeleteClick = { viewModel.deleteRepo(it) },
|
||||
onDeleteClick = { repoToDelete = it },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -912,6 +912,8 @@
|
|||
<string name="action_add_repo">Add repo</string>
|
||||
<string name="invalid_repo_url">Invalid repo url</string>
|
||||
<string name="information_empty_repos">You haven\'t added any repos yet.</string>
|
||||
<string name="notice_delete_repo_title">Delete repo?</string>
|
||||
<string name="notice_delete_repo">Are you sure you wish to delete the repo \'%s\'?</string>
|
||||
|
||||
<!-- About section -->
|
||||
<string name="version">Version</string>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue