Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Insights management to develop #9743

Merged
merged 120 commits into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
eee4ccb
Update FluxC
planarvoid Jan 15, 2019
cf9f087
Add overflow menu to title
planarvoid Jan 17, 2019
5ae3d8d
Add overflow menu resource and icons
planarvoid Jan 17, 2019
12b2fbb
Update imports to fix build
planarvoid Jan 17, 2019
bb72ec5
Implement moving blocks up and down
planarvoid Jan 22, 2019
fb0daee
Update fluxc with the fix
planarvoid Jan 22, 2019
ac253ee
Revert FluxC package changes
planarvoid Jan 22, 2019
814af3f
Remove background from an imagebutton
planarvoid Jan 22, 2019
9f66dcc
Remove unused import
planarvoid Jan 23, 2019
a34443f
Merge branch 'develop' into feature/move_insights_up_and_down
planarvoid Jan 24, 2019
04e09de
Merge branch 'feature/manage_insights_readonly' into feature/move_ins…
planarvoid Mar 19, 2019
7611dba
Merge branch 'feature/manage_insights_readonly' into feature/move_ins…
planarvoid Mar 20, 2019
e3f45f6
Update FluxC hash
planarvoid Mar 20, 2019
3c06109
Fixes after merge
planarvoid Mar 20, 2019
72e49e8
Extract popup handling into a separate class
planarvoid Mar 21, 2019
8bb0499
Removee unused code and fix lint issue
planarvoid Mar 21, 2019
bcdedde
Move the StatsListItemDecoration to the lists package
0nko Mar 21, 2019
a134591
Reduce number of requests on insights screen
planarvoid Mar 21, 2019
33f5d8e
Fix the throttle method in utils
planarvoid Mar 21, 2019
0e1adf5
Merge branch 'feature/manage_insights_readonly' into feature/move_ins…
planarvoid Mar 21, 2019
fbfc384
Update FluxC version
planarvoid Mar 22, 2019
0f3de5b
Fix scroll issue in insights
planarvoid Mar 22, 2019
38b5a14
Add new Insights management activity
0nko Mar 22, 2019
48bc11a
Add the Inisghts Management fragment
0nko Mar 22, 2019
9c1dac6
Add new stats menut and update the button resource name
0nko Mar 22, 2019
13d6ba5
Add Inisights management ViewModel
0nko Mar 22, 2019
02ef98a
Remove unused member
0nko Mar 22, 2019
88da6c0
Add the toolbar menu functionality for the Insights tab
0nko Mar 22, 2019
c57e673
Merge pull request #9047 from wordpress-mobile/feature/move_insights_…
0nko Mar 22, 2019
1c1ca59
Merge branch 'feature/manage_insights_readonly' into feature/insights…
0nko Mar 22, 2019
29ee4eb
Add InsightsManagementFragment to the ApplicationModule
0nko Mar 22, 2019
373e349
Remove the extra toolbar
0nko Mar 22, 2019
269a199
Update the title capitalization
0nko Mar 22, 2019
6cef16f
Optimize imports
0nko Mar 22, 2019
fe2acfc
Merge pull request #9463 from wordpress-mobile/feature/insights-manag…
planarvoid Mar 22, 2019
3f6e429
Add insights management list item resources
0nko Mar 25, 2019
ba8fcc9
Update the insights management fragment layout with text items
0nko Mar 25, 2019
aaa5567
Add the insights management list adapter and view holder
0nko Mar 25, 2019
cc5c80a
Add InsightModel and implement the removed insights loading
0nko Mar 25, 2019
fae598f
Add the drawable resources for insights management
0nko Mar 26, 2019
32136a4
Add new drag & drop hint string resource
0nko Mar 26, 2019
b54109f
Update the list item layout
0nko Mar 26, 2019
b4f3b2e
Add the added insights list and drag & drop hint
0nko Mar 26, 2019
20665e3
Add drag & drop ordering to added insights
0nko Mar 27, 2019
ed85544
Remove redundant code
0nko Mar 27, 2019
92d2c0b
Add the save button to the insights management screen
0nko Mar 27, 2019
46fae9b
Fix snackbar display
0nko Mar 27, 2019
ed38594
Update the ViewModel after dragging items
0nko Mar 27, 2019
a6a2b8a
Whitespace clean up
0nko Mar 27, 2019
2671904
Fix insights diff util comparisons
0nko Mar 27, 2019
9fae18a
Add insights adding and removal functionality
0nko Mar 27, 2019
36b8aa2
Update string resources
0nko Mar 28, 2019
00bed85
Create separate for added and removed insight types
0nko Mar 28, 2019
2634449
Animate list resize changes
0nko Mar 28, 2019
74f726b
Merge branch 'develop' into feature/manage_insights_readonly
0nko Mar 28, 2019
47d7c1a
Merge branch 'feature/manage_insights_readonly' into issue/9464-manag…
0nko Mar 28, 2019
9e33dc9
Close the insights management instead of showing a snackbar message
0nko Mar 28, 2019
39a2f9d
Update the FluxC reference
0nko Apr 1, 2019
f9830d8
Rename the layout view IDs for consistency
0nko Apr 1, 2019
d53c388
Initialize empty and error views
0nko Apr 1, 2019
08b47ad
Remove unused string resource
0nko Apr 1, 2019
fa838f8
Add list item decorators
0nko Apr 1, 2019
08973d1
Don't wait for data to refresh when leaving the insights management
0nko Apr 1, 2019
24f5351
Fix the empty isnights actionable screen display
0nko Apr 1, 2019
8e6998b
Fix ktlint
0nko Apr 1, 2019
73be580
Update the release notes
0nko Apr 1, 2019
bb5f8c1
Only load insights once
0nko Apr 9, 2019
2415e7c
Use larger vertical margin for the subtitle
0nko Apr 9, 2019
422918d
Hide the Save button until some change is made
0nko Apr 9, 2019
3789129
Show the touch feedback on ellipsis tap
0nko Apr 9, 2019
b4c2941
Force showing a menu icon
0nko Apr 10, 2019
8081564
Replace the simple popup menu with a custom popup window
0nko Apr 10, 2019
151714a
Fix the resources
0nko Apr 10, 2019
d1f2915
Change the menu width
0nko Apr 10, 2019
7b8fa04
Allow dragged list items to move over the entire screen
0nko Apr 11, 2019
8cba908
Make the added list items topmost
0nko Apr 11, 2019
8ceb2b8
Display a shadow (elevation) while an item is being dragged
0nko Apr 11, 2019
3c4ce39
Add the Edit button to the bottom of the insights list
0nko Apr 12, 2019
d5f313a
Remove the old Manage menu
0nko Apr 12, 2019
01420e1
Add a new type of StatsBlock to allow empty background for the link b…
0nko Apr 12, 2019
0b234fe
Disable the click listener after a tap to prevent a crash
0nko Apr 12, 2019
5fc462d
Avoid using LiveData state as in-memory cache
0nko Apr 12, 2019
c6145a1
Use constraint layout to fix the peroper list height that shows all i…
0nko Apr 12, 2019
942dbfc
Optimize imports
0nko Apr 12, 2019
c2412c8
Prevent long-press dragging
0nko Apr 12, 2019
9ec6c79
Set basline aligned attribute for better performance
0nko Apr 12, 2019
d6c613e
Remove unused string resource
0nko Apr 12, 2019
2c9fd4e
Optimize imports
0nko Apr 12, 2019
f03cd7f
Get rid of an extra coroutine builder
0nko Apr 12, 2019
a037332
Remove unused string resource
0nko Apr 12, 2019
a0f0666
Merge branch 'develop' into feature/manage_insights_readonly
0nko Apr 12, 2019
8f35da2
Merge branch 'feature/manage_insights_readonly' into issue/9464-manag…
0nko Apr 12, 2019
8452113
Add the missing drawable resources
0nko Apr 12, 2019
deecbba
Remove the common statsTypes parameter from StatsBlocks
0nko Apr 15, 2019
88b0acf
Move the UiModel construction to the mapper
0nko Apr 15, 2019
b4f3bbc
Fix the unit tests
0nko Apr 15, 2019
1af8339
Fix ktlint
0nko Apr 15, 2019
8645831
Fix the newly added insights data loading
0nko Apr 17, 2019
ddbf15a
Add additional padding between the footer and the Add Insights header
0nko Apr 17, 2019
02bf4e7
Add the reduced width layout for wide screens (landcape)
0nko Apr 17, 2019
35bbc91
Add a custom divider that has a padding at the beginning
0nko Apr 17, 2019
b0b080f
Use a regular button style
0nko Apr 17, 2019
574ded8
Delay animations until the insights are loaded to prevent weird slide…
0nko Apr 17, 2019
bbbdccc
Update the layout paddings
0nko Apr 17, 2019
6189526
Merge branch 'develop' into feature/manage_insights_readonly
0nko Apr 18, 2019
afd2221
Merge branch 'feature/manage_insights_readonly' into issue/9464-manag…
0nko Apr 18, 2019
11a9497
Update the FluxC reference and make the necessary code changes
0nko Apr 18, 2019
a5c3ac9
Fix the doble blocks bug
0nko Apr 18, 2019
e1ab010
Always show the Edit button
0nko Apr 18, 2019
f30ac7f
Correct the layout paddings
0nko Apr 23, 2019
7874a42
Fix the failing unit test
0nko Apr 23, 2019
4640b84
Add the context menu to the Annual stats block
0nko Apr 23, 2019
96de67f
Merge pull request #9501 from wordpress-mobile/issue/9464-manage-insi…
planarvoid Apr 23, 2019
b00ea2e
Use global scope for global operation in insights management
planarvoid Apr 29, 2019
5f5debc
Merge branch 'develop' into feature/manage_insights_readonly
planarvoid Apr 29, 2019
05adf40
Merge pull request #9742 from wordpress-mobile/feature/fix_coroutine_…
malinajirka Apr 29, 2019
ec9b5e8
Fix import
planarvoid May 2, 2019
5194ee0
Update release notes
planarvoid May 3, 2019
84287e6
Update fluxc version to the merge commit
planarvoid May 3, 2019
19ed06e
Merge branch 'develop' into feature/manage_insights_readonly
planarvoid May 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Added ability to toggle to compact view type for blog posts list
* Fixed several bugs on the blog posts screen
* Fixed bug that prevented audio playing in the reader
* New Insights Management for selecting the most relevant stats

