-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20735 from wordpress-mobile/issue/20689-subscribe…
…rs-card Add subscribers list card
- Loading branch information
Showing
18 changed files
with
458 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,6 @@ enum class StatsViewType { | |
TOTAL_LIKES, | ||
TOTAL_COMMENTS, | ||
TOTAL_FOLLOWERS, | ||
EMAILS, | ||
SUBSCRIBERS, | ||
EMAILS | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...s/android/ui/stats/refresh/lists/sections/subscribers/usecases/SubscribersChartUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package org.wordpress.android.ui.stats.refresh.lists.sections.subscribers.usecases | ||
|
||
import kotlinx.coroutines.CoroutineDispatcher | ||
import org.wordpress.android.R | ||
import org.wordpress.android.analytics.AnalyticsTracker | ||
import org.wordpress.android.fluxc.model.stats.LimitMode | ||
import org.wordpress.android.fluxc.model.stats.subscribers.SubscribersModel | ||
import org.wordpress.android.fluxc.network.utils.StatsGranularity.DAYS | ||
import org.wordpress.android.fluxc.store.StatsStore.SubscriberType.SUBSCRIBERS_CHART | ||
import org.wordpress.android.fluxc.store.stats.subscribers.SubscribersStore | ||
import org.wordpress.android.modules.BG_THREAD | ||
import org.wordpress.android.modules.UI_THREAD | ||
import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.StatelessUseCase | ||
import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem | ||
import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Title | ||
import org.wordpress.android.ui.stats.refresh.lists.sections.insights.InsightUseCaseFactory | ||
import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider | ||
import org.wordpress.android.util.AppLog | ||
import org.wordpress.android.util.AppLog.T | ||
import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper | ||
import javax.inject.Inject | ||
import javax.inject.Named | ||
|
||
const val SUBSCRIBERS_CHART_ITEMS_TO_LOAD = 30 | ||
|
||
class SubscribersChartUseCase @Inject constructor( | ||
private val subscribersStore: SubscribersStore, | ||
private val statsSiteProvider: StatsSiteProvider, | ||
private val subscribersMapper: SubscribersMapper, | ||
@Named(UI_THREAD) private val mainDispatcher: CoroutineDispatcher, | ||
@Named(BG_THREAD) private val backgroundDispatcher: CoroutineDispatcher, | ||
private val analyticsTracker: AnalyticsTrackerWrapper | ||
) : StatelessUseCase<SubscribersModel>(SUBSCRIBERS_CHART, mainDispatcher, backgroundDispatcher) { | ||
override fun buildLoadingItem(): List<BlockListItem> = listOf() | ||
|
||
override suspend fun loadCachedData() = subscribersStore.getSubscribers( | ||
statsSiteProvider.siteModel, | ||
DAYS, | ||
LimitMode.Top(SUBSCRIBERS_CHART_ITEMS_TO_LOAD) | ||
) | ||
|
||
override suspend fun fetchRemoteData(forced: Boolean): State<SubscribersModel> { | ||
val response = subscribersStore.fetchSubscribers( | ||
statsSiteProvider.siteModel, | ||
DAYS, | ||
LimitMode.Top(SUBSCRIBERS_CHART_ITEMS_TO_LOAD), | ||
forced | ||
) | ||
val model = response.model | ||
val error = response.error | ||
|
||
return when { | ||
error != null -> State.Error(error.message ?: error.type.name) | ||
model != null && model.dates.isNotEmpty() -> State.Data(model) | ||
else -> State.Empty() | ||
} | ||
} | ||
|
||
override fun buildUiModel(domainModel: SubscribersModel): List<BlockListItem> { | ||
val items = mutableListOf<BlockListItem>() | ||
if (domainModel.dates.isEmpty()) { | ||
AppLog.e(T.STATS, "There is no data to be shown in the subscribers chart block") | ||
} else { | ||
items.add(buildTitle()) | ||
|
||
items.add(subscribersMapper.buildChart(domainModel.dates, this::onLineSelected)) | ||
} | ||
return items | ||
} | ||
|
||
private fun buildTitle() = Title(R.string.stats_view_subscribers_chart) | ||
|
||
private fun onLineSelected() { | ||
analyticsTracker.track(AnalyticsTracker.Stat.STATS_SUBSCRIBERS_CHART_TAPPED) | ||
} | ||
|
||
class SubscribersUseCaseFactory @Inject constructor( | ||
@Named(UI_THREAD) private val mainDispatcher: CoroutineDispatcher, | ||
@Named(BG_THREAD) private val backgroundDispatcher: CoroutineDispatcher, | ||
private val statsSiteProvider: StatsSiteProvider, | ||
private val subscribersMapper: SubscribersMapper, | ||
private val subscribersStore: SubscribersStore, | ||
private val analyticsTracker: AnalyticsTrackerWrapper | ||
) : InsightUseCaseFactory { | ||
override fun build(useCaseMode: UseCaseMode) = | ||
SubscribersChartUseCase( | ||
subscribersStore, | ||
statsSiteProvider, | ||
subscribersMapper, | ||
mainDispatcher, | ||
backgroundDispatcher, | ||
analyticsTracker | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.