From a0d9f2aa7ea48c81a928f203e6d138bf60286792 Mon Sep 17 00:00:00 2001
From: YUCHEN YAN <128272509+Arvinyuchen@users.noreply.github.com>
Date: Fri, 1 Nov 2024 21:57:17 +1100
Subject: [PATCH] Make it easier to understand years statistics diagram when
there are few months (#7454)
---
ui/i18n/src/main/res/values/strings.xml | 1 +
.../ui/statistics/years/BarChartView.java | 17 ++++++++++++-----
.../res/layout/statistics_listitem_barchart.xml | 8 ++++++++
3 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/ui/i18n/src/main/res/values/strings.xml b/ui/i18n/src/main/res/values/strings.xml
index fe03c8ed5..3fb2ad923 100644
--- a/ui/i18n/src/main/res/values/strings.xml
+++ b/ui/i18n/src/main/res/values/strings.xml
@@ -751,6 +751,7 @@
Any day now
Unknown
All podcasts »
+ Time played per month
…
Edit feed URL
Changing the RSS address can easily break the playback state and episode listings of the podcast. We do NOT recommend changing it and will NOT provide support if anything goes wrong. This cannot be undone. The broken subscription CANNOT be repaired by simply changing the address back. We recommend creating a backup before continuing.
diff --git a/ui/statistics/src/main/java/de/danoeh/antennapod/ui/statistics/years/BarChartView.java b/ui/statistics/src/main/java/de/danoeh/antennapod/ui/statistics/years/BarChartView.java
index 510bcb8e1..44e33ba21 100644
--- a/ui/statistics/src/main/java/de/danoeh/antennapod/ui/statistics/years/BarChartView.java
+++ b/ui/statistics/src/main/java/de/danoeh/antennapod/ui/statistics/years/BarChartView.java
@@ -89,18 +89,25 @@ public class BarChartView extends AppCompatImageView {
paintBars.setStrokeWidth(height * 0.015f);
paintBars.setColor(colors[0]);
int colorIndex = 0;
- int lastYear = data.size() > 0 ? data.get(0).getYear() : 0;
+ int prevYear = data.isEmpty() ? 0 : data.get(0).getYear();
+ int monthsInFirstYear = 0;
+ while (monthsInFirstYear < data.size() && data.get(monthsInFirstYear).getYear() == data.get(0).getYear()) {
+ monthsInFirstYear++;
+ }
+
for (int i = 0; i < data.size(); i++) {
float x = textPadding + (i + 1) * stepSize;
- if (lastYear != data.get(i).getYear()) {
- lastYear = data.get(i).getYear();
+ if (prevYear != data.get(i).getYear() || (i == 0 && monthsInFirstYear > 4)) {
+ prevYear = data.get(i).getYear();
colorIndex++;
paintBars.setColor(colors[colorIndex % 2]);
- if (i < data.size() - 2) {
+ if (i < data.size() - 4) {
canvas.drawText(String.valueOf(data.get(i).getYear()), x + stepSize,
barHeight + (height - barHeight + textSize) / 2, paintGridText);
}
- canvas.drawLine(x, height, x, barHeight, paintGridText);
+ if (data.get(i).getMonth() == 1) {
+ canvas.drawLine(x, height, x, barHeight, paintGridText);
+ }
}
float valuePercentage = (float) Math.max(0.005, (float) data.get(i).getTimePlayed() / maxValue);
diff --git a/ui/statistics/src/main/res/layout/statistics_listitem_barchart.xml b/ui/statistics/src/main/res/layout/statistics_listitem_barchart.xml
index d70e1da07..8830a812b 100644
--- a/ui/statistics/src/main/res/layout/statistics_listitem_barchart.xml
+++ b/ui/statistics/src/main/res/layout/statistics_listitem_barchart.xml
@@ -11,6 +11,14 @@
android:layout_width="match_parent"
android:layout_height="200dp" />
+
+