@@ -28,30 +28,21 @@ import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.QuickActio
28
28
import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.QuickStartCardBuilderParams
29
29
import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.SiteInfoCardBuilderParams
30
30
import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.SiteItemsBuilderParams
31
- import org.wordpress.android.ui.mysite.MySiteSource.MySiteRefreshSource
32
- import org.wordpress.android.ui.mysite.MySiteSource.SiteIndependentSource
33
31
import org.wordpress.android.ui.mysite.MySiteUiState.PartialState
34
32
import org.wordpress.android.ui.mysite.MySiteViewModel.State.NoSites
35
33
import org.wordpress.android.ui.mysite.MySiteViewModel.State.SiteSelected
36
34
import org.wordpress.android.ui.mysite.SiteDialogModel.AddSiteIconDialogModel
37
35
import org.wordpress.android.ui.mysite.SiteDialogModel.ChangeSiteIconDialogModel
38
36
import org.wordpress.android.ui.mysite.SiteDialogModel.ShowRemoveNextStepsDialog
39
37
import org.wordpress.android.ui.mysite.cards.CardsBuilder
40
- import org.wordpress.android.ui.mysite.cards.domainregistration.DomainRegistrationSource
41
38
import org.wordpress.android.ui.mysite.cards.post.PostCardType
42
- import org.wordpress.android.ui.mysite.cards.post.PostCardsSource
43
39
import org.wordpress.android.ui.mysite.cards.post.mockdata.MockedPostsData
44
40
import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartCardBuilder
45
- import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartCardSource
46
41
import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartRepository
47
42
import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartRepository.QuickStartCategory
48
43
import org.wordpress.android.ui.mysite.dynamiccards.DynamicCardMenuFragment.DynamicCardMenuModel
49
44
import org.wordpress.android.ui.mysite.dynamiccards.DynamicCardMenuViewModel.DynamicCardMenuInteraction
50
- import org.wordpress.android.ui.mysite.dynamiccards.DynamicCardMenuViewModel.DynamicCardMenuInteraction.Hide
51
- import org.wordpress.android.ui.mysite.dynamiccards.DynamicCardMenuViewModel.DynamicCardMenuInteraction.Pin
52
- import org.wordpress.android.ui.mysite.dynamiccards.DynamicCardMenuViewModel.DynamicCardMenuInteraction.Unpin
53
45
import org.wordpress.android.ui.mysite.dynamiccards.DynamicCardsBuilder
54
- import org.wordpress.android.ui.mysite.dynamiccards.DynamicCardsSource
55
46
import org.wordpress.android.ui.mysite.items.SiteItemsBuilder
56
47
import org.wordpress.android.ui.mysite.items.listitem.ListItemAction
57
48
import org.wordpress.android.ui.pages.SnackbarMessageHolder
@@ -101,24 +92,17 @@ class MySiteViewModel @Inject constructor(
101
92
private val contextProvider : ContextProvider ,
102
93
private val siteIconUploadHandler : SiteIconUploadHandler ,
103
94
private val siteStoriesHandler : SiteStoriesHandler ,
104
- private val domainRegistrationSource : DomainRegistrationSource ,
105
- private val scanAndBackupSource : ScanAndBackupSource ,
106
95
private val displayUtilsWrapper : DisplayUtilsWrapper ,
107
96
private val quickStartRepository : QuickStartRepository ,
108
- private val quickStartCardSource : QuickStartCardSource ,
109
97
private val quickStartCardBuilder : QuickStartCardBuilder ,
110
- private val currentAvatarSource : CurrentAvatarSource ,
111
- private val dynamicCardsSource : DynamicCardsSource ,
112
98
private val unifiedCommentsListFeatureConfig : UnifiedCommentsListFeatureConfig ,
113
99
private val quickStartDynamicCardsFeatureConfig : QuickStartDynamicCardsFeatureConfig ,
114
100
private val quickStartUtilsWrapper : QuickStartUtilsWrapper ,
115
101
private val snackbarSequencer : SnackbarSequencer ,
116
102
private val cardsBuilder : CardsBuilder ,
117
103
private val dynamicCardsBuilder : DynamicCardsBuilder ,
118
- postCardsSource : PostCardsSource ,
119
- private val selectedSiteSource : SelectedSiteSource ,
120
- siteIconProgressSource : SiteIconProgressSource ,
121
- private val mySiteDashboardPhase2FeatureConfig : MySiteDashboardPhase2FeatureConfig
104
+ private val mySiteDashboardPhase2FeatureConfig : MySiteDashboardPhase2FeatureConfig ,
105
+ private val mySiteSourceManager : MySiteSourceManager
122
106
) : ScopedViewModel(mainDispatcher) {
123
107
private val _onSnackbarMessage = MutableLiveData <Event <SnackbarMessageHolder >>()
124
108
private val _onTechInputDialogShown = MutableLiveData <Event <TextInputDialogModel >>()
@@ -149,27 +133,10 @@ class MySiteViewModel @Inject constructor(
149
133
val onUploadedItem = siteIconUploadHandler.onUploadedItem
150
134
val onShowSwipeRefreshLayout = _onShowSwipeRefreshLayout
151
135
152
- private val mySiteSources: List <MySiteSource <* >> = listOf (
153
- selectedSiteSource,
154
- siteIconProgressSource,
155
- quickStartCardSource,
156
- currentAvatarSource,
157
- domainRegistrationSource,
158
- scanAndBackupSource,
159
- dynamicCardsSource,
160
- postCardsSource
161
- )
162
-
163
136
val state: LiveData <MySiteUiState > =
164
137
selectedSiteRepository.siteSelected.switchMap { siteLocalId ->
165
138
val result = MediatorLiveData <SiteIdToState >()
166
- val currentSources = if (siteLocalId != null ) {
167
- mySiteSources.map { source -> source.build(viewModelScope, siteLocalId).distinctUntilChanged() }
168
- } else {
169
- mySiteSources.filterIsInstance(SiteIndependentSource ::class .java)
170
- .map { source -> source.build(viewModelScope).distinctUntilChanged() }
171
- }
172
- for (newSource in currentSources) {
139
+ for (newSource in mySiteSourceManager.build(viewModelScope, siteLocalId)) {
173
140
result.addSource(newSource) { partialState ->
174
141
if (partialState != null ) {
175
142
result.value = (result.value ? : SiteIdToState (siteLocalId)).update(partialState)
@@ -390,7 +357,7 @@ class MySiteViewModel @Inject constructor(
390
357
}
391
358
392
359
fun onQuickStartFullScreenDialogDismiss () {
393
- quickStartCardSource.refresh ()
360
+ mySiteSourceManager.refreshQuickStart ()
394
361
}
395
362
396
363
private fun titleClick () {
@@ -484,33 +451,10 @@ class MySiteViewModel @Inject constructor(
484
451
_onNavigation .value = Event (SiteNavigationAction .OpenDomainRegistration (selectedSite))
485
452
}
486
453
487
- fun refresh () {
488
- if (mySiteDashboardPhase2FeatureConfig.isEnabled()) {
489
- refreshNew()
490
- } else {
491
- refreshOld()
492
- }
493
- }
494
-
495
- private fun refreshNew () {
496
- mySiteSources.filterIsInstance(MySiteRefreshSource ::class .java).forEach { it.refresh() }
497
- }
498
-
499
- private fun refreshOld () {
500
- selectedSiteRepository.updateSiteSettingsIfNecessary()
501
- quickStartCardSource.refresh()
502
- currentAvatarSource.refresh()
503
- }
454
+ fun refresh () = mySiteSourceManager.refresh()
504
455
505
456
fun onResume (isFirstResume : Boolean ) {
506
- when (isFirstResume) {
507
- true -> refreshOld()
508
- false -> if (mySiteDashboardPhase2FeatureConfig.isEnabled()) {
509
- refreshNew()
510
- } else {
511
- refreshOld()
512
- }
513
- }
457
+ mySiteSourceManager.onResume(isFirstResume)
514
458
checkAndShowQuickStartNotice()
515
459
_onShowSwipeRefreshLayout .postValue(Event (mySiteDashboardPhase2FeatureConfig.isEnabled()))
516
460
}
@@ -695,10 +639,8 @@ class MySiteViewModel @Inject constructor(
695
639
override fun onCleared () {
696
640
siteIconUploadHandler.clear()
697
641
siteStoriesHandler.clear()
698
- domainRegistrationSource.clear()
699
642
quickStartRepository.clear()
700
- scanAndBackupSource.clear()
701
- selectedSiteSource.clear()
643
+ mySiteSourceManager.clear()
702
644
super .onCleared()
703
645
}
704
646
@@ -719,27 +661,12 @@ class MySiteViewModel @Inject constructor(
719
661
private fun startQuickStart (siteLocalId : Int ) {
720
662
if (siteLocalId != SelectedSiteRepository .UNAVAILABLE ) {
721
663
quickStartUtilsWrapper.startQuickStart(siteLocalId)
722
- quickStartCardSource.refresh ()
664
+ mySiteSourceManager.refreshQuickStart ()
723
665
}
724
666
}
725
667
726
668
fun onQuickStartMenuInteraction (interaction : DynamicCardMenuInteraction ) {
727
- launch {
728
- when (interaction) {
729
- is DynamicCardMenuInteraction .Remove -> {
730
- analyticsTrackerWrapper.track(Stat .QUICK_START_REMOVE_CARD_TAPPED )
731
- dynamicCardsSource.removeItem(interaction.cardType)
732
- quickStartCardSource.refresh()
733
- }
734
- is Pin -> dynamicCardsSource.pinItem(interaction.cardType)
735
- is Unpin -> dynamicCardsSource.unpinItem()
736
- is Hide -> {
737
- analyticsTrackerWrapper.track(Stat .QUICK_START_HIDE_CARD_TAPPED )
738
- dynamicCardsSource.hideItem(interaction.cardType)
739
- quickStartCardSource.refresh()
740
- }
741
- }
742
- }
669
+ launch { mySiteSourceManager.onQuickStartMenuInteraction(interaction) }
743
670
}
744
671
745
672
private fun showQuickStartDialog (siteModel : SiteModel ? ) {
@@ -783,18 +710,7 @@ class MySiteViewModel @Inject constructor(
783
710
}
784
711
}
785
712
786
- fun isRefreshing () = areSourcesRefreshing()
787
-
788
- private fun areSourcesRefreshing (): Boolean {
789
- if (mySiteDashboardPhase2FeatureConfig.isEnabled()) {
790
- mySiteSources.filterIsInstance(MySiteRefreshSource ::class .java).forEach {
791
- if (it.isRefreshing() == true ) {
792
- return true
793
- }
794
- }
795
- }
796
- return false
797
- }
713
+ fun isRefreshing () = mySiteSourceManager.isRefreshing()
798
714
799
715
fun setActionableEmptyViewGone (isVisible : Boolean , setGone : () -> Unit ) {
800
716
if (isVisible) analyticsTrackerWrapper.track(Stat .MY_SITE_NO_SITES_VIEW_HIDDEN )
0 commit comments