Skip to content
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/src/main/java/to/bitkit/models/MoneyType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package to.bitkit.models

enum class MoneyType {
BITCOIN,
FIAT,
}
3 changes: 3 additions & 0 deletions app/src/main/java/to/bitkit/models/widget/CalculatorValues.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package to.bitkit.models.widget

import kotlinx.serialization.Serializable
import to.bitkit.models.BitcoinDisplayUnit

@Serializable
data class CalculatorValues(
val btcValue: String = "10000",
val fiatValue: String = "",
val satsValue: Long? = null,
val displayUnit: BitcoinDisplayUnit? = null,
)
20 changes: 17 additions & 3 deletions app/src/main/java/to/bitkit/ui/ContentView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ fun ContentView(
}
) {
Box(modifier = Modifier.fillMaxSize()) {
var isHomeCalculatorInputActive by remember { mutableStateOf(false) }

RootNavHost(
navController = navController,
drawerState = drawerState,
Expand All @@ -506,6 +508,7 @@ fun ContentView(
settingsViewModel = settingsViewModel,
currencyViewModel = currencyViewModel,
transferViewModel = transferViewModel,
onHomeCalculatorInputActiveChanged = { isHomeCalculatorInputActive = it },
)

val navBackStackEntry by navController.currentBackStackEntryAsState()
Expand All @@ -516,9 +519,18 @@ fun ContentView(
Routes.Savings::class.qualifiedName,
Routes.Spending::class.qualifiedName,
)
val hideTabBarForCalculator =
currentRoute == Routes.Home::class.qualifiedName && isHomeCalculatorInputActive

LaunchedEffect(currentRoute) {
if (currentRoute != Routes.Home::class.qualifiedName) {
isHomeCalculatorInputActive = false
}
}

if (showTabBar) {
TabBar(
isVisible = !hideTabBarForCalculator,
onSendClick = { appViewModel.showSheet(Sheet.Send()) },
onReceiveClick = { appViewModel.showSheet(Sheet.Receive()) },
onScanClick = { appViewModel.showSheet(Sheet.Send(SendRoute.QrScanner)) },
Expand Down Expand Up @@ -557,6 +569,7 @@ private fun RootNavHost(
settingsViewModel: SettingsViewModel,
currencyViewModel: CurrencyViewModel,
transferViewModel: TransferViewModel,
onHomeCalculatorInputActiveChanged: (Boolean) -> Unit,
) {
val scope = rememberCoroutineScope()

Expand All @@ -568,6 +581,7 @@ private fun RootNavHost(
settingsViewModel = settingsViewModel,
navController = navController,
drawerState = drawerState,
onCalculatorInputActiveChanged = onHomeCalculatorInputActiveChanged,
)
allActivity(
activityListViewModel = activityListViewModel,
Expand All @@ -594,7 +608,7 @@ private fun RootNavHost(
logs(navController)
suggestions(navController)
support(navController)
widgets(navController, settingsViewModel, currencyViewModel)
widgets(navController, settingsViewModel)
update()
recoveryMode(navController, appViewModel)

Expand Down Expand Up @@ -811,6 +825,7 @@ private fun NavGraphBuilder.home(
settingsViewModel: SettingsViewModel,
navController: NavHostController,
drawerState: DrawerState,
onCalculatorInputActiveChanged: (Boolean) -> Unit,
) {
composable<Routes.Home> {
val isRefreshing by walletViewModel.isRefreshing.collectAsStateWithLifecycle()
Expand All @@ -837,6 +852,7 @@ private fun NavGraphBuilder.home(
walletViewModel = walletViewModel,
appViewModel = appViewModel,
activityListViewModel = activityListViewModel,
onCalculatorInputActiveChanged = onCalculatorInputActiveChanged,
)
}
}
Expand Down Expand Up @@ -1465,7 +1481,6 @@ private fun NavGraphBuilder.support(
private fun NavGraphBuilder.widgets(
navController: NavHostController,
settingsViewModel: SettingsViewModel,
currencyViewModel: CurrencyViewModel,
) {
composableWithDefaultTransitions<Routes.WidgetsIntro> {
WidgetsIntroScreen(
Expand Down Expand Up @@ -1508,7 +1523,6 @@ private fun NavGraphBuilder.widgets(
CalculatorPreviewScreen(
onClose = { navController.navigateToHome() },
onBack = { navController.popBackStack() },
currencyViewModel = currencyViewModel
)
}
navigationWithDefaultTransitions<Routes.Headlines>(
Expand Down
24 changes: 16 additions & 8 deletions app/src/main/java/to/bitkit/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import to.bitkit.viewmodels.WalletViewModel
@AndroidEntryPoint
class MainActivity : FragmentActivity() {
private companion object {
const val KEY_CONSUMED_DEEPLINK_URI = "consumed_deeplink_uri"
const val KEY_CONSUMED_LAUNCH_INTENT = "consumed_launch_intent"
}

private val appViewModel by viewModels<AppViewModel>()
Expand All @@ -76,7 +76,7 @@ class MainActivity : FragmentActivity() {
private val settingsViewModel by viewModels<SettingsViewModel>()
private val backupsViewModel by viewModels<BackupsViewModel>()

@Suppress("LongMethod")
@Suppress("LongMethod", "CyclomaticComplexMethod")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand All @@ -88,10 +88,10 @@ class MainActivity : FragmentActivity() {
importance = NotificationManager.IMPORTANCE_LOW
)

val consumedUri = savedInstanceState?.getString(KEY_CONSUMED_DEEPLINK_URI)
val currentUri = intent?.data?.toString()
if (currentUri == null || currentUri != consumedUri) {
appViewModel.handleDeeplinkIntent(intent)
val consumedLaunchIntent = savedInstanceState?.getString(KEY_CONSUMED_LAUNCH_INTENT)
val currentLaunchIntent = intent.launchKey()
if (currentLaunchIntent == null || currentLaunchIntent != consumedLaunchIntent) {
appViewModel.handleLaunchIntent(intent)
}

installSplashScreen()
Expand Down Expand Up @@ -207,12 +207,12 @@ class MainActivity : FragmentActivity() {
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
setIntent(intent)
appViewModel.handleDeeplinkIntent(intent)
appViewModel.handleLaunchIntent(intent)
}

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
intent?.data?.toString()?.let { outState.putString(KEY_CONSUMED_DEEPLINK_URI, it) }
intent.launchKey()?.let { outState.putString(KEY_CONSUMED_LAUNCH_INTENT, it) }
}

override fun onDestroy() {
Expand All @@ -237,6 +237,14 @@ class MainActivity : FragmentActivity() {
}
}

private fun Intent?.launchKey(): String? {
this ?: return null
return when (action) {
Intent.ACTION_VIEW -> data?.toString()
else -> null
}
}

@Composable
private fun OnboardingNav(
startupNavController: NavHostController,
Expand Down
22 changes: 18 additions & 4 deletions app/src/main/java/to/bitkit/ui/components/NumberPad.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
Expand Down Expand Up @@ -71,13 +72,20 @@ fun NumberPad(
modifier: Modifier = Modifier,
type: NumberPadType = NumberPadType.SIMPLE,
availableHeight: Dp = defaultHeight,
decimalSeparator: String = KEY_DECIMAL,
errorKey: String? = null,
includeNavigationBarsPadding: Boolean = false,
) {
val focusRequester = remember { FocusRequester() }
LaunchedEffect(Unit) { focusRequester.requestFocus() }
val safeAreaModifier = if (includeNavigationBarsPadding) {
modifier.navigationBarsPadding()
} else {
modifier
}

BoxWithConstraints(
modifier = modifier
modifier = safeAreaModifier
.focusRequester(focusRequester)
.onPreviewKeyEvent { keyEvent ->
if (keyEvent.type != KeyEventType.KeyDown) return@onPreviewKeyEvent false
Expand Down Expand Up @@ -124,9 +132,10 @@ fun NumberPad(
)

NumberPadType.DECIMAL -> NumberPadKeyButton(
text = KEY_DECIMAL,
text = decimalSeparator,
onPress = onPress,
height = buttonHeight,
key = KEY_DECIMAL,
hasError = errorKey == KEY_DECIMAL,
testTag = "NDecimal",
)
Expand Down Expand Up @@ -161,14 +170,18 @@ fun NumberPad(
currencies: CurrencyState = LocalCurrencies.current,
type: NumberPadType = viewModel.getNumberPadType(currencies),
availableHeight: Dp = defaultHeight,
decimalSeparator: String = KEY_DECIMAL,
includeNavigationBarsPadding: Boolean = false,
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
NumberPad(
onPress = { key -> viewModel.handleNumberPadInput(key, currencies) },
modifier = modifier,
type = type,
availableHeight = availableHeight,
decimalSeparator = decimalSeparator,
errorKey = uiState.errorKey,
includeNavigationBarsPadding = includeNavigationBarsPadding,
)
}

Expand All @@ -186,7 +199,7 @@ private val hardwareKeyMap = mapOf(
Key.Eight to "8", Key.NumPad8 to "8",
Key.Nine to "9", Key.NumPad9 to "9",
Key.Backspace to KEY_DELETE, Key.Delete to KEY_DELETE,
Key.Period to KEY_DECIMAL, Key.NumPadDot to KEY_DECIMAL,
Key.Period to KEY_DECIMAL, Key.NumPadDot to KEY_DECIMAL, Key.Comma to KEY_DECIMAL,
)

private fun mapHardwareKey(key: Key, type: NumberPadType): String? {
Expand All @@ -201,11 +214,12 @@ fun NumberPadKeyButton(
onPress: (String) -> Unit,
height: Dp,
modifier: Modifier = Modifier,
key: String = text,
hasError: Boolean = false,
testTag: String = "N$text",
) {
NumberPadKey(
onClick = { onPress(text) },
onClick = { onPress(key) },
height = height,
haptic = if (hasError) errorHaptic else pressHaptic,
modifier = modifier.testTag(testTag),
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/java/to/bitkit/ui/components/Spacers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,20 @@ fun RowScope.FillWidth(
@Composable
fun StatusBarSpacer(modifier: Modifier = Modifier) {
Spacer(
modifier = modifier.height(Insets.Top),
modifier = modifier.height(Insets.Top)
)
}

@Composable
fun TopBarSpacer(modifier: Modifier = Modifier) {
Spacer(
modifier = modifier.height(TopBarHeight),
modifier = modifier.height(TopBarHeight)
)
}

@Composable
fun NavBarSpacer(modifier: Modifier = Modifier) {
Spacer(
modifier = modifier.height(Insets.Bottom)
)
}
Loading
Loading