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

161 lines
5.0 KiB
Kotlin
Raw Normal View History

@file:Suppress("ktlint:standard:filename")
2022-06-22 02:48:19 -07:00
2022-06-13 09:47:22 -07:00
package co.electriccoin.zcash.ui.screen.home
import androidx.activity.ComponentActivity
import androidx.activity.compose.BackHandler
2022-06-13 09:47:22 -07:00
import androidx.activity.viewModels
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.res.stringResource
2022-06-13 09:47:22 -07:00
import co.electriccoin.zcash.ui.MainActivity
import co.electriccoin.zcash.ui.R
import co.electriccoin.zcash.ui.common.viewmodel.HomeViewModel
import co.electriccoin.zcash.ui.screen.account.WrapAccount
import co.electriccoin.zcash.ui.screen.balances.WrapBalances
import co.electriccoin.zcash.ui.screen.home.model.TabItem
2022-06-13 09:47:22 -07:00
import co.electriccoin.zcash.ui.screen.home.view.Home
import co.electriccoin.zcash.ui.screen.receive.WrapReceive
import co.electriccoin.zcash.ui.screen.send.WrapSend
import co.electriccoin.zcash.ui.screen.send.model.SendArgumentsWrapper
import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
2022-06-13 09:47:22 -07:00
@Suppress("LongParameterList")
@Composable
2022-06-13 09:47:22 -07:00
internal fun MainActivity.WrapHome(
onPageChange: (HomeScreenIndex) -> Unit,
goBack: () -> Unit,
goHistory: () -> Unit,
goSettings: () -> Unit,
goScan: () -> Unit,
sendArgumentsWrapper: SendArgumentsWrapper
2022-06-13 09:47:22 -07:00
) {
WrapHome(
this,
onPageChange = onPageChange,
goBack = goBack,
goHistory = goHistory,
goScan = goScan,
goSettings = goSettings,
sendArgumentsWrapper = sendArgumentsWrapper
2022-06-13 09:47:22 -07:00
)
}
@Suppress("LongParameterList", "LongMethod")
2022-06-13 09:47:22 -07:00
@Composable
internal fun WrapHome(
activity: ComponentActivity,
goBack: () -> Unit,
goHistory: () -> Unit,
goSettings: () -> Unit,
goScan: () -> Unit,
onPageChange: (HomeScreenIndex) -> Unit,
sendArgumentsWrapper: SendArgumentsWrapper
2022-06-13 09:47:22 -07:00
) {
val homeViewModel by activity.viewModels<HomeViewModel>()
// Flow for propagating the new page index to the pager in the view layer
val forceHomePageIndexFlow: MutableSharedFlow<ForcePage?> =
MutableSharedFlow(
Int.MAX_VALUE,
Int.MAX_VALUE,
BufferOverflow.SUSPEND
[#310] [Scaffold] Progress Status Circular Bar * [#310] [Scaffold] Progress Status Circular Bar - Added Z to Home ZECs balance - Added USD balance text to Home - Prepared Text extension functions for both - Provided Zatoshi to USD conversion methods + filed related SDK conversion issue * Update Home screen UI with progress bars - Implemented scaffolding UI of progress bars - Added related texts to strings * Update Home screen UI with progress bars - Connected some of the implemented UI elements to SDK values - Added app update information to Home screen - Update WalletSnapshot with progress field * Update Home screen UI with progress bars - Capturing and handling errors from SDK Synchronizer. - Added related error strings. - Simplified Home screen UI. * Zboto font added. Load it in runtime. Import to Typography. * Updated ZEC sign icon. * Draw ZEC balance with Zboto font * Simplify Home screen balances assigning * Switch to PercentDecimal progress representatiton * Support different locales while working with fiat currency * Fix bug in checking of fiat currency value * Generalize strings to provide possibility of other fiat currencies * Add fiat currency conversion states mechanism * Add TODO comment with reference to follow up SynchronizerError issue * Add WalletDisplayValues to simplify HomeView composable * Add CurrencyConversion class for connection to Price API (and convert Zatoshi to fiat currency) * Add basic HomeView tests * Add basic HomeViewIntegration test * Review changes - Used Duration API for times - Allow injecting clock into currency conversion - Moved FiatCurrencyConversionRateState to sdk-ext-ui because I suspect that we’ll consider this to be a UI object. I based this on the fact that current/stale cutoff values are arbitrary and probably should be the domain of the UI rather than the SDK. - Added some tests, although additional coverage is needed - Added fixtures for model objects * Minor code refactoring - Move UpdateInfoFixture class to fixture dir - Remove unnecessary annotation - Add common application context method to test suite - Fix Test class import - Move several WalletSnapshotFixture parameters to const fields * Add WalletDisplayValuesTest to cover the model class. * Fix import after changes merged * Use the new MonetarySeparatorsFixture in related tests * Add a few basic Zatoshi -> USD conversion tests * Turn on core lib desugaring for sdk-ext-ui-lib module * Make WalletDisplayValues a data class I think there may be some instances where this can help with recomposition * Add preference key for fiat currency This allows us to configure reading the value with observers correctly, even if we don’t allow the user to change it right now. * Delegate symbol and formatting to JVM * Add tests for Locale Co-authored-by: Carter Jernigan <git@carterjernigan.com>
2022-07-13 00:16:05 -07:00
)
val forceIndex = forceHomePageIndexFlow.collectAsState(initial = null).value
val homeGoBack: () -> Unit = {
when (homeViewModel.screenIndex.value) {
HomeScreenIndex.ACCOUNT -> goBack()
HomeScreenIndex.SEND,
HomeScreenIndex.RECEIVE,
HomeScreenIndex.BALANCES -> forceHomePageIndexFlow.tryEmit(ForcePage())
}
}
[#310] [Scaffold] Progress Status Circular Bar * [#310] [Scaffold] Progress Status Circular Bar - Added Z to Home ZECs balance - Added USD balance text to Home - Prepared Text extension functions for both - Provided Zatoshi to USD conversion methods + filed related SDK conversion issue * Update Home screen UI with progress bars - Implemented scaffolding UI of progress bars - Added related texts to strings * Update Home screen UI with progress bars - Connected some of the implemented UI elements to SDK values - Added app update information to Home screen - Update WalletSnapshot with progress field * Update Home screen UI with progress bars - Capturing and handling errors from SDK Synchronizer. - Added related error strings. - Simplified Home screen UI. * Zboto font added. Load it in runtime. Import to Typography. * Updated ZEC sign icon. * Draw ZEC balance with Zboto font * Simplify Home screen balances assigning * Switch to PercentDecimal progress representatiton * Support different locales while working with fiat currency * Fix bug in checking of fiat currency value * Generalize strings to provide possibility of other fiat currencies * Add fiat currency conversion states mechanism * Add TODO comment with reference to follow up SynchronizerError issue * Add WalletDisplayValues to simplify HomeView composable * Add CurrencyConversion class for connection to Price API (and convert Zatoshi to fiat currency) * Add basic HomeView tests * Add basic HomeViewIntegration test * Review changes - Used Duration API for times - Allow injecting clock into currency conversion - Moved FiatCurrencyConversionRateState to sdk-ext-ui because I suspect that we’ll consider this to be a UI object. I based this on the fact that current/stale cutoff values are arbitrary and probably should be the domain of the UI rather than the SDK. - Added some tests, although additional coverage is needed - Added fixtures for model objects * Minor code refactoring - Move UpdateInfoFixture class to fixture dir - Remove unnecessary annotation - Add common application context method to test suite - Fix Test class import - Move several WalletSnapshotFixture parameters to const fields * Add WalletDisplayValuesTest to cover the model class. * Fix import after changes merged * Use the new MonetarySeparatorsFixture in related tests * Add a few basic Zatoshi -> USD conversion tests * Turn on core lib desugaring for sdk-ext-ui-lib module * Make WalletDisplayValues a data class I think there may be some instances where this can help with recomposition * Add preference key for fiat currency This allows us to configure reading the value with observers correctly, even if we don’t allow the user to change it right now. * Delegate symbol and formatting to JVM * Add tests for Locale Co-authored-by: Carter Jernigan <git@carterjernigan.com>
2022-07-13 00:16:05 -07:00
BackHandler {
homeGoBack()
}
val tabs =
persistentListOf(
TabItem(
index = HomeScreenIndex.ACCOUNT,
title = stringResource(id = R.string.home_tab_account),
testTag = HomeTag.TAB_ACCOUNT,
screenContent = {
WrapAccount(
activity = activity,
goHistory = goHistory,
goSettings = goSettings,
)
}
),
TabItem(
index = HomeScreenIndex.SEND,
title = stringResource(id = R.string.home_tab_send),
testTag = HomeTag.TAB_SEND,
screenContent = {
WrapSend(
activity = activity,
goToQrScanner = goScan,
goBack = homeGoBack,
goSettings = goSettings,
sendArgumentsWrapper = sendArgumentsWrapper
)
}
),
TabItem(
index = HomeScreenIndex.RECEIVE,
title = stringResource(id = R.string.home_tab_receive),
testTag = HomeTag.TAB_RECEIVE,
screenContent = {
WrapReceive(
activity = activity,
onSettings = goSettings,
)
}
),
TabItem(
index = HomeScreenIndex.BALANCES,
title = stringResource(id = R.string.home_tab_balances),
testTag = HomeTag.TAB_BALANCES,
screenContent = {
WrapBalances(
activity = activity,
goSettings = goSettings
)
}
)
)
Home(
subScreens = tabs,
forcePage = forceIndex,
onPageChange = onPageChange
)
}
/**
* Wrapper class used to pass forced pages index into the view layer
*/
class ForcePage(
val currentPage: HomeScreenIndex = HomeScreenIndex.ACCOUNT,
)
/**
* Enum of the Home screen sub-screens
*/
enum class HomeScreenIndex {
// WARN: Be careful when re-ordering these, as the ordinal number states for their order
ACCOUNT,
SEND,
RECEIVE,
BALANCES, ;
2022-06-13 09:47:22 -07:00
companion object {
fun fromIndex(index: Int) = entries[index]
2022-06-13 09:47:22 -07:00
}
}