2023-03-08 14:40:32 +00:00
|
|
|
package com.vitorpamplona.amethyst.ui.note
|
|
|
|
|
|
|
|
import android.content.Intent
|
|
|
|
import android.widget.Toast
|
|
|
|
import androidx.compose.foundation.clickable
|
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
import androidx.compose.foundation.layout.IntrinsicSize
|
2023-09-29 17:57:10 +00:00
|
|
|
import androidx.compose.foundation.layout.PaddingValues
|
2023-03-08 14:40:32 +00:00
|
|
|
import androidx.compose.foundation.layout.Row
|
2023-03-15 05:40:59 +00:00
|
|
|
import androidx.compose.foundation.layout.Spacer
|
2023-03-08 14:40:32 +00:00
|
|
|
import androidx.compose.foundation.layout.fillMaxHeight
|
2023-03-08 15:30:41 +00:00
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
2023-03-08 14:40:32 +00:00
|
|
|
import androidx.compose.foundation.layout.height
|
2023-03-08 17:56:54 +00:00
|
|
|
import androidx.compose.foundation.layout.padding
|
2023-03-08 14:40:32 +00:00
|
|
|
import androidx.compose.foundation.layout.size
|
|
|
|
import androidx.compose.foundation.layout.width
|
|
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
|
import androidx.compose.material.icons.filled.AlternateEmail
|
2023-03-14 17:41:39 +00:00
|
|
|
import androidx.compose.material.icons.filled.Block
|
2023-03-08 14:40:32 +00:00
|
|
|
import androidx.compose.material.icons.filled.ContentCopy
|
2023-03-08 17:24:43 +00:00
|
|
|
import androidx.compose.material.icons.filled.Delete
|
2023-03-08 15:30:41 +00:00
|
|
|
import androidx.compose.material.icons.filled.FormatQuote
|
2023-03-08 17:24:43 +00:00
|
|
|
import androidx.compose.material.icons.filled.PersonAdd
|
|
|
|
import androidx.compose.material.icons.filled.PersonRemove
|
2023-03-15 05:40:59 +00:00
|
|
|
import androidx.compose.material.icons.filled.Report
|
2023-03-08 14:40:32 +00:00
|
|
|
import androidx.compose.material.icons.filled.Share
|
2023-09-29 17:57:10 +00:00
|
|
|
import androidx.compose.material3.AlertDialog
|
|
|
|
import androidx.compose.material3.Button
|
|
|
|
import androidx.compose.material3.ButtonColors
|
|
|
|
import androidx.compose.material3.ButtonDefaults
|
|
|
|
import androidx.compose.material3.Card
|
|
|
|
import androidx.compose.material3.CardDefaults
|
|
|
|
import androidx.compose.material3.Divider
|
|
|
|
import androidx.compose.material3.Icon
|
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
import androidx.compose.material3.TextButton
|
2023-03-08 14:40:32 +00:00
|
|
|
import androidx.compose.runtime.Composable
|
2023-06-23 16:02:27 +00:00
|
|
|
import androidx.compose.runtime.MutableState
|
2023-03-08 14:40:32 +00:00
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
|
|
import androidx.compose.ui.Alignment
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
import androidx.compose.ui.draw.shadow
|
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
|
import androidx.compose.ui.graphics.toArgb
|
|
|
|
import androidx.compose.ui.graphics.vector.ImageVector
|
|
|
|
import androidx.compose.ui.platform.LocalClipboardManager
|
|
|
|
import androidx.compose.ui.platform.LocalContext
|
2023-08-10 22:04:23 +00:00
|
|
|
import androidx.compose.ui.res.painterResource
|
2023-03-08 14:40:32 +00:00
|
|
|
import androidx.compose.ui.res.stringResource
|
|
|
|
import androidx.compose.ui.res.vectorResource
|
|
|
|
import androidx.compose.ui.text.AnnotatedString
|
2023-03-09 14:19:41 +00:00
|
|
|
import androidx.compose.ui.text.style.TextAlign
|
2023-03-08 14:40:32 +00:00
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
import androidx.compose.ui.window.Popup
|
|
|
|
import androidx.core.content.ContextCompat
|
|
|
|
import androidx.core.graphics.ColorUtils
|
|
|
|
import com.vitorpamplona.amethyst.R
|
2023-03-22 19:47:01 +00:00
|
|
|
import com.vitorpamplona.amethyst.model.AddressableNote
|
2023-03-08 14:40:32 +00:00
|
|
|
import com.vitorpamplona.amethyst.model.Note
|
|
|
|
import com.vitorpamplona.amethyst.ui.components.SelectTextDialog
|
|
|
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
2023-03-14 17:41:39 +00:00
|
|
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.ReportNoteDialog
|
2023-03-15 05:40:59 +00:00
|
|
|
import com.vitorpamplona.amethyst.ui.theme.WarningColor
|
2023-09-29 17:57:10 +00:00
|
|
|
import com.vitorpamplona.amethyst.ui.theme.isLight
|
2023-06-10 14:08:06 +00:00
|
|
|
import com.vitorpamplona.amethyst.ui.theme.secondaryButtonBackground
|
2023-08-16 21:58:25 +00:00
|
|
|
import com.vitorpamplona.quartz.events.AudioTrackEvent
|
|
|
|
import com.vitorpamplona.quartz.events.FileHeaderEvent
|
|
|
|
import com.vitorpamplona.quartz.events.PeopleListEvent
|
2023-06-05 19:33:16 +00:00
|
|
|
import kotlinx.coroutines.Dispatchers
|
2023-03-08 14:40:32 +00:00
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
2023-03-15 05:40:59 +00:00
|
|
|
private fun lightenColor(color: Color, amount: Float): Color {
|
2023-03-08 14:40:32 +00:00
|
|
|
var argb = color.toArgb()
|
|
|
|
val hslOut = floatArrayOf(0f, 0f, 0f)
|
|
|
|
ColorUtils.colorToHSL(argb, hslOut)
|
|
|
|
hslOut[2] += amount
|
|
|
|
argb = ColorUtils.HSLToColor(hslOut)
|
|
|
|
return Color(argb)
|
|
|
|
}
|
|
|
|
|
2023-03-22 19:47:01 +00:00
|
|
|
val externalLinkForNote = { note: Note ->
|
|
|
|
if (note is AddressableNote) {
|
2023-03-23 14:49:01 +00:00
|
|
|
if (note.event?.getReward() != null) {
|
|
|
|
"https://nostrbounties.com/b/${note.address().toNAddr()}"
|
2023-05-15 17:17:31 +00:00
|
|
|
} else if (note.event is PeopleListEvent) {
|
|
|
|
"https://listr.lol/a/${note.address()?.toNAddr()}"
|
|
|
|
} else if (note.event is AudioTrackEvent) {
|
|
|
|
"https://zapstr.live/?track=${note.address()?.toNAddr()}"
|
2023-03-23 14:49:01 +00:00
|
|
|
} else {
|
2023-05-15 17:17:31 +00:00
|
|
|
"https://habla.news/a/${note.address()?.toNAddr()}"
|
2023-03-23 14:49:01 +00:00
|
|
|
}
|
2023-03-22 19:47:01 +00:00
|
|
|
} else {
|
2023-05-15 17:25:21 +00:00
|
|
|
if (note.event is FileHeaderEvent) {
|
|
|
|
"https://filestr.vercel.app/e/${note.toNEvent()}"
|
|
|
|
} else {
|
|
|
|
"https://snort.social/e/${note.toNEvent()}"
|
|
|
|
}
|
2023-03-22 19:47:01 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-08 14:40:32 +00:00
|
|
|
|
|
|
|
@Composable
|
2023-03-15 05:40:59 +00:00
|
|
|
private fun VerticalDivider(color: Color) =
|
2023-03-08 14:40:32 +00:00
|
|
|
Divider(
|
2023-03-08 15:39:37 +00:00
|
|
|
color = color,
|
|
|
|
modifier = Modifier
|
2023-03-08 14:40:32 +00:00
|
|
|
.fillMaxHeight()
|
|
|
|
.width(1.dp)
|
|
|
|
)
|
|
|
|
|
2023-06-09 18:07:38 +00:00
|
|
|
@Composable
|
|
|
|
fun LongPressToQuickAction(baseNote: Note, accountViewModel: AccountViewModel, content: @Composable (() -> Unit) -> Unit) {
|
2023-06-23 16:02:27 +00:00
|
|
|
val popupExpanded = remember { mutableStateOf(false) }
|
|
|
|
val showPopup = remember { { popupExpanded.value = true } }
|
2023-09-25 15:35:39 +00:00
|
|
|
val hidePopup = remember { { popupExpanded.value = false } }
|
2023-06-09 18:07:38 +00:00
|
|
|
|
|
|
|
content(showPopup)
|
|
|
|
|
2023-09-25 15:35:39 +00:00
|
|
|
NoteQuickActionMenu(baseNote, popupExpanded.value, hidePopup, accountViewModel)
|
2023-06-09 18:07:38 +00:00
|
|
|
}
|
|
|
|
|
2023-03-08 14:40:32 +00:00
|
|
|
@Composable
|
|
|
|
fun NoteQuickActionMenu(note: Note, popupExpanded: Boolean, onDismiss: () -> Unit, accountViewModel: AccountViewModel) {
|
2023-06-23 16:02:27 +00:00
|
|
|
val showSelectTextDialog = remember { mutableStateOf(false) }
|
|
|
|
val showDeleteAlertDialog = remember { mutableStateOf(false) }
|
|
|
|
val showBlockAlertDialog = remember { mutableStateOf(false) }
|
|
|
|
val showReportDialog = remember { mutableStateOf(false) }
|
2023-03-08 14:40:32 +00:00
|
|
|
|
2023-06-01 23:56:31 +00:00
|
|
|
if (popupExpanded) {
|
2023-06-23 16:02:27 +00:00
|
|
|
RenderMainPopup(
|
|
|
|
accountViewModel,
|
|
|
|
note,
|
|
|
|
onDismiss,
|
|
|
|
showBlockAlertDialog,
|
|
|
|
showDeleteAlertDialog,
|
|
|
|
showReportDialog
|
|
|
|
)
|
|
|
|
}
|
2023-06-01 23:56:31 +00:00
|
|
|
|
2023-06-23 16:02:27 +00:00
|
|
|
if (showSelectTextDialog.value) {
|
|
|
|
accountViewModel.decrypt(note)?.let {
|
|
|
|
SelectTextDialog(it) { showSelectTextDialog.value = false }
|
2023-06-01 23:56:31 +00:00
|
|
|
}
|
2023-06-23 16:02:27 +00:00
|
|
|
}
|
2023-03-15 13:11:55 +00:00
|
|
|
|
2023-06-23 16:02:27 +00:00
|
|
|
if (showDeleteAlertDialog.value) {
|
|
|
|
DeleteAlertDialog(note, accountViewModel) {
|
|
|
|
showDeleteAlertDialog.value = false
|
|
|
|
onDismiss()
|
2023-03-08 14:40:32 +00:00
|
|
|
}
|
2023-06-23 16:02:27 +00:00
|
|
|
}
|
2023-03-08 14:40:32 +00:00
|
|
|
|
2023-06-23 16:02:27 +00:00
|
|
|
if (showBlockAlertDialog.value) {
|
|
|
|
BlockAlertDialog(note, accountViewModel) {
|
|
|
|
showBlockAlertDialog.value = false
|
|
|
|
onDismiss()
|
|
|
|
}
|
|
|
|
}
|
2023-04-07 21:44:40 +00:00
|
|
|
|
2023-06-23 16:02:27 +00:00
|
|
|
if (showReportDialog.value) {
|
|
|
|
ReportNoteDialog(note, accountViewModel) {
|
|
|
|
showReportDialog.value = false
|
|
|
|
onDismiss()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
private fun RenderMainPopup(
|
|
|
|
accountViewModel: AccountViewModel,
|
|
|
|
note: Note,
|
|
|
|
onDismiss: () -> Unit,
|
|
|
|
showBlockAlertDialog: MutableState<Boolean>,
|
|
|
|
showDeleteAlertDialog: MutableState<Boolean>,
|
|
|
|
showReportDialog: MutableState<Boolean>
|
|
|
|
) {
|
|
|
|
val context = LocalContext.current
|
2023-09-29 17:57:10 +00:00
|
|
|
val primaryLight = lightenColor(MaterialTheme.colorScheme.primary, 0.1f)
|
2023-06-23 16:02:27 +00:00
|
|
|
val cardShape = RoundedCornerShape(5.dp)
|
|
|
|
val clipboardManager = LocalClipboardManager.current
|
|
|
|
val scope = rememberCoroutineScope()
|
|
|
|
|
2023-09-29 17:57:10 +00:00
|
|
|
val backgroundColor = if (MaterialTheme.colorScheme.isLight) {
|
|
|
|
MaterialTheme.colorScheme.primary
|
2023-06-23 16:02:27 +00:00
|
|
|
} else {
|
2023-09-29 17:57:10 +00:00
|
|
|
MaterialTheme.colorScheme.secondaryButtonBackground
|
2023-06-23 16:02:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
val showToast = { stringResource: Int ->
|
|
|
|
scope.launch {
|
|
|
|
Toast.makeText(
|
|
|
|
context,
|
|
|
|
context.getString(stringResource),
|
|
|
|
Toast.LENGTH_SHORT
|
|
|
|
).show()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val isOwnNote = accountViewModel.isLoggedUser(note.author)
|
|
|
|
val isFollowingUser = !isOwnNote && accountViewModel.isFollowing(note.author)
|
|
|
|
|
|
|
|
Popup(onDismissRequest = onDismiss, alignment = Alignment.Center) {
|
|
|
|
Card(
|
|
|
|
modifier = Modifier.shadow(elevation = 6.dp, shape = cardShape),
|
|
|
|
shape = cardShape,
|
2023-09-29 17:57:10 +00:00
|
|
|
colors = CardDefaults.cardColors(containerColor = backgroundColor)
|
2023-06-23 16:02:27 +00:00
|
|
|
) {
|
|
|
|
Column(modifier = Modifier.width(IntrinsicSize.Min)) {
|
|
|
|
Row(modifier = Modifier.height(IntrinsicSize.Min)) {
|
|
|
|
NoteQuickActionItem(
|
|
|
|
icon = Icons.Default.ContentCopy,
|
|
|
|
label = stringResource(R.string.quick_action_copy_text)
|
|
|
|
) {
|
|
|
|
scope.launch(Dispatchers.IO) {
|
|
|
|
clipboardManager.setText(
|
|
|
|
AnnotatedString(
|
|
|
|
accountViewModel.decrypt(note) ?: ""
|
2023-03-08 14:40:32 +00:00
|
|
|
)
|
2023-06-23 16:02:27 +00:00
|
|
|
)
|
|
|
|
showToast(R.string.copied_note_text_to_clipboard)
|
|
|
|
onDismiss()
|
2023-03-08 14:40:32 +00:00
|
|
|
}
|
2023-06-23 16:02:27 +00:00
|
|
|
}
|
|
|
|
VerticalDivider(primaryLight)
|
|
|
|
NoteQuickActionItem(
|
|
|
|
Icons.Default.AlternateEmail,
|
|
|
|
stringResource(R.string.quick_action_copy_user_id)
|
|
|
|
) {
|
|
|
|
scope.launch(Dispatchers.IO) {
|
|
|
|
clipboardManager.setText(AnnotatedString("nostr:${note.author?.pubkeyNpub()}"))
|
|
|
|
showToast(R.string.copied_user_id_to_clipboard)
|
|
|
|
onDismiss()
|
2023-03-08 15:30:41 +00:00
|
|
|
}
|
2023-06-23 16:02:27 +00:00
|
|
|
}
|
|
|
|
VerticalDivider(primaryLight)
|
|
|
|
NoteQuickActionItem(
|
|
|
|
Icons.Default.FormatQuote,
|
|
|
|
stringResource(R.string.quick_action_copy_note_id)
|
|
|
|
) {
|
|
|
|
scope.launch(Dispatchers.IO) {
|
|
|
|
clipboardManager.setText(AnnotatedString("nostr:${note.toNEvent()}"))
|
|
|
|
showToast(R.string.copied_note_id_to_clipboard)
|
|
|
|
onDismiss()
|
2023-03-08 14:40:32 +00:00
|
|
|
}
|
2023-06-23 16:02:27 +00:00
|
|
|
}
|
2023-03-14 17:41:39 +00:00
|
|
|
|
2023-06-23 16:02:27 +00:00
|
|
|
if (!isOwnNote) {
|
|
|
|
VerticalDivider(primaryLight)
|
2023-03-14 17:41:39 +00:00
|
|
|
|
2023-06-23 16:02:27 +00:00
|
|
|
NoteQuickActionItem(
|
|
|
|
Icons.Default.Block,
|
|
|
|
stringResource(R.string.quick_action_block)
|
|
|
|
) {
|
|
|
|
if (accountViewModel.hideBlockAlertDialog) {
|
2023-08-13 01:35:34 +00:00
|
|
|
note.author?.let { accountViewModel.hide(it) }
|
|
|
|
onDismiss()
|
2023-06-23 16:02:27 +00:00
|
|
|
} else {
|
|
|
|
showBlockAlertDialog.value = true
|
2023-03-08 17:24:43 +00:00
|
|
|
}
|
2023-06-23 16:02:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Divider(
|
|
|
|
color = primaryLight,
|
|
|
|
modifier = Modifier
|
|
|
|
.fillMaxWidth()
|
|
|
|
.width(1.dp)
|
|
|
|
)
|
|
|
|
Row(modifier = Modifier.height(IntrinsicSize.Min)) {
|
|
|
|
if (isOwnNote) {
|
|
|
|
NoteQuickActionItem(
|
|
|
|
Icons.Default.Delete,
|
|
|
|
stringResource(R.string.quick_action_delete)
|
|
|
|
) {
|
|
|
|
if (accountViewModel.hideDeleteRequestDialog) {
|
2023-06-05 19:33:16 +00:00
|
|
|
scope.launch(Dispatchers.IO) {
|
2023-06-23 16:02:27 +00:00
|
|
|
accountViewModel.delete(note)
|
2023-06-05 19:33:16 +00:00
|
|
|
onDismiss()
|
|
|
|
}
|
2023-06-23 16:02:27 +00:00
|
|
|
} else {
|
|
|
|
showDeleteAlertDialog.value = true
|
2023-03-08 17:24:43 +00:00
|
|
|
}
|
|
|
|
}
|
2023-06-23 16:02:27 +00:00
|
|
|
} else if (isFollowingUser) {
|
2023-03-08 14:40:32 +00:00
|
|
|
NoteQuickActionItem(
|
2023-06-23 16:02:27 +00:00
|
|
|
Icons.Default.PersonRemove,
|
|
|
|
stringResource(R.string.quick_action_unfollow)
|
2023-03-08 14:40:32 +00:00
|
|
|
) {
|
2023-06-05 19:33:16 +00:00
|
|
|
scope.launch(Dispatchers.IO) {
|
2023-06-23 16:02:27 +00:00
|
|
|
accountViewModel.unfollow(note.author!!)
|
2023-06-05 19:33:16 +00:00
|
|
|
onDismiss()
|
|
|
|
}
|
2023-03-08 14:40:32 +00:00
|
|
|
}
|
2023-06-23 16:02:27 +00:00
|
|
|
} else {
|
|
|
|
NoteQuickActionItem(
|
|
|
|
Icons.Default.PersonAdd,
|
|
|
|
stringResource(R.string.quick_action_follow)
|
|
|
|
) {
|
|
|
|
scope.launch(Dispatchers.IO) {
|
|
|
|
accountViewModel.follow(note.author!!)
|
|
|
|
onDismiss()
|
2023-03-08 14:40:32 +00:00
|
|
|
}
|
2023-06-23 16:02:27 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-08 14:40:32 +00:00
|
|
|
|
2023-06-23 16:02:27 +00:00
|
|
|
VerticalDivider(primaryLight)
|
|
|
|
NoteQuickActionItem(
|
|
|
|
icon = ImageVector.vectorResource(id = R.drawable.relays),
|
|
|
|
label = stringResource(R.string.broadcast)
|
|
|
|
) {
|
|
|
|
scope.launch(Dispatchers.IO) {
|
|
|
|
accountViewModel.broadcast(note)
|
|
|
|
// showSelectTextDialog = true
|
2023-03-08 14:40:32 +00:00
|
|
|
onDismiss()
|
|
|
|
}
|
2023-06-23 16:02:27 +00:00
|
|
|
}
|
|
|
|
VerticalDivider(primaryLight)
|
|
|
|
NoteQuickActionItem(
|
|
|
|
icon = Icons.Default.Share,
|
|
|
|
label = stringResource(R.string.quick_action_share)
|
|
|
|
) {
|
|
|
|
val sendIntent = Intent().apply {
|
|
|
|
action = Intent.ACTION_SEND
|
|
|
|
type = "text/plain"
|
|
|
|
putExtra(
|
|
|
|
Intent.EXTRA_TEXT,
|
|
|
|
externalLinkForNote(note)
|
|
|
|
)
|
|
|
|
putExtra(
|
|
|
|
Intent.EXTRA_TITLE,
|
|
|
|
context.getString(R.string.quick_action_share_browser_link)
|
|
|
|
)
|
|
|
|
}
|
2023-03-15 05:40:59 +00:00
|
|
|
|
2023-06-23 16:02:27 +00:00
|
|
|
val shareIntent = Intent.createChooser(
|
|
|
|
sendIntent,
|
|
|
|
context.getString(R.string.quick_action_share)
|
|
|
|
)
|
|
|
|
ContextCompat.startActivity(context, shareIntent, null)
|
|
|
|
onDismiss()
|
|
|
|
}
|
2023-03-15 05:40:59 +00:00
|
|
|
|
2023-06-23 16:02:27 +00:00
|
|
|
if (!isOwnNote) {
|
|
|
|
VerticalDivider(primaryLight)
|
|
|
|
|
|
|
|
NoteQuickActionItem(
|
|
|
|
Icons.Default.Report,
|
|
|
|
stringResource(R.string.quick_action_report)
|
|
|
|
) {
|
|
|
|
showReportDialog.value = true
|
2023-03-15 05:40:59 +00:00
|
|
|
}
|
2023-03-08 14:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
fun NoteQuickActionItem(icon: ImageVector, label: String, onClick: () -> Unit) {
|
|
|
|
Column(
|
|
|
|
modifier = Modifier
|
2023-03-09 14:19:41 +00:00
|
|
|
.size(70.dp)
|
2023-03-08 14:40:32 +00:00
|
|
|
.clickable { onClick() },
|
|
|
|
verticalArrangement = Arrangement.Center,
|
2023-03-08 15:39:37 +00:00
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
2023-03-08 14:40:32 +00:00
|
|
|
) {
|
|
|
|
Icon(
|
|
|
|
imageVector = icon,
|
|
|
|
contentDescription = null,
|
2023-03-14 17:41:39 +00:00
|
|
|
modifier = Modifier
|
|
|
|
.size(24.dp)
|
|
|
|
.padding(bottom = 5.dp),
|
2023-03-09 14:19:41 +00:00
|
|
|
tint = Color.White
|
2023-03-08 14:40:32 +00:00
|
|
|
)
|
2023-03-09 14:19:41 +00:00
|
|
|
Text(text = label, fontSize = 12.sp, color = Color.White, textAlign = TextAlign.Center)
|
2023-03-08 14:40:32 +00:00
|
|
|
}
|
2023-03-08 15:39:37 +00:00
|
|
|
}
|
2023-03-14 17:41:39 +00:00
|
|
|
|
|
|
|
@Composable
|
2023-06-19 22:34:52 +00:00
|
|
|
fun DeleteAlertDialog(note: Note, accountViewModel: AccountViewModel, onDismiss: () -> Unit) {
|
|
|
|
val scope = rememberCoroutineScope()
|
|
|
|
|
2023-03-15 05:40:59 +00:00
|
|
|
QuickActionAlertDialog(
|
|
|
|
title = stringResource(R.string.quick_action_request_deletion_alert_title),
|
|
|
|
textContent = stringResource(R.string.quick_action_request_deletion_alert_body),
|
|
|
|
buttonIcon = Icons.Default.Delete,
|
|
|
|
buttonText = stringResource(R.string.quick_action_delete_dialog_btn),
|
|
|
|
onClickDoOnce = {
|
2023-06-19 22:34:52 +00:00
|
|
|
scope.launch(Dispatchers.IO) {
|
|
|
|
accountViewModel.delete(note)
|
|
|
|
}
|
2023-03-15 05:40:59 +00:00
|
|
|
onDismiss()
|
|
|
|
},
|
|
|
|
onClickDontShowAgain = {
|
2023-06-19 22:34:52 +00:00
|
|
|
scope.launch(Dispatchers.IO) {
|
|
|
|
accountViewModel.delete(note)
|
|
|
|
accountViewModel.dontShowDeleteRequestDialog()
|
|
|
|
}
|
2023-03-15 05:40:59 +00:00
|
|
|
onDismiss()
|
|
|
|
},
|
|
|
|
onDismiss = onDismiss
|
|
|
|
)
|
2023-06-19 22:34:52 +00:00
|
|
|
}
|
2023-03-15 05:40:59 +00:00
|
|
|
|
|
|
|
@Composable
|
|
|
|
private fun BlockAlertDialog(note: Note, accountViewModel: AccountViewModel, onDismiss: () -> Unit) =
|
|
|
|
QuickActionAlertDialog(
|
|
|
|
title = stringResource(R.string.report_dialog_block_hide_user_btn),
|
|
|
|
textContent = stringResource(R.string.report_dialog_blocking_a_user),
|
|
|
|
buttonIcon = Icons.Default.Block,
|
|
|
|
buttonText = stringResource(R.string.quick_action_block_dialog_btn),
|
|
|
|
buttonColors = ButtonDefaults.buttonColors(
|
2023-09-29 17:57:10 +00:00
|
|
|
containerColor = WarningColor,
|
2023-03-15 05:40:59 +00:00
|
|
|
contentColor = Color.White
|
|
|
|
),
|
|
|
|
onClickDoOnce = {
|
|
|
|
note.author?.let { accountViewModel.hide(it) }
|
|
|
|
onDismiss()
|
|
|
|
},
|
|
|
|
onClickDontShowAgain = {
|
|
|
|
note.author?.let { accountViewModel.hide(it) }
|
|
|
|
accountViewModel.dontShowBlockAlertDialog()
|
|
|
|
onDismiss()
|
|
|
|
},
|
|
|
|
onDismiss = onDismiss
|
|
|
|
)
|
|
|
|
|
|
|
|
@Composable
|
2023-08-10 22:04:23 +00:00
|
|
|
fun QuickActionAlertDialog(
|
2023-03-15 05:40:59 +00:00
|
|
|
title: String,
|
|
|
|
textContent: String,
|
|
|
|
buttonIcon: ImageVector,
|
|
|
|
buttonText: String,
|
|
|
|
buttonColors: ButtonColors = ButtonDefaults.buttonColors(),
|
|
|
|
onClickDoOnce: () -> Unit,
|
|
|
|
onClickDontShowAgain: () -> Unit,
|
|
|
|
onDismiss: () -> Unit
|
2023-08-10 22:04:23 +00:00
|
|
|
) {
|
|
|
|
QuickActionAlertDialog(
|
|
|
|
title = title,
|
|
|
|
textContent = textContent,
|
|
|
|
icon = {
|
|
|
|
Icon(
|
|
|
|
imageVector = buttonIcon,
|
|
|
|
contentDescription = null
|
|
|
|
)
|
|
|
|
},
|
|
|
|
buttonText = buttonText,
|
|
|
|
buttonColors = buttonColors,
|
|
|
|
onClickDoOnce = onClickDoOnce,
|
|
|
|
onClickDontShowAgain = onClickDontShowAgain,
|
|
|
|
onDismiss = onDismiss
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
fun QuickActionAlertDialog(
|
|
|
|
title: String,
|
|
|
|
textContent: String,
|
|
|
|
buttonIconResource: Int,
|
|
|
|
buttonText: String,
|
|
|
|
buttonColors: ButtonColors = ButtonDefaults.buttonColors(),
|
|
|
|
onClickDoOnce: () -> Unit,
|
|
|
|
onClickDontShowAgain: () -> Unit,
|
|
|
|
onDismiss: () -> Unit
|
|
|
|
) {
|
|
|
|
QuickActionAlertDialog(
|
|
|
|
title = title,
|
|
|
|
textContent = textContent,
|
|
|
|
icon = {
|
|
|
|
Icon(
|
|
|
|
painter = painterResource(buttonIconResource),
|
|
|
|
contentDescription = null
|
|
|
|
)
|
|
|
|
},
|
|
|
|
buttonText = buttonText,
|
|
|
|
buttonColors = buttonColors,
|
|
|
|
onClickDoOnce = onClickDoOnce,
|
|
|
|
onClickDontShowAgain = onClickDontShowAgain,
|
|
|
|
onDismiss = onDismiss
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
fun QuickActionAlertDialog(
|
|
|
|
title: String,
|
|
|
|
textContent: String,
|
|
|
|
icon: @Composable () -> Unit,
|
|
|
|
buttonText: String,
|
|
|
|
buttonColors: ButtonColors = ButtonDefaults.buttonColors(),
|
|
|
|
onClickDoOnce: () -> Unit,
|
|
|
|
onClickDontShowAgain: () -> Unit,
|
|
|
|
onDismiss: () -> Unit
|
2023-03-15 05:40:59 +00:00
|
|
|
) {
|
2023-03-14 17:41:39 +00:00
|
|
|
AlertDialog(
|
|
|
|
onDismissRequest = onDismiss,
|
|
|
|
title = {
|
2023-03-15 05:40:59 +00:00
|
|
|
Text(title)
|
2023-03-14 17:41:39 +00:00
|
|
|
},
|
|
|
|
text = {
|
2023-03-15 05:40:59 +00:00
|
|
|
Text(textContent)
|
2023-03-14 17:41:39 +00:00
|
|
|
},
|
2023-09-29 17:57:10 +00:00
|
|
|
confirmButton = {
|
2023-03-14 17:41:39 +00:00
|
|
|
Row(
|
2023-06-19 22:34:52 +00:00
|
|
|
modifier = Modifier
|
|
|
|
.padding(all = 8.dp)
|
|
|
|
.fillMaxWidth(),
|
2023-03-14 17:41:39 +00:00
|
|
|
horizontalArrangement = Arrangement.SpaceBetween
|
|
|
|
) {
|
2023-03-15 05:40:59 +00:00
|
|
|
TextButton(onClick = onClickDontShowAgain) {
|
2023-03-14 17:41:39 +00:00
|
|
|
Text(stringResource(R.string.quick_action_dont_show_again_button))
|
|
|
|
}
|
2023-09-29 17:57:10 +00:00
|
|
|
Button(onClick = onClickDoOnce, colors = buttonColors, contentPadding = PaddingValues(horizontal = 16.dp)) {
|
2023-03-15 05:40:59 +00:00
|
|
|
Row(
|
|
|
|
verticalAlignment = Alignment.CenterVertically
|
|
|
|
) {
|
2023-08-10 22:04:23 +00:00
|
|
|
icon()
|
2023-03-15 05:40:59 +00:00
|
|
|
Spacer(Modifier.width(8.dp))
|
|
|
|
Text(buttonText)
|
|
|
|
}
|
2023-03-14 17:41:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|