Skip to content

Commit

Permalink
Merge pull request #20188 from wordpress-mobile/Stats-Traffic-By-Week…
Browse files Browse the repository at this point in the history
…-Chart

Stats Traffic Charts
  • Loading branch information
ravishanker authored Feb 26, 2024
2 parents 961d85f + 91312d4 commit 6fbf3fd
Show file tree
Hide file tree
Showing 23 changed files with 1,062 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.insights.usecases.T
import org.wordpress.android.ui.stats.refresh.lists.sections.insights.usecases.TotalFollowersUseCase.TotalFollowersUseCaseFactory
import org.wordpress.android.ui.stats.refresh.lists.sections.insights.usecases.TotalLikesUseCase.TotalLikesUseCaseFactory
import org.wordpress.android.ui.stats.refresh.lists.sections.insights.usecases.ViewsAndVisitorsUseCase.ViewsAndVisitorsUseCaseFactory
import org.wordpress.android.ui.stats.refresh.lists.sections.traffic.TrafficOverviewUseCase.TrafficOverviewUseCaseFactory
import org.wordpress.android.ui.stats.refresh.utils.SelectedTrafficGranularityManager
import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider
import org.wordpress.android.util.config.StatsTrafficTabFeatureConfig
Expand All @@ -84,6 +85,7 @@ const val LIST_STATS_USE_CASES = "ListStatsUseCases"
const val BLOCK_INSIGHTS_USE_CASES = "BlockInsightsUseCases"
const val VIEW_ALL_INSIGHTS_USE_CASES = "ViewAllInsightsUseCases"
const val GRANULAR_USE_CASE_FACTORIES = "GranularUseCaseFactories"
const val TRAFFIC_USE_CASE_FACTORIES = "TrafficUseCaseFactories"

// These are injected only internally
private const val BLOCK_DETAIL_USE_CASES = "BlockDetailUseCases"
Expand Down Expand Up @@ -209,7 +211,7 @@ class StatsModule {
searchTermsUseCaseFactory: SearchTermsUseCaseFactory,
authorsUseCaseFactory: AuthorsUseCaseFactory,
overviewUseCaseFactory: OverviewUseCaseFactory,
fileDownloadsUseCaseFactory: FileDownloadsUseCaseFactory
fileDownloadsUseCaseFactory: FileDownloadsUseCaseFactory,
): List<@JvmSuppressWildcards GranularUseCaseFactory> {
return listOf(
postsAndPagesUseCaseFactory,
Expand All @@ -220,7 +222,7 @@ class StatsModule {
searchTermsUseCaseFactory,
authorsUseCaseFactory,
overviewUseCaseFactory,
fileDownloadsUseCaseFactory
fileDownloadsUseCaseFactory,
)
}

Expand Down Expand Up @@ -273,6 +275,38 @@ class StatsModule {
)
}

/**
* Provides a list of use case factories that build use cases for the Traffic stats screen based on the given
* granularity (Day, Week, Month, Year).
*/
@Provides
@Singleton
@Named(TRAFFIC_USE_CASE_FACTORIES)
@Suppress("LongParameterList")
fun provideTrafficUseCaseFactories(
postsAndPagesUseCaseFactory: PostsAndPagesUseCaseFactory,
referrersUseCaseFactory: ReferrersUseCaseFactory,
clicksUseCaseFactory: ClicksUseCaseFactory,
countryViewsUseCaseFactory: CountryViewsUseCaseFactory,
videoPlaysUseCaseFactory: VideoPlaysUseCaseFactory,
searchTermsUseCaseFactory: SearchTermsUseCaseFactory,
authorsUseCaseFactory: AuthorsUseCaseFactory,
trafficOverviewUseCaseFactory: TrafficOverviewUseCaseFactory,
fileDownloadsUseCaseFactory: FileDownloadsUseCaseFactory
): List<@JvmSuppressWildcards GranularUseCaseFactory> {
return listOf(
postsAndPagesUseCaseFactory,
referrersUseCaseFactory,
clicksUseCaseFactory,
countryViewsUseCaseFactory,
videoPlaysUseCaseFactory,
searchTermsUseCaseFactory,
authorsUseCaseFactory,
trafficOverviewUseCaseFactory,
fileDownloadsUseCaseFactory
)
}

