[#49] Implement copy to clipboard
This commit is contained in:
parent
f738666cd2
commit
72c6628649
|
@ -34,6 +34,7 @@ class BackupViewTest {
|
|||
|
||||
assertEquals(BackupStage.EducationOverview, testSetup.getStage())
|
||||
assertEquals(0, testSetup.getOnCompleteCallbackCount())
|
||||
assertEquals(0, testSetup.getOnCopyToClipboardCount())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -43,6 +44,19 @@ class BackupViewTest {
|
|||
|
||||
assertEquals(BackupStage.Complete, testSetup.getStage())
|
||||
assertEquals(0, testSetup.getOnCompleteCallbackCount())
|
||||
assertEquals(0, testSetup.getOnCopyToClipboardCount())
|
||||
}
|
||||
|
||||
@Test
|
||||
@MediumTest
|
||||
fun copy_to_clipboard() {
|
||||
val testSetup = newTestSetup(BackupStage.Seed)
|
||||
|
||||
composeTestRule.onNodeWithText(getStringResource(R.string.new_wallet_3_button_copy)).also {
|
||||
it.performClick()
|
||||
}
|
||||
|
||||
assertEquals(1, testSetup.getOnCopyToClipboardCount())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -107,6 +121,7 @@ class BackupViewTest {
|
|||
val goToWalletButton = composeTestRule.onNodeWithText(getStringResource(R.string.new_wallet_5_button_finished))
|
||||
goToWalletButton.performClick()
|
||||
|
||||
assertEquals(0, testSetup.getOnCopyToClipboardCount())
|
||||
assertEquals(1, testSetup.getOnCompleteCallbackCount())
|
||||
}
|
||||
|
||||
|
@ -118,6 +133,7 @@ class BackupViewTest {
|
|||
val newWalletButton = composeTestRule.onNodeWithText(getStringResource(R.string.new_wallet_5_button_back))
|
||||
newWalletButton.performClick()
|
||||
|
||||
assertEquals(0, testSetup.getOnCopyToClipboardCount())
|
||||
assertEquals(0, testSetup.getOnCompleteCallbackCount())
|
||||
assertEquals(BackupStage.Seed, testSetup.getStage())
|
||||
}
|
||||
|
@ -139,6 +155,12 @@ class BackupViewTest {
|
|||
|
||||
assertEquals(BackupStage.Seed, testSetup.getStage())
|
||||
|
||||
composeTestRule.onNodeWithText(getStringResource(R.string.new_wallet_3_button_copy)).also {
|
||||
it.performClick()
|
||||
}
|
||||
|
||||
assertEquals(1, testSetup.getOnCopyToClipboardCount())
|
||||
|
||||
composeTestRule.onNodeWithText(getStringResource(R.string.new_wallet_3_button_finished)).also {
|
||||
it.performClick()
|
||||
}
|
||||
|
@ -173,8 +195,15 @@ class BackupViewTest {
|
|||
private class TestSetup(private val composeTestRule: ComposeContentTestRule, initalStage: BackupStage) {
|
||||
private val state = BackupState(initalStage)
|
||||
|
||||
private var onCopyToClipboardCount = 0
|
||||
|
||||
private var onCompleteCallbackCount = 0
|
||||
|
||||
fun getOnCopyToClipboardCount(): Int {
|
||||
composeTestRule.waitForIdle()
|
||||
return onCopyToClipboardCount
|
||||
}
|
||||
|
||||
fun getOnCompleteCallbackCount(): Int {
|
||||
composeTestRule.waitForIdle()
|
||||
return onCompleteCallbackCount
|
||||
|
@ -192,6 +221,7 @@ class BackupViewTest {
|
|||
PersistableWalletFixture.new(),
|
||||
state,
|
||||
TestChoices(),
|
||||
onCopyToClipboard = { onCopyToClipboardCount++ },
|
||||
onComplete = { onCompleteCallbackCount++ }
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package cash.z.ecc.ui
|
||||
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
|
@ -41,9 +43,19 @@ class MainActivity : ComponentActivity() {
|
|||
|
||||
@Composable
|
||||
private fun WrapBackup(persistableWallet: PersistableWallet) {
|
||||
BackupWallet(persistableWallet, backupViewModel.backupState, backupViewModel.testChoices) {
|
||||
BackupWallet(
|
||||
persistableWallet, backupViewModel.backupState, backupViewModel.testChoices,
|
||||
onCopyToClipboard = {
|
||||
val clipboardManager = getSystemService(ClipboardManager::class.java)
|
||||
val data = ClipData.newPlainText(
|
||||
getString(R.string.new_wallet_clipboard_tag),
|
||||
persistableWallet.seedPhrase.phrase
|
||||
)
|
||||
clipboardManager.setPrimaryClip(data)
|
||||
}, onComplete = {
|
||||
walletViewModel.persistBackupComplete()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
|
|
@ -42,6 +42,7 @@ fun ComposablePreview() {
|
|||
PersistableWalletFixture.new(),
|
||||
BackupState(BackupStage.Test),
|
||||
TestChoices(),
|
||||
onCopyToClipboard = {},
|
||||
onComplete = {}
|
||||
)
|
||||
}
|
||||
|
@ -55,6 +56,7 @@ fun BackupWallet(
|
|||
wallet: PersistableWallet,
|
||||
backupState: BackupState,
|
||||
selectedTestChoices: TestChoices,
|
||||
onCopyToClipboard: () -> Unit,
|
||||
onComplete: () -> Unit,
|
||||
) {
|
||||
Surface {
|
||||
|
@ -63,10 +65,9 @@ fun BackupWallet(
|
|||
BackupStage.EducationOverview -> EducationOverview(onNext = backupState::goNext)
|
||||
BackupStage.EducationRecoveryPhrase -> EducationRecoveryPhrase(onNext = backupState::goNext)
|
||||
BackupStage.Seed -> SeedPhrase(
|
||||
wallet, onNext = backupState::goNext,
|
||||
onCopyToClipboard = {
|
||||
// TODO [#49]
|
||||
}
|
||||
wallet,
|
||||
onNext = backupState::goNext,
|
||||
onCopyToClipboard = onCopyToClipboard
|
||||
)
|
||||
BackupStage.Test -> Test(
|
||||
wallet,
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<resources>
|
||||
<string name="new_wallet_clipboard_tag">Zcash Seed Phrase</string>
|
||||
|
||||
<string name="new_wallet_1_header">First things first</string>
|
||||
<string name="new_wallet_1_body_1">It is important to understand that you are in charge here. Great, right? YOU get to be the bank!</string>
|
||||
<string name="new_wallet_1_body_2">But it also means that YOU are the customer, and you need to be self-reliant.\n\nSo how do you recover funds that you‘ve hidden on a complete decentralized and private block-chain?</string>
|
||||
|
|
Loading…
Reference in New Issue