[#1196] Balances widget on Balances screen

* [#1196] Integrate Balances widget to Balances

- Closing #1196
- Changelog update
This commit is contained in:
Honza Rychnovský 2024-01-28 01:26:11 +01:00 committed by GitHub
parent b68d93b137
commit 3240c3baa8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 72 additions and 24 deletions

View File

@ -12,7 +12,7 @@ directly impact users rather than highlighting other key architectural updates.*
### Added ### Added
- The current balance UI on top of the Account screen has been reworked. It now displays the currently available - The current balance UI on top of the Account screen has been reworked. It now displays the currently available
balance as well. balance as well.
- The same current balance UI was also incorporated into the Send Form screen. - The same current balance UI was incorporated into the Send and Balances screens.
- The Send Error screen now contains a simple text with the reason for failure. The Send screen UI refactoring is - The Send Error screen now contains a simple text with the reason for failure. The Send screen UI refactoring is
still in progress. still in progress.

View File

@ -3,16 +3,22 @@
package co.electriccoin.zcash.ui.screen.balances package co.electriccoin.zcash.ui.screen.balances
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.viewModels
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import co.electriccoin.zcash.ui.common.viewmodel.WalletViewModel
import co.electriccoin.zcash.ui.screen.balances.view.Balances import co.electriccoin.zcash.ui.screen.balances.view.Balances
@Suppress("UNUSED_PARAMETER")
@Composable @Composable
internal fun WrapBalances( internal fun WrapBalances(
activity: ComponentActivity, activity: ComponentActivity,
goSettings: () -> Unit, goSettings: () -> Unit,
) { ) {
val walletViewModel by activity.viewModels<WalletViewModel>()
val walletSnapshot = walletViewModel.walletSnapshot.collectAsStateWithLifecycle().value
Balances( Balances(
walletSnapshot = walletSnapshot,
onSettings = goSettings, onSettings = goSettings,
) )
} }

View File

@ -3,28 +3,33 @@ package co.electriccoin.zcash.ui.screen.balances.view
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import co.electriccoin.zcash.ui.R import co.electriccoin.zcash.ui.R
import co.electriccoin.zcash.ui.common.BalanceWidget
import co.electriccoin.zcash.ui.common.model.WalletSnapshot
import co.electriccoin.zcash.ui.common.test.CommonTag import co.electriccoin.zcash.ui.common.test.CommonTag
import co.electriccoin.zcash.ui.design.component.Body import co.electriccoin.zcash.ui.design.component.Body
import co.electriccoin.zcash.ui.design.component.CircularScreenProgressIndicator
import co.electriccoin.zcash.ui.design.component.GradientSurface import co.electriccoin.zcash.ui.design.component.GradientSurface
import co.electriccoin.zcash.ui.design.component.SmallTopAppBar import co.electriccoin.zcash.ui.design.component.SmallTopAppBar
import co.electriccoin.zcash.ui.design.theme.ZcashTheme import co.electriccoin.zcash.ui.design.theme.ZcashTheme
import co.electriccoin.zcash.ui.fixture.WalletSnapshotFixture
import co.electriccoin.zcash.ui.screen.account.model.WalletDisplayValues
@Preview("Balances") @Preview("Balances")
@Composable @Composable
@ -32,6 +37,7 @@ private fun ComposablePreview() {
ZcashTheme(forceDarkMode = false) { ZcashTheme(forceDarkMode = false) {
GradientSurface { GradientSurface {
Balances( Balances(
walletSnapshot = WalletSnapshotFixture.new(),
onSettings = {}, onSettings = {},
) )
} }
@ -42,26 +48,35 @@ private fun ComposablePreview() {
// TODO [#1127]: https://github.com/Electric-Coin-Company/zashi-android/issues/1127 // TODO [#1127]: https://github.com/Electric-Coin-Company/zashi-android/issues/1127
@Composable @Composable
fun Balances(onSettings: () -> Unit) { fun Balances(
walletSnapshot: WalletSnapshot?,
onSettings: () -> Unit
) {
Scaffold(topBar = { Scaffold(topBar = {
BalancesTopAppBar(onSettings = onSettings) BalancesTopAppBar(onSettings = onSettings)
}) { paddingValues -> }) { paddingValues ->
BalancesMainContent( if (null == walletSnapshot) {
modifier = CircularScreenProgressIndicator()
Modifier.padding( } else {
top = paddingValues.calculateTopPadding() + ZcashTheme.dimens.spacingDefault, BalancesMainContent(
bottom = paddingValues.calculateBottomPadding() + ZcashTheme.dimens.spacingHuge, walletSnapshot = walletSnapshot,
start = ZcashTheme.dimens.screenHorizontalSpacingRegular, modifier =
end = ZcashTheme.dimens.screenHorizontalSpacingRegular Modifier.padding(
) top = paddingValues.calculateTopPadding() + ZcashTheme.dimens.spacingDefault,
) bottom = paddingValues.calculateBottomPadding() + ZcashTheme.dimens.spacingHuge,
start = ZcashTheme.dimens.screenHorizontalSpacingRegular,
end = ZcashTheme.dimens.screenHorizontalSpacingRegular
)
)
}
} }
} }
@Composable @Composable
private fun BalancesTopAppBar(onSettings: () -> Unit) { private fun BalancesTopAppBar(onSettings: () -> Unit) {
SmallTopAppBar( SmallTopAppBar(
showTitleLogo = true, showTitleLogo = false,
titleText = stringResource(id = R.string.balances_title),
hamburgerMenuActions = { hamburgerMenuActions = {
IconButton( IconButton(
onClick = onSettings, onClick = onSettings,
@ -77,21 +92,46 @@ private fun BalancesTopAppBar(onSettings: () -> Unit) {
} }
@Composable @Composable
private fun BalancesMainContent(modifier: Modifier = Modifier) { private fun BalancesMainContent(
walletSnapshot: WalletSnapshot,
modifier: Modifier = Modifier
) {
val walletDisplayValues =
WalletDisplayValues.getNextValues(
LocalContext.current,
walletSnapshot
)
Column( Column(
modifier = modifier =
Modifier Modifier
.imePadding() .fillMaxHeight()
.fillMaxSize() // .verticalScroll(rememberScrollState()) Uncomment this once the whole screen UI is implemented
.verticalScroll(rememberScrollState())
.then(modifier), .then(modifier),
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) { ) {
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingDefault)) Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingDefault))
Body(stringResource(id = R.string.not_implemented_yet)) if (walletDisplayValues.zecAmountText.isNotEmpty()) {
BalanceWidget(
walletSnapshot = walletSnapshot,
isReferenceToBalances = false,
onReferenceClick = {}
)
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingDefault))
}
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingDefault)) Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Body(
text = stringResource(id = R.string.balances_coming_soon),
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingDefault))
}
} }
} }

View File

@ -1,3 +1,5 @@
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="balances_title">Balances</string> <string name="balances_title">Balances</string>
<string name="balances_coming_soon">Coming soon:\n\nBalances overview,\nTransparent
funds shielding,\nBlock synchronization indicator</string>
</resources> </resources>

View File

@ -398,7 +398,7 @@ private fun balancesScreenshots(
// TODO [#1127]: Implement Balances screen // TODO [#1127]: Implement Balances screen
// TODO [#1127]: https://github.com/Electric-Coin-Company/zashi-android/issues/1127 // TODO [#1127]: https://github.com/Electric-Coin-Company/zashi-android/issues/1127
composeTestRule.onNodeWithText(resContext.getString(R.string.not_implemented_yet)).also { composeTestRule.onNodeWithText(resContext.getString(R.string.balances_coming_soon)).also {
it.assertExists() it.assertExists()
ScreenshotTest.takeScreenshot(tag, "Balances 1") ScreenshotTest.takeScreenshot(tag, "Balances 1")
} }