/**
* Provides a singleton usecase that represents the TRAFFIC stats screen.
* @param useCasesFactories build the use cases for the DAYS granularity
Expand All @@ -285,7 +319,7 @@ class StatsModule {
@Named(BG_THREAD) bgDispatcher: CoroutineDispatcher,
@Named(UI_THREAD) mainDispatcher: CoroutineDispatcher,
statsSiteProvider: StatsSiteProvider,
@Named(GRANULAR_USE_CASE_FACTORIES) useCasesFactories: List<@JvmSuppressWildcards GranularUseCaseFactory>,
@Named(TRAFFIC_USE_CASE_FACTORIES) useCasesFactories: List<@JvmSuppressWildcards GranularUseCaseFactory>,
selectedTrafficGranularityManager: SelectedTrafficGranularityManager,
uiModelMapper: UiModelMapper
): BaseListUseCase {
Expand Down Expand Up @@ -421,7 +455,10 @@ class StatsModule {
trafficTabFeatureConfig: StatsTrafficTabFeatureConfig
): Map<StatsSection, BaseListUseCase> {
return if (trafficTabFeatureConfig.isEnabled()) {
mapOf(StatsSection.TRAFFIC to trafficUseCase, StatsSection.INSIGHTS to insightsUseCase)
mapOf(
StatsSection.TRAFFIC to trafficUseCase,
StatsSection.INSIGHTS to insightsUseCase
)
} else {
mapOf(
StatsSection.INSIGHTS to insightsUseCase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider
import org.wordpress.android.ui.stats.refresh.utils.drawDateSelector
import org.wordpress.android.ui.utils.UiHelpers
import org.wordpress.android.util.WPSwipeToRefreshHelper
import org.wordpress.android.util.config.StatsTrafficTabFeatureConfig
import org.wordpress.android.util.extensions.getParcelableCompat
import org.wordpress.android.util.extensions.getParcelableExtraCompat
import org.wordpress.android.util.extensions.getSerializableCompat
Expand All @@ -61,6 +62,10 @@ class StatsViewAllFragment : Fragment(R.layout.stats_view_all_fragment) {

@Inject
lateinit var uiHelpers: UiHelpers

@Inject
lateinit var trafficTabFeatureConfig: StatsTrafficTabFeatureConfig

private lateinit var viewModel: StatsViewAllViewModel
private lateinit var swipeToRefreshHelper: SwipeToRefreshHelper
private var binding: StatsViewAllFragmentBinding? = null
Expand Down Expand Up @@ -283,7 +288,7 @@ class StatsViewAllFragment : Fragment(R.layout.stats_view_all_fragment) {
private fun loadData(recyclerView: RecyclerView, data: List<BlockListItem>) {
val adapter: BlockListAdapter
if (recyclerView.adapter == null) {
adapter = BlockListAdapter(imageManager)
adapter = BlockListAdapter(imageManager, trafficTabFeatureConfig.isEnabled())
recyclerView.adapter = adapter
} else {
adapter = recyclerView.adapter as BlockListAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import org.wordpress.android.ui.stats.refresh.lists.viewholders.BlockListViewHol
import org.wordpress.android.ui.stats.refresh.lists.viewholders.LoadingViewHolder
import org.wordpress.android.util.image.ImageManager

class StatsBlockAdapter(val imageManager: ImageManager) : Adapter<BaseStatsViewHolder>() {
class StatsBlockAdapter(
val imageManager: ImageManager,
private val trafficTabEnabled: Boolean
) : Adapter<BaseStatsViewHolder>() {
private var items: List<StatsBlock> = listOf()

fun update(newItems: List<StatsBlock>) {
Expand All @@ -30,8 +33,8 @@ class StatsBlockAdapter(val imageManager: ImageManager) : Adapter<BaseStatsViewH

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseStatsViewHolder {
return when (values()[viewType]) {
SUCCESS, ERROR, EMPTY -> BlockListViewHolder(parent, imageManager)
LOADING -> LoadingViewHolder(parent, imageManager)
SUCCESS, ERROR, EMPTY -> BlockListViewHolder(parent, imageManager, trafficTabEnabled)
LOADING -> LoadingViewHolder(parent, imageManager, trafficTabEnabled)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ class StatsListFragment : ViewPagerFragment(R.layout.stats_list_fragment) {

val adapter: StatsBlockAdapter
if (recyclerView.adapter == null) {
adapter = StatsBlockAdapter(imageManager)
adapter = StatsBlockAdapter(imageManager, statsTrafficTabFeatureConfig.isEnabled())
recyclerView.adapter = adapter
} else {
adapter = recyclerView.adapter as StatsBlockAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import org.wordpress.android.fluxc.network.utils.StatsGranularity
import org.wordpress.android.fluxc.store.StatsStore
import org.wordpress.android.modules.UI_THREAD
import org.wordpress.android.ui.stats.refresh.DAY_STATS_USE_CASE
import org.wordpress.android.ui.stats.refresh.GRANULAR_USE_CASE_FACTORIES
import org.wordpress.android.ui.stats.refresh.INSIGHTS_USE_CASE
import org.wordpress.android.ui.stats.refresh.MONTH_STATS_USE_CASE
import org.wordpress.android.ui.stats.refresh.NavigationTarget
Expand All @@ -24,6 +23,7 @@ import org.wordpress.android.ui.stats.refresh.TOTAL_COMMENTS_DETAIL_USE_CASE
import org.wordpress.android.ui.stats.refresh.TOTAL_FOLLOWERS_DETAIL_USE_CASE
import org.wordpress.android.ui.stats.refresh.TOTAL_LIKES_DETAIL_USE_CASE
import org.wordpress.android.ui.stats.refresh.TRAFFIC_USE_CASE
import org.wordpress.android.ui.stats.refresh.TRAFFIC_USE_CASE_FACTORIES
import org.wordpress.android.ui.stats.refresh.VIEWS_AND_VISITORS_USE_CASE
import org.wordpress.android.ui.stats.refresh.WEEK_STATS_USE_CASE
import org.wordpress.android.ui.stats.refresh.YEAR_STATS_USE_CASE
Expand Down Expand Up @@ -217,7 +217,7 @@ class TrafficListViewModel @Inject constructor(
@Named(TRAFFIC_USE_CASE) private val trafficStatsUseCase: BaseListUseCase,
private val analyticsTracker: AnalyticsTrackerWrapper,
dateSelectorFactory: StatsDateSelector.Factory,
@Named(GRANULAR_USE_CASE_FACTORIES)
@Named(TRAFFIC_USE_CASE_FACTORIES)
private val useCasesFactories: List<@JvmSuppressWildcards GranularUseCaseFactory>,
private val selectedTrafficGranularityManager: SelectedTrafficGranularityManager,
) : StatsListViewModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.
import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.ValueItem
import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.ValueWithChartItem
import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.ValuesItem
import org.wordpress.android.ui.stats.refresh.lists.sections.traffic.TrafficBarChartViewHolder
import org.wordpress.android.ui.stats.refresh.lists.sections.traffic.TrafficFourColumnsViewHolder
import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.ActionCardViewHolder
import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.ActivityViewHolder
import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.BarChartViewHolder
Expand Down Expand Up @@ -117,7 +119,10 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.ValueWi
import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.ValuesViewHolder
import org.wordpress.android.util.image.ImageManager

class BlockListAdapter(val imageManager: ImageManager) : Adapter<BlockListItemViewHolder>() {
class BlockListAdapter(
val imageManager: ImageManager,
private val trafficTabEnabled: Boolean
) : Adapter<BlockListItemViewHolder>() {
private var items: List<BlockListItem> = listOf()
fun update(newItems: List<BlockListItem>) {
val diffResult = DiffUtil.calculateDiff(
Expand All @@ -142,10 +147,10 @@ class BlockListAdapter(val imageManager: ImageManager) : Adapter<BlockListItemVi
LIST_ITEM -> ListItemViewHolder(parent)
EMPTY -> EmptyViewHolder(parent)
TEXT -> TextViewHolder(parent)
COLUMNS -> FourColumnsViewHolder(parent)
COLUMNS -> if (trafficTabEnabled) TrafficFourColumnsViewHolder(parent) else FourColumnsViewHolder(parent)
CHIPS -> ChipsViewHolder(parent)
LINK -> LinkViewHolder(parent)
BAR_CHART -> BarChartViewHolder(parent)
BAR_CHART -> if (trafficTabEnabled) TrafficBarChartViewHolder(parent) else BarChartViewHolder(parent)
PIE_CHART -> PieChartViewHolder(parent)
LINE_CHART -> LineChartViewHolder(parent)
CHART_LEGEND -> ChartLegendViewHolder(parent)
Expand Down Expand Up @@ -193,9 +198,11 @@ class BlockListAdapter(val imageManager: ImageManager) : Adapter<BlockListItemVi
is ListItemViewHolder -> holder.bind(item as ListItem)
is TextViewHolder -> holder.bind(item as Text)
is FourColumnsViewHolder -> holder.bind(item as Columns, payloads)
is TrafficFourColumnsViewHolder -> holder.bind(item as Columns, payloads)
is ChipsViewHolder -> holder.bind(item as Chips)
is LinkViewHolder -> holder.bind(item as Link)
is BarChartViewHolder -> holder.bind(item as BarChartItem)
is TrafficBarChartViewHolder -> holder.bind(item as BarChartItem)
is PieChartViewHolder -> holder.bind(item as PieChartItem)
is LineChartViewHolder -> holder.bind(item as LineChartItem)
is ChartLegendViewHolder -> holder.bind(item as ChartLegend)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ sealed class BlockListItem(val type: Type) {
@StringRes val unit: Int,
val isFirst: Boolean = false,
val change: String? = null,
val period: Int = 0,
val state: State = POSITIVE,
val contentDescription: String
) : BlockListItem(VALUE_ITEM) {
Expand Down
Loading

0 comments on commit 6fbf3fd

Please sign in to comment.