Show alert first time deleting a note

This commit is contained in:
maxmoney21m
2023-03-09 01:56:54 +08:00
parent 07e4c82c1b
commit 9e58ef1110
5 changed files with 65 additions and 2 deletions

View File

@@ -25,6 +25,7 @@ class LocalPreferences(context: Context) {
const val TRANSLATE_TO = "translateTo" const val TRANSLATE_TO = "translateTo"
const val ZAP_AMOUNTS = "zapAmounts" const val ZAP_AMOUNTS = "zapAmounts"
const val LATEST_CONTACT_LIST = "latestContactList" const val LATEST_CONTACT_LIST = "latestContactList"
const val HIDE_DELETE_REQUEST_INFO = "hideDeleteRequestInfo"
val LAST_READ: (String) -> String = { route -> "last_read_route_$route" } val LAST_READ: (String) -> String = { route -> "last_read_route_$route" }
} }
@@ -49,6 +50,7 @@ class LocalPreferences(context: Context) {
account.translateTo.let { putString(PrefKeys.TRANSLATE_TO, it) } account.translateTo.let { putString(PrefKeys.TRANSLATE_TO, it) }
account.zapAmountChoices.let { putString(PrefKeys.ZAP_AMOUNTS, gson.toJson(it)) } account.zapAmountChoices.let { putString(PrefKeys.ZAP_AMOUNTS, gson.toJson(it)) }
account.backupContactList.let { putString(PrefKeys.LATEST_CONTACT_LIST, Event.gson.toJson(it)) } account.backupContactList.let { putString(PrefKeys.LATEST_CONTACT_LIST, Event.gson.toJson(it)) }
putBoolean(PrefKeys.HIDE_DELETE_REQUEST_INFO, account.hideDeleteRequestInfo)
}.apply() }.apply()
} }
@@ -89,6 +91,8 @@ class LocalPreferences(context: Context) {
mapOf<String, String>() mapOf<String, String>()
} }
val hideDeleteRequestInfo = getBoolean(PrefKeys.HIDE_DELETE_REQUEST_INFO, false)
if (pubKey != null) { if (pubKey != null) {
return Account( return Account(
Persona(privKey = privKey?.toByteArray(), pubKey = pubKey.toByteArray()), Persona(privKey = privKey?.toByteArray(), pubKey = pubKey.toByteArray()),
@@ -99,6 +103,7 @@ class LocalPreferences(context: Context) {
languagePreferences, languagePreferences,
translateTo, translateTo,
zapAmountChoices, zapAmountChoices,
hideDeleteRequestInfo,
latestContactList latestContactList
) )
} else { } else {

View File

@@ -56,6 +56,7 @@ class Account(
var languagePreferences: Map<String, String> = mapOf(), var languagePreferences: Map<String, String> = mapOf(),
var translateTo: String = Locale.getDefault().language, var translateTo: String = Locale.getDefault().language,
var zapAmountChoices: List<Long> = listOf(500L, 1000L, 5000L), var zapAmountChoices: List<Long> = listOf(500L, 1000L, 5000L),
var hideDeleteRequestInfo: Boolean = false,
var backupContactList: ContactListEvent? = null var backupContactList: ContactListEvent? = null
) { ) {
var transientHiddenUsers: Set<String> = setOf() var transientHiddenUsers: Set<String> = setOf()
@@ -540,6 +541,11 @@ class Account(
saveable.invalidateData() saveable.invalidateData()
} }
fun setHideDeleteRequestInfo() {
hideDeleteRequestInfo = true
saveable.invalidateData()
}
init { init {
backupContactList?.let { backupContactList?.let {
println("Loading saved contacts ${it.toJson()}") println("Loading saved contacts ${it.toJson()}")

View File

@@ -10,14 +10,18 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.AlertDialog
import androidx.compose.material.Button
import androidx.compose.material.Card import androidx.compose.material.Card
import androidx.compose.material.Divider import androidx.compose.material.Divider
import androidx.compose.material.Icon import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AlternateEmail import androidx.compose.material.icons.filled.AlternateEmail
import androidx.compose.material.icons.filled.ContentCopy import androidx.compose.material.icons.filled.ContentCopy
@@ -82,6 +86,7 @@ fun NoteQuickActionMenu(note: Note, popupExpanded: Boolean, onDismiss: () -> Uni
val clipboardManager = LocalClipboardManager.current val clipboardManager = LocalClipboardManager.current
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
var showSelectTextDialog by remember { mutableStateOf(false) } var showSelectTextDialog by remember { mutableStateOf(false) }
var showDeleteAlertDialog by remember { mutableStateOf(false) }
val isOwnNote = note.author == accountViewModel.userProfile() val isOwnNote = note.author == accountViewModel.userProfile()
val isFollowingUser = !isOwnNote && accountViewModel.isFollowing(note.author!!) val isFollowingUser = !isOwnNote && accountViewModel.isFollowing(note.author!!)
@@ -138,8 +143,12 @@ fun NoteQuickActionMenu(note: Note, popupExpanded: Boolean, onDismiss: () -> Uni
Row(modifier = Modifier.height(IntrinsicSize.Min)) { Row(modifier = Modifier.height(IntrinsicSize.Min)) {
if (isOwnNote) { if (isOwnNote) {
NoteQuickActionItem(Icons.Default.Delete, stringResource(R.string.quick_action_delete)) { NoteQuickActionItem(Icons.Default.Delete, stringResource(R.string.quick_action_delete)) {
accountViewModel.delete(note) if (accountViewModel.hideDeleteRequestInfo()) {
onDismiss() accountViewModel.delete(note)
onDismiss()
} else {
showDeleteAlertDialog = true
}
} }
} else if (isFollowingUser) { } else if (isFollowingUser) {
NoteQuickActionItem(Icons.Default.PersonRemove, stringResource(R.string.quick_action_unfollow)) { NoteQuickActionItem(Icons.Default.PersonRemove, stringResource(R.string.quick_action_unfollow)) {
@@ -189,6 +198,39 @@ fun NoteQuickActionMenu(note: Note, popupExpanded: Boolean, onDismiss: () -> Uni
SelectTextDialog(it) { showSelectTextDialog = false } SelectTextDialog(it) { showSelectTextDialog = false }
} }
} }
if (showDeleteAlertDialog) {
AlertDialog(
onDismissRequest = { onDismiss() },
title = {
Text(text = stringResource(R.string.quick_action_request_deletion_alert_title))
},
text = {
Text(text = stringResource(R.string.quick_action_request_deletion_alert_body))
},
buttons = {
Row(
modifier = Modifier.padding(all = 8.dp).fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
TextButton(
onClick = {
accountViewModel.setHideDeleteRequestInfo()
accountViewModel.delete(note)
onDismiss()
}
) {
Text("Don't show again")
}
Button(
onClick = { accountViewModel.delete(note); onDismiss() }
) {
Text("Delete")
}
}
}
)
}
} }
@Composable @Composable

View File

@@ -128,4 +128,12 @@ class AccountViewModel(private val account: Account) : ViewModel() {
fun isFollowing(user: User): Boolean { fun isFollowing(user: User): Boolean {
return account.userProfile().isFollowing(user) return account.userProfile().isFollowing(user)
} }
fun hideDeleteRequestInfo(): Boolean {
return account.hideDeleteRequestInfo
}
fun setHideDeleteRequestInfo() {
account.setHideDeleteRequestInfo()
}
} }

View File

@@ -205,4 +205,6 @@
<string name="quick_action_delete">Delete</string> <string name="quick_action_delete">Delete</string>
<string name="quick_action_unfollow">Unfollow</string> <string name="quick_action_unfollow">Unfollow</string>
<string name="quick_action_follow">Follow</string> <string name="quick_action_follow">Follow</string>
<string name="quick_action_request_deletion_alert_title">Request Deletion</string>
<string name="quick_action_request_deletion_alert_body">Amethyst will request that your note be deleted from the relays you are currently connected to. There is no guarantee that your note will be permanently deleted from those relays, or from other relays where it may be stored.</string>
</resources> </resources>