secant-android-wallet/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/backup/AndroidBackup.kt

69 lines
2.3 KiB
Kotlin
Raw Normal View History

package co.electriccoin.zcash.ui.screen.backup
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import androidx.activity.ComponentActivity
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import cash.z.ecc.sdk.model.PersistableWallet
import co.electriccoin.zcash.ui.MainActivity
import co.electriccoin.zcash.ui.R
import co.electriccoin.zcash.ui.screen.backup.ext.Saver
import co.electriccoin.zcash.ui.screen.backup.state.BackupState
import co.electriccoin.zcash.ui.screen.backup.state.TestChoices
import co.electriccoin.zcash.ui.screen.backup.view.BackupWallet
@Composable
internal fun MainActivity.WrapBackup(
persistableWallet: PersistableWallet,
onBackupComplete: () -> Unit
) {
WrapBackup(this, persistableWallet, onBackupComplete)
}
// This layer of indirection allows for activity re-creation tests
@Composable
internal fun WrapBackup(
activity: ComponentActivity,
persistableWallet: PersistableWallet,
onBackupComplete: () -> Unit
) {
WrapBackup(
2022-06-22 02:48:19 -07:00
persistableWallet,
onCopyToClipboard = { copyToClipboard(activity.applicationContext, persistableWallet) },
onBackupComplete = onBackupComplete
)
}
[#653] Refactor Backup flow screens * [#653] Move copy to buffer action - Trigger this action after seed phrase panel click and confirm via dialog window - Added basic ui tests - Added also dialog integration test - Added related strings * Revert "[#653] Move copy to buffer action" This reverts commit 813eab00b747a779be5ef652745002f65c04572c. * [#150] Refactoring the Backup flow to use Compose Scaffold * Fix Backup flow screenshot test - Removed scroll actions above nodes, which are no longer part of scroll behaviour - bottom navigation buttons are now part of Compose Scaffold component. * Added scroll actions in screenshot test of Profile screen - After tested the whole app with screenshot test on smaller screen device 4WVGA Nexus S * Remove unnecessary screenshot test click action - This click action on the Profile screen title seems to be unnecessary for the test and creates confusion * ScreenshotTest module auto components init - Changed the way we auto-initialize components in ScreenshotTest module - Now we use androidx-startup library for it - And we disabled the default way * Add system back button navigation support * Enable scrolling for Backup Test screen * Fix Screenshot test on small screen in landscape - Tested and fixed cases in which our screenshot test wasn't successful - Tested on 4 WVGA Nexus S in landscpae mode * Code clean * Address review comments + stages refactoring - Flattened BackupStage sealed class. Test and Failure are now regular stages. - Introduced CheckSeed stage, instead of reusing Seed phrase for re-viewing. - Simplified BackupView and custom Saver implementations. - List of possible screen state stages is now lazy loaded value, instead of method. - Some of the stages now override stage moving methods to enhance Backup screen state machine, as it's not linear. - Existing tests updated to align with the new implementation of stages. * Remove `run` block * Rename CheckSeed -> ReviewSeed Check might imply to another reader of the code that there is some going back to the test. I went with the word Review which seems to better convey how that screen is passive for the user. * Simplify list construction This should have better performance. * Crash instead of allowing back navigation * Add documentation * Fix initialization error * Add non-localized string tag Co-authored-by: Carter Jernigan <git@carterjernigan.com>
2022-11-22 23:17:06 -08:00
// This extra layer of indirection allows unit tests to validate the screen state retention.
@Composable
internal fun WrapBackup(
persistableWallet: PersistableWallet,
onCopyToClipboard: () -> Unit,
onBackupComplete: () -> Unit
) {
val testChoices by rememberSaveable(stateSaver = TestChoices.Saver) { mutableStateOf(TestChoices()) }
[#653] Refactor Backup flow screens * [#653] Move copy to buffer action - Trigger this action after seed phrase panel click and confirm via dialog window - Added basic ui tests - Added also dialog integration test - Added related strings * Revert "[#653] Move copy to buffer action" This reverts commit 813eab00b747a779be5ef652745002f65c04572c. * [#150] Refactoring the Backup flow to use Compose Scaffold * Fix Backup flow screenshot test - Removed scroll actions above nodes, which are no longer part of scroll behaviour - bottom navigation buttons are now part of Compose Scaffold component. * Added scroll actions in screenshot test of Profile screen - After tested the whole app with screenshot test on smaller screen device 4WVGA Nexus S * Remove unnecessary screenshot test click action - This click action on the Profile screen title seems to be unnecessary for the test and creates confusion * ScreenshotTest module auto components init - Changed the way we auto-initialize components in ScreenshotTest module - Now we use androidx-startup library for it - And we disabled the default way * Add system back button navigation support * Enable scrolling for Backup Test screen * Fix Screenshot test on small screen in landscape - Tested and fixed cases in which our screenshot test wasn't successful - Tested on 4 WVGA Nexus S in landscpae mode * Code clean * Address review comments + stages refactoring - Flattened BackupStage sealed class. Test and Failure are now regular stages. - Introduced CheckSeed stage, instead of reusing Seed phrase for re-viewing. - Simplified BackupView and custom Saver implementations. - List of possible screen state stages is now lazy loaded value, instead of method. - Some of the stages now override stage moving methods to enhance Backup screen state machine, as it's not linear. - Existing tests updated to align with the new implementation of stages. * Remove `run` block * Rename CheckSeed -> ReviewSeed Check might imply to another reader of the code that there is some going back to the test. I went with the word Review which seems to better convey how that screen is passive for the user. * Simplify list construction This should have better performance. * Crash instead of allowing back navigation * Add documentation * Fix initialization error * Add non-localized string tag Co-authored-by: Carter Jernigan <git@carterjernigan.com>
2022-11-22 23:17:06 -08:00
val backupState by rememberSaveable(stateSaver = BackupState.Saver) { mutableStateOf(BackupState()) }
BackupWallet(
persistableWallet,
backupState,
testChoices,
onCopyToClipboard = onCopyToClipboard,
onComplete = onBackupComplete,
null
)
}
fun copyToClipboard(context: Context, persistableWallet: PersistableWallet) {
val clipboardManager = context.getSystemService(ClipboardManager::class.java)
val data = ClipData.newPlainText(
context.getString(R.string.new_wallet_clipboard_tag),
persistableWallet.seedPhrase.joinToString()
)
clipboardManager.setPrimaryClip(data)
}