mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-27 20:26:33 +02:00
Merge pull request #1003 from greenart7c3/main
Add delete all drafts button
This commit is contained in:
@@ -729,6 +729,10 @@ class AccountViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun delete(notes: List<Note>) {
|
||||||
|
viewModelScope.launch(Dispatchers.IO) { account.delete(notes) }
|
||||||
|
}
|
||||||
|
|
||||||
fun delete(note: Note) {
|
fun delete(note: Note) {
|
||||||
viewModelScope.launch(Dispatchers.IO) { account.delete(note) }
|
viewModelScope.launch(Dispatchers.IO) { account.delete(note) }
|
||||||
}
|
}
|
||||||
|
@@ -23,21 +23,32 @@ package com.vitorpamplona.amethyst.ui.screen.loggedIn
|
|||||||
import androidx.compose.animation.animateContentSize
|
import androidx.compose.animation.animateContentSize
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.LazyListState
|
import androidx.compose.foundation.lazy.LazyListState
|
||||||
import androidx.compose.foundation.lazy.itemsIndexed
|
import androidx.compose.foundation.lazy.itemsIndexed
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.ElevatedButton
|
||||||
import androidx.compose.material3.HorizontalDivider
|
import androidx.compose.material3.HorizontalDivider
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.DisposableEffect
|
import androidx.compose.runtime.DisposableEffect
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalLifecycleOwner
|
import androidx.compose.ui.platform.LocalLifecycleOwner
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.LifecycleEventObserver
|
import androidx.lifecycle.LifecycleEventObserver
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.ui.components.SwipeToDeleteContainer
|
import com.vitorpamplona.amethyst.ui.components.SwipeToDeleteContainer
|
||||||
import com.vitorpamplona.amethyst.ui.note.NoteCompose
|
import com.vitorpamplona.amethyst.ui.note.NoteCompose
|
||||||
import com.vitorpamplona.amethyst.ui.screen.FeedState
|
import com.vitorpamplona.amethyst.ui.screen.FeedState
|
||||||
@@ -114,17 +125,73 @@ private fun DraftFeedLoaded(
|
|||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
|
var showDeleteDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
if (showDeleteDialog) {
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = {
|
||||||
|
showDeleteDialog = false
|
||||||
|
},
|
||||||
|
title = {
|
||||||
|
Text(text = stringResource(R.string.drafts))
|
||||||
|
},
|
||||||
|
text = {
|
||||||
|
Text(text = stringResource(R.string.delete_all_drafts_confirmation))
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(
|
||||||
|
onClick = {
|
||||||
|
accountViewModel.delete(state.feed.value)
|
||||||
|
showDeleteDialog = false
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
Text(text = stringResource(R.string.yes))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(
|
||||||
|
onClick = {
|
||||||
|
showDeleteDialog = false
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
Text(text = stringResource(R.string.no))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
contentPadding = FeedPadding,
|
contentPadding = FeedPadding,
|
||||||
state = listState,
|
state = listState,
|
||||||
) {
|
) {
|
||||||
|
stickyHeader {
|
||||||
|
Row(
|
||||||
|
Modifier
|
||||||
|
.fillMaxWidth(),
|
||||||
|
Arrangement.Center,
|
||||||
|
) {
|
||||||
|
ElevatedButton(
|
||||||
|
onClick = { showDeleteDialog = true },
|
||||||
|
) {
|
||||||
|
Text(stringResource(R.string.delete_all))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
itemsIndexed(state.feed.value, key = { _, item -> item.idHex }) { _, item ->
|
itemsIndexed(state.feed.value, key = { _, item -> item.idHex }) { _, item ->
|
||||||
SwipeToDeleteContainer(
|
SwipeToDeleteContainer(
|
||||||
modifier = Modifier.fillMaxWidth().animateContentSize(),
|
modifier =
|
||||||
|
Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.animateContentSize(),
|
||||||
onStartToEnd = { accountViewModel.delete(item) },
|
onStartToEnd = { accountViewModel.delete(item) },
|
||||||
onEndToStart = { accountViewModel.delete(item) },
|
onEndToStart = { accountViewModel.delete(item) },
|
||||||
) {
|
) {
|
||||||
Row(Modifier.fillMaxWidth().animateItemPlacement().background(MaterialTheme.colorScheme.background)) {
|
Row(
|
||||||
|
Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.animateItemPlacement()
|
||||||
|
.background(MaterialTheme.colorScheme.background),
|
||||||
|
) {
|
||||||
NoteCompose(
|
NoteCompose(
|
||||||
item,
|
item,
|
||||||
routeForLastRead = routeForLastRead,
|
routeForLastRead = routeForLastRead,
|
||||||
|
@@ -949,4 +949,6 @@
|
|||||||
<string name="http_status_511">Network Authentication Required - The client must be authenticated to access the network</string>
|
<string name="http_status_511">Network Authentication Required - The client must be authenticated to access the network</string>
|
||||||
|
|
||||||
<string name="add_a_nip96_server">Add a NIP-96 Server</string>
|
<string name="add_a_nip96_server">Add a NIP-96 Server</string>
|
||||||
|
<string name="delete_all">Delete all</string>
|
||||||
|
<string name="delete_all_drafts_confirmation">Are you sure you want to delete all drafts?</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Reference in New Issue
Block a user