Skip to content

Commit

Permalink
Merge pull request #20776 from wordpress-mobile/fix/subcribers-chart-…
Browse files Browse the repository at this point in the history
…issues

Fix subscribers chart issues
  • Loading branch information
irfano authored May 22, 2024
2 parents bddec83 + e31a090 commit b8d617e
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class SubscribersChartMarkerView @Inject constructor(
@Inject
lateinit var statsDateFormatter: StatsDateFormatter
private val countView = findViewById<TextView>(R.id.marker_text1)
private val dateView = findViewById<TextView>(R.id.marker_text2)
private val labelView = findViewById<TextView>(R.id.marker_text2)
private val dateView = findViewById<TextView>(R.id.marker_text3)

override fun refreshContent(e: Entry?, highlight: Highlight?) {
val lineChart = chartView as? LineChart ?: return
Expand All @@ -46,6 +47,12 @@ class SubscribersChartMarkerView @Inject constructor(

val count = yValue.toLong()
countView.text = count.toString()
val label = if (count > 1) {
R.string.stats_subscribers_marker_view_plural
} else {
R.string.stats_subscribers_marker_view_singular
}
labelView.setText(label)
val date = statsDateFormatter.getStatsDateFromPeriodDay(e.data.toString())
dateView.text = date

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SubscribersChartUseCase @Inject constructor(
@Named(BG_THREAD) private val backgroundDispatcher: CoroutineDispatcher,
private val analyticsTracker: AnalyticsTrackerWrapper
) : StatelessUseCase<SubscribersModel>(SUBSCRIBERS_CHART, mainDispatcher, backgroundDispatcher) {
override fun buildLoadingItem(): List<BlockListItem> = listOf()
override fun buildLoadingItem(): List<BlockListItem> = listOf(Title(R.string.stats_view_subscribers))

override suspend fun loadCachedData() = subscribersStore.getSubscribers(
statsSiteProvider.siteModel,
Expand Down Expand Up @@ -68,7 +68,7 @@ class SubscribersChartUseCase @Inject constructor(
return items
}

private fun buildTitle() = Title(R.string.stats_view_subscribers_chart)
private fun buildTitle() = Title(R.string.stats_view_subscriber_growth)

private fun onLineSelected() {
analyticsTracker.track(AnalyticsTracker.Stat.STATS_SUBSCRIBERS_CHART_TAPPED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SubscribersMapper @Inject constructor(
}

val contentDescriptions = statsUtils.getSubscribersChartEntryContentDescriptions(
R.string.stats_view_subscribers_chart,
R.string.stats_subscribers_marker_view_plural,
chartItems
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class SubscribersChartViewHolder(parent: ViewGroup) : BlockListItemViewHolder(
}

private fun getData(item: SubscribersChartItem): List<ILineDataSet> {
val data = if (item.entries.isEmpty() || item.entries.all { it.value == 0 }) {
val data = if (item.entries.isEmpty()) {
buildEmptyDataSet(item.entries.size)
} else {
val mappedEntries = item.entries.mapIndexed { index, pair -> toLineEntry(pair, index) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class LineChartLabelFormatter @Inject constructor(
) : ValueFormatter() {
override fun getAxisLabel(value: Float, axis: AxisBase?): String {
val index = value.toInt()
return if (entries.isNotEmpty() && index in 0..entries.size) {
return if (entries.isNotEmpty() && index in entries.indices) {
entries[index].label
} else {
""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SubscribersChartLabelFormatter @Inject constructor(
) : ValueFormatter() {
override fun getAxisLabel(value: Float, axis: AxisBase?): String {
val index = value.toInt()
return if (entries.isNotEmpty() && index in 0..entries.size) {
return if (entries.isNotEmpty() && index in entries.indices) {
entries[index].label
} else {
""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
tools:text="6500" />

<TextView
android:id="@+id/marker_text2"
style="@style/TextAppearance.MaterialComponents.Caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/stats_view_subscribers_chart"
android:text="@string/stats_subscribers_marker_view_plural"
android:textColor="@color/stats_tool_tip_body" />

<TextView
android:id="@+id/marker_text2"
android:id="@+id/marker_text3"
style="@style/TextAppearance.MaterialComponents.Caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
4 changes: 3 additions & 1 deletion WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1327,9 +1327,11 @@
<string name="stats_view_total_likes">Total Likes</string>
<string name="stats_view_total_comments">Total Comments</string>
<string name="stats_view_total_subscribers">Total Subscribers</string>
<string name="stats_view_subscribers_chart">Subscribers</string>
<string name="stats_view_subscriber_growth">Subscriber Growth</string>
<string name="stats_view_subscribers">Subscribers</string>
<string name="stats_view_emails">Emails</string>
<string name="stats_subscribers_marker_view_singular">Subscriber</string>
<string name="stats_subscribers_marker_view_plural">Subscribers</string>

<!-- stats: followers -->
<string name="stats_followers_seconds_ago">seconds ago</string>
Expand Down

0 comments on commit b8d617e

Please sign in to comment.