2021-10-09 07:36:58 -07:00
|
|
|
package cash.z.ecc.ui
|
2021-09-14 14:02:06 -07:00
|
|
|
|
2021-12-02 12:33:55 -08:00
|
|
|
import android.content.ClipData
|
|
|
|
import android.content.ClipboardManager
|
2021-09-14 14:02:06 -07:00
|
|
|
import android.os.Bundle
|
|
|
|
import androidx.activity.ComponentActivity
|
|
|
|
import androidx.activity.compose.setContent
|
2021-10-09 07:37:03 -07:00
|
|
|
import androidx.activity.viewModels
|
2021-11-17 12:19:49 -08:00
|
|
|
import androidx.compose.runtime.Composable
|
2021-11-12 04:09:30 -08:00
|
|
|
import androidx.compose.runtime.collectAsState
|
2021-11-17 12:19:49 -08:00
|
|
|
import cash.z.ecc.sdk.model.PersistableWallet
|
|
|
|
import cash.z.ecc.ui.screen.backup.view.BackupWallet
|
|
|
|
import cash.z.ecc.ui.screen.backup.viewmodel.BackupViewModel
|
2021-11-12 04:09:30 -08:00
|
|
|
import cash.z.ecc.ui.screen.home.view.Home
|
2021-11-17 12:19:49 -08:00
|
|
|
import cash.z.ecc.ui.screen.home.viewmodel.WalletState
|
2021-11-12 04:09:30 -08:00
|
|
|
import cash.z.ecc.ui.screen.home.viewmodel.WalletViewModel
|
2021-10-09 07:37:03 -07:00
|
|
|
import cash.z.ecc.ui.screen.onboarding.view.Onboarding
|
|
|
|
import cash.z.ecc.ui.screen.onboarding.viewmodel.OnboardingViewModel
|
2021-10-31 10:36:51 -07:00
|
|
|
import cash.z.ecc.ui.theme.ZcashTheme
|
2021-09-14 14:02:06 -07:00
|
|
|
|
|
|
|
class MainActivity : ComponentActivity() {
|
2021-10-09 07:37:03 -07:00
|
|
|
|
2021-11-12 04:09:30 -08:00
|
|
|
private val walletViewModel by viewModels<WalletViewModel>()
|
|
|
|
|
2021-10-09 07:37:03 -07:00
|
|
|
private val onboardingViewModel by viewModels<OnboardingViewModel>()
|
2021-11-17 12:19:49 -08:00
|
|
|
private val backupViewModel by viewModels<BackupViewModel>()
|
2021-10-09 07:37:03 -07:00
|
|
|
|
2021-09-14 14:02:06 -07:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
setContent {
|
2021-10-31 10:36:51 -07:00
|
|
|
ZcashTheme {
|
2021-11-17 12:19:49 -08:00
|
|
|
when (val walletState = walletViewModel.state.collectAsState().value) {
|
|
|
|
WalletState.Loading -> {
|
|
|
|
// For now, keep displaying splash screen
|
2021-11-12 04:09:30 -08:00
|
|
|
}
|
2021-11-17 12:19:49 -08:00
|
|
|
WalletState.NoWallet -> WrapOnboarding()
|
|
|
|
is WalletState.NeedsBackup -> WrapBackup(walletState.persistableWallet)
|
|
|
|
is WalletState.Ready -> Home(walletState.persistableWallet)
|
2021-11-12 04:09:30 -08:00
|
|
|
}
|
2021-09-14 14:02:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-17 12:19:49 -08:00
|
|
|
|
|
|
|
@Composable
|
|
|
|
private fun WrapBackup(persistableWallet: PersistableWallet) {
|
2021-12-02 12:33:55 -08:00
|
|
|
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 = {
|
2021-11-17 12:19:49 -08:00
|
|
|
walletViewModel.persistBackupComplete()
|
|
|
|
}
|
2021-12-02 12:33:55 -08:00
|
|
|
)
|
2021-11-17 12:19:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
private fun WrapOnboarding() {
|
|
|
|
Onboarding(
|
|
|
|
onboardingState = onboardingViewModel.onboardingState,
|
|
|
|
onImportWallet = { TODO("Implement wallet import") },
|
|
|
|
onCreateWallet = {
|
|
|
|
walletViewModel.createAndPersistWallet()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
2021-09-14 14:02:06 -07:00
|
|
|
}
|