Skip to content

Commit e711bd3

Browse files
authored
Merge pull request #279 from synonymdev/feat/sheets-polish
Polish bottom sheets
2 parents c333267 + 80ba66a commit e711bd3

File tree

68 files changed

+2112
-1974
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2112
-1974
lines changed

app/detekt-baseline.xml

Lines changed: 53 additions & 109 deletions
Large diffs are not rendered by default.

app/src/androidTest/java/to/bitkit/ui/screens/wallets/activity/BoostTransactionSheetTest.kt renamed to app/src/androidTest/java/to/bitkit/ui/sheets/BoostTransactionSheetTest.kt

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
package to.bitkit.ui.screens.wallets.activity
1+
package to.bitkit.ui.sheets
22

3+
import android.R
4+
import androidx.compose.ui.Modifier
5+
import androidx.compose.ui.graphics.Color
36
import androidx.compose.ui.platform.testTag
7+
import androidx.compose.ui.res.painterResource
48
import androidx.compose.ui.test.assertHasClickAction
59
import androidx.compose.ui.test.assertIsDisplayed
610
import androidx.compose.ui.test.assertIsEnabled
@@ -16,6 +20,10 @@ import org.junit.Before
1620
import org.junit.Rule
1721
import org.junit.Test
1822
import org.junit.runner.RunWith
23+
import to.bitkit.ui.sheets.BoostTransactionContent
24+
import to.bitkit.ui.sheets.BoostTransactionTestTags
25+
import to.bitkit.ui.sheets.BoostTransactionUiState
26+
import to.bitkit.ui.sheets.QuantityButton
1927
import to.bitkit.ui.theme.AppThemeSurface
2028

