Skip to content

Commit a488d26

Browse files
committed
feat: handle widget visibility from settings
1 parent f7e9b3a commit a488d26

File tree

2 files changed

+36
-26
lines changed

2 files changed

+36
-26
lines changed

app/src/main/java/to/bitkit/ui/screens/wallets/HomeScreen.kt

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ fun HomeScreen(
164164
composable<HomeRoutes.Home> {
165165
val homeViewModel: HomeViewModel = hiltViewModel()
166166
val suggestions by homeViewModel.suggestions.collectAsStateWithLifecycle()
167+
val showWidgets by homeViewModel.showWidgets.collectAsStateWithLifecycle(initialValue = true)
167168
val context = LocalContext.current
168169
val hasSeenTransferIntro by settingsViewModel.hasSeenTransferIntro.collectAsStateWithLifecycle()
169170
val hasSeenShopIntro by settingsViewModel.hasSeenShopIntro.collectAsStateWithLifecycle()
@@ -174,6 +175,7 @@ fun HomeScreen(
174175

175176
HomeContentView(
176177
uiState = uiState,
178+
showWidgets = showWidgets,
177179
article = article,
178180
suggestions = suggestions,
179181
rootNavController = rootNavController,
@@ -325,6 +327,7 @@ fun HomeScreen(
325327
private fun HomeContentView(
326328
uiState: MainUiState,
327329
article: ArticleModel?,
330+
showWidgets: Boolean,
328331
suggestions: List<Suggestion>,
329332
onRemoveSuggestion: (Suggestion) -> Unit,
330333
onClickSuggestion: (Suggestion) -> Unit,
@@ -423,35 +426,41 @@ private fun HomeContentView(
423426
}
424427
}
425428
}
426-
Spacer(modifier = Modifier.height(32.dp))
427-
Text13Up(stringResource(R.string.widgets__widgets), color = Colors.White64) //TODO check widgets visibility from settings
428429

429-
Column(modifier = Modifier.fillMaxWidth()) { //TODO IMPLEMENT DRAGABLE IN OTHER PR
430-
Spacer(modifier = Modifier.height(16.dp))
430+
if (showWidgets) {
431+
Spacer(modifier = Modifier.height(32.dp))
432+
Text13Up(
433+
stringResource(R.string.widgets__widgets),
434+
color = Colors.White64
435+
)
431436

432-
article?.let {
433-
HeadlineCard( //TODO CHECK PREFERENCES
434-
modifier = Modifier.fillMaxWidth(),
435-
headline = article.title,
436-
time = article.timeAgo,
437-
source = article.publisher,
438-
link = article.link
439-
)
437+
Column(modifier = Modifier.fillMaxWidth()) { //TODO IMPLEMENT DRAGABLE IN OTHER PR
438+
Spacer(modifier = Modifier.height(16.dp))
439+
440+
article?.let {
441+
HeadlineCard( //TODO CHECK PREFERENCES
442+
modifier = Modifier.fillMaxWidth(),
443+
headline = article.title,
444+
time = article.timeAgo,
445+
source = article.publisher,
446+
link = article.link
447+
)
448+
}
440449
}
450+
Spacer(modifier = Modifier.height(32.dp))
451+
TertiaryButton(
452+
text = stringResource(R.string.widgets__add),
453+
icon = {
454+
Icon(
455+
painter = painterResource(R.drawable.ic_plus),
456+
contentDescription = null,
457+
tint = Colors.White80
458+
)
459+
},
460+
onClick = onClickAddWidget
461+
)
441462
}
442463
Spacer(modifier = Modifier.height(32.dp))
443-
TertiaryButton(
444-
text = stringResource(R.string.widgets__add),
445-
icon = {
446-
Icon(
447-
painter = painterResource(R.drawable.ic_plus),
448-
contentDescription = null,
449-
tint = Colors.White80
450-
)
451-
},
452-
onClick = onClickAddWidget
453-
)
454-
Spacer(modifier = Modifier.height(32.dp))
455464
Text13Up(stringResource(R.string.wallet__activity), color = Colors.White64)
456465
Spacer(modifier = Modifier.height(16.dp))
457466
val activity = activityListViewModel ?: return@Column
@@ -532,7 +541,8 @@ private fun HomeContentViewPreview() {
532541
onClickSuggestion = {},
533542
onRemoveSuggestion = {},
534543
onClickAddWidget = {},
535-
article = null
544+
article = null,
545+
showWidgets = true,
536546
)
537547
}
538548
}

app/src/main/java/to/bitkit/ui/screens/wallets/HomeViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class HomeViewModel @Inject constructor(
4141
val suggestions: StateFlow<List<Suggestion>> = createSuggestionsFlow()
4242

4343
// Widget-related flows
44-
private val showWidgets = settingsStore.data.map { it.showWidgets }
44+
val showWidgets = settingsStore.data.map { it.showWidgets }
4545

4646
private val articles: StateFlow<List<ArticleModel>> = widgetsRepo.articlesFlow
4747
.map { articles -> articles.map { it.toArticleModel() } }

0 commit comments

Comments
 (0)