Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7718296
feat: widget size data layer logic
jvsena42 Jun 3, 2026
6ea4127
feat: widget size domain logic
jvsena42 Jun 3, 2026
ba646fb
feat: re-enabled compact mode and implement size saving logic
jvsena42 Jun 3, 2026
eabc02e
feat: calculator compact mode
jvsena42 Jun 3, 2026
760a102
feat: data layer
jvsena42 Jun 3, 2026
6e93d8c
feat: widgets grid
jvsena42 Jun 3, 2026
4e7baa4
fix: add a guard to reorder only when target slot changes
jvsena42 Jun 3, 2026
5f577a9
fix: number pad overlap calculator
jvsena42 Jun 3, 2026
00d9216
chore: rename changelog fragment
jvsena42 Jun 3, 2026
f8ee4b6
fix: animate calculator to previous position on number pad dismiss
jvsena42 Jun 3, 2026
7291cb6
fix: remove active orange border
jvsena42 Jun 3, 2026
37f5141
fix: input corner radius
jvsena42 Jun 3, 2026
a2e9000
fix: make calculator preview read-only
jvsena42 Jun 3, 2026
6bee689
fix: display cached calculator value on widget gallery
jvsena42 Jun 3, 2026
6a4c300
fix: drop first emission with default value
jvsena42 Jun 3, 2026
2805dc9
refactor: remove dead code and component renaming
jvsena42 Jun 3, 2026
a1a405e
test: calculator widget instrumented test
jvsena42 Jun 3, 2026
8b26f64
fix: preview crash
jvsena42 Jun 3, 2026
0db04ea
refactor: code cleanup
jvsena42 Jun 3, 2026
799b078
refactor: make isWide immutable for compose stability
jvsena42 Jun 4, 2026
c84244d
refactor: break into smaller self-explanatory private methods
jvsena42 Jun 4, 2026
d9c4778
fix: align name to center
jvsena42 Jun 4, 2026
125c0aa
fix: adapt small card width
jvsena42 Jun 4, 2026
35f64d0
fix: use gray6 bg for all widget cards
jvsena42 Jun 4, 2026
fe00c78
fix: set drag preview alpha
jvsena42 Jun 4, 2026
149f9a0
fix: keep edit screen in back stack from ger
jvsena42 Jun 4, 2026
6822332
fix: always enable widget settings button
jvsena42 Jun 4, 2026
4b6a497
feat: edge-to-edge scroll for widget size pager
jvsena42 Jun 4, 2026
a2d0009
feat: edge-to-edge scroll for widget size pager
jvsena42 Jun 4, 2026
c953b96
fix: remove adjacent page peek in widget carousel
jvsena42 Jun 4, 2026
2ceb8f1
Merge branch 'master' into feat/in-app-v61
jvsena42 Jun 4, 2026
f23f0cb
fix: show decimal placeholder in small calculator
jvsena42 Jun 4, 2026
b2c2cba
fix: disable widget settings only for suggestions
jvsena42 Jun 4, 2026
3d22482
test: CalculatorWidget
piotr-iohk Jun 4, 2026
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
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
package to.bitkit.ui.screens.widgets.calculator

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.assertTextContains
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasSetTextAction
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.test.performTextClearance
import androidx.compose.ui.test.performTextInput
import androidx.compose.ui.test.printToString
import androidx.compose.ui.test.onAllNodesWithTag
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStore
Expand DownExpand Up@@ -50,6 +50,7 @@ import to.bitkit.test.annotations.CalculatorWidget
import to.bitkit.test.annotations.DeviceIntegration
import to.bitkit.test.annotations.DeviceUiIntegration
import to.bitkit.ui.screens.widgets.calculator.components.CalculatorCard
import to.bitkit.ui.screens.widgets.calculator.components.CalculatorNumberPadBar
import to.bitkit.ui.theme.AppThemeSurface
import java.util.Locale
import javax.inject.Inject
Expand All@@ -62,7 +63,7 @@ import kotlin.test.assertEquals
@CalculatorWidget
@DeviceIntegration
@DeviceUiIntegration
class CalculatorCardIntegrationTest {
class CalculatorWidgetInputTest {

@get:Rule
val hiltRule = HiltAndroidRule(this)
Expand DownExpand Up@@ -154,41 +155,27 @@ class CalculatorCardIntegrationTest {
}

@Test
fun btcInputUpdatesFiatValueAndPersistsWidgetState() {
setCalculatorCard()
fun btcInputViaNumberPadUpdatesFiatAndPersistsWidgetState() {
setCalculatorWidget()

replaceInput(BTC_INPUT_INDEX, "12340")
composeTestRule.onNodeWithTag(BTC_INPUT_TAG).performClick()
awaitNumberPad()
tapKeys("N1", "N2", "N3", "N4", "N0")

waitForValues(
btcValue = "12340",
fiatValue = "12.34",
)

assertInputText(BTC_INPUT_INDEX, "12 340")
assertInputText(FIAT_INPUT_INDEX, "12.34")
assertPersistedValues(
btcValue = "12340",
fiatValue = "12.34",
)
waitForValues(btcValue = "12340", fiatValue = "12.34")
assertPersistedValues(btcValue = "12340", fiatValue = "12.34")
}

@Test
fun fiatInputUpdatesBtcValueAndPersistsWidgetState() {
setCalculatorCard()
fun fiatInputViaNumberPadUpdatesBtcAndPersistsWidgetState() {
setCalculatorWidget()

replaceInput(FIAT_INPUT_INDEX, "10.00")
composeTestRule.onNodeWithTag(FIAT_INPUT_TAG).performClick()
awaitNumberPad()
tapKeys("N1", "N0", "NDecimal", "N0", "N0")

waitForValues(
btcValue = "10000",
fiatValue = "10.00",
)

assertInputText(BTC_INPUT_INDEX, "10 000")
assertInputText(FIAT_INPUT_INDEX, "10.00")
assertPersistedValues(
btcValue = "10000",
fiatValue = "10.00",
)
waitForValues(btcValue = "10000", fiatValue = "10.00")
assertPersistedValues(btcValue = "10000", fiatValue = "10.00")
}

private fun createCalculatorViewModel(): CalculatorViewModel {
Expand All@@ -206,80 +193,70 @@ class CalculatorCardIntegrationTest {
)[CalculatorViewModel::class.java]
}

private fun setCalculatorCard() {
private fun setCalculatorWidget() {
composeTestRule.setContent {
AppThemeSurface {
CalculatorCard(
calculatorViewModel = calculatorViewModel,
modifier = Modifier.fillMaxWidth()
)
val state by calculatorViewModel.uiState.collectAsState()
Box(modifier = Modifier.fillMaxSize()) {
CalculatorCard(
btcPrimaryDisplayUnit = state.displayUnit,
btcValue = state.btcValue,
fiatSymbol = state.currencySymbol,
fiatName = state.selectedCurrency,
fiatValue = state.fiatValue,
activeInput = state.activeInput,
onSelectInput = calculatorViewModel::onInputSelected,
modifier = Modifier.fillMaxWidth()
)
state.activeInput?.let { active ->
CalculatorNumberPadBar(
activeInput = active,
btcValue = state.btcValue,
fiatValue = state.fiatValue,
btcPrimaryDisplayUnit = state.displayUnit,
onBtcChange = calculatorViewModel::onBtcInputChanged,
onFiatChange = calculatorViewModel::onFiatInputChanged,
modifier = Modifier.align(Alignment.BottomCenter)
)
}
}
}
}
composeTestRule.waitForIdle()
}

private fun awaitNumberPad() {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
composeTestRule.onAllNodes(hasSetTextAction()).fetchSemanticsNodes().size == INPUT_COUNT
composeTestRule.onAllNodesWithTag(NUMBER_PAD_TAG).fetchSemanticsNodes().isNotEmpty()
}
}

private fun inputAt(index: Int) = composeTestRule.onAllNodes(hasSetTextAction())[index]

private fun replaceInput(
index: Int,
text: String,
) {
inputAt(index).performTextClearance()
inputAt(index).performTextInput(text)
private fun tapKeys(vararg keys: String) {
keys.forEach { key ->
composeTestRule.onNodeWithTag(key).performClick()
composeTestRule.waitForIdle()
}
}

private fun waitForValues(
btcValue: String,
fiatValue: String,
) {
runCatching {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
calculatorViewModel.uiState.value.btcValue == btcValue &&
calculatorViewModel.uiState.value.fiatValue == fiatValue
}
}.onFailure {
throw AssertionError(
buildString {
append("Expected calculatorValues btcValue='$btcValue', fiatValue='$fiatValue', ")
append("but was '${calculatorViewModel.uiState.value}'. Persisted values were ")
append("'${widgetsRepo.widgetsDataFlow.value.calculatorValues}'. Semantics tree:\n")
append(composeTestRule.onRoot(useUnmergedTree = true).printToString())
},
it,
)
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
calculatorViewModel.uiState.value.btcValue == btcValue &&
calculatorViewModel.uiState.value.fiatValue == fiatValue
}

val expectedValues = CalculatorValues(
btcValue = btcValue,
fiatValue = fiatValue,
satsValue = btcValue.toLong(),
displayUnit = BitcoinDisplayUnit.MODERN,
)
runCatching {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
widgetsRepo.widgetsDataFlow.value.calculatorValues == expectedValues
}
}.onFailure {
throw AssertionError(
"Expected persisted values '$expectedValues', but was " +
"'${widgetsRepo.widgetsDataFlow.value.calculatorValues}'",
it,
)
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
widgetsRepo.widgetsDataFlow.value.calculatorValues == expectedValues
}
}

private fun assertInputText(
inputIndex: Int,
text: String,
) {
inputAt(inputIndex).assertTextContains(text, substring = true)
composeTestRule.onNode(hasText(text, substring = true), useUnmergedTree = true)
.assertIsDisplayed()
}

private fun assertPersistedValues(
btcValue: String,
fiatValue: String,
Expand All@@ -296,9 +273,9 @@ class CalculatorCardIntegrationTest {
}

companion object {
private const val BTC_INPUT_INDEX = 0
private const val FIAT_INPUT_INDEX = 1
private const val INPUT_COUNT = 2
private const val BTC_INPUT_TAG = "CalculatorBtcInput"
private const val FIAT_INPUT_TAG = "CalculatorFiatInput"
private const val NUMBER_PAD_TAG = "CalculatorNumberPad"
private const val TIMEOUT_MS = 5_000L
private const val TEST_CREATED_AT = 0L
private const val TEST_USD_RATE = "100000"
Expand DownExpand Up@@ -330,6 +307,7 @@ class CalculatorCardIntegrationTest {

@Provides
@Named("enablePolling")
@Suppress("FunctionOnlyReturningConstant")
fun provideEnablePolling(): Boolean = false
}
}
38 changes: 28 additions & 10 deletions app/src/main/java/to/bitkit/data/WidgetsStore.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ import to.bitkit.data.dto.BlockDTO
import to.bitkit.data.dto.WeatherDTO
import to.bitkit.data.dto.price.PriceDTO
import to.bitkit.data.serializers.WidgetsSerializer
import to.bitkit.models.WidgetSize
import to.bitkit.models.WidgetType
import to.bitkit.models.WidgetWithPosition
import to.bitkit.models.WidgetsBackupV1
Expand DownExpand Up@@ -123,15 +124,28 @@ class WidgetsStore @Inject constructor(
Logger.info("Deleted all widgets data.")
}

suspend fun addWidget(type: WidgetType) {
if (store.data.first().widgets.map { it.type }.contains(type)) return
suspend fun addWidget(type: WidgetType, size: WidgetSize = WidgetSize.default(type)) {
store.updateData { data ->
val existing = data.widgets.firstOrNull { it.type == type }
if (existing != null) {
data.copy(
widgets = data.widgets
.map { if (it.type == type) it.copy(size = size) else it }
.sortedBy { it.position }
)
} else {
val nextPosition = (data.widgets.maxOfOrNull { it.position } ?: -1) + 1
data.copy(
widgets = (data.widgets + WidgetWithPosition(type = type, position = nextPosition, size = size))
.sortedBy { it.position }
)
}
}
}

suspend fun updateWidgetSize(type: WidgetType, size: WidgetSize) {
store.updateData { data ->
val nextPosition = (data.widgets.maxOfOrNull { it.position } ?: -1) + 1
data.copy(
widgets = (data.widgets + WidgetWithPosition(type = type, position = nextPosition))
.sortedBy { it.position }
)
data.copy(widgets = data.widgets.map { if (it.type == type) it.copy(size = size) else it })
}
}

Expand DownExpand Up@@ -161,9 +175,13 @@ class WidgetsStore @Inject constructor(
@Serializable
data class WidgetsData(
val widgets: List<WidgetWithPosition> = listOf(
WidgetWithPosition(type = WidgetType.SUGGESTIONS, position = 0),
WidgetWithPosition(type = WidgetType.PRICE, position = 1),
WidgetWithPosition(type = WidgetType.BLOCK, position = 2),
WidgetWithPosition(type = WidgetType.SUGGESTIONS, position = 0, size = WidgetSize.WIDE),
WidgetWithPosition(type = WidgetType.PRICE, position = 1, size = WidgetSize.WIDE),
WidgetWithPosition(type = WidgetType.BLOCK, position = 2, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.FACTS, position = 3, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.WEATHER, position = 4, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.CALCULATOR, position = 5, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.NEWS, position = 6, size = WidgetSize.WIDE),
),
val headlinePreferences: HeadlinePreferences = HeadlinePreferences(),
val blocksPreferences: BlocksPreferences = BlocksPreferences(),
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/to/bitkit/models/WidgetSize.kt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
package to.bitkit.models

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
enum class WidgetSize {
@SerialName("small")
SMALL,

@SerialName("wide")
WIDE;

companion object {
fun default(type: WidgetType): WidgetSize = when (type) {
WidgetType.PRICE,
WidgetType.NEWS,
WidgetType.SUGGESTIONS,
-> WIDE

else -> SMALL
}
}
}
4 changes: 4 additions & 0 deletions app/src/main/java/to/bitkit/models/WidgetWithPosition.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,4 +8,8 @@ import kotlinx.serialization.Serializable
data class WidgetWithPosition(
val type: WidgetType,
val position: Int = 0,
val size: WidgetSize = WidgetSize.WIDE,
)

fun WidgetWithPosition.effectiveSize(): WidgetSize =
if (type == WidgetType.SUGGESTIONS) WidgetSize.WIDE else size
7 changes: 6 additions & 1 deletion app/src/main/java/to/bitkit/repositories/WidgetsRepo.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,7 @@ import to.bitkit.data.widgets.PriceService
import to.bitkit.data.widgets.WeatherService
import to.bitkit.data.widgets.WidgetService
import to.bitkit.di.BgDispatcher
import to.bitkit.models.WidgetSize
import to.bitkit.models.WidgetType
import to.bitkit.models.WidgetWithPosition
import to.bitkit.models.widget.BlocksPreferences
Expand DownExpand Up@@ -173,7 +174,11 @@ class WidgetsRepo @Inject constructor(
Logger.verbose("Stopped refresh coroutine for $widgetType", context = TAG)
}

suspend fun addWidget(type: WidgetType) = withContext(bgDispatcher) { widgetsStore.addWidget(type) }
suspend fun addWidget(type: WidgetType, size: WidgetSize = WidgetSize.default(type)) =
withContext(bgDispatcher) { widgetsStore.addWidget(type, size) }

suspend fun updateWidgetSize(type: WidgetType, size: WidgetSize) =
withContext(bgDispatcher) { widgetsStore.updateWidgetSize(type, size) }

suspend fun deleteWidget(type: WidgetType) = withContext(bgDispatcher) { widgetsStore.deleteWidget(type) }

Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7718296
feat: widget size data layer logic
jvsena42 Jun 3, 2026
6ea4127
feat: widget size domain logic
jvsena42 Jun 3, 2026
ba646fb
feat: re-enabled compact mode and implement size saving logic
jvsena42 Jun 3, 2026
eabc02e
feat: calculator compact mode
jvsena42 Jun 3, 2026
760a102
feat: data layer
jvsena42 Jun 3, 2026
6e93d8c
feat: widgets grid
jvsena42 Jun 3, 2026
4e7baa4
fix: add a guard to reorder only when target slot changes
jvsena42 Jun 3, 2026
5f577a9
fix: number pad overlap calculator
jvsena42 Jun 3, 2026
00d9216
chore: rename changelog fragment
jvsena42 Jun 3, 2026
f8ee4b6
fix: animate calculator to previous position on number pad dismiss
jvsena42 Jun 3, 2026
7291cb6
fix: remove active orange border
jvsena42 Jun 3, 2026
37f5141
fix: input corner radius
jvsena42 Jun 3, 2026
a2e9000
fix: make calculator preview read-only
jvsena42 Jun 3, 2026
6bee689
fix: display cached calculator value on widget gallery
jvsena42 Jun 3, 2026
6a4c300
fix: drop first emission with default value
jvsena42 Jun 3, 2026
2805dc9
refactor: remove dead code and component renaming
jvsena42 Jun 3, 2026
a1a405e
test: calculator widget instrumented test
jvsena42 Jun 3, 2026
8b26f64
fix: preview crash
jvsena42 Jun 3, 2026
0db04ea
refactor: code cleanup
jvsena42 Jun 3, 2026
799b078
refactor: make isWide immutable for compose stability
jvsena42 Jun 4, 2026
c84244d
refactor: break into smaller self-explanatory private methods
jvsena42 Jun 4, 2026
d9c4778
fix: align name to center
jvsena42 Jun 4, 2026
125c0aa
fix: adapt small card width
jvsena42 Jun 4, 2026
35f64d0
fix: use gray6 bg for all widget cards
jvsena42 Jun 4, 2026
fe00c78
fix: set drag preview alpha
jvsena42 Jun 4, 2026
149f9a0
fix: keep edit screen in back stack from ger
jvsena42 Jun 4, 2026
6822332
fix: always enable widget settings button
jvsena42 Jun 4, 2026
4b6a497
feat: edge-to-edge scroll for widget size pager
jvsena42 Jun 4, 2026
a2d0009
feat: edge-to-edge scroll for widget size pager
jvsena42 Jun 4, 2026
c953b96
fix: remove adjacent page peek in widget carousel
jvsena42 Jun 4, 2026
2ceb8f1
Merge branch 'master' into feat/in-app-v61
jvsena42 Jun 4, 2026
f23f0cb
fix: show decimal placeholder in small calculator
jvsena42 Jun 4, 2026
b2c2cba
fix: disable widget settings only for suggestions
jvsena42 Jun 4, 2026
3d22482
test: CalculatorWidget
piotr-iohk Jun 4, 2026
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
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
package to.bitkit.ui.screens.widgets.calculator

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.assertTextContains
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasSetTextAction
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.test.performTextClearance
import androidx.compose.ui.test.performTextInput
import androidx.compose.ui.test.printToString
import androidx.compose.ui.test.onAllNodesWithTag
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStore
Expand DownExpand Up@@ -50,6 +50,7 @@ import to.bitkit.test.annotations.CalculatorWidget
import to.bitkit.test.annotations.DeviceIntegration
import to.bitkit.test.annotations.DeviceUiIntegration
import to.bitkit.ui.screens.widgets.calculator.components.CalculatorCard
import to.bitkit.ui.screens.widgets.calculator.components.CalculatorNumberPadBar
import to.bitkit.ui.theme.AppThemeSurface
import java.util.Locale
import javax.inject.Inject
Expand All@@ -62,7 +63,7 @@ import kotlin.test.assertEquals
@CalculatorWidget
@DeviceIntegration
@DeviceUiIntegration
class CalculatorCardIntegrationTest {
class CalculatorWidgetInputTest {

@get:Rule
val hiltRule = HiltAndroidRule(this)
Expand DownExpand Up@@ -154,41 +155,27 @@ class CalculatorCardIntegrationTest {
}

@Test
fun btcInputUpdatesFiatValueAndPersistsWidgetState() {
setCalculatorCard()
fun btcInputViaNumberPadUpdatesFiatAndPersistsWidgetState() {
setCalculatorWidget()

replaceInput(BTC_INPUT_INDEX, "12340")
composeTestRule.onNodeWithTag(BTC_INPUT_TAG).performClick()
awaitNumberPad()
tapKeys("N1", "N2", "N3", "N4", "N0")

waitForValues(
btcValue = "12340",
fiatValue = "12.34",
)

assertInputText(BTC_INPUT_INDEX, "12 340")
assertInputText(FIAT_INPUT_INDEX, "12.34")
assertPersistedValues(
btcValue = "12340",
fiatValue = "12.34",
)
waitForValues(btcValue = "12340", fiatValue = "12.34")
assertPersistedValues(btcValue = "12340", fiatValue = "12.34")
}

@Test
fun fiatInputUpdatesBtcValueAndPersistsWidgetState() {
setCalculatorCard()
fun fiatInputViaNumberPadUpdatesBtcAndPersistsWidgetState() {
setCalculatorWidget()

replaceInput(FIAT_INPUT_INDEX, "10.00")
composeTestRule.onNodeWithTag(FIAT_INPUT_TAG).performClick()
awaitNumberPad()
tapKeys("N1", "N0", "NDecimal", "N0", "N0")

waitForValues(
btcValue = "10000",
fiatValue = "10.00",
)

assertInputText(BTC_INPUT_INDEX, "10 000")
assertInputText(FIAT_INPUT_INDEX, "10.00")
assertPersistedValues(
btcValue = "10000",
fiatValue = "10.00",
)
waitForValues(btcValue = "10000", fiatValue = "10.00")
assertPersistedValues(btcValue = "10000", fiatValue = "10.00")
}

private fun createCalculatorViewModel(): CalculatorViewModel {
Expand All@@ -206,80 +193,70 @@ class CalculatorCardIntegrationTest {
)[CalculatorViewModel::class.java]
}

private fun setCalculatorCard() {
private fun setCalculatorWidget() {
composeTestRule.setContent {
AppThemeSurface {
CalculatorCard(
calculatorViewModel = calculatorViewModel,
modifier = Modifier.fillMaxWidth()
)
val state by calculatorViewModel.uiState.collectAsState()
Box(modifier = Modifier.fillMaxSize()) {
CalculatorCard(
btcPrimaryDisplayUnit = state.displayUnit,
btcValue = state.btcValue,
fiatSymbol = state.currencySymbol,
fiatName = state.selectedCurrency,
fiatValue = state.fiatValue,
activeInput = state.activeInput,
onSelectInput = calculatorViewModel::onInputSelected,
modifier = Modifier.fillMaxWidth()
)
state.activeInput?.let { active ->
CalculatorNumberPadBar(
activeInput = active,
btcValue = state.btcValue,
fiatValue = state.fiatValue,
btcPrimaryDisplayUnit = state.displayUnit,
onBtcChange = calculatorViewModel::onBtcInputChanged,
onFiatChange = calculatorViewModel::onFiatInputChanged,
modifier = Modifier.align(Alignment.BottomCenter)
)
}
}
}
}
composeTestRule.waitForIdle()
}

private fun awaitNumberPad() {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
composeTestRule.onAllNodes(hasSetTextAction()).fetchSemanticsNodes().size == INPUT_COUNT
composeTestRule.onAllNodesWithTag(NUMBER_PAD_TAG).fetchSemanticsNodes().isNotEmpty()
}
}

private fun inputAt(index: Int) = composeTestRule.onAllNodes(hasSetTextAction())[index]

private fun replaceInput(
index: Int,
text: String,
) {
inputAt(index).performTextClearance()
inputAt(index).performTextInput(text)
private fun tapKeys(vararg keys: String) {
keys.forEach { key ->
composeTestRule.onNodeWithTag(key).performClick()
composeTestRule.waitForIdle()
}
}

private fun waitForValues(
btcValue: String,
fiatValue: String,
) {
runCatching {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
calculatorViewModel.uiState.value.btcValue == btcValue &&
calculatorViewModel.uiState.value.fiatValue == fiatValue
}
}.onFailure {
throw AssertionError(
buildString {
append("Expected calculatorValues btcValue='$btcValue', fiatValue='$fiatValue', ")
append("but was '${calculatorViewModel.uiState.value}'. Persisted values were ")
append("'${widgetsRepo.widgetsDataFlow.value.calculatorValues}'. Semantics tree:\n")
append(composeTestRule.onRoot(useUnmergedTree = true).printToString())
},
it,
)
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
calculatorViewModel.uiState.value.btcValue == btcValue &&
calculatorViewModel.uiState.value.fiatValue == fiatValue
}

val expectedValues = CalculatorValues(
btcValue = btcValue,
fiatValue = fiatValue,
satsValue = btcValue.toLong(),
displayUnit = BitcoinDisplayUnit.MODERN,
)
runCatching {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
widgetsRepo.widgetsDataFlow.value.calculatorValues == expectedValues
}
}.onFailure {
throw AssertionError(
"Expected persisted values '$expectedValues', but was " +
"'${widgetsRepo.widgetsDataFlow.value.calculatorValues}'",
it,
)
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
widgetsRepo.widgetsDataFlow.value.calculatorValues == expectedValues
}
}

private fun assertInputText(
inputIndex: Int,
text: String,
) {
inputAt(inputIndex).assertTextContains(text, substring = true)
composeTestRule.onNode(hasText(text, substring = true), useUnmergedTree = true)
.assertIsDisplayed()
}

private fun assertPersistedValues(
btcValue: String,
fiatValue: String,
Expand All@@ -296,9 +273,9 @@ class CalculatorCardIntegrationTest {
}

companion object {
private const val BTC_INPUT_INDEX = 0
private const val FIAT_INPUT_INDEX = 1
private const val INPUT_COUNT = 2
private const val BTC_INPUT_TAG = "CalculatorBtcInput"
private const val FIAT_INPUT_TAG = "CalculatorFiatInput"
private const val NUMBER_PAD_TAG = "CalculatorNumberPad"
private const val TIMEOUT_MS = 5_000L
private const val TEST_CREATED_AT = 0L
private const val TEST_USD_RATE = "100000"
Expand DownExpand Up@@ -330,6 +307,7 @@ class CalculatorCardIntegrationTest {

@Provides
@Named("enablePolling")
@Suppress("FunctionOnlyReturningConstant")
fun provideEnablePolling(): Boolean = false
}
}
38 changes: 28 additions & 10 deletions app/src/main/java/to/bitkit/data/WidgetsStore.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ import to.bitkit.data.dto.BlockDTO
import to.bitkit.data.dto.WeatherDTO
import to.bitkit.data.dto.price.PriceDTO
import to.bitkit.data.serializers.WidgetsSerializer
import to.bitkit.models.WidgetSize
import to.bitkit.models.WidgetType
import to.bitkit.models.WidgetWithPosition
import to.bitkit.models.WidgetsBackupV1
Expand DownExpand Up@@ -123,15 +124,28 @@ class WidgetsStore @Inject constructor(
Logger.info("Deleted all widgets data.")
}

suspend fun addWidget(type: WidgetType) {
if (store.data.first().widgets.map { it.type }.contains(type)) return
suspend fun addWidget(type: WidgetType, size: WidgetSize = WidgetSize.default(type)) {
store.updateData { data ->
val existing = data.widgets.firstOrNull { it.type == type }
if (existing != null) {
data.copy(
widgets = data.widgets
.map { if (it.type == type) it.copy(size = size) else it }
.sortedBy { it.position }
)
} else {
val nextPosition = (data.widgets.maxOfOrNull { it.position } ?: -1) + 1
data.copy(
widgets = (data.widgets + WidgetWithPosition(type = type, position = nextPosition, size = size))
.sortedBy { it.position }
)
}
}
}

suspend fun updateWidgetSize(type: WidgetType, size: WidgetSize) {
store.updateData { data ->
val nextPosition = (data.widgets.maxOfOrNull { it.position } ?: -1) + 1
data.copy(
widgets = (data.widgets + WidgetWithPosition(type = type, position = nextPosition))
.sortedBy { it.position }
)
data.copy(widgets = data.widgets.map { if (it.type == type) it.copy(size = size) else it })
}
}

Expand DownExpand Up@@ -161,9 +175,13 @@ class WidgetsStore @Inject constructor(
@Serializable
data class WidgetsData(
val widgets: List<WidgetWithPosition> = listOf(
WidgetWithPosition(type = WidgetType.SUGGESTIONS, position = 0),
WidgetWithPosition(type = WidgetType.PRICE, position = 1),
WidgetWithPosition(type = WidgetType.BLOCK, position = 2),
WidgetWithPosition(type = WidgetType.SUGGESTIONS, position = 0, size = WidgetSize.WIDE),
WidgetWithPosition(type = WidgetType.PRICE, position = 1, size = WidgetSize.WIDE),
WidgetWithPosition(type = WidgetType.BLOCK, position = 2, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.FACTS, position = 3, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.WEATHER, position = 4, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.CALCULATOR, position = 5, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.NEWS, position = 6, size = WidgetSize.WIDE),
),
val headlinePreferences: HeadlinePreferences = HeadlinePreferences(),
val blocksPreferences: BlocksPreferences = BlocksPreferences(),
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/to/bitkit/models/WidgetSize.kt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
package to.bitkit.models

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
enum class WidgetSize {
@SerialName("small")
SMALL,

@SerialName("wide")
WIDE;

companion object {
fun default(type: WidgetType): WidgetSize = when (type) {
WidgetType.PRICE,
WidgetType.NEWS,
WidgetType.SUGGESTIONS,
-> WIDE

else -> SMALL
}
}
}
4 changes: 4 additions & 0 deletions app/src/main/java/to/bitkit/models/WidgetWithPosition.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,4 +8,8 @@ import kotlinx.serialization.Serializable
data class WidgetWithPosition(
val type: WidgetType,
val position: Int = 0,
val size: WidgetSize = WidgetSize.WIDE,
)

fun WidgetWithPosition.effectiveSize(): WidgetSize =
if (type == WidgetType.SUGGESTIONS) WidgetSize.WIDE else size
7 changes: 6 additions & 1 deletion app/src/main/java/to/bitkit/repositories/WidgetsRepo.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,7 @@ import to.bitkit.data.widgets.PriceService
import to.bitkit.data.widgets.WeatherService
import to.bitkit.data.widgets.WidgetService
import to.bitkit.di.BgDispatcher
import to.bitkit.models.WidgetSize
import to.bitkit.models.WidgetType
import to.bitkit.models.WidgetWithPosition
import to.bitkit.models.widget.BlocksPreferences
Expand DownExpand Up@@ -173,7 +174,11 @@ class WidgetsRepo @Inject constructor(
Logger.verbose("Stopped refresh coroutine for $widgetType", context = TAG)
}

suspend fun addWidget(type: WidgetType) = withContext(bgDispatcher) { widgetsStore.addWidget(type) }
suspend fun addWidget(type: WidgetType, size: WidgetSize = WidgetSize.default(type)) =
withContext(bgDispatcher) { widgetsStore.addWidget(type, size) }

suspend fun updateWidgetSize(type: WidgetType, size: WidgetSize) =
withContext(bgDispatcher) { widgetsStore.updateWidgetSize(type, size) }

suspend fun deleteWidget(type: WidgetType) = withContext(bgDispatcher) { widgetsStore.deleteWidget(type) }

Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7718296
feat: widget size data layer logic
jvsena42 Jun 3, 2026
6ea4127
feat: widget size domain logic
jvsena42 Jun 3, 2026
ba646fb
feat: re-enabled compact mode and implement size saving logic
jvsena42 Jun 3, 2026
eabc02e
feat: calculator compact mode
jvsena42 Jun 3, 2026
760a102
feat: data layer
jvsena42 Jun 3, 2026
6e93d8c
feat: widgets grid
jvsena42 Jun 3, 2026
4e7baa4
fix: add a guard to reorder only when target slot changes
jvsena42 Jun 3, 2026
5f577a9
fix: number pad overlap calculator
jvsena42 Jun 3, 2026
00d9216
chore: rename changelog fragment
jvsena42 Jun 3, 2026
f8ee4b6
fix: animate calculator to previous position on number pad dismiss
jvsena42 Jun 3, 2026
7291cb6
fix: remove active orange border
jvsena42 Jun 3, 2026
37f5141
fix: input corner radius
jvsena42 Jun 3, 2026
a2e9000
fix: make calculator preview read-only
jvsena42 Jun 3, 2026
6bee689
fix: display cached calculator value on widget gallery
jvsena42 Jun 3, 2026
6a4c300
fix: drop first emission with default value
jvsena42 Jun 3, 2026
2805dc9
refactor: remove dead code and component renaming
jvsena42 Jun 3, 2026
a1a405e
test: calculator widget instrumented test
jvsena42 Jun 3, 2026
8b26f64
fix: preview crash
jvsena42 Jun 3, 2026
0db04ea
refactor: code cleanup
jvsena42 Jun 3, 2026
799b078
refactor: make isWide immutable for compose stability
jvsena42 Jun 4, 2026
c84244d
refactor: break into smaller self-explanatory private methods
jvsena42 Jun 4, 2026
d9c4778
fix: align name to center
jvsena42 Jun 4, 2026
125c0aa
fix: adapt small card width
jvsena42 Jun 4, 2026
35f64d0
fix: use gray6 bg for all widget cards
jvsena42 Jun 4, 2026
fe00c78
fix: set drag preview alpha
jvsena42 Jun 4, 2026
149f9a0
fix: keep edit screen in back stack from ger
jvsena42 Jun 4, 2026
6822332
fix: always enable widget settings button
jvsena42 Jun 4, 2026
4b6a497
feat: edge-to-edge scroll for widget size pager
jvsena42 Jun 4, 2026
a2d0009
feat: edge-to-edge scroll for widget size pager
jvsena42 Jun 4, 2026
c953b96
fix: remove adjacent page peek in widget carousel
jvsena42 Jun 4, 2026
2ceb8f1
Merge branch 'master' into feat/in-app-v61
jvsena42 Jun 4, 2026
f23f0cb
fix: show decimal placeholder in small calculator
jvsena42 Jun 4, 2026
b2c2cba
fix: disable widget settings only for suggestions
jvsena42 Jun 4, 2026
3d22482
test: CalculatorWidget
piotr-iohk Jun 4, 2026
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
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
package to.bitkit.ui.screens.widgets.calculator

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.assertTextContains
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasSetTextAction
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.test.performTextClearance
import androidx.compose.ui.test.performTextInput
import androidx.compose.ui.test.printToString
import androidx.compose.ui.test.onAllNodesWithTag
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStore
Expand DownExpand Up@@ -50,6 +50,7 @@ import to.bitkit.test.annotations.CalculatorWidget
import to.bitkit.test.annotations.DeviceIntegration
import to.bitkit.test.annotations.DeviceUiIntegration
import to.bitkit.ui.screens.widgets.calculator.components.CalculatorCard
import to.bitkit.ui.screens.widgets.calculator.components.CalculatorNumberPadBar
import to.bitkit.ui.theme.AppThemeSurface
import java.util.Locale
import javax.inject.Inject
Expand All@@ -62,7 +63,7 @@ import kotlin.test.assertEquals
@CalculatorWidget
@DeviceIntegration
@DeviceUiIntegration
class CalculatorCardIntegrationTest {
class CalculatorWidgetInputTest {

@get:Rule
val hiltRule = HiltAndroidRule(this)
Expand DownExpand Up@@ -154,41 +155,27 @@ class CalculatorCardIntegrationTest {
}

@Test
fun btcInputUpdatesFiatValueAndPersistsWidgetState() {
setCalculatorCard()
fun btcInputViaNumberPadUpdatesFiatAndPersistsWidgetState() {
setCalculatorWidget()

replaceInput(BTC_INPUT_INDEX, "12340")
composeTestRule.onNodeWithTag(BTC_INPUT_TAG).performClick()
awaitNumberPad()
tapKeys("N1", "N2", "N3", "N4", "N0")

waitForValues(
btcValue = "12340",
fiatValue = "12.34",
)

assertInputText(BTC_INPUT_INDEX, "12 340")
assertInputText(FIAT_INPUT_INDEX, "12.34")
assertPersistedValues(
btcValue = "12340",
fiatValue = "12.34",
)
waitForValues(btcValue = "12340", fiatValue = "12.34")
assertPersistedValues(btcValue = "12340", fiatValue = "12.34")
}

@Test
fun fiatInputUpdatesBtcValueAndPersistsWidgetState() {
setCalculatorCard()
fun fiatInputViaNumberPadUpdatesBtcAndPersistsWidgetState() {
setCalculatorWidget()

replaceInput(FIAT_INPUT_INDEX, "10.00")
composeTestRule.onNodeWithTag(FIAT_INPUT_TAG).performClick()
awaitNumberPad()
tapKeys("N1", "N0", "NDecimal", "N0", "N0")

waitForValues(
btcValue = "10000",
fiatValue = "10.00",
)

assertInputText(BTC_INPUT_INDEX, "10 000")
assertInputText(FIAT_INPUT_INDEX, "10.00")
assertPersistedValues(
btcValue = "10000",
fiatValue = "10.00",
)
waitForValues(btcValue = "10000", fiatValue = "10.00")
assertPersistedValues(btcValue = "10000", fiatValue = "10.00")
}

private fun createCalculatorViewModel(): CalculatorViewModel {
Expand All@@ -206,80 +193,70 @@ class CalculatorCardIntegrationTest {
)[CalculatorViewModel::class.java]
}

private fun setCalculatorCard() {
private fun setCalculatorWidget() {
composeTestRule.setContent {
AppThemeSurface {
CalculatorCard(
calculatorViewModel = calculatorViewModel,
modifier = Modifier.fillMaxWidth()
)
val state by calculatorViewModel.uiState.collectAsState()
Box(modifier = Modifier.fillMaxSize()) {
CalculatorCard(
btcPrimaryDisplayUnit = state.displayUnit,
btcValue = state.btcValue,
fiatSymbol = state.currencySymbol,
fiatName = state.selectedCurrency,
fiatValue = state.fiatValue,
activeInput = state.activeInput,
onSelectInput = calculatorViewModel::onInputSelected,
modifier = Modifier.fillMaxWidth()
)
state.activeInput?.let { active ->
CalculatorNumberPadBar(
activeInput = active,
btcValue = state.btcValue,
fiatValue = state.fiatValue,
btcPrimaryDisplayUnit = state.displayUnit,
onBtcChange = calculatorViewModel::onBtcInputChanged,
onFiatChange = calculatorViewModel::onFiatInputChanged,
modifier = Modifier.align(Alignment.BottomCenter)
)
}
}
}
}
composeTestRule.waitForIdle()
}

private fun awaitNumberPad() {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
composeTestRule.onAllNodes(hasSetTextAction()).fetchSemanticsNodes().size == INPUT_COUNT
composeTestRule.onAllNodesWithTag(NUMBER_PAD_TAG).fetchSemanticsNodes().isNotEmpty()
}
}

private fun inputAt(index: Int) = composeTestRule.onAllNodes(hasSetTextAction())[index]

private fun replaceInput(
index: Int,
text: String,
) {
inputAt(index).performTextClearance()
inputAt(index).performTextInput(text)
private fun tapKeys(vararg keys: String) {
keys.forEach { key ->
composeTestRule.onNodeWithTag(key).performClick()
composeTestRule.waitForIdle()
}
}

private fun waitForValues(
btcValue: String,
fiatValue: String,
) {
runCatching {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
calculatorViewModel.uiState.value.btcValue == btcValue &&
calculatorViewModel.uiState.value.fiatValue == fiatValue
}
}.onFailure {
throw AssertionError(
buildString {
append("Expected calculatorValues btcValue='$btcValue', fiatValue='$fiatValue', ")
append("but was '${calculatorViewModel.uiState.value}'. Persisted values were ")
append("'${widgetsRepo.widgetsDataFlow.value.calculatorValues}'. Semantics tree:\n")
append(composeTestRule.onRoot(useUnmergedTree = true).printToString())
},
it,
)
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
calculatorViewModel.uiState.value.btcValue == btcValue &&
calculatorViewModel.uiState.value.fiatValue == fiatValue
}

val expectedValues = CalculatorValues(
btcValue = btcValue,
fiatValue = fiatValue,
satsValue = btcValue.toLong(),
displayUnit = BitcoinDisplayUnit.MODERN,
)
runCatching {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
widgetsRepo.widgetsDataFlow.value.calculatorValues == expectedValues
}
}.onFailure {
throw AssertionError(
"Expected persisted values '$expectedValues', but was " +
"'${widgetsRepo.widgetsDataFlow.value.calculatorValues}'",
it,
)
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
widgetsRepo.widgetsDataFlow.value.calculatorValues == expectedValues
}
}

private fun assertInputText(
inputIndex: Int,
text: String,
) {
inputAt(inputIndex).assertTextContains(text, substring = true)
composeTestRule.onNode(hasText(text, substring = true), useUnmergedTree = true)
.assertIsDisplayed()
}

private fun assertPersistedValues(
btcValue: String,
fiatValue: String,
Expand All@@ -296,9 +273,9 @@ class CalculatorCardIntegrationTest {
}

companion object {
private const val BTC_INPUT_INDEX = 0
private const val FIAT_INPUT_INDEX = 1
private const val INPUT_COUNT = 2
private const val BTC_INPUT_TAG = "CalculatorBtcInput"
private const val FIAT_INPUT_TAG = "CalculatorFiatInput"
private const val NUMBER_PAD_TAG = "CalculatorNumberPad"
private const val TIMEOUT_MS = 5_000L
private const val TEST_CREATED_AT = 0L
private const val TEST_USD_RATE = "100000"
Expand DownExpand Up@@ -330,6 +307,7 @@ class CalculatorCardIntegrationTest {

@Provides
@Named("enablePolling")
@Suppress("FunctionOnlyReturningConstant")
fun provideEnablePolling(): Boolean = false
}
}
38 changes: 28 additions & 10 deletions app/src/main/java/to/bitkit/data/WidgetsStore.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ import to.bitkit.data.dto.BlockDTO
import to.bitkit.data.dto.WeatherDTO
import to.bitkit.data.dto.price.PriceDTO
import to.bitkit.data.serializers.WidgetsSerializer
import to.bitkit.models.WidgetSize
import to.bitkit.models.WidgetType
import to.bitkit.models.WidgetWithPosition
import to.bitkit.models.WidgetsBackupV1
Expand DownExpand Up@@ -123,15 +124,28 @@ class WidgetsStore @Inject constructor(
Logger.info("Deleted all widgets data.")
}

suspend fun addWidget(type: WidgetType) {
if (store.data.first().widgets.map { it.type }.contains(type)) return
suspend fun addWidget(type: WidgetType, size: WidgetSize = WidgetSize.default(type)) {
store.updateData { data ->
val existing = data.widgets.firstOrNull { it.type == type }
if (existing != null) {
data.copy(
widgets = data.widgets
.map { if (it.type == type) it.copy(size = size) else it }
.sortedBy { it.position }
)
} else {
val nextPosition = (data.widgets.maxOfOrNull { it.position } ?: -1) + 1
data.copy(
widgets = (data.widgets + WidgetWithPosition(type = type, position = nextPosition, size = size))
.sortedBy { it.position }
)
}
}
}

suspend fun updateWidgetSize(type: WidgetType, size: WidgetSize) {
store.updateData { data ->
val nextPosition = (data.widgets.maxOfOrNull { it.position } ?: -1) + 1
data.copy(
widgets = (data.widgets + WidgetWithPosition(type = type, position = nextPosition))
.sortedBy { it.position }
)
data.copy(widgets = data.widgets.map { if (it.type == type) it.copy(size = size) else it })
}
}

Expand DownExpand Up@@ -161,9 +175,13 @@ class WidgetsStore @Inject constructor(
@Serializable
data class WidgetsData(
val widgets: List<WidgetWithPosition> = listOf(
WidgetWithPosition(type = WidgetType.SUGGESTIONS, position = 0),
WidgetWithPosition(type = WidgetType.PRICE, position = 1),
WidgetWithPosition(type = WidgetType.BLOCK, position = 2),
WidgetWithPosition(type = WidgetType.SUGGESTIONS, position = 0, size = WidgetSize.WIDE),
WidgetWithPosition(type = WidgetType.PRICE, position = 1, size = WidgetSize.WIDE),
WidgetWithPosition(type = WidgetType.BLOCK, position = 2, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.FACTS, position = 3, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.WEATHER, position = 4, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.CALCULATOR, position = 5, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.NEWS, position = 6, size = WidgetSize.WIDE),
),
val headlinePreferences: HeadlinePreferences = HeadlinePreferences(),
val blocksPreferences: BlocksPreferences = BlocksPreferences(),
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/to/bitkit/models/WidgetSize.kt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
package to.bitkit.models

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
enum class WidgetSize {
@SerialName("small")
SMALL,

@SerialName("wide")
WIDE;

companion object {
fun default(type: WidgetType): WidgetSize = when (type) {
WidgetType.PRICE,
WidgetType.NEWS,
WidgetType.SUGGESTIONS,
-> WIDE

else -> SMALL
}
}
}
4 changes: 4 additions & 0 deletions app/src/main/java/to/bitkit/models/WidgetWithPosition.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,4 +8,8 @@ import kotlinx.serialization.Serializable
data class WidgetWithPosition(
val type: WidgetType,
val position: Int = 0,
val size: WidgetSize = WidgetSize.WIDE,
)

fun WidgetWithPosition.effectiveSize(): WidgetSize =
if (type == WidgetType.SUGGESTIONS) WidgetSize.WIDE else size
7 changes: 6 additions & 1 deletion app/src/main/java/to/bitkit/repositories/WidgetsRepo.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,7 @@ import to.bitkit.data.widgets.PriceService
import to.bitkit.data.widgets.WeatherService
import to.bitkit.data.widgets.WidgetService
import to.bitkit.di.BgDispatcher
import to.bitkit.models.WidgetSize
import to.bitkit.models.WidgetType
import to.bitkit.models.WidgetWithPosition
import to.bitkit.models.widget.BlocksPreferences
Expand DownExpand Up@@ -173,7 +174,11 @@ class WidgetsRepo @Inject constructor(
Logger.verbose("Stopped refresh coroutine for $widgetType", context = TAG)
}

suspend fun addWidget(type: WidgetType) = withContext(bgDispatcher) { widgetsStore.addWidget(type) }
suspend fun addWidget(type: WidgetType, size: WidgetSize = WidgetSize.default(type)) =
withContext(bgDispatcher) { widgetsStore.addWidget(type, size) }

suspend fun updateWidgetSize(type: WidgetType, size: WidgetSize) =
withContext(bgDispatcher) { widgetsStore.updateWidgetSize(type, size) }

suspend fun deleteWidget(type: WidgetType) = withContext(bgDispatcher) { widgetsStore.deleteWidget(type) }

Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7718296
feat: widget size data layer logic
jvsena42 Jun 3, 2026
6ea4127
feat: widget size domain logic
jvsena42 Jun 3, 2026
ba646fb
feat: re-enabled compact mode and implement size saving logic
jvsena42 Jun 3, 2026
eabc02e
feat: calculator compact mode
jvsena42 Jun 3, 2026
760a102
feat: data layer
jvsena42 Jun 3, 2026
6e93d8c
feat: widgets grid
jvsena42 Jun 3, 2026
4e7baa4
fix: add a guard to reorder only when target slot changes
jvsena42 Jun 3, 2026
5f577a9
fix: number pad overlap calculator
jvsena42 Jun 3, 2026
00d9216
chore: rename changelog fragment
jvsena42 Jun 3, 2026
f8ee4b6
fix: animate calculator to previous position on number pad dismiss
jvsena42 Jun 3, 2026
7291cb6
fix: remove active orange border
jvsena42 Jun 3, 2026
37f5141
fix: input corner radius
jvsena42 Jun 3, 2026
a2e9000
fix: make calculator preview read-only
jvsena42 Jun 3, 2026
6bee689
fix: display cached calculator value on widget gallery
jvsena42 Jun 3, 2026
6a4c300
fix: drop first emission with default value
jvsena42 Jun 3, 2026
2805dc9
refactor: remove dead code and component renaming
jvsena42 Jun 3, 2026
a1a405e
test: calculator widget instrumented test
jvsena42 Jun 3, 2026
8b26f64
fix: preview crash
jvsena42 Jun 3, 2026
0db04ea
refactor: code cleanup
jvsena42 Jun 3, 2026
799b078
refactor: make isWide immutable for compose stability
jvsena42 Jun 4, 2026
c84244d
refactor: break into smaller self-explanatory private methods
jvsena42 Jun 4, 2026
d9c4778
fix: align name to center
jvsena42 Jun 4, 2026
125c0aa
fix: adapt small card width
jvsena42 Jun 4, 2026
35f64d0
fix: use gray6 bg for all widget cards
jvsena42 Jun 4, 2026
fe00c78
fix: set drag preview alpha
jvsena42 Jun 4, 2026
149f9a0
fix: keep edit screen in back stack from ger
jvsena42 Jun 4, 2026
6822332
fix: always enable widget settings button
jvsena42 Jun 4, 2026
4b6a497
feat: edge-to-edge scroll for widget size pager
jvsena42 Jun 4, 2026
a2d0009
feat: edge-to-edge scroll for widget size pager
jvsena42 Jun 4, 2026
c953b96
fix: remove adjacent page peek in widget carousel
jvsena42 Jun 4, 2026
2ceb8f1
Merge branch 'master' into feat/in-app-v61
jvsena42 Jun 4, 2026
f23f0cb
fix: show decimal placeholder in small calculator
jvsena42 Jun 4, 2026
b2c2cba
fix: disable widget settings only for suggestions
jvsena42 Jun 4, 2026
3d22482
test: CalculatorWidget
piotr-iohk Jun 4, 2026
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
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
package to.bitkit.ui.screens.widgets.calculator

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.assertTextContains
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasSetTextAction
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.test.performTextClearance
import androidx.compose.ui.test.performTextInput
import androidx.compose.ui.test.printToString
import androidx.compose.ui.test.onAllNodesWithTag
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStore
Expand DownExpand Up@@ -50,6 +50,7 @@ import to.bitkit.test.annotations.CalculatorWidget
import to.bitkit.test.annotations.DeviceIntegration
import to.bitkit.test.annotations.DeviceUiIntegration
import to.bitkit.ui.screens.widgets.calculator.components.CalculatorCard
import to.bitkit.ui.screens.widgets.calculator.components.CalculatorNumberPadBar
import to.bitkit.ui.theme.AppThemeSurface
import java.util.Locale
import javax.inject.Inject
Expand All@@ -62,7 +63,7 @@ import kotlin.test.assertEquals
@CalculatorWidget
@DeviceIntegration
@DeviceUiIntegration
class CalculatorCardIntegrationTest {
class CalculatorWidgetInputTest {

@get:Rule
val hiltRule = HiltAndroidRule(this)
Expand DownExpand Up@@ -154,41 +155,27 @@ class CalculatorCardIntegrationTest {
}

@Test
fun btcInputUpdatesFiatValueAndPersistsWidgetState() {
setCalculatorCard()
fun btcInputViaNumberPadUpdatesFiatAndPersistsWidgetState() {
setCalculatorWidget()

replaceInput(BTC_INPUT_INDEX, "12340")
composeTestRule.onNodeWithTag(BTC_INPUT_TAG).performClick()
awaitNumberPad()
tapKeys("N1", "N2", "N3", "N4", "N0")

waitForValues(
btcValue = "12340",
fiatValue = "12.34",
)

assertInputText(BTC_INPUT_INDEX, "12 340")
assertInputText(FIAT_INPUT_INDEX, "12.34")
assertPersistedValues(
btcValue = "12340",
fiatValue = "12.34",
)
waitForValues(btcValue = "12340", fiatValue = "12.34")
assertPersistedValues(btcValue = "12340", fiatValue = "12.34")
}

@Test
fun fiatInputUpdatesBtcValueAndPersistsWidgetState() {
setCalculatorCard()
fun fiatInputViaNumberPadUpdatesBtcAndPersistsWidgetState() {
setCalculatorWidget()

replaceInput(FIAT_INPUT_INDEX, "10.00")
composeTestRule.onNodeWithTag(FIAT_INPUT_TAG).performClick()
awaitNumberPad()
tapKeys("N1", "N0", "NDecimal", "N0", "N0")

waitForValues(
btcValue = "10000",
fiatValue = "10.00",
)

assertInputText(BTC_INPUT_INDEX, "10 000")
assertInputText(FIAT_INPUT_INDEX, "10.00")
assertPersistedValues(
btcValue = "10000",
fiatValue = "10.00",
)
waitForValues(btcValue = "10000", fiatValue = "10.00")
assertPersistedValues(btcValue = "10000", fiatValue = "10.00")
}

private fun createCalculatorViewModel(): CalculatorViewModel {
Expand All@@ -206,80 +193,70 @@ class CalculatorCardIntegrationTest {
)[CalculatorViewModel::class.java]
}

private fun setCalculatorCard() {
private fun setCalculatorWidget() {
composeTestRule.setContent {
AppThemeSurface {
CalculatorCard(
calculatorViewModel = calculatorViewModel,
modifier = Modifier.fillMaxWidth()
)
val state by calculatorViewModel.uiState.collectAsState()
Box(modifier = Modifier.fillMaxSize()) {
CalculatorCard(
btcPrimaryDisplayUnit = state.displayUnit,
btcValue = state.btcValue,
fiatSymbol = state.currencySymbol,
fiatName = state.selectedCurrency,
fiatValue = state.fiatValue,
activeInput = state.activeInput,
onSelectInput = calculatorViewModel::onInputSelected,
modifier = Modifier.fillMaxWidth()
)
state.activeInput?.let { active ->
CalculatorNumberPadBar(
activeInput = active,
btcValue = state.btcValue,
fiatValue = state.fiatValue,
btcPrimaryDisplayUnit = state.displayUnit,
onBtcChange = calculatorViewModel::onBtcInputChanged,
onFiatChange = calculatorViewModel::onFiatInputChanged,
modifier = Modifier.align(Alignment.BottomCenter)
)
}
}
}
}
composeTestRule.waitForIdle()
}

private fun awaitNumberPad() {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
composeTestRule.onAllNodes(hasSetTextAction()).fetchSemanticsNodes().size == INPUT_COUNT
composeTestRule.onAllNodesWithTag(NUMBER_PAD_TAG).fetchSemanticsNodes().isNotEmpty()
}
}

private fun inputAt(index: Int) = composeTestRule.onAllNodes(hasSetTextAction())[index]

private fun replaceInput(
index: Int,
text: String,
) {
inputAt(index).performTextClearance()
inputAt(index).performTextInput(text)
private fun tapKeys(vararg keys: String) {
keys.forEach { key ->
composeTestRule.onNodeWithTag(key).performClick()
composeTestRule.waitForIdle()
}
}

private fun waitForValues(
btcValue: String,
fiatValue: String,
) {
runCatching {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
calculatorViewModel.uiState.value.btcValue == btcValue &&
calculatorViewModel.uiState.value.fiatValue == fiatValue
}
}.onFailure {
throw AssertionError(
buildString {
append("Expected calculatorValues btcValue='$btcValue', fiatValue='$fiatValue', ")
append("but was '${calculatorViewModel.uiState.value}'. Persisted values were ")
append("'${widgetsRepo.widgetsDataFlow.value.calculatorValues}'. Semantics tree:\n")
append(composeTestRule.onRoot(useUnmergedTree = true).printToString())
},
it,
)
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
calculatorViewModel.uiState.value.btcValue == btcValue &&
calculatorViewModel.uiState.value.fiatValue == fiatValue
}

val expectedValues = CalculatorValues(
btcValue = btcValue,
fiatValue = fiatValue,
satsValue = btcValue.toLong(),
displayUnit = BitcoinDisplayUnit.MODERN,
)
runCatching {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
widgetsRepo.widgetsDataFlow.value.calculatorValues == expectedValues
}
}.onFailure {
throw AssertionError(
"Expected persisted values '$expectedValues', but was " +
"'${widgetsRepo.widgetsDataFlow.value.calculatorValues}'",
it,
)
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
widgetsRepo.widgetsDataFlow.value.calculatorValues == expectedValues
}
}

private fun assertInputText(
inputIndex: Int,
text: String,
) {
inputAt(inputIndex).assertTextContains(text, substring = true)
composeTestRule.onNode(hasText(text, substring = true), useUnmergedTree = true)
.assertIsDisplayed()
}

private fun assertPersistedValues(
btcValue: String,
fiatValue: String,
Expand All@@ -296,9 +273,9 @@ class CalculatorCardIntegrationTest {
}

companion object {
private const val BTC_INPUT_INDEX = 0
private const val FIAT_INPUT_INDEX = 1
private const val INPUT_COUNT = 2
private const val BTC_INPUT_TAG = "CalculatorBtcInput"
private const val FIAT_INPUT_TAG = "CalculatorFiatInput"
private const val NUMBER_PAD_TAG = "CalculatorNumberPad"
private const val TIMEOUT_MS = 5_000L
private const val TEST_CREATED_AT = 0L
private const val TEST_USD_RATE = "100000"
Expand DownExpand Up@@ -330,6 +307,7 @@ class CalculatorCardIntegrationTest {

@Provides
@Named("enablePolling")
@Suppress("FunctionOnlyReturningConstant")
fun provideEnablePolling(): Boolean = false
}
}
38 changes: 28 additions & 10 deletions app/src/main/java/to/bitkit/data/WidgetsStore.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ import to.bitkit.data.dto.BlockDTO
import to.bitkit.data.dto.WeatherDTO
import to.bitkit.data.dto.price.PriceDTO
import to.bitkit.data.serializers.WidgetsSerializer
import to.bitkit.models.WidgetSize
import to.bitkit.models.WidgetType
import to.bitkit.models.WidgetWithPosition
import to.bitkit.models.WidgetsBackupV1
Expand DownExpand Up@@ -123,15 +124,28 @@ class WidgetsStore @Inject constructor(
Logger.info("Deleted all widgets data.")
}

suspend fun addWidget(type: WidgetType) {
if (store.data.first().widgets.map { it.type }.contains(type)) return
suspend fun addWidget(type: WidgetType, size: WidgetSize = WidgetSize.default(type)) {
store.updateData { data ->
val existing = data.widgets.firstOrNull { it.type == type }
if (existing != null) {
data.copy(
widgets = data.widgets
.map { if (it.type == type) it.copy(size = size) else it }
.sortedBy { it.position }
)
} else {
val nextPosition = (data.widgets.maxOfOrNull { it.position } ?: -1) + 1
data.copy(
widgets = (data.widgets + WidgetWithPosition(type = type, position = nextPosition, size = size))
.sortedBy { it.position }
)
}
}
}

suspend fun updateWidgetSize(type: WidgetType, size: WidgetSize) {
store.updateData { data ->
val nextPosition = (data.widgets.maxOfOrNull { it.position } ?: -1) + 1
data.copy(
widgets = (data.widgets + WidgetWithPosition(type = type, position = nextPosition))
.sortedBy { it.position }
)
data.copy(widgets = data.widgets.map { if (it.type == type) it.copy(size = size) else it })
}
}

Expand DownExpand Up@@ -161,9 +175,13 @@ class WidgetsStore @Inject constructor(
@Serializable
data class WidgetsData(
val widgets: List<WidgetWithPosition> = listOf(
WidgetWithPosition(type = WidgetType.SUGGESTIONS, position = 0),
WidgetWithPosition(type = WidgetType.PRICE, position = 1),
WidgetWithPosition(type = WidgetType.BLOCK, position = 2),
WidgetWithPosition(type = WidgetType.SUGGESTIONS, position = 0, size = WidgetSize.WIDE),
WidgetWithPosition(type = WidgetType.PRICE, position = 1, size = WidgetSize.WIDE),
WidgetWithPosition(type = WidgetType.BLOCK, position = 2, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.FACTS, position = 3, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.WEATHER, position = 4, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.CALCULATOR, position = 5, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.NEWS, position = 6, size = WidgetSize.WIDE),
),
val headlinePreferences: HeadlinePreferences = HeadlinePreferences(),
val blocksPreferences: BlocksPreferences = BlocksPreferences(),
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/to/bitkit/models/WidgetSize.kt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
package to.bitkit.models

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
enum class WidgetSize {
@SerialName("small")
SMALL,

@SerialName("wide")
WIDE;

companion object {
fun default(type: WidgetType): WidgetSize = when (type) {
WidgetType.PRICE,
WidgetType.NEWS,
WidgetType.SUGGESTIONS,
-> WIDE

else -> SMALL
}
}
}
4 changes: 4 additions & 0 deletions app/src/main/java/to/bitkit/models/WidgetWithPosition.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,4 +8,8 @@ import kotlinx.serialization.Serializable
data class WidgetWithPosition(
val type: WidgetType,
val position: Int = 0,
val size: WidgetSize = WidgetSize.WIDE,
)

fun WidgetWithPosition.effectiveSize(): WidgetSize =
if (type == WidgetType.SUGGESTIONS) WidgetSize.WIDE else size
7 changes: 6 additions & 1 deletion app/src/main/java/to/bitkit/repositories/WidgetsRepo.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,7 @@ import to.bitkit.data.widgets.PriceService
import to.bitkit.data.widgets.WeatherService
import to.bitkit.data.widgets.WidgetService
import to.bitkit.di.BgDispatcher
import to.bitkit.models.WidgetSize
import to.bitkit.models.WidgetType
import to.bitkit.models.WidgetWithPosition
import to.bitkit.models.widget.BlocksPreferences
Expand DownExpand Up@@ -173,7 +174,11 @@ class WidgetsRepo @Inject constructor(
Logger.verbose("Stopped refresh coroutine for $widgetType", context = TAG)
}

suspend fun addWidget(type: WidgetType) = withContext(bgDispatcher) { widgetsStore.addWidget(type) }
suspend fun addWidget(type: WidgetType, size: WidgetSize = WidgetSize.default(type)) =
withContext(bgDispatcher) { widgetsStore.addWidget(type, size) }

suspend fun updateWidgetSize(type: WidgetType, size: WidgetSize) =
withContext(bgDispatcher) { widgetsStore.updateWidgetSize(type, size) }

suspend fun deleteWidget(type: WidgetType) = withContext(bgDispatcher) { widgetsStore.deleteWidget(type) }

Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7718296
feat: widget size data layer logic
jvsena42 Jun 3, 2026
6ea4127
feat: widget size domain logic
jvsena42 Jun 3, 2026
ba646fb
feat: re-enabled compact mode and implement size saving logic
jvsena42 Jun 3, 2026
eabc02e
feat: calculator compact mode
jvsena42 Jun 3, 2026
760a102
feat: data layer
jvsena42 Jun 3, 2026
6e93d8c
feat: widgets grid
jvsena42 Jun 3, 2026
4e7baa4
fix: add a guard to reorder only when target slot changes
jvsena42 Jun 3, 2026
5f577a9
fix: number pad overlap calculator
jvsena42 Jun 3, 2026
00d9216
chore: rename changelog fragment
jvsena42 Jun 3, 2026
f8ee4b6
fix: animate calculator to previous position on number pad dismiss
jvsena42 Jun 3, 2026
7291cb6
fix: remove active orange border
jvsena42 Jun 3, 2026
37f5141
fix: input corner radius
jvsena42 Jun 3, 2026
a2e9000
fix: make calculator preview read-only
jvsena42 Jun 3, 2026
6bee689
fix: display cached calculator value on widget gallery
jvsena42 Jun 3, 2026
6a4c300
fix: drop first emission with default value
jvsena42 Jun 3, 2026
2805dc9
refactor: remove dead code and component renaming
jvsena42 Jun 3, 2026
a1a405e
test: calculator widget instrumented test
jvsena42 Jun 3, 2026
8b26f64
fix: preview crash
jvsena42 Jun 3, 2026
0db04ea
refactor: code cleanup
jvsena42 Jun 3, 2026
799b078
refactor: make isWide immutable for compose stability
jvsena42 Jun 4, 2026
c84244d
refactor: break into smaller self-explanatory private methods
jvsena42 Jun 4, 2026
d9c4778
fix: align name to center
jvsena42 Jun 4, 2026
125c0aa
fix: adapt small card width
jvsena42 Jun 4, 2026
35f64d0
fix: use gray6 bg for all widget cards
jvsena42 Jun 4, 2026
fe00c78
fix: set drag preview alpha
jvsena42 Jun 4, 2026
149f9a0
fix: keep edit screen in back stack from ger
jvsena42 Jun 4, 2026
6822332
fix: always enable widget settings button
jvsena42 Jun 4, 2026
4b6a497
feat: edge-to-edge scroll for widget size pager
jvsena42 Jun 4, 2026
a2d0009
feat: edge-to-edge scroll for widget size pager
jvsena42 Jun 4, 2026
c953b96
fix: remove adjacent page peek in widget carousel
jvsena42 Jun 4, 2026
2ceb8f1
Merge branch 'master' into feat/in-app-v61
jvsena42 Jun 4, 2026
f23f0cb
fix: show decimal placeholder in small calculator
jvsena42 Jun 4, 2026
b2c2cba
fix: disable widget settings only for suggestions
jvsena42 Jun 4, 2026
3d22482
test: CalculatorWidget
piotr-iohk Jun 4, 2026
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
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
package to.bitkit.ui.screens.widgets.calculator

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.assertTextContains
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasSetTextAction
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.test.performTextClearance
import androidx.compose.ui.test.performTextInput
import androidx.compose.ui.test.printToString
import androidx.compose.ui.test.onAllNodesWithTag
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStore
Expand DownExpand Up@@ -50,6 +50,7 @@ import to.bitkit.test.annotations.CalculatorWidget
import to.bitkit.test.annotations.DeviceIntegration
import to.bitkit.test.annotations.DeviceUiIntegration
import to.bitkit.ui.screens.widgets.calculator.components.CalculatorCard
import to.bitkit.ui.screens.widgets.calculator.components.CalculatorNumberPadBar
import to.bitkit.ui.theme.AppThemeSurface
import java.util.Locale
import javax.inject.Inject
Expand All@@ -62,7 +63,7 @@ import kotlin.test.assertEquals
@CalculatorWidget
@DeviceIntegration
@DeviceUiIntegration
class CalculatorCardIntegrationTest {
class CalculatorWidgetInputTest {

@get:Rule
val hiltRule = HiltAndroidRule(this)
Expand DownExpand Up@@ -154,41 +155,27 @@ class CalculatorCardIntegrationTest {
}

@Test
fun btcInputUpdatesFiatValueAndPersistsWidgetState() {
setCalculatorCard()
fun btcInputViaNumberPadUpdatesFiatAndPersistsWidgetState() {
setCalculatorWidget()

replaceInput(BTC_INPUT_INDEX, "12340")
composeTestRule.onNodeWithTag(BTC_INPUT_TAG).performClick()
awaitNumberPad()
tapKeys("N1", "N2", "N3", "N4", "N0")

waitForValues(
btcValue = "12340",
fiatValue = "12.34",
)

assertInputText(BTC_INPUT_INDEX, "12 340")
assertInputText(FIAT_INPUT_INDEX, "12.34")
assertPersistedValues(
btcValue = "12340",
fiatValue = "12.34",
)
waitForValues(btcValue = "12340", fiatValue = "12.34")
assertPersistedValues(btcValue = "12340", fiatValue = "12.34")
}

@Test
fun fiatInputUpdatesBtcValueAndPersistsWidgetState() {
setCalculatorCard()
fun fiatInputViaNumberPadUpdatesBtcAndPersistsWidgetState() {
setCalculatorWidget()

replaceInput(FIAT_INPUT_INDEX, "10.00")
composeTestRule.onNodeWithTag(FIAT_INPUT_TAG).performClick()
awaitNumberPad()
tapKeys("N1", "N0", "NDecimal", "N0", "N0")

waitForValues(
btcValue = "10000",
fiatValue = "10.00",
)

assertInputText(BTC_INPUT_INDEX, "10 000")
assertInputText(FIAT_INPUT_INDEX, "10.00")
assertPersistedValues(
btcValue = "10000",
fiatValue = "10.00",
)
waitForValues(btcValue = "10000", fiatValue = "10.00")
assertPersistedValues(btcValue = "10000", fiatValue = "10.00")
}

private fun createCalculatorViewModel(): CalculatorViewModel {
Expand All@@ -206,80 +193,70 @@ class CalculatorCardIntegrationTest {
)[CalculatorViewModel::class.java]
}

private fun setCalculatorCard() {
private fun setCalculatorWidget() {
composeTestRule.setContent {
AppThemeSurface {
CalculatorCard(
calculatorViewModel = calculatorViewModel,
modifier = Modifier.fillMaxWidth()
)
val state by calculatorViewModel.uiState.collectAsState()
Box(modifier = Modifier.fillMaxSize()) {
CalculatorCard(
btcPrimaryDisplayUnit = state.displayUnit,
btcValue = state.btcValue,
fiatSymbol = state.currencySymbol,
fiatName = state.selectedCurrency,
fiatValue = state.fiatValue,
activeInput = state.activeInput,
onSelectInput = calculatorViewModel::onInputSelected,
modifier = Modifier.fillMaxWidth()
)
state.activeInput?.let { active ->
CalculatorNumberPadBar(
activeInput = active,
btcValue = state.btcValue,
fiatValue = state.fiatValue,
btcPrimaryDisplayUnit = state.displayUnit,
onBtcChange = calculatorViewModel::onBtcInputChanged,
onFiatChange = calculatorViewModel::onFiatInputChanged,
modifier = Modifier.align(Alignment.BottomCenter)
)
}
}
}
}
composeTestRule.waitForIdle()
}

private fun awaitNumberPad() {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
composeTestRule.onAllNodes(hasSetTextAction()).fetchSemanticsNodes().size == INPUT_COUNT
composeTestRule.onAllNodesWithTag(NUMBER_PAD_TAG).fetchSemanticsNodes().isNotEmpty()
}
}

private fun inputAt(index: Int) = composeTestRule.onAllNodes(hasSetTextAction())[index]

private fun replaceInput(
index: Int,
text: String,
) {
inputAt(index).performTextClearance()
inputAt(index).performTextInput(text)
private fun tapKeys(vararg keys: String) {
keys.forEach { key ->
composeTestRule.onNodeWithTag(key).performClick()
composeTestRule.waitForIdle()
}
}

private fun waitForValues(
btcValue: String,
fiatValue: String,
) {
runCatching {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
calculatorViewModel.uiState.value.btcValue == btcValue &&
calculatorViewModel.uiState.value.fiatValue == fiatValue
}
}.onFailure {
throw AssertionError(
buildString {
append("Expected calculatorValues btcValue='$btcValue', fiatValue='$fiatValue', ")
append("but was '${calculatorViewModel.uiState.value}'. Persisted values were ")
append("'${widgetsRepo.widgetsDataFlow.value.calculatorValues}'. Semantics tree:\n")
append(composeTestRule.onRoot(useUnmergedTree = true).printToString())
},
it,
)
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
calculatorViewModel.uiState.value.btcValue == btcValue &&
calculatorViewModel.uiState.value.fiatValue == fiatValue
}

val expectedValues = CalculatorValues(
btcValue = btcValue,
fiatValue = fiatValue,
satsValue = btcValue.toLong(),
displayUnit = BitcoinDisplayUnit.MODERN,
)
runCatching {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
widgetsRepo.widgetsDataFlow.value.calculatorValues == expectedValues
}
}.onFailure {
throw AssertionError(
"Expected persisted values '$expectedValues', but was " +
"'${widgetsRepo.widgetsDataFlow.value.calculatorValues}'",
it,
)
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
widgetsRepo.widgetsDataFlow.value.calculatorValues == expectedValues
}
}

private fun assertInputText(
inputIndex: Int,
text: String,
) {
inputAt(inputIndex).assertTextContains(text, substring = true)
composeTestRule.onNode(hasText(text, substring = true), useUnmergedTree = true)
.assertIsDisplayed()
}

private fun assertPersistedValues(
btcValue: String,
fiatValue: String,
Expand All@@ -296,9 +273,9 @@ class CalculatorCardIntegrationTest {
}

companion object {
private const val BTC_INPUT_INDEX = 0
private const val FIAT_INPUT_INDEX = 1
private const val INPUT_COUNT = 2
private const val BTC_INPUT_TAG = "CalculatorBtcInput"
private const val FIAT_INPUT_TAG = "CalculatorFiatInput"
private const val NUMBER_PAD_TAG = "CalculatorNumberPad"
private const val TIMEOUT_MS = 5_000L
private const val TEST_CREATED_AT = 0L
private const val TEST_USD_RATE = "100000"
Expand DownExpand Up@@ -330,6 +307,7 @@ class CalculatorCardIntegrationTest {

@Provides
@Named("enablePolling")
@Suppress("FunctionOnlyReturningConstant")
fun provideEnablePolling(): Boolean = false
}
}
38 changes: 28 additions & 10 deletions app/src/main/java/to/bitkit/data/WidgetsStore.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ import to.bitkit.data.dto.BlockDTO
import to.bitkit.data.dto.WeatherDTO
import to.bitkit.data.dto.price.PriceDTO
import to.bitkit.data.serializers.WidgetsSerializer
import to.bitkit.models.WidgetSize
import to.bitkit.models.WidgetType
import to.bitkit.models.WidgetWithPosition
import to.bitkit.models.WidgetsBackupV1
Expand DownExpand Up@@ -123,15 +124,28 @@ class WidgetsStore @Inject constructor(
Logger.info("Deleted all widgets data.")
}

suspend fun addWidget(type: WidgetType) {
if (store.data.first().widgets.map { it.type }.contains(type)) return
suspend fun addWidget(type: WidgetType, size: WidgetSize = WidgetSize.default(type)) {
store.updateData { data ->
val existing = data.widgets.firstOrNull { it.type == type }
if (existing != null) {
data.copy(
widgets = data.widgets
.map { if (it.type == type) it.copy(size = size) else it }
.sortedBy { it.position }
)
} else {
val nextPosition = (data.widgets.maxOfOrNull { it.position } ?: -1) + 1
data.copy(
widgets = (data.widgets + WidgetWithPosition(type = type, position = nextPosition, size = size))
.sortedBy { it.position }
)
}
}
}

suspend fun updateWidgetSize(type: WidgetType, size: WidgetSize) {
store.updateData { data ->
val nextPosition = (data.widgets.maxOfOrNull { it.position } ?: -1) + 1
data.copy(
widgets = (data.widgets + WidgetWithPosition(type = type, position = nextPosition))
.sortedBy { it.position }
)
data.copy(widgets = data.widgets.map { if (it.type == type) it.copy(size = size) else it })
}
}

Expand DownExpand Up@@ -161,9 +175,13 @@ class WidgetsStore @Inject constructor(
@Serializable
data class WidgetsData(
val widgets: List<WidgetWithPosition> = listOf(
WidgetWithPosition(type = WidgetType.SUGGESTIONS, position = 0),
WidgetWithPosition(type = WidgetType.PRICE, position = 1),
WidgetWithPosition(type = WidgetType.BLOCK, position = 2),
WidgetWithPosition(type = WidgetType.SUGGESTIONS, position = 0, size = WidgetSize.WIDE),
WidgetWithPosition(type = WidgetType.PRICE, position = 1, size = WidgetSize.WIDE),
WidgetWithPosition(type = WidgetType.BLOCK, position = 2, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.FACTS, position = 3, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.WEATHER, position = 4, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.CALCULATOR, position = 5, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.NEWS, position = 6, size = WidgetSize.WIDE),
),
val headlinePreferences: HeadlinePreferences = HeadlinePreferences(),
val blocksPreferences: BlocksPreferences = BlocksPreferences(),
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/to/bitkit/models/WidgetSize.kt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
package to.bitkit.models

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
enum class WidgetSize {
@SerialName("small")
SMALL,

@SerialName("wide")
WIDE;

companion object {
fun default(type: WidgetType): WidgetSize = when (type) {
WidgetType.PRICE,
WidgetType.NEWS,
WidgetType.SUGGESTIONS,
-> WIDE

else -> SMALL
}
}
}
4 changes: 4 additions & 0 deletions app/src/main/java/to/bitkit/models/WidgetWithPosition.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,4 +8,8 @@ import kotlinx.serialization.Serializable
data class WidgetWithPosition(
val type: WidgetType,
val position: Int = 0,
val size: WidgetSize = WidgetSize.WIDE,
)

fun WidgetWithPosition.effectiveSize(): WidgetSize =
if (type == WidgetType.SUGGESTIONS) WidgetSize.WIDE else size
7 changes: 6 additions & 1 deletion app/src/main/java/to/bitkit/repositories/WidgetsRepo.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,7 @@ import to.bitkit.data.widgets.PriceService
import to.bitkit.data.widgets.WeatherService
import to.bitkit.data.widgets.WidgetService
import to.bitkit.di.BgDispatcher
import to.bitkit.models.WidgetSize
import to.bitkit.models.WidgetType
import to.bitkit.models.WidgetWithPosition
import to.bitkit.models.widget.BlocksPreferences
Expand DownExpand Up@@ -173,7 +174,11 @@ class WidgetsRepo @Inject constructor(
Logger.verbose("Stopped refresh coroutine for $widgetType", context = TAG)
}

suspend fun addWidget(type: WidgetType) = withContext(bgDispatcher) { widgetsStore.addWidget(type) }
suspend fun addWidget(type: WidgetType, size: WidgetSize = WidgetSize.default(type)) =
withContext(bgDispatcher) { widgetsStore.addWidget(type, size) }

suspend fun updateWidgetSize(type: WidgetType, size: WidgetSize) =
withContext(bgDispatcher) { widgetsStore.updateWidgetSize(type, size) }

suspend fun deleteWidget(type: WidgetType) = withContext(bgDispatcher) { widgetsStore.deleteWidget(type) }

Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7718296
feat: widget size data layer logic
jvsena42 Jun 3, 2026
6ea4127
feat: widget size domain logic
jvsena42 Jun 3, 2026
ba646fb
feat: re-enabled compact mode and implement size saving logic
jvsena42 Jun 3, 2026
eabc02e
feat: calculator compact mode
jvsena42 Jun 3, 2026
760a102
feat: data layer
jvsena42 Jun 3, 2026
6e93d8c
feat: widgets grid
jvsena42 Jun 3, 2026
4e7baa4
fix: add a guard to reorder only when target slot changes
jvsena42 Jun 3, 2026
5f577a9
fix: number pad overlap calculator
jvsena42 Jun 3, 2026
00d9216
chore: rename changelog fragment
jvsena42 Jun 3, 2026
f8ee4b6
fix: animate calculator to previous position on number pad dismiss
jvsena42 Jun 3, 2026
7291cb6
fix: remove active orange border
jvsena42 Jun 3, 2026
37f5141
fix: input corner radius
jvsena42 Jun 3, 2026
a2e9000
fix: make calculator preview read-only
jvsena42 Jun 3, 2026
6bee689
fix: display cached calculator value on widget gallery
jvsena42 Jun 3, 2026
6a4c300
fix: drop first emission with default value
jvsena42 Jun 3, 2026
2805dc9
refactor: remove dead code and component renaming
jvsena42 Jun 3, 2026
a1a405e
test: calculator widget instrumented test
jvsena42 Jun 3, 2026
8b26f64
fix: preview crash
jvsena42 Jun 3, 2026
0db04ea
refactor: code cleanup
jvsena42 Jun 3, 2026
799b078
refactor: make isWide immutable for compose stability
jvsena42 Jun 4, 2026
c84244d
refactor: break into smaller self-explanatory private methods
jvsena42 Jun 4, 2026
d9c4778
fix: align name to center
jvsena42 Jun 4, 2026
125c0aa
fix: adapt small card width
jvsena42 Jun 4, 2026
35f64d0
fix: use gray6 bg for all widget cards
jvsena42 Jun 4, 2026
fe00c78
fix: set drag preview alpha
jvsena42 Jun 4, 2026
149f9a0
fix: keep edit screen in back stack from ger
jvsena42 Jun 4, 2026
6822332
fix: always enable widget settings button
jvsena42 Jun 4, 2026
4b6a497
feat: edge-to-edge scroll for widget size pager
jvsena42 Jun 4, 2026
a2d0009
feat: edge-to-edge scroll for widget size pager
jvsena42 Jun 4, 2026
c953b96
fix: remove adjacent page peek in widget carousel
jvsena42 Jun 4, 2026
2ceb8f1
Merge branch 'master' into feat/in-app-v61
jvsena42 Jun 4, 2026
f23f0cb
fix: show decimal placeholder in small calculator
jvsena42 Jun 4, 2026
b2c2cba
fix: disable widget settings only for suggestions
jvsena42 Jun 4, 2026
3d22482
test: CalculatorWidget
piotr-iohk Jun 4, 2026
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
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
package to.bitkit.ui.screens.widgets.calculator

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.assertTextContains
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasSetTextAction
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.test.performTextClearance
import androidx.compose.ui.test.performTextInput
import androidx.compose.ui.test.printToString
import androidx.compose.ui.test.onAllNodesWithTag
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStore
Expand DownExpand Up@@ -50,6 +50,7 @@ import to.bitkit.test.annotations.CalculatorWidget
import to.bitkit.test.annotations.DeviceIntegration
import to.bitkit.test.annotations.DeviceUiIntegration
import to.bitkit.ui.screens.widgets.calculator.components.CalculatorCard
import to.bitkit.ui.screens.widgets.calculator.components.CalculatorNumberPadBar
import to.bitkit.ui.theme.AppThemeSurface
import java.util.Locale
import javax.inject.Inject
Expand All@@ -62,7 +63,7 @@ import kotlin.test.assertEquals
@CalculatorWidget
@DeviceIntegration
@DeviceUiIntegration
class CalculatorCardIntegrationTest {
class CalculatorWidgetInputTest {

@get:Rule
val hiltRule = HiltAndroidRule(this)
Expand DownExpand Up@@ -154,41 +155,27 @@ class CalculatorCardIntegrationTest {
}

@Test
fun btcInputUpdatesFiatValueAndPersistsWidgetState() {
setCalculatorCard()
fun btcInputViaNumberPadUpdatesFiatAndPersistsWidgetState() {
setCalculatorWidget()

replaceInput(BTC_INPUT_INDEX, "12340")
composeTestRule.onNodeWithTag(BTC_INPUT_TAG).performClick()
awaitNumberPad()
tapKeys("N1", "N2", "N3", "N4", "N0")

waitForValues(
btcValue = "12340",
fiatValue = "12.34",
)

assertInputText(BTC_INPUT_INDEX, "12 340")
assertInputText(FIAT_INPUT_INDEX, "12.34")
assertPersistedValues(
btcValue = "12340",
fiatValue = "12.34",
)
waitForValues(btcValue = "12340", fiatValue = "12.34")
assertPersistedValues(btcValue = "12340", fiatValue = "12.34")
}

@Test
fun fiatInputUpdatesBtcValueAndPersistsWidgetState() {
setCalculatorCard()
fun fiatInputViaNumberPadUpdatesBtcAndPersistsWidgetState() {
setCalculatorWidget()

replaceInput(FIAT_INPUT_INDEX, "10.00")
composeTestRule.onNodeWithTag(FIAT_INPUT_TAG).performClick()
awaitNumberPad()
tapKeys("N1", "N0", "NDecimal", "N0", "N0")

waitForValues(
btcValue = "10000",
fiatValue = "10.00",
)

assertInputText(BTC_INPUT_INDEX, "10 000")
assertInputText(FIAT_INPUT_INDEX, "10.00")
assertPersistedValues(
btcValue = "10000",
fiatValue = "10.00",
)
waitForValues(btcValue = "10000", fiatValue = "10.00")
assertPersistedValues(btcValue = "10000", fiatValue = "10.00")
}

private fun createCalculatorViewModel(): CalculatorViewModel {
Expand All@@ -206,80 +193,70 @@ class CalculatorCardIntegrationTest {
)[CalculatorViewModel::class.java]
}

private fun setCalculatorCard() {
private fun setCalculatorWidget() {
composeTestRule.setContent {
AppThemeSurface {
CalculatorCard(
calculatorViewModel = calculatorViewModel,
modifier = Modifier.fillMaxWidth()
)
val state by calculatorViewModel.uiState.collectAsState()
Box(modifier = Modifier.fillMaxSize()) {
CalculatorCard(
btcPrimaryDisplayUnit = state.displayUnit,
btcValue = state.btcValue,
fiatSymbol = state.currencySymbol,
fiatName = state.selectedCurrency,
fiatValue = state.fiatValue,
activeInput = state.activeInput,
onSelectInput = calculatorViewModel::onInputSelected,
modifier = Modifier.fillMaxWidth()
)
state.activeInput?.let { active ->
CalculatorNumberPadBar(
activeInput = active,
btcValue = state.btcValue,
fiatValue = state.fiatValue,
btcPrimaryDisplayUnit = state.displayUnit,
onBtcChange = calculatorViewModel::onBtcInputChanged,
onFiatChange = calculatorViewModel::onFiatInputChanged,
modifier = Modifier.align(Alignment.BottomCenter)
)
}
}
}
}
composeTestRule.waitForIdle()
}

private fun awaitNumberPad() {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
composeTestRule.onAllNodes(hasSetTextAction()).fetchSemanticsNodes().size == INPUT_COUNT
composeTestRule.onAllNodesWithTag(NUMBER_PAD_TAG).fetchSemanticsNodes().isNotEmpty()
}
}

private fun inputAt(index: Int) = composeTestRule.onAllNodes(hasSetTextAction())[index]

private fun replaceInput(
index: Int,
text: String,
) {
inputAt(index).performTextClearance()
inputAt(index).performTextInput(text)
private fun tapKeys(vararg keys: String) {
keys.forEach { key ->
composeTestRule.onNodeWithTag(key).performClick()
composeTestRule.waitForIdle()
}
}

private fun waitForValues(
btcValue: String,
fiatValue: String,
) {
runCatching {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
calculatorViewModel.uiState.value.btcValue == btcValue &&
calculatorViewModel.uiState.value.fiatValue == fiatValue
}
}.onFailure {
throw AssertionError(
buildString {
append("Expected calculatorValues btcValue='$btcValue', fiatValue='$fiatValue', ")
append("but was '${calculatorViewModel.uiState.value}'. Persisted values were ")
append("'${widgetsRepo.widgetsDataFlow.value.calculatorValues}'. Semantics tree:\n")
append(composeTestRule.onRoot(useUnmergedTree = true).printToString())
},
it,
)
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
calculatorViewModel.uiState.value.btcValue == btcValue &&
calculatorViewModel.uiState.value.fiatValue == fiatValue
}

val expectedValues = CalculatorValues(
btcValue = btcValue,
fiatValue = fiatValue,
satsValue = btcValue.toLong(),
displayUnit = BitcoinDisplayUnit.MODERN,
)
runCatching {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
widgetsRepo.widgetsDataFlow.value.calculatorValues == expectedValues
}
}.onFailure {
throw AssertionError(
"Expected persisted values '$expectedValues', but was " +
"'${widgetsRepo.widgetsDataFlow.value.calculatorValues}'",
it,
)
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
widgetsRepo.widgetsDataFlow.value.calculatorValues == expectedValues
}
}

private fun assertInputText(
inputIndex: Int,
text: String,
) {
inputAt(inputIndex).assertTextContains(text, substring = true)
composeTestRule.onNode(hasText(text, substring = true), useUnmergedTree = true)
.assertIsDisplayed()
}

private fun assertPersistedValues(
btcValue: String,
fiatValue: String,
Expand All@@ -296,9 +273,9 @@ class CalculatorCardIntegrationTest {
}

companion object {
private const val BTC_INPUT_INDEX = 0
private const val FIAT_INPUT_INDEX = 1
private const val INPUT_COUNT = 2
private const val BTC_INPUT_TAG = "CalculatorBtcInput"
private const val FIAT_INPUT_TAG = "CalculatorFiatInput"
private const val NUMBER_PAD_TAG = "CalculatorNumberPad"
private const val TIMEOUT_MS = 5_000L
private const val TEST_CREATED_AT = 0L
private const val TEST_USD_RATE = "100000"
Expand DownExpand Up@@ -330,6 +307,7 @@ class CalculatorCardIntegrationTest {

@Provides
@Named("enablePolling")
@Suppress("FunctionOnlyReturningConstant")
fun provideEnablePolling(): Boolean = false
}
}
38 changes: 28 additions & 10 deletions app/src/main/java/to/bitkit/data/WidgetsStore.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ import to.bitkit.data.dto.BlockDTO
import to.bitkit.data.dto.WeatherDTO
import to.bitkit.data.dto.price.PriceDTO
import to.bitkit.data.serializers.WidgetsSerializer
import to.bitkit.models.WidgetSize
import to.bitkit.models.WidgetType
import to.bitkit.models.WidgetWithPosition
import to.bitkit.models.WidgetsBackupV1
Expand DownExpand Up@@ -123,15 +124,28 @@ class WidgetsStore @Inject constructor(
Logger.info("Deleted all widgets data.")
}

suspend fun addWidget(type: WidgetType) {
if (store.data.first().widgets.map { it.type }.contains(type)) return
suspend fun addWidget(type: WidgetType, size: WidgetSize = WidgetSize.default(type)) {
store.updateData { data ->
val existing = data.widgets.firstOrNull { it.type == type }
if (existing != null) {
data.copy(
widgets = data.widgets
.map { if (it.type == type) it.copy(size = size) else it }
.sortedBy { it.position }
)
} else {
val nextPosition = (data.widgets.maxOfOrNull { it.position } ?: -1) + 1
data.copy(
widgets = (data.widgets + WidgetWithPosition(type = type, position = nextPosition, size = size))
.sortedBy { it.position }
)
}
}
}

suspend fun updateWidgetSize(type: WidgetType, size: WidgetSize) {
store.updateData { data ->
val nextPosition = (data.widgets.maxOfOrNull { it.position } ?: -1) + 1
data.copy(
widgets = (data.widgets + WidgetWithPosition(type = type, position = nextPosition))
.sortedBy { it.position }
)
data.copy(widgets = data.widgets.map { if (it.type == type) it.copy(size = size) else it })
}
}

Expand DownExpand Up@@ -161,9 +175,13 @@ class WidgetsStore @Inject constructor(
@Serializable
data class WidgetsData(
val widgets: List<WidgetWithPosition> = listOf(
WidgetWithPosition(type = WidgetType.SUGGESTIONS, position = 0),
WidgetWithPosition(type = WidgetType.PRICE, position = 1),
WidgetWithPosition(type = WidgetType.BLOCK, position = 2),
WidgetWithPosition(type = WidgetType.SUGGESTIONS, position = 0, size = WidgetSize.WIDE),
WidgetWithPosition(type = WidgetType.PRICE, position = 1, size = WidgetSize.WIDE),
WidgetWithPosition(type = WidgetType.BLOCK, position = 2, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.FACTS, position = 3, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.WEATHER, position = 4, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.CALCULATOR, position = 5, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.NEWS, position = 6, size = WidgetSize.WIDE),
),
val headlinePreferences: HeadlinePreferences = HeadlinePreferences(),
val blocksPreferences: BlocksPreferences = BlocksPreferences(),
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/to/bitkit/models/WidgetSize.kt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
package to.bitkit.models

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
enum class WidgetSize {
@SerialName("small")
SMALL,

@SerialName("wide")
WIDE;

companion object {
fun default(type: WidgetType): WidgetSize = when (type) {
WidgetType.PRICE,
WidgetType.NEWS,
WidgetType.SUGGESTIONS,
-> WIDE

else -> SMALL
}
}
}
4 changes: 4 additions & 0 deletions app/src/main/java/to/bitkit/models/WidgetWithPosition.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,4 +8,8 @@ import kotlinx.serialization.Serializable
data class WidgetWithPosition(
val type: WidgetType,
val position: Int = 0,
val size: WidgetSize = WidgetSize.WIDE,
)

fun WidgetWithPosition.effectiveSize(): WidgetSize =
if (type == WidgetType.SUGGESTIONS) WidgetSize.WIDE else size
7 changes: 6 additions & 1 deletion app/src/main/java/to/bitkit/repositories/WidgetsRepo.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,7 @@ import to.bitkit.data.widgets.PriceService
import to.bitkit.data.widgets.WeatherService
import to.bitkit.data.widgets.WidgetService
import to.bitkit.di.BgDispatcher
import to.bitkit.models.WidgetSize
import to.bitkit.models.WidgetType
import to.bitkit.models.WidgetWithPosition
import to.bitkit.models.widget.BlocksPreferences
Expand DownExpand Up@@ -173,7 +174,11 @@ class WidgetsRepo @Inject constructor(
Logger.verbose("Stopped refresh coroutine for $widgetType", context = TAG)
}

suspend fun addWidget(type: WidgetType) = withContext(bgDispatcher) { widgetsStore.addWidget(type) }
suspend fun addWidget(type: WidgetType, size: WidgetSize = WidgetSize.default(type)) =
withContext(bgDispatcher) { widgetsStore.addWidget(type, size) }

suspend fun updateWidgetSize(type: WidgetType, size: WidgetSize) =
withContext(bgDispatcher) { widgetsStore.updateWidgetSize(type, size) }

suspend fun deleteWidget(type: WidgetType) = withContext(bgDispatcher) { widgetsStore.deleteWidget(type) }

Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7718296
feat: widget size data layer logic
jvsena42 Jun 3, 2026
6ea4127
feat: widget size domain logic
jvsena42 Jun 3, 2026
ba646fb
feat: re-enabled compact mode and implement size saving logic
jvsena42 Jun 3, 2026
eabc02e
feat: calculator compact mode
jvsena42 Jun 3, 2026
760a102
feat: data layer
jvsena42 Jun 3, 2026
6e93d8c
feat: widgets grid
jvsena42 Jun 3, 2026
4e7baa4
fix: add a guard to reorder only when target slot changes
jvsena42 Jun 3, 2026
5f577a9
fix: number pad overlap calculator
jvsena42 Jun 3, 2026
00d9216
chore: rename changelog fragment
jvsena42 Jun 3, 2026
f8ee4b6
fix: animate calculator to previous position on number pad dismiss
jvsena42 Jun 3, 2026
7291cb6
fix: remove active orange border
jvsena42 Jun 3, 2026
37f5141
fix: input corner radius
jvsena42 Jun 3, 2026
a2e9000
fix: make calculator preview read-only
jvsena42 Jun 3, 2026
6bee689
fix: display cached calculator value on widget gallery
jvsena42 Jun 3, 2026
6a4c300
fix: drop first emission with default value
jvsena42 Jun 3, 2026
2805dc9
refactor: remove dead code and component renaming
jvsena42 Jun 3, 2026
a1a405e
test: calculator widget instrumented test
jvsena42 Jun 3, 2026
8b26f64
fix: preview crash
jvsena42 Jun 3, 2026
0db04ea
refactor: code cleanup
jvsena42 Jun 3, 2026
799b078
refactor: make isWide immutable for compose stability
jvsena42 Jun 4, 2026
c84244d
refactor: break into smaller self-explanatory private methods
jvsena42 Jun 4, 2026
d9c4778
fix: align name to center
jvsena42 Jun 4, 2026
125c0aa
fix: adapt small card width
jvsena42 Jun 4, 2026
35f64d0
fix: use gray6 bg for all widget cards
jvsena42 Jun 4, 2026
fe00c78
fix: set drag preview alpha
jvsena42 Jun 4, 2026
149f9a0
fix: keep edit screen in back stack from ger
jvsena42 Jun 4, 2026
6822332
fix: always enable widget settings button
jvsena42 Jun 4, 2026
4b6a497
feat: edge-to-edge scroll for widget size pager
jvsena42 Jun 4, 2026
a2d0009
feat: edge-to-edge scroll for widget size pager
jvsena42 Jun 4, 2026
c953b96
fix: remove adjacent page peek in widget carousel
jvsena42 Jun 4, 2026
2ceb8f1
Merge branch 'master' into feat/in-app-v61
jvsena42 Jun 4, 2026
f23f0cb
fix: show decimal placeholder in small calculator
jvsena42 Jun 4, 2026
b2c2cba
fix: disable widget settings only for suggestions
jvsena42 Jun 4, 2026
3d22482
test: CalculatorWidget
piotr-iohk Jun 4, 2026
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
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
package to.bitkit.ui.screens.widgets.calculator

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.assertTextContains
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasSetTextAction
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.test.performTextClearance
import androidx.compose.ui.test.performTextInput
import androidx.compose.ui.test.printToString
import androidx.compose.ui.test.onAllNodesWithTag
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStore
Expand DownExpand Up@@ -50,6 +50,7 @@ import to.bitkit.test.annotations.CalculatorWidget
import to.bitkit.test.annotations.DeviceIntegration
import to.bitkit.test.annotations.DeviceUiIntegration
import to.bitkit.ui.screens.widgets.calculator.components.CalculatorCard
import to.bitkit.ui.screens.widgets.calculator.components.CalculatorNumberPadBar
import to.bitkit.ui.theme.AppThemeSurface
import java.util.Locale
import javax.inject.Inject
Expand All@@ -62,7 +63,7 @@ import kotlin.test.assertEquals
@CalculatorWidget
@DeviceIntegration
@DeviceUiIntegration
class CalculatorCardIntegrationTest {
class CalculatorWidgetInputTest {

@get:Rule
val hiltRule = HiltAndroidRule(this)
Expand DownExpand Up@@ -154,41 +155,27 @@ class CalculatorCardIntegrationTest {
}

@Test
fun btcInputUpdatesFiatValueAndPersistsWidgetState() {
setCalculatorCard()
fun btcInputViaNumberPadUpdatesFiatAndPersistsWidgetState() {
setCalculatorWidget()

replaceInput(BTC_INPUT_INDEX, "12340")
composeTestRule.onNodeWithTag(BTC_INPUT_TAG).performClick()
awaitNumberPad()
tapKeys("N1", "N2", "N3", "N4", "N0")

waitForValues(
btcValue = "12340",
fiatValue = "12.34",
)

assertInputText(BTC_INPUT_INDEX, "12 340")
assertInputText(FIAT_INPUT_INDEX, "12.34")
assertPersistedValues(
btcValue = "12340",
fiatValue = "12.34",
)
waitForValues(btcValue = "12340", fiatValue = "12.34")
assertPersistedValues(btcValue = "12340", fiatValue = "12.34")
}

@Test
fun fiatInputUpdatesBtcValueAndPersistsWidgetState() {
setCalculatorCard()
fun fiatInputViaNumberPadUpdatesBtcAndPersistsWidgetState() {
setCalculatorWidget()

replaceInput(FIAT_INPUT_INDEX, "10.00")
composeTestRule.onNodeWithTag(FIAT_INPUT_TAG).performClick()
awaitNumberPad()
tapKeys("N1", "N0", "NDecimal", "N0", "N0")

waitForValues(
btcValue = "10000",
fiatValue = "10.00",
)

assertInputText(BTC_INPUT_INDEX, "10 000")
assertInputText(FIAT_INPUT_INDEX, "10.00")
assertPersistedValues(
btcValue = "10000",
fiatValue = "10.00",
)
waitForValues(btcValue = "10000", fiatValue = "10.00")
assertPersistedValues(btcValue = "10000", fiatValue = "10.00")
}

private fun createCalculatorViewModel(): CalculatorViewModel {
Expand All@@ -206,80 +193,70 @@ class CalculatorCardIntegrationTest {
)[CalculatorViewModel::class.java]
}

private fun setCalculatorCard() {
private fun setCalculatorWidget() {
composeTestRule.setContent {
AppThemeSurface {
CalculatorCard(
calculatorViewModel = calculatorViewModel,
modifier = Modifier.fillMaxWidth()
)
val state by calculatorViewModel.uiState.collectAsState()
Box(modifier = Modifier.fillMaxSize()) {
CalculatorCard(
btcPrimaryDisplayUnit = state.displayUnit,
btcValue = state.btcValue,
fiatSymbol = state.currencySymbol,
fiatName = state.selectedCurrency,
fiatValue = state.fiatValue,
activeInput = state.activeInput,
onSelectInput = calculatorViewModel::onInputSelected,
modifier = Modifier.fillMaxWidth()
)
state.activeInput?.let { active ->
CalculatorNumberPadBar(
activeInput = active,
btcValue = state.btcValue,
fiatValue = state.fiatValue,
btcPrimaryDisplayUnit = state.displayUnit,
onBtcChange = calculatorViewModel::onBtcInputChanged,
onFiatChange = calculatorViewModel::onFiatInputChanged,
modifier = Modifier.align(Alignment.BottomCenter)
)
}
}
}
}
composeTestRule.waitForIdle()
}

private fun awaitNumberPad() {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
composeTestRule.onAllNodes(hasSetTextAction()).fetchSemanticsNodes().size == INPUT_COUNT
composeTestRule.onAllNodesWithTag(NUMBER_PAD_TAG).fetchSemanticsNodes().isNotEmpty()
}
}

private fun inputAt(index: Int) = composeTestRule.onAllNodes(hasSetTextAction())[index]

private fun replaceInput(
index: Int,
text: String,
) {
inputAt(index).performTextClearance()
inputAt(index).performTextInput(text)
private fun tapKeys(vararg keys: String) {
keys.forEach { key ->
composeTestRule.onNodeWithTag(key).performClick()
composeTestRule.waitForIdle()
}
}

private fun waitForValues(
btcValue: String,
fiatValue: String,
) {
runCatching {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
calculatorViewModel.uiState.value.btcValue == btcValue &&
calculatorViewModel.uiState.value.fiatValue == fiatValue
}
}.onFailure {
throw AssertionError(
buildString {
append("Expected calculatorValues btcValue='$btcValue', fiatValue='$fiatValue', ")
append("but was '${calculatorViewModel.uiState.value}'. Persisted values were ")
append("'${widgetsRepo.widgetsDataFlow.value.calculatorValues}'. Semantics tree:\n")
append(composeTestRule.onRoot(useUnmergedTree = true).printToString())
},
it,
)
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
calculatorViewModel.uiState.value.btcValue == btcValue &&
calculatorViewModel.uiState.value.fiatValue == fiatValue
}

val expectedValues = CalculatorValues(
btcValue = btcValue,
fiatValue = fiatValue,
satsValue = btcValue.toLong(),
displayUnit = BitcoinDisplayUnit.MODERN,
)
runCatching {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
widgetsRepo.widgetsDataFlow.value.calculatorValues == expectedValues
}
}.onFailure {
throw AssertionError(
"Expected persisted values '$expectedValues', but was " +
"'${widgetsRepo.widgetsDataFlow.value.calculatorValues}'",
it,
)
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
widgetsRepo.widgetsDataFlow.value.calculatorValues == expectedValues
}
}

private fun assertInputText(
inputIndex: Int,
text: String,
) {
inputAt(inputIndex).assertTextContains(text, substring = true)
composeTestRule.onNode(hasText(text, substring = true), useUnmergedTree = true)
.assertIsDisplayed()
}

private fun assertPersistedValues(
btcValue: String,
fiatValue: String,
Expand All@@ -296,9 +273,9 @@ class CalculatorCardIntegrationTest {
}

companion object {
private const val BTC_INPUT_INDEX = 0
private const val FIAT_INPUT_INDEX = 1
private const val INPUT_COUNT = 2
private const val BTC_INPUT_TAG = "CalculatorBtcInput"
private const val FIAT_INPUT_TAG = "CalculatorFiatInput"
private const val NUMBER_PAD_TAG = "CalculatorNumberPad"
private const val TIMEOUT_MS = 5_000L
private const val TEST_CREATED_AT = 0L
private const val TEST_USD_RATE = "100000"
Expand DownExpand Up@@ -330,6 +307,7 @@ class CalculatorCardIntegrationTest {

@Provides
@Named("enablePolling")
@Suppress("FunctionOnlyReturningConstant")
fun provideEnablePolling(): Boolean = false
}
}
38 changes: 28 additions & 10 deletions app/src/main/java/to/bitkit/data/WidgetsStore.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ import to.bitkit.data.dto.BlockDTO
import to.bitkit.data.dto.WeatherDTO
import to.bitkit.data.dto.price.PriceDTO
import to.bitkit.data.serializers.WidgetsSerializer
import to.bitkit.models.WidgetSize
import to.bitkit.models.WidgetType
import to.bitkit.models.WidgetWithPosition
import to.bitkit.models.WidgetsBackupV1
Expand DownExpand Up@@ -123,15 +124,28 @@ class WidgetsStore @Inject constructor(
Logger.info("Deleted all widgets data.")
}

suspend fun addWidget(type: WidgetType) {
if (store.data.first().widgets.map { it.type }.contains(type)) return
suspend fun addWidget(type: WidgetType, size: WidgetSize = WidgetSize.default(type)) {
store.updateData { data ->
val existing = data.widgets.firstOrNull { it.type == type }
if (existing != null) {
data.copy(
widgets = data.widgets
.map { if (it.type == type) it.copy(size = size) else it }
.sortedBy { it.position }
)
} else {
val nextPosition = (data.widgets.maxOfOrNull { it.position } ?: -1) + 1
data.copy(
widgets = (data.widgets + WidgetWithPosition(type = type, position = nextPosition, size = size))
.sortedBy { it.position }
)
}
}
}

suspend fun updateWidgetSize(type: WidgetType, size: WidgetSize) {
store.updateData { data ->
val nextPosition = (data.widgets.maxOfOrNull { it.position } ?: -1) + 1
data.copy(
widgets = (data.widgets + WidgetWithPosition(type = type, position = nextPosition))
.sortedBy { it.position }
)
data.copy(widgets = data.widgets.map { if (it.type == type) it.copy(size = size) else it })
}
}

Expand DownExpand Up@@ -161,9 +175,13 @@ class WidgetsStore @Inject constructor(
@Serializable
data class WidgetsData(
val widgets: List<WidgetWithPosition> = listOf(
WidgetWithPosition(type = WidgetType.SUGGESTIONS, position = 0),
WidgetWithPosition(type = WidgetType.PRICE, position = 1),
WidgetWithPosition(type = WidgetType.BLOCK, position = 2),
WidgetWithPosition(type = WidgetType.SUGGESTIONS, position = 0, size = WidgetSize.WIDE),
WidgetWithPosition(type = WidgetType.PRICE, position = 1, size = WidgetSize.WIDE),
WidgetWithPosition(type = WidgetType.BLOCK, position = 2, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.FACTS, position = 3, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.WEATHER, position = 4, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.CALCULATOR, position = 5, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.NEWS, position = 6, size = WidgetSize.WIDE),
),
val headlinePreferences: HeadlinePreferences = HeadlinePreferences(),
val blocksPreferences: BlocksPreferences = BlocksPreferences(),
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/to/bitkit/models/WidgetSize.kt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
package to.bitkit.models

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
enum class WidgetSize {
@SerialName("small")
SMALL,

@SerialName("wide")
WIDE;

companion object {
fun default(type: WidgetType): WidgetSize = when (type) {
WidgetType.PRICE,
WidgetType.NEWS,
WidgetType.SUGGESTIONS,
-> WIDE

else -> SMALL
}
}
}
4 changes: 4 additions & 0 deletions app/src/main/java/to/bitkit/models/WidgetWithPosition.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,4 +8,8 @@ import kotlinx.serialization.Serializable
data class WidgetWithPosition(
val type: WidgetType,
val position: Int = 0,
val size: WidgetSize = WidgetSize.WIDE,
)

fun WidgetWithPosition.effectiveSize(): WidgetSize =
if (type == WidgetType.SUGGESTIONS) WidgetSize.WIDE else size
7 changes: 6 additions & 1 deletion app/src/main/java/to/bitkit/repositories/WidgetsRepo.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,7 @@ import to.bitkit.data.widgets.PriceService
import to.bitkit.data.widgets.WeatherService
import to.bitkit.data.widgets.WidgetService
import to.bitkit.di.BgDispatcher
import to.bitkit.models.WidgetSize
import to.bitkit.models.WidgetType
import to.bitkit.models.WidgetWithPosition
import to.bitkit.models.widget.BlocksPreferences
Expand DownExpand Up@@ -173,7 +174,11 @@ class WidgetsRepo @Inject constructor(
Logger.verbose("Stopped refresh coroutine for $widgetType", context = TAG)
}

suspend fun addWidget(type: WidgetType) = withContext(bgDispatcher) { widgetsStore.addWidget(type) }
suspend fun addWidget(type: WidgetType, size: WidgetSize = WidgetSize.default(type)) =
withContext(bgDispatcher) { widgetsStore.addWidget(type, size) }

suspend fun updateWidgetSize(type: WidgetType, size: WidgetSize) =
withContext(bgDispatcher) { widgetsStore.updateWidgetSize(type, size) }

suspend fun deleteWidget(type: WidgetType) = withContext(bgDispatcher) { widgetsStore.deleteWidget(type) }

Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7718296
feat: widget size data layer logic
jvsena42 Jun 3, 2026
6ea4127
feat: widget size domain logic
jvsena42 Jun 3, 2026
ba646fb
feat: re-enabled compact mode and implement size saving logic
jvsena42 Jun 3, 2026
eabc02e
feat: calculator compact mode
jvsena42 Jun 3, 2026
760a102
feat: data layer
jvsena42 Jun 3, 2026
6e93d8c
feat: widgets grid
jvsena42 Jun 3, 2026
4e7baa4
fix: add a guard to reorder only when target slot changes
jvsena42 Jun 3, 2026
5f577a9
fix: number pad overlap calculator
jvsena42 Jun 3, 2026
00d9216
chore: rename changelog fragment
jvsena42 Jun 3, 2026
f8ee4b6
fix: animate calculator to previous position on number pad dismiss
jvsena42 Jun 3, 2026
7291cb6
fix: remove active orange border
jvsena42 Jun 3, 2026
37f5141
fix: input corner radius
jvsena42 Jun 3, 2026
a2e9000
fix: make calculator preview read-only
jvsena42 Jun 3, 2026
6bee689
fix: display cached calculator value on widget gallery
jvsena42 Jun 3, 2026
6a4c300
fix: drop first emission with default value
jvsena42 Jun 3, 2026
2805dc9
refactor: remove dead code and component renaming
jvsena42 Jun 3, 2026
a1a405e
test: calculator widget instrumented test
jvsena42 Jun 3, 2026
8b26f64
fix: preview crash
jvsena42 Jun 3, 2026
0db04ea
refactor: code cleanup
jvsena42 Jun 3, 2026
799b078
refactor: make isWide immutable for compose stability
jvsena42 Jun 4, 2026
c84244d
refactor: break into smaller self-explanatory private methods
jvsena42 Jun 4, 2026
d9c4778
fix: align name to center
jvsena42 Jun 4, 2026
125c0aa
fix: adapt small card width
jvsena42 Jun 4, 2026
35f64d0
fix: use gray6 bg for all widget cards
jvsena42 Jun 4, 2026
fe00c78
fix: set drag preview alpha
jvsena42 Jun 4, 2026
149f9a0
fix: keep edit screen in back stack from ger
jvsena42 Jun 4, 2026
6822332
fix: always enable widget settings button
jvsena42 Jun 4, 2026
4b6a497
feat: edge-to-edge scroll for widget size pager
jvsena42 Jun 4, 2026
a2d0009
feat: edge-to-edge scroll for widget size pager
jvsena42 Jun 4, 2026
c953b96
fix: remove adjacent page peek in widget carousel
jvsena42 Jun 4, 2026
2ceb8f1
Merge branch 'master' into feat/in-app-v61
jvsena42 Jun 4, 2026
f23f0cb
fix: show decimal placeholder in small calculator
jvsena42 Jun 4, 2026
b2c2cba
fix: disable widget settings only for suggestions
jvsena42 Jun 4, 2026
3d22482
test: CalculatorWidget
piotr-iohk Jun 4, 2026
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
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
package to.bitkit.ui.screens.widgets.calculator

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.assertTextContains
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasSetTextAction
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.test.performTextClearance
import androidx.compose.ui.test.performTextInput
import androidx.compose.ui.test.printToString
import androidx.compose.ui.test.onAllNodesWithTag
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStore
Expand DownExpand Up@@ -50,6 +50,7 @@ import to.bitkit.test.annotations.CalculatorWidget
import to.bitkit.test.annotations.DeviceIntegration
import to.bitkit.test.annotations.DeviceUiIntegration
import to.bitkit.ui.screens.widgets.calculator.components.CalculatorCard
import to.bitkit.ui.screens.widgets.calculator.components.CalculatorNumberPadBar
import to.bitkit.ui.theme.AppThemeSurface
import java.util.Locale
import javax.inject.Inject
Expand All@@ -62,7 +63,7 @@ import kotlin.test.assertEquals
@CalculatorWidget
@DeviceIntegration
@DeviceUiIntegration
class CalculatorCardIntegrationTest {
class CalculatorWidgetInputTest {

@get:Rule
val hiltRule = HiltAndroidRule(this)
Expand DownExpand Up@@ -154,41 +155,27 @@ class CalculatorCardIntegrationTest {
}

@Test
fun btcInputUpdatesFiatValueAndPersistsWidgetState() {
setCalculatorCard()
fun btcInputViaNumberPadUpdatesFiatAndPersistsWidgetState() {
setCalculatorWidget()

replaceInput(BTC_INPUT_INDEX, "12340")
composeTestRule.onNodeWithTag(BTC_INPUT_TAG).performClick()
awaitNumberPad()
tapKeys("N1", "N2", "N3", "N4", "N0")

waitForValues(
btcValue = "12340",
fiatValue = "12.34",
)

assertInputText(BTC_INPUT_INDEX, "12 340")
assertInputText(FIAT_INPUT_INDEX, "12.34")
assertPersistedValues(
btcValue = "12340",
fiatValue = "12.34",
)
waitForValues(btcValue = "12340", fiatValue = "12.34")
assertPersistedValues(btcValue = "12340", fiatValue = "12.34")
}

@Test
fun fiatInputUpdatesBtcValueAndPersistsWidgetState() {
setCalculatorCard()
fun fiatInputViaNumberPadUpdatesBtcAndPersistsWidgetState() {
setCalculatorWidget()

replaceInput(FIAT_INPUT_INDEX, "10.00")
composeTestRule.onNodeWithTag(FIAT_INPUT_TAG).performClick()
awaitNumberPad()
tapKeys("N1", "N0", "NDecimal", "N0", "N0")

waitForValues(
btcValue = "10000",
fiatValue = "10.00",
)

assertInputText(BTC_INPUT_INDEX, "10 000")
assertInputText(FIAT_INPUT_INDEX, "10.00")
assertPersistedValues(
btcValue = "10000",
fiatValue = "10.00",
)
waitForValues(btcValue = "10000", fiatValue = "10.00")
assertPersistedValues(btcValue = "10000", fiatValue = "10.00")
}

private fun createCalculatorViewModel(): CalculatorViewModel {
Expand All@@ -206,80 +193,70 @@ class CalculatorCardIntegrationTest {
)[CalculatorViewModel::class.java]
}

private fun setCalculatorCard() {
private fun setCalculatorWidget() {
composeTestRule.setContent {
AppThemeSurface {
CalculatorCard(
calculatorViewModel = calculatorViewModel,
modifier = Modifier.fillMaxWidth()
)
val state by calculatorViewModel.uiState.collectAsState()
Box(modifier = Modifier.fillMaxSize()) {
CalculatorCard(
btcPrimaryDisplayUnit = state.displayUnit,
btcValue = state.btcValue,
fiatSymbol = state.currencySymbol,
fiatName = state.selectedCurrency,
fiatValue = state.fiatValue,
activeInput = state.activeInput,
onSelectInput = calculatorViewModel::onInputSelected,
modifier = Modifier.fillMaxWidth()
)
state.activeInput?.let { active ->
CalculatorNumberPadBar(
activeInput = active,
btcValue = state.btcValue,
fiatValue = state.fiatValue,
btcPrimaryDisplayUnit = state.displayUnit,
onBtcChange = calculatorViewModel::onBtcInputChanged,
onFiatChange = calculatorViewModel::onFiatInputChanged,
modifier = Modifier.align(Alignment.BottomCenter)
)
}
}
}
}
composeTestRule.waitForIdle()
}

private fun awaitNumberPad() {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
composeTestRule.onAllNodes(hasSetTextAction()).fetchSemanticsNodes().size == INPUT_COUNT
composeTestRule.onAllNodesWithTag(NUMBER_PAD_TAG).fetchSemanticsNodes().isNotEmpty()
}
}

private fun inputAt(index: Int) = composeTestRule.onAllNodes(hasSetTextAction())[index]

private fun replaceInput(
index: Int,
text: String,
) {
inputAt(index).performTextClearance()
inputAt(index).performTextInput(text)
private fun tapKeys(vararg keys: String) {
keys.forEach { key ->
composeTestRule.onNodeWithTag(key).performClick()
composeTestRule.waitForIdle()
}
}

private fun waitForValues(
btcValue: String,
fiatValue: String,
) {
runCatching {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
calculatorViewModel.uiState.value.btcValue == btcValue &&
calculatorViewModel.uiState.value.fiatValue == fiatValue
}
}.onFailure {
throw AssertionError(
buildString {
append("Expected calculatorValues btcValue='$btcValue', fiatValue='$fiatValue', ")
append("but was '${calculatorViewModel.uiState.value}'. Persisted values were ")
append("'${widgetsRepo.widgetsDataFlow.value.calculatorValues}'. Semantics tree:\n")
append(composeTestRule.onRoot(useUnmergedTree = true).printToString())
},
it,
)
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
calculatorViewModel.uiState.value.btcValue == btcValue &&
calculatorViewModel.uiState.value.fiatValue == fiatValue
}

val expectedValues = CalculatorValues(
btcValue = btcValue,
fiatValue = fiatValue,
satsValue = btcValue.toLong(),
displayUnit = BitcoinDisplayUnit.MODERN,
)
runCatching {
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
widgetsRepo.widgetsDataFlow.value.calculatorValues == expectedValues
}
}.onFailure {
throw AssertionError(
"Expected persisted values '$expectedValues', but was " +
"'${widgetsRepo.widgetsDataFlow.value.calculatorValues}'",
it,
)
composeTestRule.waitUntil(timeoutMillis = TIMEOUT_MS) {
widgetsRepo.widgetsDataFlow.value.calculatorValues == expectedValues
}
}

private fun assertInputText(
inputIndex: Int,
text: String,
) {
inputAt(inputIndex).assertTextContains(text, substring = true)
composeTestRule.onNode(hasText(text, substring = true), useUnmergedTree = true)
.assertIsDisplayed()
}

private fun assertPersistedValues(
btcValue: String,
fiatValue: String,
Expand All@@ -296,9 +273,9 @@ class CalculatorCardIntegrationTest {
}

companion object {
private const val BTC_INPUT_INDEX = 0
private const val FIAT_INPUT_INDEX = 1
private const val INPUT_COUNT = 2
private const val BTC_INPUT_TAG = "CalculatorBtcInput"
private const val FIAT_INPUT_TAG = "CalculatorFiatInput"
private const val NUMBER_PAD_TAG = "CalculatorNumberPad"
private const val TIMEOUT_MS = 5_000L
private const val TEST_CREATED_AT = 0L
private const val TEST_USD_RATE = "100000"
Expand DownExpand Up@@ -330,6 +307,7 @@ class CalculatorCardIntegrationTest {

@Provides
@Named("enablePolling")
@Suppress("FunctionOnlyReturningConstant")
fun provideEnablePolling(): Boolean = false
}
}
38 changes: 28 additions & 10 deletions app/src/main/java/to/bitkit/data/WidgetsStore.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ import to.bitkit.data.dto.BlockDTO
import to.bitkit.data.dto.WeatherDTO
import to.bitkit.data.dto.price.PriceDTO
import to.bitkit.data.serializers.WidgetsSerializer
import to.bitkit.models.WidgetSize
import to.bitkit.models.WidgetType
import to.bitkit.models.WidgetWithPosition
import to.bitkit.models.WidgetsBackupV1
Expand DownExpand Up@@ -123,15 +124,28 @@ class WidgetsStore @Inject constructor(
Logger.info("Deleted all widgets data.")
}

suspend fun addWidget(type: WidgetType) {
if (store.data.first().widgets.map { it.type }.contains(type)) return
suspend fun addWidget(type: WidgetType, size: WidgetSize = WidgetSize.default(type)) {
store.updateData { data ->
val existing = data.widgets.firstOrNull { it.type == type }
if (existing != null) {
data.copy(
widgets = data.widgets
.map { if (it.type == type) it.copy(size = size) else it }
.sortedBy { it.position }
)
} else {
val nextPosition = (data.widgets.maxOfOrNull { it.position } ?: -1) + 1
data.copy(
widgets = (data.widgets + WidgetWithPosition(type = type, position = nextPosition, size = size))
.sortedBy { it.position }
)
}
}
}

suspend fun updateWidgetSize(type: WidgetType, size: WidgetSize) {
store.updateData { data ->
val nextPosition = (data.widgets.maxOfOrNull { it.position } ?: -1) + 1
data.copy(
widgets = (data.widgets + WidgetWithPosition(type = type, position = nextPosition))
.sortedBy { it.position }
)
data.copy(widgets = data.widgets.map { if (it.type == type) it.copy(size = size) else it })
}
}

Expand DownExpand Up@@ -161,9 +175,13 @@ class WidgetsStore @Inject constructor(
@Serializable
data class WidgetsData(
val widgets: List<WidgetWithPosition> = listOf(
WidgetWithPosition(type = WidgetType.SUGGESTIONS, position = 0),
WidgetWithPosition(type = WidgetType.PRICE, position = 1),
WidgetWithPosition(type = WidgetType.BLOCK, position = 2),
WidgetWithPosition(type = WidgetType.SUGGESTIONS, position = 0, size = WidgetSize.WIDE),
WidgetWithPosition(type = WidgetType.PRICE, position = 1, size = WidgetSize.WIDE),
WidgetWithPosition(type = WidgetType.BLOCK, position = 2, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.FACTS, position = 3, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.WEATHER, position = 4, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.CALCULATOR, position = 5, size = WidgetSize.SMALL),
WidgetWithPosition(type = WidgetType.NEWS, position = 6, size = WidgetSize.WIDE),
),
val headlinePreferences: HeadlinePreferences = HeadlinePreferences(),
val blocksPreferences: BlocksPreferences = BlocksPreferences(),
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/to/bitkit/models/WidgetSize.kt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
package to.bitkit.models

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
enum class WidgetSize {
@SerialName("small")
SMALL,

@SerialName("wide")
WIDE;

companion object {
fun default(type: WidgetType): WidgetSize = when (type) {
WidgetType.PRICE,
WidgetType.NEWS,
WidgetType.SUGGESTIONS,
-> WIDE

else -> SMALL
}
}
}
4 changes: 4 additions & 0 deletions app/src/main/java/to/bitkit/models/WidgetWithPosition.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,4 +8,8 @@ import kotlinx.serialization.Serializable
data class WidgetWithPosition(
val type: WidgetType,
val position: Int = 0,
val size: WidgetSize = WidgetSize.WIDE,
)

fun WidgetWithPosition.effectiveSize(): WidgetSize =
if (type == WidgetType.SUGGESTIONS) WidgetSize.WIDE else size
7 changes: 6 additions & 1 deletion app/src/main/java/to/bitkit/repositories/WidgetsRepo.kt
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,7 @@ import to.bitkit.data.widgets.PriceService
import to.bitkit.data.widgets.WeatherService
import to.bitkit.data.widgets.WidgetService
import to.bitkit.di.BgDispatcher
import to.bitkit.models.WidgetSize
import to.bitkit.models.WidgetType
import to.bitkit.models.WidgetWithPosition
import to.bitkit.models.widget.BlocksPreferences
Expand DownExpand Up@@ -173,7 +174,11 @@ class WidgetsRepo @Inject constructor(
Logger.verbose("Stopped refresh coroutine for $widgetType", context = TAG)
}

suspend fun addWidget(type: WidgetType) = withContext(bgDispatcher) { widgetsStore.addWidget(type) }
suspend fun addWidget(type: WidgetType, size: WidgetSize = WidgetSize.default(type)) =
withContext(bgDispatcher) { widgetsStore.addWidget(type, size) }

suspend fun updateWidgetSize(type: WidgetType, size: WidgetSize) =
withContext(bgDispatcher) { widgetsStore.updateWidgetSize(type, size) }

suspend fun deleteWidget(type: WidgetType) = withContext(bgDispatcher) { widgetsStore.deleteWidget(type) }

Expand Down
Loading
Loading