From 9dd47553851e51ed80af9b9eec36e287a4cd374f Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Sat, 2 Mar 2024 15:53:27 +0300 Subject: [PATCH 1/3] Remove unused function from `UiModelMapper` --- .../android/ui/stats/refresh/lists/UiModelMapper.kt | 7 ------- 1 file changed, 7 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt index a69bf8b49887..0ff84d5ded09 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt @@ -83,13 +83,6 @@ class UiModelMapper return mapStatsWithOverview(PostDetailType.POST_OVERVIEW, useCaseModels, showError) } - fun mapViewsVisitorsDetailStats( - useCaseModels: List, - showError: (Int) -> Unit - ): UiModel { - return mapStatsWithOverview(TimeStatsType.OVERVIEW, useCaseModels, showError) - } - @Suppress("CyclomaticComplexMethod") private fun mapStatsWithOverview( overViewType: StatsType, From 86e57060f5037fd0b756f60f04ca1e2008549fd8 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Sat, 2 Mar 2024 17:03:58 +0300 Subject: [PATCH 2/3] Reformat if and when cases on `UiModelMapper` This just reformats the code without introducing any changes. --- .../ui/stats/refresh/lists/UiModelMapper.kt | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt index 0ff84d5ded09..d1fd0bcd541a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt @@ -98,30 +98,30 @@ class UiModelMapper return if (!allFailing && (overviewHasData || !overviewIsFailing)) { if (useCaseModels.isNotEmpty()) { UiModel.Success(useCaseModels.mapNotNull { useCaseModel -> - if ((useCaseModel.type == overViewType) && useCaseModel.data != null) { - StatsBlock.Success(useCaseModel.type, useCaseModel.data) - } else { - when (useCaseModel.state) { - SUCCESS -> StatsBlock.Success(useCaseModel.type, useCaseModel.data ?: listOf()) - ERROR -> useCaseModel.stateData?.let { - StatsBlock.Error( - useCaseModel.type, - useCaseModel.stateData - ) - } - LOADING -> useCaseModel.stateData?.let { - StatsBlock.Loading( - useCaseModel.type, - useCaseModel.stateData - ) - } - EMPTY -> useCaseModel.stateData?.let { - StatsBlock.EmptyBlock( - useCaseModel.type, - useCaseModel.stateData - ) - } + when { + useCaseModel.type == overViewType && useCaseModel.data != null -> StatsBlock.Success( + useCaseModel.type, + useCaseModel.data + ) + + useCaseModel.state == SUCCESS -> StatsBlock.Success( + useCaseModel.type, + useCaseModel.data ?: listOf() + ) + + useCaseModel.state == LOADING -> useCaseModel.stateData?.let { + StatsBlock.Loading(useCaseModel.type, useCaseModel.stateData) } + + useCaseModel.state == ERROR -> useCaseModel.stateData?.let { + StatsBlock.Error(useCaseModel.type, useCaseModel.stateData) + } + + useCaseModel.state == EMPTY -> useCaseModel.stateData?.let { + StatsBlock.EmptyBlock(useCaseModel.type, useCaseModel.stateData) + } + + else -> null } }) } else { From c069412cd36e80d3963a8d67ef8c5d56d10d18b8 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Sat, 2 Mar 2024 17:04:14 +0300 Subject: [PATCH 3/3] Send LOADING to the UI model of stats screen if the state is loading --- .../android/ui/stats/refresh/lists/UiModelMapper.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt index d1fd0bcd541a..4eefe9cab16c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt @@ -99,6 +99,10 @@ class UiModelMapper if (useCaseModels.isNotEmpty()) { UiModel.Success(useCaseModels.mapNotNull { useCaseModel -> when { + useCaseModel.state == LOADING -> useCaseModel.stateData?.let { + StatsBlock.Loading(useCaseModel.type, useCaseModel.stateData) + } + useCaseModel.type == overViewType && useCaseModel.data != null -> StatsBlock.Success( useCaseModel.type, useCaseModel.data @@ -109,10 +113,6 @@ class UiModelMapper useCaseModel.data ?: listOf() ) - useCaseModel.state == LOADING -> useCaseModel.stateData?.let { - StatsBlock.Loading(useCaseModel.type, useCaseModel.stateData) - } - useCaseModel.state == ERROR -> useCaseModel.stateData?.let { StatsBlock.Error(useCaseModel.type, useCaseModel.stateData) }