diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/AppNavigation.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/AppNavigation.kt index c6ab5bdb6..d2427b4cc 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/AppNavigation.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/AppNavigation.kt @@ -107,6 +107,7 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.RelayInformationScre import com.vitorpamplona.amethyst.ui.screen.loggedIn.search.SearchScreen import com.vitorpamplona.amethyst.ui.screen.loggedIn.settings.AllSettingsScreen import com.vitorpamplona.amethyst.ui.screen.loggedIn.settings.NIP47SetupScreen +import com.vitorpamplona.amethyst.ui.screen.loggedIn.settings.UpdateZapAmountScreen import com.vitorpamplona.amethyst.ui.screen.loggedIn.settings.SecurityFiltersScreen import com.vitorpamplona.amethyst.ui.screen.loggedIn.settings.SettingsScreen import com.vitorpamplona.amethyst.ui.screen.loggedIn.settings.UserSettingsScreen @@ -172,6 +173,7 @@ fun AppNavigation( composableFromEnd { SettingsScreen(accountViewModel, nav) } composableFromEnd { UserSettingsScreen(accountViewModel, nav) } composableFromBottomArgs { NIP47SetupScreen(accountViewModel, nav, it.nip47) } + composableFromBottomArgs { UpdateZapAmountScreen(accountViewModel, nav, it.nip47) } composableFromEndArgs { AllRelayListScreen(accountViewModel, nav) } composableFromEndArgs { AllMediaServersScreen(accountViewModel, nav) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/routes/Routes.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/routes/Routes.kt index 106dee44f..aea7a845d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/routes/Routes.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/routes/Routes.kt @@ -117,6 +117,10 @@ sealed class Route { val nip47: String? = null, ) : Route() + @Serializable data class UpdateZapAmount( + val nip47: String? = null, + ) : Route() + @Serializable data class Profile( val id: String, ) : Route() @@ -352,6 +356,7 @@ fun getRouteWithArguments(navController: NavHostController): Route? { dest.hasRoute() -> entry.toRoute() dest.hasRoute() -> entry.toRoute() dest.hasRoute() -> entry.toRoute() + dest.hasRoute() -> entry.toRoute() dest.hasRoute() -> entry.toRoute() dest.hasRoute() -> entry.toRoute() dest.hasRoute() -> entry.toRoute() diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/ReactionsRow.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/ReactionsRow.kt index 89874e20c..d4f02a667 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/ReactionsRow.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/ReactionsRow.kt @@ -1039,7 +1039,6 @@ fun ZapReaction( nav: INav, ) { var wantsToZap by remember { mutableStateOf(false) } - var wantsToChangeZapAmount by remember { mutableStateOf(false) } var wantsToSetCustomZap by remember { mutableStateOf(false) } val context = LocalContext.current @@ -1090,7 +1089,7 @@ fun ZapReaction( ) } }, - onLongClick = { wantsToChangeZapAmount = true }, + onLongClick = { nav.nav(Route.UpdateZapAmount()) }, onDoubleClick = { wantsToSetCustomZap = true }, ), ) { @@ -1107,7 +1106,7 @@ fun ZapReaction( onChangeAmount = { scope.launch { wantsToZap = false - wantsToChangeZapAmount = true + nav.nav(Route.UpdateZapAmount()) } }, onError = { _, message, user -> @@ -1133,13 +1132,6 @@ fun ZapReaction( ) } - if (wantsToChangeZapAmount) { - UpdateZapAmountDialog( - onClose = { wantsToChangeZapAmount = false }, - accountViewModel = accountViewModel, - ) - } - if (wantsToSetCustomZap) { ZapCustomDialog( onZapStarts = { zapStartingTime = TimeUtils.now() }, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/UpdateZapAmountDialog.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/UpdateZapAmountDialog.kt index 527758391..52859f724 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/UpdateZapAmountDialog.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/UpdateZapAmountDialog.kt @@ -57,7 +57,6 @@ import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField -import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -78,14 +77,9 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.text.input.VisualTransformation import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp -import androidx.compose.ui.window.Dialog -import androidx.compose.ui.window.DialogProperties -import androidx.lifecycle.viewmodel.compose.viewModel import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.ui.components.TextSpinner import com.vitorpamplona.amethyst.ui.components.TitleExplainer -import com.vitorpamplona.amethyst.ui.note.buttons.CloseButton -import com.vitorpamplona.amethyst.ui.note.buttons.SaveButton import com.vitorpamplona.amethyst.ui.painterRes import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.keyBackup.getFragmentActivity @@ -99,70 +93,6 @@ import com.vitorpamplona.amethyst.ui.theme.placeholderText import com.vitorpamplona.quartz.nip57Zaps.LnZapEvent import kotlinx.collections.immutable.toImmutableList -@Composable -fun UpdateZapAmountDialog( - onClose: () -> Unit, - nip47uri: String? = null, - accountViewModel: AccountViewModel, -) { - val postViewModel: UpdateZapAmountViewModel = viewModel() - postViewModel.init(accountViewModel) - - LaunchedEffect(accountViewModel, postViewModel) { - postViewModel.load() - } - UpdateZapAmountDialog(postViewModel, onClose, nip47uri, accountViewModel) -} - -@Composable -fun UpdateZapAmountDialog( - postViewModel: UpdateZapAmountViewModel, - onClose: () -> Unit, - nip47uri: String? = null, - accountViewModel: AccountViewModel, -) { - Dialog( - onDismissRequest = { onClose() }, - properties = - DialogProperties( - usePlatformDefaultWidth = false, - dismissOnClickOutside = false, - decorFitsSystemWindows = false, - ), - ) { - Surface( - modifier = Modifier.fillMaxWidth(), - ) { - Column { - Row( - modifier = Modifier.fillMaxWidth().padding(10.dp), - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically, - ) { - CloseButton( - onPress = { - postViewModel.cancel() - onClose() - }, - ) - - SaveButton( - onPost = { - postViewModel.sendPost() - onClose() - }, - isActive = postViewModel.hasChanged(), - ) - } - - Spacer(modifier = Modifier.height(10.dp)) - - UpdateZapAmountContent(postViewModel, onClose, nip47uri, accountViewModel) - } - } - } -} - @OptIn(ExperimentalLayoutApi::class) @Composable fun UpdateZapAmountContent( diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/AllSettingsScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/AllSettingsScreen.kt index 1b9ee3abd..764fcc9f1 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/AllSettingsScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/AllSettingsScreen.kt @@ -58,7 +58,6 @@ import com.vitorpamplona.amethyst.ui.navigation.navs.INav import com.vitorpamplona.amethyst.ui.navigation.routes.Route import com.vitorpamplona.amethyst.ui.navigation.topbars.TopBarWithBackButton import com.vitorpamplona.amethyst.ui.note.UpdateReactionTypeDialog -import com.vitorpamplona.amethyst.ui.note.UpdateZapAmountDialog import com.vitorpamplona.amethyst.ui.painterRes import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.keyBackup.AccountBackupDialog @@ -85,7 +84,6 @@ fun AllSettingsScreen( val tint = MaterialTheme.colorScheme.onBackground var showReactionDialog by remember { mutableStateOf(false) } - var wantsToChangeZapAmount by remember { mutableStateOf(false) } if (showReactionDialog) { UpdateReactionTypeDialog( @@ -95,13 +93,6 @@ fun AllSettingsScreen( ) } - if (wantsToChangeZapAmount) { - UpdateZapAmountDialog( - onClose = { wantsToChangeZapAmount = false }, - accountViewModel = accountViewModel, - ) - } - Scaffold( topBar = { TopBarWithBackButton(stringRes(id = R.string.settings), nav::popBack) @@ -135,7 +126,7 @@ fun AllSettingsScreen( title = R.string.zaps, icon = Icons.Outlined.Bolt, tint = tint, - onClick = { wantsToChangeZapAmount = true }, + onClick = { nav.nav(Route.UpdateZapAmount()) }, ) HorizontalDivider() SettingsNavigationRow( diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/UpdateZapAmountScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/UpdateZapAmountScreen.kt new file mode 100644 index 000000000..055620acd --- /dev/null +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/UpdateZapAmountScreen.kt @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2025 Vitor Pamplona + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.vitorpamplona.amethyst.ui.screen.loggedIn.settings + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Scaffold +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.ui.Modifier +import androidx.lifecycle.viewmodel.compose.viewModel +import com.vitorpamplona.amethyst.R +import com.vitorpamplona.amethyst.ui.navigation.navs.INav +import com.vitorpamplona.amethyst.ui.navigation.topbars.SavingTopBar +import com.vitorpamplona.amethyst.ui.note.UpdateZapAmountContent +import com.vitorpamplona.amethyst.ui.note.UpdateZapAmountViewModel +import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel + +@Composable +fun UpdateZapAmountScreen( + accountViewModel: AccountViewModel, + nav: INav, + nip47: String? = null, +) { + val postViewModel: UpdateZapAmountViewModel = viewModel() + postViewModel.init(accountViewModel) + + LaunchedEffect(accountViewModel, postViewModel) { + postViewModel.load() + } + + UpdateZapAmountScreen(postViewModel, accountViewModel, nav, nip47) +} + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun UpdateZapAmountScreen( + postViewModel: UpdateZapAmountViewModel, + accountViewModel: AccountViewModel, + nav: INav, + nip47: String? = null, +) { + Scaffold( + topBar = { + SavingTopBar( + titleRes = R.string.zaps, + isActive = postViewModel::hasChanged, + onCancel = { + postViewModel.cancel() + nav.popBack() + }, + onPost = { + postViewModel.sendPost() + nav.popBack() + }, + ) + }, + ) { + Column(Modifier.padding(it)) { + UpdateZapAmountContent(postViewModel, onClose = { + postViewModel.cancel() + nav.popBack() + }, nip47, accountViewModel) + } + } +}