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

Stats - File downloads stats card #10411

Merged
merged 11 commits into from Aug 22, 2019

Show message when selected date is before July 29 2019

  • Loading branch information...
planarvoid committed Aug 19, 2019
commit 1fc8a815944de43b2c27c6c2d23cc3cdf75f8c77

This file was deleted.

@@ -29,6 +29,7 @@ sealed class NavigationTarget {
data class ViewVideoPlays(val statsGranularity: StatsGranularity, val selectedDate: Date) : NavigationTarget()
data class ViewSearchTerms(val statsGranularity: StatsGranularity, val selectedDate: Date) : NavigationTarget()
data class ViewAuthors(val statsGranularity: StatsGranularity, val selectedDate: Date) : NavigationTarget()
data class ViewFileDownloads(val statsGranularity: StatsGranularity, val selectedDate: Date) : NavigationTarget()
data class ViewUrl(val url: String) : NavigationTarget()
object ViewMonthsAndYearsStats : NavigationTarget()
object ViewDayAverageStats : NavigationTarget()
@@ -10,7 +10,7 @@ import org.wordpress.android.fluxc.network.utils.StatsGranularity
import org.wordpress.android.fluxc.store.StatsStore.TimeStatsType.FILE_DOWNLOADS
import org.wordpress.android.fluxc.store.stats.time.FileDownloadsStore
import org.wordpress.android.modules.UI_THREAD
import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewVideoPlays
import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewFileDownloads
import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.UseCaseMode.BLOCK
import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.UseCaseMode.VIEW_ALL
import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem
@@ -23,16 +23,22 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Title
import org.wordpress.android.ui.stats.refresh.lists.sections.granular.GranularStatelessUseCase
import org.wordpress.android.ui.stats.refresh.lists.sections.granular.GranularUseCaseFactory
import org.wordpress.android.ui.stats.refresh.lists.sections.granular.SelectedDateProvider
import org.wordpress.android.ui.stats.refresh.utils.ContentDescriptionHelper
import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider
import org.wordpress.android.ui.stats.refresh.utils.toFormattedString
import org.wordpress.android.ui.stats.refresh.utils.trackGranular
import org.wordpress.android.util.LocaleManagerWrapper
import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper
import java.util.Calendar
import java.util.Date
import javax.inject.Inject
import javax.inject.Named

private const val BLOCK_ITEM_COUNT = 6
private const val VIEW_ALL_ITEM_COUNT = 1000
private const val THRESHOLD_YEAR = 2019
private const val THRESHOLD_MONTH = Calendar.JUNE
private const val THRESHOLD_DAY = 29

class FileDownloadsUseCase
constructor(
@@ -42,6 +48,8 @@ constructor(
statsSiteProvider: StatsSiteProvider,
selectedDateProvider: SelectedDateProvider,
private val analyticsTracker: AnalyticsTrackerWrapper,
private val contentDescriptionHelper: ContentDescriptionHelper,
private val localeManagerWrapper: LocaleManagerWrapper,
private val useCaseMode: UseCaseMode
) : GranularStatelessUseCase<FileDownloadsModel>(
FILE_DOWNLOADS,
@@ -63,6 +71,17 @@ constructor(
)
}

override fun buildEmptyItem(): List<BlockListItem> {
val selectedDate = selectedDateProvider.getSelectedDate(statsGranularity)
val startCalendar = localeManagerWrapper.getCurrentCalendar()
startCalendar.set(THRESHOLD_YEAR, THRESHOLD_MONTH, THRESHOLD_DAY, 0, 0, 0)
return if (selectedDate != null && selectedDate.before(startCalendar.time)) {
buildLoadingItem() + listOf(Empty(textResource = R.string.stats_data_not_recorded_for_period))
} else {
super.buildEmptyItem()
}
}

override suspend fun fetchRemoteData(selectedDate: Date, site: SiteModel, forced: Boolean): State<FileDownloadsModel> {
val response = store.fetchFileDownloads(
site,
@@ -91,12 +110,18 @@ constructor(
if (domainModel.fileDownloads.isEmpty()) {
items.add(Empty(R.string.stats_no_data_for_period))
} else {
items.add(Header(R.string.stats_file_downloads_title_label, R.string.stats_file_downloads_value_label))
val header = Header(R.string.stats_file_downloads_title_label, R.string.stats_file_downloads_value_label)
items.add(header)
items.addAll(domainModel.fileDownloads.mapIndexed { index, fileDownloads ->
ListItemWithIcon(
text = fileDownloads.filename,
value = fileDownloads.downloads.toFormattedString(),
showDivider = index < domainModel.fileDownloads.size - 1
showDivider = index < domainModel.fileDownloads.size - 1,
contentDescription = contentDescriptionHelper.buildContentDescription(
header,
fileDownloads.filename,
fileDownloads.downloads
)
)
})

@@ -113,9 +138,9 @@ constructor(
}

private fun onViewMoreClick(statsGranularity: StatsGranularity) {
analyticsTracker.trackGranular(AnalyticsTracker.Stat.STATS_VIDEO_PLAYS_VIEW_MORE_TAPPED, statsGranularity)
analyticsTracker.trackGranular(AnalyticsTracker.Stat.STATS_FILE_DOWNLOADS_VIEW_MORE_TAPPED, statsGranularity)
navigateTo(
ViewVideoPlays(
ViewFileDownloads(
statsGranularity,
selectedDateProvider.getSelectedDate(statsGranularity) ?: Date()
)
@@ -128,7 +153,9 @@ constructor(
private val store: FileDownloadsStore,
private val selectedDateProvider: SelectedDateProvider,
private val statsSiteProvider: StatsSiteProvider,
private val analyticsTracker: AnalyticsTrackerWrapper
private val analyticsTracker: AnalyticsTrackerWrapper,
private val contentDescriptionHelper: ContentDescriptionHelper,
private val localeManagerWrapper: LocaleManagerWrapper
) : GranularUseCaseFactory {
override fun build(granularity: StatsGranularity, useCaseMode: UseCaseMode) =
FileDownloadsUseCase(
@@ -138,6 +165,8 @@ constructor(
statsSiteProvider,
selectedDateProvider,
analyticsTracker,
contentDescriptionHelper,
localeManagerWrapper,
useCaseMode
)
}
@@ -13,6 +13,7 @@ import org.wordpress.android.ui.stats.StatsViewType.CLICKS
import org.wordpress.android.ui.stats.StatsViewType.COMMENTS
import org.wordpress.android.ui.stats.StatsViewType.DETAIL_MONTHS_AND_YEARS
import org.wordpress.android.ui.stats.StatsViewType.DETAIL_RECENT_WEEKS
import org.wordpress.android.ui.stats.StatsViewType.FILE_DOWNLOADS
import org.wordpress.android.ui.stats.StatsViewType.FOLLOWERS
import org.wordpress.android.ui.stats.StatsViewType.GEOVIEWS
import org.wordpress.android.ui.stats.StatsViewType.PUBLICIZE
@@ -29,6 +30,7 @@ import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewAuthors
import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewClicks
import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewCommentsStats
import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewCountries
import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewFileDownloads
import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewFollowersStats
import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewInsightsManagement
import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewMonthsAndYearsStats
@@ -171,6 +173,14 @@ class StatsNavigator
siteProvider.siteModel.id
)
}
is ViewFileDownloads -> {
ActivityLauncher.viewAllGranularStats(
activity,
target.statsGranularity,
FILE_DOWNLOADS,
siteProvider.siteModel.id
)
}
is ViewAnnualStats -> {
ActivityLauncher.viewAllGranularStats(activity, YEARS, ANNUAL_STATS, siteProvider.siteModel.id)
}
@@ -830,6 +830,7 @@
<string name="stats_menu_move_up">Move up</string>
<string name="stats_menu_move_down">Move down</string>
<string name="stats_menu_remove">Remove from insights</string>
<string name="stats_data_not_recorded_for_period">File download stats were not recorded before June 28th 2019.</string>

<!-- Stats accessibility strings -->
<string name="stats_loading_card">Loading selected card data</string>
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.