[#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(BackupStage.EducationOverview, testSetup.getStage())
|
||||||
assertEquals(0, testSetup.getOnCompleteCallbackCount())
|
assertEquals(0, testSetup.getOnCompleteCallbackCount())
|
||||||
|
assertEquals(0, testSetup.getOnCopyToClipboardCount())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -43,6 +44,19 @@ class BackupViewTest {
|
||||||
|
|
||||||
assertEquals(BackupStage.Complete, testSetup.getStage())
|
assertEquals(BackupStage.Complete, testSetup.getStage())
|
||||||
assertEquals(0, testSetup.getOnCompleteCallbackCount())
|
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
|
@Test
|
||||||
|
@ -107,6 +121,7 @@ class BackupViewTest {
|
||||||
val goToWalletButton = composeTestRule.onNodeWithText(getStringResource(R.string.new_wallet_5_button_finished))
|
val goToWalletButton = composeTestRule.onNodeWithText(getStringResource(R.string.new_wallet_5_button_finished))
|
||||||
goToWalletButton.performClick()
|
goToWalletButton.performClick()
|
||||||
|
|
||||||
|
assertEquals(0, testSetup.getOnCopyToClipboardCount())
|
||||||
assertEquals(1, testSetup.getOnCompleteCallbackCount())
|
assertEquals(1, testSetup.getOnCompleteCallbackCount())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,6 +133,7 @@ class BackupViewTest {
|
||||||
val newWalletButton = composeTestRule.onNodeWithText(getStringResource(R.string.new_wallet_5_button_back))
|
val newWalletButton = composeTestRule.onNodeWithText(getStringResource(R.string.new_wallet_5_button_back))
|
||||||
newWalletButton.performClick()
|
newWalletButton.performClick()
|
||||||
|
|
||||||
|
assertEquals(0, testSetup.getOnCopyToClipboardCount())
|
||||||
assertEquals(0, testSetup.getOnCompleteCallbackCount())
|
assertEquals(0, testSetup.getOnCompleteCallbackCount())
|
||||||
assertEquals(BackupStage.Seed, testSetup.getStage())
|
assertEquals(BackupStage.Seed, testSetup.getStage())
|
||||||
}
|
}
|
||||||
|
@ -139,6 +155,12 @@ class BackupViewTest {
|
||||||
|
|
||||||
assertEquals(BackupStage.Seed, testSetup.getStage())
|
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 {
|
composeTestRule.onNodeWithText(getStringResource(R.string.new_wallet_3_button_finished)).also {
|
||||||
it.performClick()
|
it.performClick()
|
||||||
}
|
}
|
||||||
|
@ -173,8 +195,15 @@ class BackupViewTest {
|
||||||
private class TestSetup(private val composeTestRule: ComposeContentTestRule, initalStage: BackupStage) {
|
private class TestSetup(private val composeTestRule: ComposeContentTestRule, initalStage: BackupStage) {
|
||||||
private val state = BackupState(initalStage)
|
private val state = BackupState(initalStage)
|
||||||
|
|
||||||
|
private var onCopyToClipboardCount = 0
|
||||||
|
|
||||||
private var onCompleteCallbackCount = 0
|
private var onCompleteCallbackCount = 0
|
||||||
|
|
||||||
|
fun getOnCopyToClipboardCount(): Int {
|
||||||
|
composeTestRule.waitForIdle()
|
||||||
|
return onCopyToClipboardCount
|
||||||
|
}
|
||||||
|
|
||||||
fun getOnCompleteCallbackCount(): Int {
|
fun getOnCompleteCallbackCount(): Int {
|
||||||
composeTestRule.waitForIdle()
|
composeTestRule.waitForIdle()
|
||||||
return onCompleteCallbackCount
|
return onCompleteCallbackCount
|
||||||
|
@ -192,6 +221,7 @@ class BackupViewTest {
|
||||||
PersistableWalletFixture.new(),
|
PersistableWalletFixture.new(),
|
||||||
state,
|
state,
|
||||||
TestChoices(),
|
TestChoices(),
|
||||||
|
onCopyToClipboard = { onCopyToClipboardCount++ },
|
||||||
onComplete = { onCompleteCallbackCount++ }
|
onComplete = { onCompleteCallbackCount++ }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package cash.z.ecc.ui
|
package cash.z.ecc.ui
|
||||||
|
|
||||||
|
import android.content.ClipData
|
||||||
|
import android.content.ClipboardManager
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
|
@ -41,9 +43,19 @@ class MainActivity : ComponentActivity() {
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun WrapBackup(persistableWallet: PersistableWallet) {
|
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()
|
walletViewModel.persistBackupComplete()
|
||||||
}
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|
|
@ -42,6 +42,7 @@ fun ComposablePreview() {
|
||||||
PersistableWalletFixture.new(),
|
PersistableWalletFixture.new(),
|
||||||
BackupState(BackupStage.Test),
|
BackupState(BackupStage.Test),
|
||||||
TestChoices(),
|
TestChoices(),
|
||||||
|
onCopyToClipboard = {},
|
||||||
onComplete = {}
|
onComplete = {}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -55,6 +56,7 @@ fun BackupWallet(
|
||||||
wallet: PersistableWallet,
|
wallet: PersistableWallet,
|
||||||
backupState: BackupState,
|
backupState: BackupState,
|
||||||
selectedTestChoices: TestChoices,
|
selectedTestChoices: TestChoices,
|
||||||
|
onCopyToClipboard: () -> Unit,
|
||||||
onComplete: () -> Unit,
|
onComplete: () -> Unit,
|
||||||
) {
|
) {
|
||||||
Surface {
|
Surface {
|
||||||
|
@ -63,10 +65,9 @@ fun BackupWallet(
|
||||||
BackupStage.EducationOverview -> EducationOverview(onNext = backupState::goNext)
|
BackupStage.EducationOverview -> EducationOverview(onNext = backupState::goNext)
|
||||||
BackupStage.EducationRecoveryPhrase -> EducationRecoveryPhrase(onNext = backupState::goNext)
|
BackupStage.EducationRecoveryPhrase -> EducationRecoveryPhrase(onNext = backupState::goNext)
|
||||||
BackupStage.Seed -> SeedPhrase(
|
BackupStage.Seed -> SeedPhrase(
|
||||||
wallet, onNext = backupState::goNext,
|
wallet,
|
||||||
onCopyToClipboard = {
|
onNext = backupState::goNext,
|
||||||
// TODO [#49]
|
onCopyToClipboard = onCopyToClipboard
|
||||||
}
|
|
||||||
)
|
)
|
||||||
BackupStage.Test -> Test(
|
BackupStage.Test -> Test(
|
||||||
wallet,
|
wallet,
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
<resources>
|
<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_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_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>
|
<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