2129
@HiltAndroidTest
@@ -308,13 +316,13 @@ class BoostTransactionContentTest {
308316
composeTestRule.setContent {
309317
AppThemeSurface {
310318
QuantityButton(
311-
icon = androidx.compose.ui.res.painterResource(android.R.drawable.ic_delete),
312-
iconColor = androidx.compose.ui.graphics.Color.Red,
313-
backgroundColor = androidx.compose.ui.graphics.Color.Gray,
319+
icon = painterResource(R.drawable.ic_delete),
320+
iconColor = Color.Red,
321+
backgroundColor = Color.Gray,
314322
enabled = true,
315323
contentDescription = "Test button",
316324
onClick = { onClickCalled = true },
317-
modifier = androidx.compose.ui.Modifier.testTag("test_quantity_button")
325+
modifier = Modifier.testTag("test_quantity_button")
318326
)
319327
}
320328
}
@@ -332,13 +340,13 @@ class BoostTransactionContentTest {
332340
composeTestRule.setContent {
333341
AppThemeSurface {
334342
QuantityButton(
335-
icon = androidx.compose.ui.res.painterResource(android.R.drawable.ic_delete),
336-
iconColor = androidx.compose.ui.graphics.Color.Red,
337-
backgroundColor = androidx.compose.ui.graphics.Color.Gray,
343+
icon = painterResource(R.drawable.ic_delete),
344+
iconColor = Color.Red,
345+
backgroundColor = Color.Gray,
338346
enabled = false,
339347
contentDescription = "Test button",
340348
onClick = { onClickCalled = true },
341-
modifier = androidx.compose.ui.Modifier.testTag("test_quantity_button_disabled")
349+
modifier = Modifier.testTag("test_quantity_button_disabled")
342350
)
343351
}
344352
}

app/src/androidTest/java/to/bitkit/ui/screens/wallets/sheets/NewTransactionSheetViewTest.kt renamed to app/src/androidTest/java/to/bitkit/ui/sheets/NewTransactionSheetViewTest.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package to.bitkit.ui.screens.wallets.sheets
1+
package to.bitkit.ui.sheets
22

3-
import androidx.compose.ui.test.*
43
import androidx.compose.ui.test.junit4.createComposeRule
4+
import androidx.compose.ui.test.onNodeWithTag
5+
import androidx.compose.ui.test.performClick
56
import dagger.hilt.android.testing.HiltAndroidRule
67
import dagger.hilt.android.testing.HiltAndroidTest
78
import org.junit.Before
@@ -59,7 +60,7 @@ class NewTransactionSheetViewTest {
5960
composeTestRule.mainClock.advanceTimeBy(1000)
6061
composeTestRule.waitForIdle()
6162

62-
// composeTestRule.onNodeWithTag("balance_header").assertExists() Doesn't work because of viewmodel instance
63+
// composeTestRule.onNodeWithTag("balance_header").assertExists() Doesn't work because of viewmodel instance
6364
composeTestRule.onNodeWithTag("sent_buttons_row").assertExists()
6465

6566
// Verify buttons exist and click interactions work
@@ -105,7 +106,7 @@ class NewTransactionSheetViewTest {
105106
composeTestRule.waitForIdle()
106107

107108
composeTestRule.onNodeWithTag("confetti_animation").assertExists()
108-
// composeTestRule.onNodeWithTag("balance_header").assertExists()
109+
// composeTestRule.onNodeWithTag("balance_header").assertExists()
109110
composeTestRule.onNodeWithTag("sent_buttons_row").assertDoesNotExist()
110111

111112
// Verify only OK button exists for received transactions
Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package to.bitkit.ext
22

3-
import java.text.DecimalFormat
4-
import java.text.DecimalFormatSymbols
53
import java.time.Instant
64

75
fun ULong.toActivityItemDate(): String {
@@ -11,20 +9,3 @@ fun ULong.toActivityItemDate(): String {
119
fun ULong.toActivityItemTime(): String {
1210
return Instant.ofEpochSecond(this.toLong()).formatted(DatePattern.ACTIVITY_TIME)
1311
}
14-
15-
fun Number.formatWithDotSeparator(): String {
16-
val symbols = DecimalFormatSymbols().apply {
17-
groupingSeparator = '.'
18-
decimalSeparator = ','
19-
}
20-
val decimalFormat = DecimalFormat("#,###", symbols)
21-
return decimalFormat.format(this)
22-
}
23-
24-
fun ULong.formatWithDotSeparator(): String {
25-
return this.toLong().formatWithDotSeparator()
26-
}
27-
28-
fun UInt.formatWithDotSeparator(): String {
29-
return this.toInt().formatWithDotSeparator()
30-
}

app/src/main/java/to/bitkit/ext/String.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fun String.truncate(length: Int): String {
2222

2323
fun String.removeSpaces() = this.filterNot { it.isWhitespace() }
2424

25+
fun String.toLongOrDefault(defaultValue: Long = 0): Long = toLongOrNull() ?: defaultValue
2526

2627
/**
2728
* Pluralizes this string using the ICU MessageFormat with the provided arguments map.

app/src/main/java/to/bitkit/models/Currency.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,26 @@ data class FxRate(
4040

4141
/** aka. Unit */
4242
enum class PrimaryDisplay {
43-
BITCOIN, FIAT
43+
BITCOIN, FIAT;
44+
45+
operator fun not(): PrimaryDisplay {
46+
return when (this) {
47+
BITCOIN -> FIAT
48+
FIAT -> BITCOIN
49+
}
50+
}
4451
}
4552

4653
/** aka. Denomination */
4754
enum class BitcoinDisplayUnit {
48-
MODERN, CLASSIC
55+
MODERN, CLASSIC;
56+
57+
operator fun not(): BitcoinDisplayUnit {
58+
return when (this) {
59+
MODERN -> CLASSIC
60+
CLASSIC -> MODERN
61+
}
62+
}
4963
}
5064

5165
data class ConvertedAmount(
@@ -64,7 +78,6 @@ data class ConvertedAmount(
6478
)
6579

6680
fun bitcoinDisplay(unit: BitcoinDisplayUnit): BitcoinDisplayComponents {
67-
val symbol = BITCOIN_SYMBOL
6881
val spaceSeparator = ' '
6982
val formattedValue = when (unit) {
7083
BitcoinDisplayUnit.MODERN -> {
@@ -80,7 +93,7 @@ data class ConvertedAmount(
8093
}
8194
}
8295
return BitcoinDisplayComponents(
83-
symbol = symbol,
96+
symbol = BITCOIN_SYMBOL,
8497
value = formattedValue,
8598
)
8699
}

app/src/main/java/to/bitkit/ui/ContentView.kt

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import to.bitkit.models.NodeLifecycleState
3535
import to.bitkit.models.Toast
3636
import to.bitkit.models.WidgetType
3737
import to.bitkit.ui.components.AuthCheckScreen
38-
import to.bitkit.ui.components.BottomSheetType
38+
import to.bitkit.ui.components.Sheet
3939
import to.bitkit.ui.components.SheetHost
4040
import to.bitkit.ui.onboarding.InitializingWalletView
4141
import to.bitkit.ui.onboarding.WalletRestoreErrorView
@@ -75,9 +75,8 @@ import to.bitkit.ui.screens.wallets.activity.ActivityDetailScreen
7575
import to.bitkit.ui.screens.wallets.activity.ActivityExploreScreen
7676
import to.bitkit.ui.screens.wallets.activity.DateRangeSelectorSheet
7777
import to.bitkit.ui.screens.wallets.activity.TagSelectorSheet
78-
import to.bitkit.ui.screens.wallets.receive.ReceiveQrSheet
79-
import to.bitkit.ui.screens.wallets.send.SendOptionsView
80-
import to.bitkit.ui.screens.wallets.sheets.LnurlAuthSheet
78+
import to.bitkit.ui.screens.wallets.receive.ReceiveSheet
79+
import to.bitkit.ui.sheets.SendSheet
8180
import to.bitkit.ui.screens.wallets.suggestion.BuyIntroScreen
8281
import to.bitkit.ui.screens.widgets.AddWidgetsScreen
8382
import to.bitkit.ui.screens.widgets.WidgetsIntroScreen
@@ -113,8 +112,6 @@ import to.bitkit.ui.settings.advanced.CoinSelectPreferenceScreen
113112
import to.bitkit.ui.settings.advanced.ElectrumConfigScreen
114113
import to.bitkit.ui.settings.advanced.RgsServerScreen
115114
import to.bitkit.ui.settings.appStatus.AppStatusScreen
116-
import to.bitkit.ui.settings.backups.BackupNavigationSheet
117-
import to.bitkit.ui.settings.backups.BackupSheet
118115
import to.bitkit.ui.settings.backups.ResetAndRestoreScreen
119116
import to.bitkit.ui.settings.general.DefaultUnitSettingsScreen
120117
import to.bitkit.ui.settings.general.GeneralSettingsScreen
@@ -130,14 +127,16 @@ import to.bitkit.ui.settings.pin.ChangePinNewScreen
130127
import to.bitkit.ui.settings.pin.ChangePinResultScreen
131128
import to.bitkit.ui.settings.pin.ChangePinScreen
132129
import to.bitkit.ui.settings.pin.DisablePinScreen
133-
import to.bitkit.ui.settings.pin.PinNavigationSheet
134130
import to.bitkit.ui.settings.quickPay.QuickPayIntroScreen
135131
import to.bitkit.ui.settings.quickPay.QuickPaySettingsScreen
136132
import to.bitkit.ui.settings.support.ReportIssueResultScreen
137133
import to.bitkit.ui.settings.support.ReportIssueScreen
138134
import to.bitkit.ui.settings.support.SupportScreen
139135
import to.bitkit.ui.settings.transactionSpeed.CustomFeeSettingsScreen
140136
import to.bitkit.ui.settings.transactionSpeed.TransactionSpeedSettingsScreen
137+
import to.bitkit.ui.sheets.BackupSheet
138+
import to.bitkit.ui.sheets.LnurlAuthSheet
139+
import to.bitkit.ui.sheets.PinSheet
141140
import to.bitkit.ui.utils.AutoReadClipboardHandler
142141
import to.bitkit.ui.utils.composableWithDefaultTransitions
143142
import to.bitkit.ui.utils.screenSlideIn
@@ -321,8 +320,8 @@ fun ContentView(
321320
onDismiss = { appViewModel.hideSheet() },
322321
sheets = {
323322
when (val sheet = currentSheet) {
324-
is BottomSheetType.Send -> {
325-
SendOptionsView(
323+
is Sheet.Send -> {
324+
SendSheet(
326325
appViewModel = appViewModel,
327326
walletViewModel = walletViewModel,
328327
startDestination = sheet.route,
@@ -335,38 +334,21 @@ fun ContentView(
335334
)
336335
}
337336

338-
is BottomSheetType.Receive -> {
337+
is Sheet.Receive -> {
339338
val walletUiState by walletViewModel.uiState.collectAsState()
340-
ReceiveQrSheet(
339+
ReceiveSheet(
341340
walletState = walletUiState,
342341
navigateToExternalConnection = {
343342
navController.navigate(Routes.ExternalConnection)
344343
}
345344
)
346345
}
347346

348-
is BottomSheetType.ActivityDateRangeSelector -> DateRangeSelectorSheet()
349-
is BottomSheetType.ActivityTagSelector -> TagSelectorSheet()
350-
351-
is BottomSheetType.PinSetup -> PinNavigationSheet(
352-
onDismiss = { appViewModel.hideSheet() },
353-
)
354-
355-
BottomSheetType.Backup -> BackupSheet(
356-
onDismiss = { appViewModel.hideSheet() },
357-
onBackupClick = {
358-
appViewModel.hideSheet()
359-
appViewModel.showSheet(BottomSheetType.BackupNavigation)
360-
},
361-
walletViewModel = walletViewModel
362-
)
363-
364-
BottomSheetType.BackupNavigation -> BackupNavigationSheet(
365-
onDismiss = { appViewModel.hideSheet() },
366-
)
367-
368-
is BottomSheetType.LnurlAuth -> LnurlAuthSheet(sheet, appViewModel)
369-
347+
is Sheet.ActivityDateRangeSelector -> DateRangeSelectorSheet()
348+
is Sheet.ActivityTagSelector -> TagSelectorSheet()
349+
is Sheet.Pin -> PinSheet(sheet, appViewModel)
350+
is Sheet.Backup -> BackupSheet(sheet, appViewModel)
351+
is Sheet.LnurlAuth -> LnurlAuthSheet(sheet, appViewModel)
370352
null -> Unit
371353
}
372354
}
@@ -552,7 +534,7 @@ private fun RootNavHost(
552534
// TODO show receive sheet -> ReceiveAmount
553535
navController.navigateToHome()
554536
delay(500) // Wait for nav to actually finish
555-
appViewModel.showSheet(BottomSheetType.Receive)
537+
appViewModel.showSheet(Sheet.Receive)
556538
}
557539
},
558540
onAdvanced = { navController.navigate(Routes.FundingAdvanced) },

app/src/main/java/to/bitkit/ui/MainActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import kotlinx.serialization.Serializable
2626
import to.bitkit.androidServices.LightningNodeService
2727
import to.bitkit.androidServices.LightningNodeService.Companion.CHANNEL_ID_NODE
2828
import to.bitkit.ui.components.AuthCheckView
29-
import to.bitkit.ui.components.ForgotPinSheet
29+
import to.bitkit.ui.sheets.ForgotPinSheet
3030
import to.bitkit.ui.components.InactivityTracker
3131
import to.bitkit.ui.components.IsOnlineTracker
3232
import to.bitkit.ui.components.ToastOverlay
@@ -37,7 +37,7 @@ import to.bitkit.ui.onboarding.RestoreWalletView
3737
import to.bitkit.ui.onboarding.TermsOfUseScreen
3838
import to.bitkit.ui.onboarding.WarningMultipleDevicesScreen
3939
import to.bitkit.ui.screens.SplashScreen
40-
import to.bitkit.ui.screens.wallets.sheets.NewTransactionSheet
40+
import to.bitkit.ui.sheets.NewTransactionSheet
4141
import to.bitkit.ui.theme.AppThemeSurface
4242
import to.bitkit.ui.utils.enableAppEdgeToEdge
4343
import to.bitkit.ui.utils.screenScaleIn

0 commit comments

Comments
 (0)