Skip to content

Commit c666e85

Browse files
authored
Merge pull request #956 from synonymdev/fix/blocks-widget-948
fix: limit blocks widget to 4 fields
2 parents 7116e00 + 6c2de25 commit c666e85

37 files changed

Lines changed: 411 additions & 652 deletions

File tree

app/src/androidTest/java/to/bitkit/ui/screens/widgets/blocks/BlockCardTest.kt

Lines changed: 71 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import androidx.compose.ui.test.junit4.createComposeRule
55
import androidx.compose.ui.test.onNodeWithTag
66
import org.junit.Rule
77
import org.junit.Test
8+
import to.bitkit.models.widget.BlockModel
9+
import to.bitkit.models.widget.BlocksPreferences
810
import to.bitkit.test.annotations.ComposeUi
911
import to.bitkit.ui.theme.AppThemeSurface
1012

@@ -20,27 +22,23 @@ class BlockCardTest {
2022
private val testTransactions = "2,175"
2123
private val testSize = "1,606Kb"
2224
private val testFees = "25 059 357"
23-
private val testSource = "mempool.io"
25+
26+
private val fullBlock = BlockModel(
27+
height = testBlock,
28+
time = testTime,
29+
date = testDate,
30+
transactionCount = testTransactions,
31+
size = testSize,
32+
fees = testFees,
33+
)
2434

2535
@Test
26-
fun testBlockCardWithAllElements() {
36+
fun testBlockCardWithDefaultFields() {
2737
composeTestRule.setContent {
2838
AppThemeSurface {
2939
BlockCard(
30-
showBlock = true,
31-
showTime = true,
32-
showDate = true,
33-
showTransactions = true,
34-
showSize = true,
35-
showFees = true,
36-
showSource = true,
37-
block = testBlock,
38-
time = testTime,
39-
date = testDate,
40-
transactions = testTransactions,
41-
size = testSize,
42-
fees = testFees,
43-
source = testSource,
40+
preferences = BlocksPreferences(),
41+
block = fullBlock,
4442
)
4543
}
4644
}
@@ -49,66 +47,58 @@ class BlockCardTest {
4947
composeTestRule.onNodeWithTag("time_row", useUnmergedTree = true).assertExists()
5048
composeTestRule.onNodeWithTag("date_row", useUnmergedTree = true).assertExists()
5149
composeTestRule.onNodeWithTag("transactions_row", useUnmergedTree = true).assertExists()
52-
composeTestRule.onNodeWithTag("size_row", useUnmergedTree = true).assertExists()
53-
composeTestRule.onNodeWithTag("fees_row", useUnmergedTree = true).assertExists()
54-
composeTestRule.onNodeWithTag("source_row", useUnmergedTree = true).assertExists()
50+
composeTestRule.onNodeWithTag("size_row", useUnmergedTree = true).assertDoesNotExist()
51+
composeTestRule.onNodeWithTag("fees_row", useUnmergedTree = true).assertDoesNotExist()
5552

5653
composeTestRule.onNodeWithTag("block_text", useUnmergedTree = true).assertTextEquals(testBlock)
5754
composeTestRule.onNodeWithTag("time_text", useUnmergedTree = true).assertTextEquals(testTime)
5855
composeTestRule.onNodeWithTag("date_text", useUnmergedTree = true).assertTextEquals(testDate)
5956
composeTestRule.onNodeWithTag("transactions_text", useUnmergedTree = true).assertTextEquals(testTransactions)
60-
composeTestRule.onNodeWithTag("size_text", useUnmergedTree = true).assertTextEquals(testSize)
61-
composeTestRule.onNodeWithTag("fees_text", useUnmergedTree = true).assertTextEquals(testFees)
62-
composeTestRule.onNodeWithTag("source_text", useUnmergedTree = true).assertTextEquals(testSource)
6357
}
6458

6559
@Test
66-
fun testBlockCardWithoutSource() {
60+
fun testBlockCardWithSizeAndFees() {
6761
composeTestRule.setContent {
6862
AppThemeSurface {
6963
BlockCard(
70-
showBlock = true,
71-
showTime = true,
72-
showDate = true,
73-
showTransactions = true,
74-
showSize = true,
75-
showFees = true,
76-
showSource = false,
77-
block = testBlock,
78-
time = testTime,
79-
date = testDate,
80-
transactions = testTransactions,
81-
size = testSize,
82-
fees = testFees,
83-
source = testSource,
64+
preferences = BlocksPreferences(
65+
showBlock = true,
66+
showTime = true,
67+
showDate = false,
68+
showTransactions = false,
69+
showSize = true,
70+
showFees = true,
71+
),
72+
block = fullBlock,
8473
)
8574
}
8675
}
8776

8877
composeTestRule.onNodeWithTag("block_row", useUnmergedTree = true).assertExists()
89-
composeTestRule.onNodeWithTag("source_row", useUnmergedTree = true).assertDoesNotExist()
90-
composeTestRule.onNodeWithTag("source_text", useUnmergedTree = true).assertDoesNotExist()
78+
composeTestRule.onNodeWithTag("time_row", useUnmergedTree = true).assertExists()
79+
composeTestRule.onNodeWithTag("size_row", useUnmergedTree = true).assertExists()
80+
composeTestRule.onNodeWithTag("fees_row", useUnmergedTree = true).assertExists()
81+
composeTestRule.onNodeWithTag("date_row", useUnmergedTree = true).assertDoesNotExist()
82+
composeTestRule.onNodeWithTag("transactions_row", useUnmergedTree = true).assertDoesNotExist()
83+
84+
composeTestRule.onNodeWithTag("size_text", useUnmergedTree = true).assertTextEquals(testSize)
85+
composeTestRule.onNodeWithTag("fees_text", useUnmergedTree = true).assertTextEquals(testFees)
9186
}
9287

9388
@Test
9489
fun testBlockCardWithoutFees() {
9590
composeTestRule.setContent {
9691
AppThemeSurface {
9792
BlockCard(
98-
showBlock = true,
99-
showTime = true,
100-
showDate = true,
101-
showTransactions = true,
102-
showSize = true,
103-
showFees = false,
104-
showSource = true,
105-
block = testBlock,
106-
time = testTime,
107-
date = testDate,
108-
transactions = testTransactions,
109-
size = testSize,
110-
fees = testFees,
111-
source = testSource,
93+
preferences = BlocksPreferences(
94+
showBlock = true,
95+
showTime = true,
96+
showDate = true,
97+
showTransactions = false,
98+
showSize = false,
99+
showFees = false,
100+
),
101+
block = fullBlock,
112102
)
113103
}
114104
}
@@ -123,20 +113,22 @@ class BlockCardTest {
123113
composeTestRule.setContent {
124114
AppThemeSurface {
125115
BlockCard(
126-
showBlock = true,
127-
showTime = false,
128-
showDate = false,
129-
showTransactions = false,
130-
showSize = false,
131-
showFees = false,
132-
showSource = false,
133-
block = testBlock,
134-
time = "",
135-
date = "",
136-
transactions = "",
137-
size = "",
138-
fees = "",
139-
source = "",
116+
preferences = BlocksPreferences(
117+
showBlock = true,
118+
showTime = false,
119+
showDate = false,
120+
showTransactions = false,
121+
showSize = false,
122+
showFees = false,
123+
),
124+
block = BlockModel(
125+
height = testBlock,
126+
time = "",
127+
date = "",
128+
transactionCount = "",
129+
size = "",
130+
fees = "",
131+
),
140132
)
141133
}
142134
}
@@ -147,28 +139,22 @@ class BlockCardTest {
147139
composeTestRule.onNodeWithTag("transactions_row", useUnmergedTree = true).assertDoesNotExist()
148140
composeTestRule.onNodeWithTag("size_row", useUnmergedTree = true).assertDoesNotExist()
149141
composeTestRule.onNodeWithTag("fees_row", useUnmergedTree = true).assertDoesNotExist()
150-
composeTestRule.onNodeWithTag("source_row", useUnmergedTree = true).assertDoesNotExist()
151142
}
152143

153144
@Test
154145
fun testBlockCardWithEmptyValues() {
155146
composeTestRule.setContent {
156147
AppThemeSurface {
157148
BlockCard(
158-
showBlock = true,
159-
showTime = true,
160-
showDate = true,
161-
showTransactions = true,
162-
showSize = true,
163-
showFees = true,
164-
showSource = true,
165-
block = "",
166-
time = "",
167-
date = "",
168-
transactions = "",
169-
size = "",
170-
fees = "",
171-
source = "",
149+
preferences = BlocksPreferences(),
150+
block = BlockModel(
151+
height = "",
152+
time = "",
153+
date = "",
154+
transactionCount = "",
155+
size = "",
156+
fees = "",
157+
),
172158
)
173159
}
174160
}
@@ -179,28 +165,15 @@ class BlockCardTest {
179165
composeTestRule.onNodeWithTag("transactions_row", useUnmergedTree = true).assertDoesNotExist()
180166
composeTestRule.onNodeWithTag("size_row", useUnmergedTree = true).assertDoesNotExist()
181167
composeTestRule.onNodeWithTag("fees_row", useUnmergedTree = true).assertDoesNotExist()
182-
composeTestRule.onNodeWithTag("source_row", useUnmergedTree = true).assertDoesNotExist()
183168
}
184169

185170
@Test
186-
fun testBlockCardSmallWithAllElements() {
171+
fun testBlockCardSmallWithDefaultFields() {
187172
composeTestRule.setContent {
188173
AppThemeSurface {
189174
BlockCardSmall(
190-
showBlock = true,
191-
showTime = true,
192-
showDate = true,
193-
showTransactions = true,
194-
showSize = true,
195-
showFees = true,
196-
showSource = true,
197-
block = testBlock,
198-
time = testTime,
199-
date = testDate,
200-
transactions = testTransactions,
201-
size = testSize,
202-
fees = testFees,
203-
source = testSource,
175+
preferences = BlocksPreferences(),
176+
block = fullBlock,
204177
)
205178
}
206179
}

app/src/main/java/to/bitkit/appwidget/config/AppWidgetConfigScreen.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,7 @@ fun AppWidgetConfigScreen(
3434

3535
AppWidgetType.BLOCKS -> BlocksConfigContent(
3636
state = state,
37-
onToggleBlock = { viewModel.toggleBlockShowBlock() },
38-
onToggleTime = { viewModel.toggleBlockShowTime() },
39-
onToggleDate = { viewModel.toggleBlockShowDate() },
40-
onToggleTransactions = { viewModel.toggleBlockShowTransactions() },
41-
onToggleSize = { viewModel.toggleBlockShowSize() },
42-
onToggleFees = { viewModel.toggleBlockShowFees() },
43-
onToggleSource = { viewModel.toggleBlockShowSource() },
37+
onToggleField = { viewModel.toggleBlockField(it) },
4438
onReset = { viewModel.resetPreferences() },
4539
onSave = { viewModel.saveAndFinish(onConfirm) },
4640
onCancel = onCancel,

app/src/main/java/to/bitkit/appwidget/config/AppWidgetConfigViewModel.kt

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import to.bitkit.data.dto.price.GraphPeriod
2525
import to.bitkit.data.dto.price.TradingPair
2626
import to.bitkit.models.widget.ArticleModel
2727
import to.bitkit.models.widget.BlocksPreferences
28+
import to.bitkit.models.widget.BlocksWidgetField
29+
import to.bitkit.models.widget.toggleField
2830
import to.bitkit.models.widget.HeadlinePreferences
2931
import to.bitkit.models.widget.PricePreferences
3032
import to.bitkit.models.widget.WeatherDataOption
@@ -118,49 +120,9 @@ class AppWidgetConfigViewModel @Inject constructor(
118120
}
119121
}
120122

121-
fun toggleBlockShowBlock() {
123+
fun toggleBlockField(field: BlocksWidgetField) {
122124
_uiState.update {
123-
it.copy(blocksPreferences = it.blocksPreferences.copy(showBlock = !it.blocksPreferences.showBlock))
124-
}
125-
}
126-
127-
fun toggleBlockShowTime() {
128-
_uiState.update {
129-
it.copy(blocksPreferences = it.blocksPreferences.copy(showTime = !it.blocksPreferences.showTime))
130-
}
131-
}
132-
133-
fun toggleBlockShowDate() {
134-
_uiState.update {
135-
it.copy(blocksPreferences = it.blocksPreferences.copy(showDate = !it.blocksPreferences.showDate))
136-
}
137-
}
138-
139-
fun toggleBlockShowTransactions() {
140-
_uiState.update {
141-
it.copy(
142-
blocksPreferences = it.blocksPreferences.copy(
143-
showTransactions = !it.blocksPreferences.showTransactions,
144-
),
145-
)
146-
}
147-
}
148-
149-
fun toggleBlockShowSize() {
150-
_uiState.update {
151-
it.copy(blocksPreferences = it.blocksPreferences.copy(showSize = !it.blocksPreferences.showSize))
152-
}
153-
}
154-
155-
fun toggleBlockShowFees() {
156-
_uiState.update {
157-
it.copy(blocksPreferences = it.blocksPreferences.copy(showFees = !it.blocksPreferences.showFees))
158-
}
159-
}
160-
161-
fun toggleBlockShowSource() {
162-
_uiState.update {
163-
it.copy(blocksPreferences = it.blocksPreferences.copy(showSource = !it.blocksPreferences.showSource))
125+
it.copy(blocksPreferences = it.blocksPreferences.toggleField(field))
164126
}
165127
}
166128

@@ -307,7 +269,6 @@ private fun HomeBlocksPreferences.toInApp() = BlocksPreferences(
307269
showTransactions = showTransactions,
308270
showSize = showSize,
309271
showFees = showFees,
310-
showSource = showSource,
311272
)
312273

313274
private fun BlocksPreferences.toHome() = HomeBlocksPreferences(
@@ -317,7 +278,6 @@ private fun BlocksPreferences.toHome() = HomeBlocksPreferences(
317278
showTransactions = showTransactions,
318279
showSize = showSize,
319280
showFees = showFees,
320-
showSource = showSource,
321281
)
322282

323283
private fun HomeWeatherPreferences.toInApp() = WeatherPreferences(selectedOption = selectedOption)

0 commit comments

Comments
 (0)