Skip to content

Commit 3fd01a2

Browse files
committed
feat: handle show widgets call
1 parent 17b0d12 commit 3fd01a2

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ class HomeViewModel @Inject constructor(
3737
private val articles: StateFlow<List<ArticleModel>> = createArticlesFlow()
3838
private val _currentArticle = MutableStateFlow(articles.value.firstOrNull())
3939
val currentArticle: StateFlow<ArticleModel?> = _currentArticle.asStateFlow()
40+
private val showWidgets = settingsStore.data.map { it.showWidgets }
4041

4142
init {
42-
setupArticles()
43+
setupWidgets()
4344
}
4445

4546
fun removeSuggestion(suggestion: Suggestion) {
@@ -104,21 +105,25 @@ class HomeViewModel @Inject constructor(
104105
return articles.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), emptyList())
105106
}
106107

107-
private fun setupArticles() {
108+
private fun setupWidgets() {
108109
viewModelScope.launch {
109-
val settings = settingsStore.data.first()
110-
if (!settings.showWidgets) return@launch //TODO also filter !settings.widgets.map { it.type }.contains(WidgetType.NEWS) when implement drag and drop
111-
widgetsRepo.updateArticles()
112-
articles.first { it.isNotEmpty() }
113-
getRandomArticle()
110+
showWidgets.collect { show ->
111+
if (show) {
112+
widgetsRepo.updateArticles()
113+
articles.first { it.isNotEmpty() }
114+
getRandomArticle()
115+
} else {
116+
_currentArticle.update { null }
117+
}
118+
}
114119
}
115120
}
116121

117122
private fun getRandomArticle() {
118123
viewModelScope.launch {
119124
_currentArticle.update { articles.value.randomOrNull() }
120125
delay(30.seconds)
121-
getRandomArticle()
126+
if (showWidgets.first()) getRandomArticle()
122127
}
123128
}
124129
}

0 commit comments

Comments
 (0)