Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show confirmation dialog when deleting selected sources #506

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,7 @@ val DeTwineStrings =
groupAddNew = "Add new",
appBarAllFeeds = "All feeds",
edit = "Edit",
buttonAddToGroup = "Add to group..."
buttonAddToGroup = "Add to group...",
removeSources = "Delete sources",
removeSourcesDesc = "Do you want to delete selected sources?",
)
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,7 @@ val EnTwineStrings =
groupAddNew = "Add new",
appBarAllFeeds = "All feeds",
edit = "Edit",
buttonAddToGroup = "Add to group..."
buttonAddToGroup = "Add to group...",
removeSources = "Delete sources",
removeSourcesDesc = "Do you want to delete selected sources?",
)
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,7 @@ val TrTwineStrings =
groupAddNew = "Add new",
appBarAllFeeds = "All feeds",
edit = "Edit",
buttonAddToGroup = "Add to group..."
buttonAddToGroup = "Add to group...",
removeSources = "Delete sources",
removeSourcesDesc = "Do you want to delete selected sources?",
)
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ data class TwineStrings(
val appBarAllFeeds: String,
val edit: String,
val buttonAddToGroup: String,
val removeSources: String,
val removeSourcesDesc: String,
)

object Locales {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ sealed interface FeedsEvent {

data object UnPinSelectedSources : FeedsEvent

data object DeleteSelectedSources : FeedsEvent
data object DeleteSelectedSourcesClicked : FeedsEvent

data class OnCreateGroup(val name: String) : FeedsEvent

Expand All @@ -65,4 +65,8 @@ sealed interface FeedsEvent {
data object OnAddToGroupClicked : FeedsEvent

data object OnNewFeedClicked : FeedsEvent

data object DismissDeleteConfirmation : FeedsEvent

data object DeleteSelectedSources : FeedsEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class FeedsPresenter(
FeedsEvent.OnChangeFeedsViewModeClick -> onChangeFeedsViewModeClick()
is FeedsEvent.OnHomeSelected -> onHomeSelected()
FeedsEvent.CancelSourcesSelection -> onCancelSourcesSelection()
FeedsEvent.DeleteSelectedSources -> onDeleteSelectedSources()
FeedsEvent.DeleteSelectedSourcesClicked -> onDeleteSelectedSourcesClicked()
FeedsEvent.PinSelectedSources -> onPinSelectedSources()
FeedsEvent.UnPinSelectedSources -> onUnpinSelectedSources()
is FeedsEvent.OnCreateGroup -> onCreateGroup(event.name)
Expand All @@ -177,9 +177,26 @@ class FeedsPresenter(
FeedsEvent.OnNewFeedClicked -> {
// no-op
}
FeedsEvent.DeleteSelectedSources -> deleteSelectedSources()
FeedsEvent.DismissDeleteConfirmation -> dismissDeleteConfirmation()
}
}

private fun dismissDeleteConfirmation() {
_state.update { it.copy(showDeleteConfirmation = false) }
}

private fun deleteSelectedSources() {
coroutineScope
.launch { rssRepository.deleteSources(_state.value.selectedSources) }
.invokeOnCompletion {
if (_state.value.selectedSources.any { it.id == _state.value.activeSource?.id }) {
observableActiveSource.clearSelection()
}
dispatch(FeedsEvent.CancelSourcesSelection)
}
}

private fun onGroupsSelected(groupIds: Set<String>) {
coroutineScope.launch {
rssRepository.addFeedIdsToGroups(
Expand Down Expand Up @@ -217,15 +234,8 @@ class FeedsPresenter(
.invokeOnCompletion { dispatch(FeedsEvent.CancelSourcesSelection) }
}

private fun onDeleteSelectedSources() {
coroutineScope
.launch { rssRepository.deleteSources(_state.value.selectedSources) }
.invokeOnCompletion {
if (_state.value.selectedSources.any { it.id == _state.value.activeSource?.id }) {
observableActiveSource.clearSelection()
}
dispatch(FeedsEvent.CancelSourcesSelection)
}
private fun onDeleteSelectedSourcesClicked() {
_state.update { it.copy(showDeleteConfirmation = true) }
}

private fun onCancelSourcesSelection() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal data class FeedsState(
val selectedSources: Set<Source>,
val numberOfFeeds: Int,
val numberOfFeedGroups: Int,
val showDeleteConfirmation: Boolean,
) {

val isInMultiSelectMode: Boolean
Expand All @@ -56,7 +57,8 @@ internal data class FeedsState(
isPinnedSectionExpanded = true,
selectedSources = emptySet(),
numberOfFeeds = 0,
numberOfFeedGroups = 0
numberOfFeedGroups = 0,
showDeleteConfirmation = false
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ import androidx.compose.material.icons.filled.GridView
import androidx.compose.material.icons.outlined.ViewAgenda
import androidx.compose.material.icons.rounded.Close
import androidx.compose.material.icons.rounded.Search
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.darkColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
Expand Down Expand Up @@ -95,6 +97,13 @@ internal fun BottomSheetExpandedContent(

var showNewGroupDialog by remember { mutableStateOf(false) }

if (state.showDeleteConfirmation) {
DeleteConfirmationDialog(
onDelete = { feedsPresenter.dispatch(FeedsEvent.DeleteSelectedSources) },
dismiss = { feedsPresenter.dispatch(FeedsEvent.DismissDeleteConfirmation) }
)
}

Scaffold(
modifier = Modifier.fillMaxSize().consumeWindowInsets(WindowInsets.statusBars).then(modifier),
topBar = {
Expand Down Expand Up @@ -169,7 +178,7 @@ internal fun BottomSheetExpandedContent(
modifier = Modifier.weight(1f),
icon = TwineIcons.Delete,
label = LocalStrings.current.actionDelete,
onClick = { feedsPresenter.dispatch(FeedsEvent.DeleteSelectedSources) }
onClick = { feedsPresenter.dispatch(FeedsEvent.DeleteSelectedSourcesClicked) }
)

if (state.selectedSources.size == 1) {
Expand Down Expand Up @@ -358,3 +367,51 @@ private fun SearchBar(
Spacer(Modifier.requiredWidth(20.dp))
}
}

@Composable
fun DeleteConfirmationDialog(
onDelete: () -> Unit,
dismiss: () -> Unit,
modifier: Modifier = Modifier
) {
AlertDialog(
modifier = modifier,
onDismissRequest = dismiss,
confirmButton = {
TextButton(
onClick = {
onDelete()
dismiss()
},
shape = MaterialTheme.shapes.large
) {
Text(
text = LocalStrings.current.delete,
style = MaterialTheme.typography.labelLarge,
color = MaterialTheme.colorScheme.error
)
}
},
dismissButton = {
TextButton(onClick = dismiss, shape = MaterialTheme.shapes.large) {
Text(
text = LocalStrings.current.buttonCancel,
style = MaterialTheme.typography.labelLarge,
color = AppTheme.colorScheme.textEmphasisMed
)
}
},
title = {
Text(text = LocalStrings.current.removeSources, color = AppTheme.colorScheme.textEmphasisMed)
},
text = {
Text(
text = LocalStrings.current.removeSourcesDesc,
color = AppTheme.colorScheme.textEmphasisMed
)
},
containerColor = AppTheme.colorScheme.tintedSurface,
titleContentColor = AppTheme.colorScheme.onSurface,
textContentColor = AppTheme.colorScheme.onSurface,
)
}