12.3
-----
Expand Down
6 changes: 5 additions & 1 deletion WordPress/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,13 @@
android:theme="@style/Calypso.NoActionBar" />
<activity
android:name=".ui.stats.refresh.StatsViewAllActivity"
android:label="@string/stats"
android:launchMode="singleTop"
android:theme="@style/Calypso.NoActionBar" />
<activity
android:name=".ui.stats.refresh.lists.sections.insights.management.InsightsManagementActivity"
android:label="@string/stats_manage_insights"
android:launchMode="singleTop"
android:theme="@style/CalypsoTheme" />
<activity
android:name=".ui.stats.refresh.lists.detail.StatsDetailActivity"
android:label="@string/stats"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.wordpress.android.ui.stats.refresh.StatsViewAllFragment;
import org.wordpress.android.ui.stats.refresh.lists.StatsListFragment;
import org.wordpress.android.ui.stats.refresh.lists.detail.StatsDetailFragment;
import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementFragment;
import org.wordpress.android.util.wizard.WizardManager;
import org.wordpress.android.viewmodel.helpers.ConnectionStatus;
import org.wordpress.android.viewmodel.helpers.ConnectionStatusLiveData;
Expand All @@ -38,6 +39,9 @@ public static NewsService provideLocalNewsService(Context context) {
@ContributesAndroidInjector
abstract StatsViewAllFragment contributeStatsViewAllFragment();

@ContributesAndroidInjector
abstract InsightsManagementFragment contributeInsightsManagementFragment();

@ContributesAndroidInjector
abstract StatsFragment contributeStatsFragment();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.wordpress.android.ui.stats.refresh.lists.MonthsListViewModel;
import org.wordpress.android.ui.stats.refresh.lists.WeeksListViewModel;
import org.wordpress.android.ui.stats.refresh.lists.YearsListViewModel;
import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel;
import org.wordpress.android.ui.stats.refresh.lists.detail.DetailListViewModel;
import org.wordpress.android.ui.stats.refresh.lists.detail.StatsDetailViewModel;
import org.wordpress.android.viewmodel.ViewModelFactory;
Expand Down Expand Up @@ -132,6 +133,11 @@ abstract class ViewModelModule {
@ViewModelKey(StatsViewModel.class)
abstract ViewModel statsViewModel(StatsViewModel viewModel);

@Binds
@IntoMap
@ViewModelKey(InsightsManagementViewModel.class)
abstract ViewModel insightsManagementViewModel(InsightsManagementViewModel viewModel);

@Binds
@IntoMap
@ViewModelKey(HistoryViewModel.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import org.wordpress.android.ui.stats.models.StatsPostModel;
import org.wordpress.android.ui.stats.refresh.StatsActivity;
import org.wordpress.android.ui.stats.refresh.StatsViewAllFragment;
import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementActivity;
import org.wordpress.android.ui.stats.refresh.lists.detail.StatsDetailActivity;
import org.wordpress.android.ui.stockmedia.StockMediaPickerActivity;
import org.wordpress.android.ui.themes.ThemeBrowserActivity;
Expand Down Expand Up @@ -312,6 +313,11 @@ public static void viewAllGranularStats(Context context, StatsGranularity granul
context.startActivity(intent);
}

public static void viewInsightsManagement(Context context) {
Intent intent = new Intent(context, InsightsManagementActivity.class);
context.startActivity(intent);
}

public static void viewBlogStatsAfterJetpackSetup(Context context, SiteModel site) {
if (site == null) {
AppLog.e(T.STATS, "SiteModel is null when opening the stats.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.
import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.HEADER
import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.INFO
import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LINK
import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LINK_BUTTON
import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LIST_ITEM
import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LIST_ITEM_WITH_ICON
import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LOADING_ITEM
Expand Down Expand Up @@ -64,6 +65,7 @@ class BlockDiffCallback(
CHART_LEGEND,
REFERRED_ITEM,
QUICK_SCAN_ITEM,
LINK_BUTTON,
EMPTY -> oldItem == newItem
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ sealed class NavigationTarget {
object ViewDayAverageStats : NavigationTarget()
object ViewRecentWeeksStats : NavigationTarget()
object ViewAnnualStats : NavigationTarget()
object ViewInsightsManagement : NavigationTarget()
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSect
import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.MONTHS
import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.WEEKS
import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.YEARS
import org.wordpress.android.ui.stats.refresh.utils.StatsNavigator
import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider
import org.wordpress.android.util.WPSwipeToRefreshHelper
import org.wordpress.android.util.helpers.SwipeToRefreshHelper
Expand All @@ -49,15 +50,12 @@ class StatsFragment : DaggerFragment() {
@Inject lateinit var statsSiteProvider: StatsSiteProvider
private lateinit var viewModel: StatsViewModel
private lateinit var swipeToRefreshHelper: SwipeToRefreshHelper
@Inject lateinit var navigator: StatsNavigator

private var restorePreviousSearch = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
setHasOptionsMenu(true)
return inflater.inflate(R.layout.stats_fragment, container, false)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class StatsModule {
mainDispatcher,
statsSiteProvider,
useCases,
{ statsStore.getInsights() },
{ statsStore.getAddedInsights(statsSiteProvider.siteModel) },
uiModelMapper::mapInsights
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class StatsViewAllFragment : DaggerFragment() {
super.onSaveInstanceState(outState)
}

private fun initializeViews(savedInstanceState: Bundle?) {
private fun initializeViews(savedInstanceState: Bundle?) {
val layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)

savedInstanceState?.getParcelable<Parcelable>(listStateKey)?.let {
Expand All @@ -97,10 +97,10 @@ class StatsViewAllFragment : DaggerFragment() {
viewModel.onPullToRefresh()
}

select_next_date.setOnClickListener {
nextDateButton.setOnClickListener {
viewModel.onNextDateSelected()
}
select_previous_date.setOnClickListener {
previousDateButton.setOnClickListener {
viewModel.onPreviousDateSelected()
}
}
Expand Down Expand Up @@ -173,8 +173,8 @@ class StatsViewAllFragment : DaggerFragment() {
if (it != null) {
recyclerView.visibility = if (it is StatsBlock.Success) View.VISIBLE else View.GONE
loadingContainer.visibility = if (it is StatsBlock.Loading) View.VISIBLE else View.GONE
actionable_error_view.visibility = if (it is StatsBlock.Error) View.VISIBLE else View.GONE
actionable_empty_view.visibility = if (it is StatsBlock.EmptyBlock) View.VISIBLE else View.GONE
statsErrorView.visibility = if (it is StatsBlock.Error) View.VISIBLE else View.GONE
statsEmptyView.visibility = if (it is StatsBlock.EmptyBlock) View.VISIBLE else View.GONE
when (it) {
is StatsBlock.Success -> {
loadData(recyclerView, prepareLayout(it.data, it.type))
Expand All @@ -183,7 +183,7 @@ class StatsViewAllFragment : DaggerFragment() {
loadData(loadingRecyclerView, prepareLayout(it.data, it.type))
}
is StatsBlock.Error -> {
actionable_error_view.button.setOnClickListener {
statsErrorView.button.setOnClickListener {
viewModel.onRetryClick()
}
}
Expand All @@ -201,14 +201,14 @@ class StatsViewAllFragment : DaggerFragment() {
if (date_selection_toolbar.visibility != dateSelectorVisibility) {
date_selection_toolbar.visibility = dateSelectorVisibility
}
selected_date.text = dateSelectorUiModel?.date ?: ""
selectedDateTextView.text = dateSelectorUiModel?.date ?: ""
val enablePreviousButton = dateSelectorUiModel?.enableSelectPrevious == true
if (select_previous_date.isEnabled != enablePreviousButton) {
select_previous_date.isEnabled = enablePreviousButton
if (previousDateButton.isEnabled != enablePreviousButton) {
previousDateButton.isEnabled = enablePreviousButton
}
val enableNextButton = dateSelectorUiModel?.enableSelectNext == true
if (select_next_date.isEnabled != enableNextButton) {
select_next_date.isEnabled = enableNextButton
if (nextDateButton.isEnabled != enableNextButton) {
nextDateButton.isEnabled = enableNextButton
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class StatsViewModel
listUseCases[statsSection]?.onListSelected()

_toolbarHasShadow.value = statsSection == INSIGHTS

when (statsSection) {
INSIGHTS -> analyticsTracker.track(STATS_INSIGHTS_ACCESSED)
DAYS -> analyticsTracker.track(STATS_PERIOD_DAYS_ACCESSED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.wordpress.android.R
import org.wordpress.android.fluxc.store.StatsStore.StatsTypes
import org.wordpress.android.fluxc.store.StatsStore.StatsType
import org.wordpress.android.ui.pages.SnackbarMessageHolder
import org.wordpress.android.ui.stats.refresh.NavigationTarget
import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.UiModel
import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase
import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.UseCaseModel
import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider
import org.wordpress.android.util.DistinctMutableLiveData
import org.wordpress.android.util.PackageUtils
import org.wordpress.android.util.combineMap
import org.wordpress.android.util.distinct
Expand All @@ -28,29 +27,34 @@ class BaseListUseCase(
private val mainDispatcher: CoroutineDispatcher,
private val statsSiteProvider: StatsSiteProvider,
private val useCases: List<BaseStatsUseCase<*, *>>,
private val getStatsTypes: suspend () -> List<StatsTypes>,
private val mapUiModel: (useCaseModels: List<UseCaseModel>, showError: (Int) -> Unit) -> UiModel
private val getStatsTypes: suspend () -> List<StatsType>,
private val mapUiModel: (
useCaseModels: List<UseCaseModel>,
MutableLiveData<Event<NavigationTarget>>,
showError: (Int) -> Unit
) -> UiModel
) {
private val blockListData = combineMap(
useCases.associateBy { it.type }.mapValues { entry -> entry.value.liveData }
)
private val statsTypes = DistinctMutableLiveData<List<StatsTypes>>(listOf())
val data: MediatorLiveData<UiModel> = mergeNotNull(statsTypes, blockListData) { insights, map ->
insights.mapNotNull {
private val statsTypes = MutableLiveData<List<StatsType>>()
val data: MediatorLiveData<UiModel> = mergeNotNull(statsTypes, blockListData) { types, map ->
types.mapNotNull {
if (map.containsKey(it)) {
map[it]
} else {
null
}
}
}.map { useCaseModels ->
mapUiModel(useCaseModels) { message ->
mapUiModel(useCaseModels, mutableNavigationTarget) { message ->
mutableSnackbarMessage.postValue(message)
}
}.distinct()

private val mutableNavigationTarget = MutableLiveData<Event<NavigationTarget>>()
val navigationTarget: LiveData<Event<NavigationTarget>> = mergeNotNull(
useCases.map { it.navigationTarget },
useCases.map { it.navigationTarget } + mutableNavigationTarget,
distinct = false
)

Expand All @@ -70,16 +74,26 @@ class BaseListUseCase(
loadData(true, forced)
}

suspend fun refreshTypes(): List<StatsType> {
val items = getStatsTypes()
withContext(mainDispatcher) {
statsTypes.value = items
}
return items
}

private suspend fun loadData(refresh: Boolean, forced: Boolean) {
if (statsSiteProvider.hasLoadedSite()) {
withContext(bgDispatcher) {
if (PackageUtils.isDebugBuild() && useCases.distinctBy { it.type }.size < useCases.size) {
throw RuntimeException("Duplicate stats type in a use case")
}
useCases.forEach { block -> launch { block.fetch(refresh, forced) } }
val items = getStatsTypes()
withContext(mainDispatcher) {
statsTypes.value = items
val visibleTypes = refreshTypes()
visibleTypes.forEach { type ->
useCases.find { it.type == type }
?.let { block -> launch(bgDispatcher) {
block.fetch(refresh, forced) }
}
}
}
} else {
Expand All @@ -89,7 +103,6 @@ class BaseListUseCase(

fun onCleared() {
mutableSnackbarMessage.value = null
statsTypes.clear()
blockListData.value = null
useCases.forEach { it.clear() }
data.value = null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
package org.wordpress.android.ui.stats.refresh.lists

import org.wordpress.android.fluxc.store.StatsStore.StatsTypes
import org.wordpress.android.fluxc.store.StatsStore.StatsType
import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.CONTROL
import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.EMPTY
import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.ERROR
import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.LOADING
import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.SUCCESS
import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem

sealed class StatsBlock(val type: Type, open val statsTypes: StatsTypes, open val data: List<BlockListItem>) {
sealed class StatsBlock(val type: Type, open val data: List<BlockListItem>) {
enum class Type {
SUCCESS,
ERROR,
EMPTY,
LOADING
LOADING,
CONTROL
}

data class Success(
override val statsTypes: StatsTypes,
val statsType: StatsType,
override val data: List<BlockListItem>
) : StatsBlock(SUCCESS, statsTypes, data)
) : StatsBlock(SUCCESS, data)

data class Error(
override val statsTypes: StatsTypes,
val statsType: StatsType,
override val data: List<BlockListItem> = listOf()
) : StatsBlock(ERROR, statsTypes, data)
) : StatsBlock(ERROR, data)

data class EmptyBlock(
override val statsTypes: StatsTypes,
val statsType: StatsType,
override val data: List<BlockListItem>
) : StatsBlock(EMPTY, statsTypes, data)
) : StatsBlock(EMPTY, data)

data class Loading(
override val statsTypes: StatsTypes,
val statsType: StatsType,
override val data: List<BlockListItem>
) : StatsBlock(LOADING, statsTypes, data)
) : StatsBlock(LOADING, data)

data class Control(
override val data: List<BlockListItem>
) : StatsBlock(CONTROL, data)
}
Loading