File tree Expand file tree Collapse file tree 1 file changed +13
-8
lines changed
app/src/main/java/to/bitkit/ui/screens/wallets Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments