Add 'create a pin' button to backups sub pin entry sheet.

This commit is contained in:
Alex Hart 2024-08-07 11:48:38 -03:00 committed by mtang-signal
parent b9da045f79
commit 16a732171a
4 changed files with 38 additions and 9 deletions

View file

@ -1105,6 +1105,7 @@
<activity android:name=".components.settings.app.subscription.donate.CheckoutFlowActivity"
android:theme="@style/Theme.Signal.DayNight.NoActionBar"
android:windowSoftInputMode="adjustResize"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"
android:exported="false"/>

View file

@ -13,6 +13,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.fragment.findNavController
@ -23,6 +24,7 @@ import org.thoughtcrime.securesms.components.settings.app.subscription.donate.In
import org.thoughtcrime.securesms.compose.ComposeFragment
import org.thoughtcrime.securesms.compose.Nav
import org.thoughtcrime.securesms.database.InAppPaymentTable
import org.thoughtcrime.securesms.lock.v2.CreateSvrPinActivity
import org.thoughtcrime.securesms.util.navigation.safeNavigate
import org.thoughtcrime.securesms.util.viewModel
@ -57,14 +59,19 @@ class MessageBackupsFlowFragment : ComposeFragment(), InAppPaymentCheckoutDelega
skipPartiallyExpanded = true
)
val lifecycleOwner = LocalLifecycleOwner.current
LaunchedEffect(Unit) {
navController.setLifecycleOwner(this@MessageBackupsFlowFragment)
requireActivity().onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
viewModel.goToPreviousScreen()
requireActivity().onBackPressedDispatcher.addCallback(
lifecycleOwner,
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
viewModel.goToPreviousScreen()
}
}
})
)
}
Nav.Host(
@ -95,7 +102,8 @@ class MessageBackupsFlowFragment : ComposeFragment(), InAppPaymentCheckoutDelega
onPinChanged = viewModel::onPinEntryUpdated,
pinKeyboardType = state.pinKeyboardType,
onPinKeyboardTypeSelected = viewModel::onPinKeyboardTypeUpdated,
onNextClick = viewModel::goToNextScreen
onNextClick = viewModel::goToNextScreen,
onCreateNewPinClick = this@MessageBackupsFlowFragment::createANewPin
)
}
@ -188,6 +196,11 @@ class MessageBackupsFlowFragment : ComposeFragment(), InAppPaymentCheckoutDelega
}
}
private fun createANewPin() {
viewModel.onPinEntryUpdated("")
startActivity(CreateSvrPinActivity.getIntentForPinChangeFromSettings(requireContext()))
}
private fun cancelSubscription() {
findNavController().safeNavigate(
MessageBackupsFlowFragmentDirections.actionDonateToSignalFragmentToStripePaymentInProgressFragment(

View file

@ -7,6 +7,8 @@ package org.thoughtcrime.securesms.backup.v2.ui.subscription
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
@ -54,7 +56,8 @@ fun MessageBackupsPinConfirmationScreen(
onPinChanged: (String) -> Unit,
pinKeyboardType: PinKeyboardType,
onPinKeyboardTypeSelected: (PinKeyboardType) -> Unit,
onNextClick: () -> Unit
onNextClick: () -> Unit,
onCreateNewPinClick: () -> Unit
) {
val focusRequester = remember { FocusRequester() }
Surface {
@ -139,12 +142,21 @@ fun MessageBackupsPinConfirmationScreen(
}
}
Box(
contentAlignment = Alignment.BottomEnd,
Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 16.dp)
) {
if (isPinIncorrect) {
TextButton(onClick = onCreateNewPinClick) {
Text(
text = stringResource(id = R.string.MessageBackupsPinConfirmationScreen__create_new_pin)
)
}
}
Spacer(modifier = Modifier.weight(1f))
Buttons.LargeTonal(
onClick = onNextClick
) {
@ -171,7 +183,8 @@ private fun MessageBackupsPinConfirmationScreenPreview() {
onPinChanged = {},
pinKeyboardType = PinKeyboardType.ALPHA_NUMERIC,
onPinKeyboardTypeSelected = {},
onNextClick = {}
onNextClick = {},
onCreateNewPinClick = {}
)
}
}

View file

@ -7346,6 +7346,8 @@
<string name="MessageBackupsPinConfirmationScreen__next">Next</string>
<!-- Action button to switch keyboard type -->
<string name="MessageBackupsPinConfirmationScreen__switch_keyboard">Switch keyboard</string>
<!-- Action button to create a new pin if we type the incorrect one -->
<string name="MessageBackupsPinConfirmationScreen__create_new_pin">Create new pin</string>
<!-- MessageBackupsPinEducationScreen -->
<!-- Screen headline -->