Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Add listening goals, chart styles, and a customizable stats page

Barnabas50ac438451d1
diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb
index 96117123..deaf0764 100644
--- a/lib/l10n/app_en.arb
+++ b/lib/l10n/app_en.arb
@@ -403,6 +403,45 @@
"statsAddedBackToYear": "Added back to this year",
"statsHiddenFromYear": "Hidden from this year",
"statsNothingHidden": "Nothing hidden",
+ "settingsCustomizeStats": "Customize stats",
+ "statsGoalTitle": "Listening goal",
+ "statsGoalOff": "Off",
+ "statsGoalDaily": "Daily",
+ "statsGoalWeekly": "Weekly",
+ "statsGoalMonthly": "Monthly",
+ "statsGoalTarget": "Target",
+ "statsGoalEnterTitle": "Set target",
+ "statsGoalEnterTimeHint": "Minutes or h:mm",
+ "statsBooksShort": "{count} books",
+ "@statsBooksShort": {
+ "placeholders": { "count": { "type": "int" } }
+ },
+ "statsBookChallengeTitle": "Reading challenge",
+ "statsBookChallengeDesc": "Books to finish this year",
+ "statsDailyGoal": "Daily goal",
+ "statsWeeklyGoal": "Weekly goal",
+ "statsMonthlyGoal": "Monthly goal",
+ "statsGoalProgress": "{done} / {target}",
+ "@statsGoalProgress": {
+ "placeholders": { "done": { "type": "String" }, "target": { "type": "String" } }
+ },
+ "statsBookChallengeProgress": "{done} of {target} books",
+ "@statsBookChallengeProgress": {
+ "placeholders": { "done": { "type": "int" }, "target": { "type": "int" } }
+ },
+ "statsGoalReached": "Goal reached",
+ "statsChartTitle": "Listening chart",
+ "statsChartBar": "Bar",
+ "statsChartLine": "Line",
+ "statsChartHeatmap": "Heatmap",
+ "statsChartDays7": "7 days",
+ "statsChartDays30": "30 days",
+ "statsLast30Days": "Last 30 days",
+ "statsThisYearTitle": "This year",
+ "statsSectionsTitle": "Sections",
+ "statsSectionTimePeriods": "Time periods",
+ "statsHeatmapLess": "Less",
+ "statsHeatmapMore": "More",
"statsDaysActive": "Days Active",
"statsDailyAverage": "Daily Average",
"statsLast7Days": "Last 7 Days",
diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart
index 22f1f061..dab676d9 100644
--- a/lib/l10n/app_localizations.dart
+++ b/lib/l10n/app_localizations.dart
@@ -1456,6 +1456,186 @@ abstract class AppLocalizations {
/// **'Nothing hidden'**
String get statsNothingHidden;
+ /// No description provided for @settingsCustomizeStats.
+ ///
+ /// In en, this message translates to:
+ /// **'Customize stats'**
+ String get settingsCustomizeStats;
+
+ /// No description provided for @statsGoalTitle.
+ ///
+ /// In en, this message translates to:
+ /// **'Listening goal'**
+ String get statsGoalTitle;
+
+ /// No description provided for @statsGoalOff.
+ ///
+ /// In en, this message translates to:
+ /// **'Off'**
+ String get statsGoalOff;
+
+ /// No description provided for @statsGoalDaily.
+ ///
+ /// In en, this message translates to:
+ /// **'Daily'**
+ String get statsGoalDaily;
+
+ /// No description provided for @statsGoalWeekly.
+ ///
+ /// In en, this message translates to:
+ /// **'Weekly'**
+ String get statsGoalWeekly;
+
+ /// No description provided for @statsGoalMonthly.
+ ///
+ /// In en, this message translates to:
+ /// **'Monthly'**
+ String get statsGoalMonthly;
+
+ /// No description provided for @statsGoalTarget.
+ ///
+ /// In en, this message translates to:
+ /// **'Target'**
+ String get statsGoalTarget;
+
+ /// No description provided for @statsGoalEnterTitle.
+ ///
+ /// In en, this message translates to:
+ /// **'Set target'**
+ String get statsGoalEnterTitle;
+
+ /// No description provided for @statsGoalEnterTimeHint.
+ ///
+ /// In en, this message translates to:
+ /// **'Minutes or h:mm'**
+ String get statsGoalEnterTimeHint;
+
+ /// No description provided for @statsBooksShort.
+ ///
+ /// In en, this message translates to:
+ /// **'{count} books'**
+ String statsBooksShort(int count);
+
+ /// No description provided for @statsBookChallengeTitle.
+ ///
+ /// In en, this message translates to:
+ /// **'Reading challenge'**
+ String get statsBookChallengeTitle;
+
+ /// No description provided for @statsBookChallengeDesc.
+ ///
+ /// In en, this message translates to:
+ /// **'Books to finish this year'**
+ String get statsBookChallengeDesc;
+
+ /// No description provided for @statsDailyGoal.
+ ///
+ /// In en, this message translates to:
+ /// **'Daily goal'**
+ String get statsDailyGoal;
+
+ /// No description provided for @statsWeeklyGoal.
+ ///
+ /// In en, this message translates to:
+ /// **'Weekly goal'**
+ String get statsWeeklyGoal;
+
+ /// No description provided for @statsMonthlyGoal.
+ ///
+ /// In en, this message translates to:
+ /// **'Monthly goal'**
+ String get statsMonthlyGoal;
+
+ /// No description provided for @statsGoalProgress.
+ ///
+ /// In en, this message translates to:
+ /// **'{done} / {target}'**
+ String statsGoalProgress(String done, String target);
+
+ /// No description provided for @statsBookChallengeProgress.
+ ///
+ /// In en, this message translates to:
+ /// **'{done} of {target} books'**
+ String statsBookChallengeProgress(int done, int target);
+
+ /// No description provided for @statsGoalReached.
+ ///
+ /// In en, this message translates to:
+ /// **'Goal reached'**
+ String get statsGoalReached;
+
+ /// No description provided for @statsChartTitle.
+ ///
+ /// In en, this message translates to:
+ /// **'Listening chart'**
+ String get statsChartTitle;
+
+ /// No description provided for @statsChartBar.
+ ///
+ /// In en, this message translates to:
+ /// **'Bar'**
+ String get statsChartBar;
+
+ /// No description provided for @statsChartLine.
+ ///
+ /// In en, this message translates to:
+ /// **'Line'**
+ String get statsChartLine;
+
+ /// No description provided for @statsChartHeatmap.
+ ///
+ /// In en, this message translates to:
+ /// **'Heatmap'**
+ String get statsChartHeatmap;
+
+ /// No description provided for @statsChartDays7.
+ ///
+ /// In en, this message translates to:
+ /// **'7 days'**
+ String get statsChartDays7;
+
+ /// No description provided for @statsChartDays30.
+ ///
+ /// In en, this message translates to:
+ /// **'30 days'**
+ String get statsChartDays30;
+
+ /// No description provided for @statsLast30Days.
+ ///
+ /// In en, this message translates to:
+ /// **'Last 30 days'**
+ String get statsLast30Days;
+
+ /// No description provided for @statsThisYearTitle.
+ ///
+ /// In en, this message translates to:
+ /// **'This year'**
+ String get statsThisYearTitle;
+
+ /// No description provided for @statsSectionsTitle.
+ ///
+ /// In en, this message translates to:
+ /// **'Sections'**
+ String get statsSectionsTitle;
+
+ /// No description provided for @statsSectionTimePeriods.
+ ///
+ /// In en, this message translates to:
+ /// **'Time periods'**
+ String get statsSectionTimePeriods;
+
+ /// No description provided for @statsHeatmapLess.
+ ///
+ /// In en, this message translates to:
+ /// **'Less'**
+ String get statsHeatmapLess;
+
+ /// No description provided for @statsHeatmapMore.
+ ///
+ /// In en, this message translates to:
+ /// **'More'**
+ String get statsHeatmapMore;
+
/// No description provided for @statsDaysActive.
///
/// In en, this message translates to:
diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart
index 329508d3..137847d0 100644
--- a/lib/l10n/app_localizations_de.dart
+++ b/lib/l10n/app_localizations_de.dart
@@ -754,6 +754,102 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get statsNothingHidden => 'Nothing hidden';
+ @override
+ String get settingsCustomizeStats => 'Customize stats';
+
+ @override
+ String get statsGoalTitle => 'Listening goal';
+
+ @override
+ String get statsGoalOff => 'Off';
+
+ @override
+ String get statsGoalDaily => 'Daily';
+
+ @override
+ String get statsGoalWeekly => 'Weekly';
+
+ @override
+ String get statsGoalMonthly => 'Monthly';
+
+ @override
+ String get statsGoalTarget => 'Target';
+
+ @override
+ String get statsGoalEnterTitle => 'Set target';
+
+ @override
+ String get statsGoalEnterTimeHint => 'Minutes or h:mm';
+
+ @override
+ String statsBooksShort(int count) {
+ return '$count books';
+ }
+
+ @override
+ String get statsBookChallengeTitle => 'Reading challenge';
+
+ @override
+ String get statsBookChallengeDesc => 'Books to finish this year';
+
+ @override
+ String get statsDailyGoal => 'Daily goal';
+
+ @override
+ String get statsWeeklyGoal => 'Weekly goal';
+
+ @override
+ String get statsMonthlyGoal => 'Monthly goal';
+
+ @override
+ String statsGoalProgress(String done, String target) {
+ return '$done / $target';
+ }
+
+ @override
+ String statsBookChallengeProgress(int done, int target) {
+ return '$done of $target books';
+ }
+
+ @override
+ String get statsGoalReached => 'Goal reached';
+
+ @override
+ String get statsChartTitle => 'Listening chart';
+
+ @override
+ String get statsChartBar => 'Bar';
+
+ @override
+ String get statsChartLine => 'Line';
+
+ @override
+ String get statsChartHeatmap => 'Heatmap';
+
+ @override
+ String get statsChartDays7 => '7 days';
+
+ @override
+ String get statsChartDays30 => '30 days';
+
+ @override
+ String get statsLast30Days => 'Last 30 days';
+
+ @override
+ String get statsThisYearTitle => 'This year';
+
+ @override
+ String get statsSectionsTitle => 'Sections';
+
+ @override
+ String get statsSectionTimePeriods => 'Time periods';
+
+ @override
+ String get statsHeatmapLess => 'Less';
+
+ @override
+ String get statsHeatmapMore => 'More';
+
@override
String get statsDaysActive => 'Aktive Tage';
diff --git a/lib/l10n/app_localizations_el.dart b/lib/l10n/app_localizations_el.dart
index 1a72fa74..b9c66e28 100644
--- a/lib/l10n/app_localizations_el.dart
+++ b/lib/l10n/app_localizations_el.dart
@@ -749,6 +749,102 @@ class AppLocalizationsEl extends AppLocalizations {
@override
String get statsNothingHidden => 'Nothing hidden';
+ @override
+ String get settingsCustomizeStats => 'Customize stats';
+
+ @override
+ String get statsGoalTitle => 'Listening goal';
+
+ @override
+ String get statsGoalOff => 'Off';
+
+ @override
+ String get statsGoalDaily => 'Daily';
+
+ @override
+ String get statsGoalWeekly => 'Weekly';
+
+ @override
+ String get statsGoalMonthly => 'Monthly';
+
+ @override
+ String get statsGoalTarget => 'Target';
+
+ @override
+ String get statsGoalEnterTitle => 'Set target';
+
+ @override
+ String get statsGoalEnterTimeHint => 'Minutes or h:mm';
+
+ @override
+ String statsBooksShort(int count) {
+ return '$count books';
+ }
+
+ @override
+ String get statsBookChallengeTitle => 'Reading challenge';
+
+ @override
+ String get statsBookChallengeDesc => 'Books to finish this year';
+
+ @override
+ String get statsDailyGoal => 'Daily goal';
+
+ @override
+ String get statsWeeklyGoal => 'Weekly goal';
+
+ @override
+ String get statsMonthlyGoal => 'Monthly goal';
+
+ @override
+ String statsGoalProgress(String done, String target) {
+ return '$done / $target';
+ }
+
+ @override
+ String statsBookChallengeProgress(int done, int target) {
+ return '$done of $target books';
+ }
+
+ @override
+ String get statsGoalReached => 'Goal reached';
+
+ @override
+ String get statsChartTitle => 'Listening chart';
+
+ @override
+ String get statsChartBar => 'Bar';
+
+ @override
+ String get statsChartLine => 'Line';
+
+ @override
+ String get statsChartHeatmap => 'Heatmap';
+
+ @override
+ String get statsChartDays7 => '7 days';
+
+ @override
+ String get statsChartDays30 => '30 days';
+
+ @override
+ String get statsLast30Days => 'Last 30 days';
+
+ @override
+ String get statsThisYearTitle => 'This year';
+
+ @override
+ String get statsSectionsTitle => 'Sections';
+
+ @override
+ String get statsSectionTimePeriods => 'Time periods';
+
+ @override
+ String get statsHeatmapLess => 'Less';
+
+ @override
+ String get statsHeatmapMore => 'More';
+
@override
String get statsDaysActive => 'Days Active';
diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart
index c358ef5c..f183e4a3 100644
--- a/lib/l10n/app_localizations_en.dart
+++ b/lib/l10n/app_localizations_en.dart
@@ -749,6 +749,102 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get statsNothingHidden => 'Nothing hidden';
+ @override
+ String get settingsCustomizeStats => 'Customize stats';
+
+ @override
+ String get statsGoalTitle => 'Listening goal';
+
+ @override
+ String get statsGoalOff => 'Off';
+
+ @override
+ String get statsGoalDaily => 'Daily';
+
+ @override
+ String get statsGoalWeekly => 'Weekly';
+
+ @override
+ String get statsGoalMonthly => 'Monthly';
+
+ @override
+ String get statsGoalTarget => 'Target';
+
+ @override
+ String get statsGoalEnterTitle => 'Set target';
+
+ @override
+ String get statsGoalEnterTimeHint => 'Minutes or h:mm';
+
+ @override
+ String statsBooksShort(int count) {
+ return '$count books';
+ }
+
+ @override
+ String get statsBookChallengeTitle => 'Reading challenge';
+
+ @override
+ String get statsBookChallengeDesc => 'Books to finish this year';
+
+ @override
+ String get statsDailyGoal => 'Daily goal';
+
+ @override
+ String get statsWeeklyGoal => 'Weekly goal';
+
+ @override
+ String get statsMonthlyGoal => 'Monthly goal';
+
+ @override
+ String statsGoalProgress(String done, String target) {
+ return '$done / $target';
+ }
+
+ @override
+ String statsBookChallengeProgress(int done, int target) {
+ return '$done of $target books';
+ }
+
+ @override
+ String get statsGoalReached => 'Goal reached';
+
+ @override
+ String get statsChartTitle => 'Listening chart';
+
+ @override
+ String get statsChartBar => 'Bar';
+
+ @override
+ String get statsChartLine => 'Line';
+
+ @override
+ String get statsChartHeatmap => 'Heatmap';
+
+ @override
+ String get statsChartDays7 => '7 days';
+
+ @override
+ String get statsChartDays30 => '30 days';
+
+ @override
+ String get statsLast30Days => 'Last 30 days';
+
+ @override
+ String get statsThisYearTitle => 'This year';
+
+ @override
+ String get statsSectionsTitle => 'Sections';
+
+ @override
+ String get statsSectionTimePeriods => 'Time periods';
+
+ @override
+ String get statsHeatmapLess => 'Less';
+
+ @override
+ String get statsHeatmapMore => 'More';
+
@override
String get statsDaysActive => 'Days Active';
diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dart
index d009ec8c..2d51a2a8 100644
--- a/lib/l10n/app_localizations_es.dart
+++ b/lib/l10n/app_localizations_es.dart
@@ -749,6 +749,102 @@ class AppLocalizationsEs extends AppLocalizations {
@override
String get statsNothingHidden => 'Nothing hidden';
+ @override
+ String get settingsCustomizeStats => 'Customize stats';
+
+ @override
+ String get statsGoalTitle => 'Listening goal';
+
+ @override
+ String get statsGoalOff => 'Off';
+
+ @override
+ String get statsGoalDaily => 'Daily';
+
+ @override
+ String get statsGoalWeekly => 'Weekly';
+
+ @override
+ String get statsGoalMonthly => 'Monthly';
+
+ @override
+ String get statsGoalTarget => 'Target';
+
+ @override
+ String get statsGoalEnterTitle => 'Set target';
+
+ @override
+ String get statsGoalEnterTimeHint => 'Minutes or h:mm';
+
+ @override
+ String statsBooksShort(int count) {
+ return '$count books';
+ }
+
+ @override
+ String get statsBookChallengeTitle => 'Reading challenge';
+
+ @override
+ String get statsBookChallengeDesc => 'Books to finish this year';
+
+ @override
+ String get statsDailyGoal => 'Daily goal';
+
+ @override
+ String get statsWeeklyGoal => 'Weekly goal';
+
+ @override
+ String get statsMonthlyGoal => 'Monthly goal';
+
+ @override
+ String statsGoalProgress(String done, String target) {
+ return '$done / $target';
+ }
+
+ @override
+ String statsBookChallengeProgress(int done, int target) {
+ return '$done of $target books';
+ }
+
+ @override
+ String get statsGoalReached => 'Goal reached';
+
+ @override
+ String get statsChartTitle => 'Listening chart';
+
+ @override
+ String get statsChartBar => 'Bar';
+
+ @override
+ String get statsChartLine => 'Line';
+
+ @override
+ String get statsChartHeatmap => 'Heatmap';
+
+ @override
+ String get statsChartDays7 => '7 days';
+
+ @override
+ String get statsChartDays30 => '30 days';
+
+ @override
+ String get statsLast30Days => 'Last 30 days';
+
+ @override
+ String get statsThisYearTitle => 'This year';
+
+ @override
+ String get statsSectionsTitle => 'Sections';
+
+ @override
+ String get statsSectionTimePeriods => 'Time periods';
+
+ @override
+ String get statsHeatmapLess => 'Less';
+
+ @override
+ String get statsHeatmapMore => 'More';
+
@override
String get statsDaysActive => 'Days Active';
diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dart
index f28e50cb..81ff68f7 100644
--- a/lib/l10n/app_localizations_fr.dart
+++ b/lib/l10n/app_localizations_fr.dart
@@ -751,6 +751,102 @@ class AppLocalizationsFr extends AppLocalizations {
@override
String get statsNothingHidden => 'Nothing hidden';
+ @override
+ String get settingsCustomizeStats => 'Customize stats';
+
+ @override
+ String get statsGoalTitle => 'Listening goal';
+
+ @override
+ String get statsGoalOff => 'Off';
+
+ @override
+ String get statsGoalDaily => 'Daily';
+
+ @override
+ String get statsGoalWeekly => 'Weekly';
+
+ @override
+ String get statsGoalMonthly => 'Monthly';
+
+ @override
+ String get statsGoalTarget => 'Target';
+
+ @override
+ String get statsGoalEnterTitle => 'Set target';
+
+ @override
+ String get statsGoalEnterTimeHint => 'Minutes or h:mm';
+
+ @override
+ String statsBooksShort(int count) {
+ return '$count books';
+ }
+
+ @override
+ String get statsBookChallengeTitle => 'Reading challenge';
+
+ @override
+ String get statsBookChallengeDesc => 'Books to finish this year';
+
+ @override
+ String get statsDailyGoal => 'Daily goal';
+
+ @override
+ String get statsWeeklyGoal => 'Weekly goal';
+
+ @override
+ String get statsMonthlyGoal => 'Monthly goal';
+
+ @override
+ String statsGoalProgress(String done, String target) {
+ return '$done / $target';
+ }
+
+ @override
+ String statsBookChallengeProgress(int done, int target) {
+ return '$done of $target books';
+ }
+
+ @override
+ String get statsGoalReached => 'Goal reached';
+
+ @override
+ String get statsChartTitle => 'Listening chart';
+
+ @override
+ String get statsChartBar => 'Bar';
+
+ @override
+ String get statsChartLine => 'Line';
+
+ @override
+ String get statsChartHeatmap => 'Heatmap';
+
+ @override
+ String get statsChartDays7 => '7 days';
+
+ @override
+ String get statsChartDays30 => '30 days';
+
+ @override
+ String get statsLast30Days => 'Last 30 days';
+
+ @override
+ String get statsThisYearTitle => 'This year';
+
+ @override
+ String get statsSectionsTitle => 'Sections';
+
+ @override
+ String get statsSectionTimePeriods => 'Time periods';
+
+ @override
+ String get statsHeatmapLess => 'Less';
+
+ @override
+ String get statsHeatmapMore => 'More';
+
@override
String get statsDaysActive => 'Days Active';
diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dart
index d50a6f19..38af1229 100644
--- a/lib/l10n/app_localizations_it.dart
+++ b/lib/l10n/app_localizations_it.dart
@@ -749,6 +749,102 @@ class AppLocalizationsIt extends AppLocalizations {
@override
String get statsNothingHidden => 'Nothing hidden';
+ @override
+ String get settingsCustomizeStats => 'Customize stats';
+
+ @override
+ String get statsGoalTitle => 'Listening goal';
+
+ @override
+ String get statsGoalOff => 'Off';
+
+ @override
+ String get statsGoalDaily => 'Daily';
+
+ @override
+ String get statsGoalWeekly => 'Weekly';
+
+ @override
+ String get statsGoalMonthly => 'Monthly';
+
+ @override
+ String get statsGoalTarget => 'Target';
+
+ @override
+ String get statsGoalEnterTitle => 'Set target';
+
+ @override
+ String get statsGoalEnterTimeHint => 'Minutes or h:mm';
+
+ @override
+ String statsBooksShort(int count) {
+ return '$count books';
+ }
+
+ @override
+ String get statsBookChallengeTitle => 'Reading challenge';
+
+ @override
+ String get statsBookChallengeDesc => 'Books to finish this year';
+
+ @override
+ String get statsDailyGoal => 'Daily goal';
+
+ @override
+ String get statsWeeklyGoal => 'Weekly goal';
+
+ @override
+ String get statsMonthlyGoal => 'Monthly goal';
+
+ @override
+ String statsGoalProgress(String done, String target) {
+ return '$done / $target';
+ }
+
+ @override
+ String statsBookChallengeProgress(int done, int target) {
+ return '$done of $target books';
+ }
+
+ @override
+ String get statsGoalReached => 'Goal reached';
+
+ @override
+ String get statsChartTitle => 'Listening chart';
+
+ @override
+ String get statsChartBar => 'Bar';
+
+ @override
+ String get statsChartLine => 'Line';
+
+ @override
+ String get statsChartHeatmap => 'Heatmap';
+
+ @override
+ String get statsChartDays7 => '7 days';
+
+ @override
+ String get statsChartDays30 => '30 days';
+
+ @override
+ String get statsLast30Days => 'Last 30 days';
+
+ @override
+ String get statsThisYearTitle => 'This year';
+
+ @override
+ String get statsSectionsTitle => 'Sections';
+
+ @override
+ String get statsSectionTimePeriods => 'Time periods';
+
+ @override
+ String get statsHeatmapLess => 'Less';
+
+ @override
+ String get statsHeatmapMore => 'More';
+
@override
String get statsDaysActive => 'Days Active';
diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dart
index e2837c81..3cc3d449 100644
--- a/lib/l10n/app_localizations_ja.dart
+++ b/lib/l10n/app_localizations_ja.dart
@@ -749,6 +749,102 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get statsNothingHidden => 'Nothing hidden';
+ @override
+ String get settingsCustomizeStats => 'Customize stats';
+
+ @override
+ String get statsGoalTitle => 'Listening goal';
+
+ @override
+ String get statsGoalOff => 'Off';
+
+ @override
+ String get statsGoalDaily => 'Daily';
+
+ @override
+ String get statsGoalWeekly => 'Weekly';
+
+ @override
+ String get statsGoalMonthly => 'Monthly';
+
+ @override
+ String get statsGoalTarget => 'Target';
+
+ @override
+ String get statsGoalEnterTitle => 'Set target';
+
+ @override
+ String get statsGoalEnterTimeHint => 'Minutes or h:mm';
+
+ @override
+ String statsBooksShort(int count) {
+ return '$count books';
+ }
+
+ @override
+ String get statsBookChallengeTitle => 'Reading challenge';
+
+ @override
+ String get statsBookChallengeDesc => 'Books to finish this year';
+
+ @override
+ String get statsDailyGoal => 'Daily goal';
+
+ @override
+ String get statsWeeklyGoal => 'Weekly goal';
+
+ @override
+ String get statsMonthlyGoal => 'Monthly goal';
+
+ @override
+ String statsGoalProgress(String done, String target) {
+ return '$done / $target';
+ }
+
+ @override
+ String statsBookChallengeProgress(int done, int target) {
+ return '$done of $target books';
+ }
+
+ @override
+ String get statsGoalReached => 'Goal reached';
+
+ @override
+ String get statsChartTitle => 'Listening chart';
+
+ @override
+ String get statsChartBar => 'Bar';
+
+ @override
+ String get statsChartLine => 'Line';
+
+ @override
+ String get statsChartHeatmap => 'Heatmap';
+
+ @override
+ String get statsChartDays7 => '7 days';
+
+ @override
+ String get statsChartDays30 => '30 days';
+
+ @override
+ String get statsLast30Days => 'Last 30 days';
+
+ @override
+ String get statsThisYearTitle => 'This year';
+
+ @override
+ String get statsSectionsTitle => 'Sections';
+
+ @override
+ String get statsSectionTimePeriods => 'Time periods';
+
+ @override
+ String get statsHeatmapLess => 'Less';
+
+ @override
+ String get statsHeatmapMore => 'More';
+
@override
String get statsDaysActive => 'Days Active';
diff --git a/lib/l10n/app_localizations_no.dart b/lib/l10n/app_localizations_no.dart
index 727cd97c..46ce603e 100644
--- a/lib/l10n/app_localizations_no.dart
+++ b/lib/l10n/app_localizations_no.dart
@@ -749,6 +749,102 @@ class AppLocalizationsNo extends AppLocalizations {
@override
String get statsNothingHidden => 'Nothing hidden';
+ @override
+ String get settingsCustomizeStats => 'Customize stats';
+
+ @override
+ String get statsGoalTitle => 'Listening goal';
+
+ @override
+ String get statsGoalOff => 'Off';
+
+ @override
+ String get statsGoalDaily => 'Daily';
+
+ @override
+ String get statsGoalWeekly => 'Weekly';
+
+ @override
+ String get statsGoalMonthly => 'Monthly';
+
+ @override
+ String get statsGoalTarget => 'Target';
+
+ @override
+ String get statsGoalEnterTitle => 'Set target';
+
+ @override
+ String get statsGoalEnterTimeHint => 'Minutes or h:mm';
+
+ @override
+ String statsBooksShort(int count) {
+ return '$count books';
+ }
+
+ @override
+ String get statsBookChallengeTitle => 'Reading challenge';
+
+ @override
+ String get statsBookChallengeDesc => 'Books to finish this year';
+
+ @override
+ String get statsDailyGoal => 'Daily goal';
+
+ @override
+ String get statsWeeklyGoal => 'Weekly goal';
+
+ @override
+ String get statsMonthlyGoal => 'Monthly goal';
+
+ @override
+ String statsGoalProgress(String done, String target) {
+ return '$done / $target';
+ }
+
+ @override
+ String statsBookChallengeProgress(int done, int target) {
+ return '$done of $target books';
+ }
+
+ @override
+ String get statsGoalReached => 'Goal reached';
+
+ @override
+ String get statsChartTitle => 'Listening chart';
+
+ @override
+ String get statsChartBar => 'Bar';
+
+ @override
+ String get statsChartLine => 'Line';
+
+ @override
+ String get statsChartHeatmap => 'Heatmap';
+
+ @override
+ String get statsChartDays7 => '7 days';
+
+ @override
+ String get statsChartDays30 => '30 days';
+
+ @override
+ String get statsLast30Days => 'Last 30 days';
+
+ @override
+ String get statsThisYearTitle => 'This year';
+
+ @override
+ String get statsSectionsTitle => 'Sections';
+
+ @override
+ String get statsSectionTimePeriods => 'Time periods';
+
+ @override
+ String get statsHeatmapLess => 'Less';
+
+ @override
+ String get statsHeatmapMore => 'More';
+
@override
String get statsDaysActive => 'Days Active';
diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dart
index f01bb225..33c5d64e 100644
--- a/lib/l10n/app_localizations_pt.dart
+++ b/lib/l10n/app_localizations_pt.dart
@@ -749,6 +749,102 @@ class AppLocalizationsPt extends AppLocalizations {
@override
String get statsNothingHidden => 'Nothing hidden';
+ @override
+ String get settingsCustomizeStats => 'Customize stats';
+
+ @override
+ String get statsGoalTitle => 'Listening goal';
+
+ @override
+ String get statsGoalOff => 'Off';
+
+ @override
+ String get statsGoalDaily => 'Daily';
+
+ @override
+ String get statsGoalWeekly => 'Weekly';
+
+ @override
+ String get statsGoalMonthly => 'Monthly';
+
+ @override
+ String get statsGoalTarget => 'Target';
+
+ @override
+ String get statsGoalEnterTitle => 'Set target';
+
+ @override
+ String get statsGoalEnterTimeHint => 'Minutes or h:mm';
+
+ @override
+ String statsBooksShort(int count) {
+ return '$count books';
+ }
+
+ @override
+ String get statsBookChallengeTitle => 'Reading challenge';
+
+ @override
+ String get statsBookChallengeDesc => 'Books to finish this year';
+
+ @override
+ String get statsDailyGoal => 'Daily goal';
+
+ @override
+ String get statsWeeklyGoal => 'Weekly goal';
+
+ @override
+ String get statsMonthlyGoal => 'Monthly goal';
+
+ @override
+ String statsGoalProgress(String done, String target) {
+ return '$done / $target';
+ }
+
+ @override
+ String statsBookChallengeProgress(int done, int target) {
+ return '$done of $target books';
+ }
+
+ @override
+ String get statsGoalReached => 'Goal reached';
+
+ @override
+ String get statsChartTitle => 'Listening chart';
+
+ @override
+ String get statsChartBar => 'Bar';
+
+ @override
+ String get statsChartLine => 'Line';
+
+ @override
+ String get statsChartHeatmap => 'Heatmap';
+
+ @override
+ String get statsChartDays7 => '7 days';
+
+ @override
+ String get statsChartDays30 => '30 days';
+
+ @override
+ String get statsLast30Days => 'Last 30 days';
+
+ @override
+ String get statsThisYearTitle => 'This year';
+
+ @override
+ String get statsSectionsTitle => 'Sections';
+
+ @override
+ String get statsSectionTimePeriods => 'Time periods';
+
+ @override
+ String get statsHeatmapLess => 'Less';
+
+ @override
+ String get statsHeatmapMore => 'More';
+
@override
String get statsDaysActive => 'Days Active';
diff --git a/lib/l10n/app_localizations_ro.dart b/lib/l10n/app_localizations_ro.dart
index f48e6217..ce9187c9 100644
--- a/lib/l10n/app_localizations_ro.dart
+++ b/lib/l10n/app_localizations_ro.dart
@@ -749,6 +749,102 @@ class AppLocalizationsRo extends AppLocalizations {
@override
String get statsNothingHidden => 'Nothing hidden';
+ @override
+ String get settingsCustomizeStats => 'Customize stats';
+
+ @override
+ String get statsGoalTitle => 'Listening goal';
+
+ @override
+ String get statsGoalOff => 'Off';
+
+ @override
+ String get statsGoalDaily => 'Daily';
+
+ @override
+ String get statsGoalWeekly => 'Weekly';
+
+ @override
+ String get statsGoalMonthly => 'Monthly';
+
+ @override
+ String get statsGoalTarget => 'Target';
+
+ @override
+ String get statsGoalEnterTitle => 'Set target';
+
+ @override
+ String get statsGoalEnterTimeHint => 'Minutes or h:mm';
+
+ @override
+ String statsBooksShort(int count) {
+ return '$count books';
+ }
+
+ @override
+ String get statsBookChallengeTitle => 'Reading challenge';
+
+ @override
+ String get statsBookChallengeDesc => 'Books to finish this year';
+
+ @override
+ String get statsDailyGoal => 'Daily goal';
+
+ @override
+ String get statsWeeklyGoal => 'Weekly goal';
+
+ @override
+ String get statsMonthlyGoal => 'Monthly goal';
+
+ @override
+ String statsGoalProgress(String done, String target) {
+ return '$done / $target';
+ }
+
+ @override
+ String statsBookChallengeProgress(int done, int target) {
+ return '$done of $target books';
+ }
+
+ @override
+ String get statsGoalReached => 'Goal reached';
+
+ @override
+ String get statsChartTitle => 'Listening chart';
+
+ @override
+ String get statsChartBar => 'Bar';
+
+ @override
+ String get statsChartLine => 'Line';
+
+ @override
+ String get statsChartHeatmap => 'Heatmap';
+
+ @override
+ String get statsChartDays7 => '7 days';
+
+ @override
+ String get statsChartDays30 => '30 days';
+
+ @override
+ String get statsLast30Days => 'Last 30 days';
+
+ @override
+ String get statsThisYearTitle => 'This year';
+
+ @override
+ String get statsSectionsTitle => 'Sections';
+
+ @override
+ String get statsSectionTimePeriods => 'Time periods';
+
+ @override
+ String get statsHeatmapLess => 'Less';
+
+ @override
+ String get statsHeatmapMore => 'More';
+
@override
String get statsDaysActive => 'Days Active';
diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dart
index ba394818..f68d689d 100644
--- a/lib/l10n/app_localizations_ru.dart
+++ b/lib/l10n/app_localizations_ru.dart
@@ -750,6 +750,102 @@ class AppLocalizationsRu extends AppLocalizations {
@override
String get statsNothingHidden => 'Nothing hidden';
+ @override
+ String get settingsCustomizeStats => 'Customize stats';
+
+ @override
+ String get statsGoalTitle => 'Listening goal';
+
+ @override
+ String get statsGoalOff => 'Off';
+
+ @override
+ String get statsGoalDaily => 'Daily';
+
+ @override
+ String get statsGoalWeekly => 'Weekly';
+
+ @override
+ String get statsGoalMonthly => 'Monthly';
+
+ @override
+ String get statsGoalTarget => 'Target';
+
+ @override
+ String get statsGoalEnterTitle => 'Set target';
+
+ @override
+ String get statsGoalEnterTimeHint => 'Minutes or h:mm';
+
+ @override
+ String statsBooksShort(int count) {
+ return '$count books';
+ }
+
+ @override
+ String get statsBookChallengeTitle => 'Reading challenge';
+
+ @override
+ String get statsBookChallengeDesc => 'Books to finish this year';
+
+ @override
+ String get statsDailyGoal => 'Daily goal';
+
+ @override
+ String get statsWeeklyGoal => 'Weekly goal';
+
+ @override
+ String get statsMonthlyGoal => 'Monthly goal';
+
+ @override
+ String statsGoalProgress(String done, String target) {
+ return '$done / $target';
+ }
+
+ @override
+ String statsBookChallengeProgress(int done, int target) {
+ return '$done of $target books';
+ }
+
+ @override
+ String get statsGoalReached => 'Goal reached';
+
+ @override
+ String get statsChartTitle => 'Listening chart';
+
+ @override
+ String get statsChartBar => 'Bar';
+
+ @override
+ String get statsChartLine => 'Line';
+
+ @override
+ String get statsChartHeatmap => 'Heatmap';
+
+ @override
+ String get statsChartDays7 => '7 days';
+
+ @override
+ String get statsChartDays30 => '30 days';
+
+ @override
+ String get statsLast30Days => 'Last 30 days';
+
+ @override
+ String get statsThisYearTitle => 'This year';
+
+ @override
+ String get statsSectionsTitle => 'Sections';
+
+ @override
+ String get statsSectionTimePeriods => 'Time periods';
+
+ @override
+ String get statsHeatmapLess => 'Less';
+
+ @override
+ String get statsHeatmapMore => 'More';
+
@override
String get statsDaysActive => 'Days Active';
diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart
index 2e0279d1..15730a30 100644
--- a/lib/l10n/app_localizations_zh.dart
+++ b/lib/l10n/app_localizations_zh.dart
@@ -738,6 +738,102 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get statsNothingHidden => 'Nothing hidden';
+ @override
+ String get settingsCustomizeStats => 'Customize stats';
+
+ @override
+ String get statsGoalTitle => 'Listening goal';
+
+ @override
+ String get statsGoalOff => 'Off';
+
+ @override
+ String get statsGoalDaily => 'Daily';
+
+ @override
+ String get statsGoalWeekly => 'Weekly';
+
+ @override
+ String get statsGoalMonthly => 'Monthly';
+
+ @override
+ String get statsGoalTarget => 'Target';
+
+ @override
+ String get statsGoalEnterTitle => 'Set target';
+
+ @override
+ String get statsGoalEnterTimeHint => 'Minutes or h:mm';
+
+ @override
+ String statsBooksShort(int count) {
+ return '$count books';
+ }
+
+ @override
+ String get statsBookChallengeTitle => 'Reading challenge';
+
+ @override
+ String get statsBookChallengeDesc => 'Books to finish this year';
+
+ @override
+ String get statsDailyGoal => 'Daily goal';
+
+ @override
+ String get statsWeeklyGoal => 'Weekly goal';
+
+ @override
+ String get statsMonthlyGoal => 'Monthly goal';
+
+ @override
+ String statsGoalProgress(String done, String target) {
+ return '$done / $target';
+ }
+
+ @override
+ String statsBookChallengeProgress(int done, int target) {
+ return '$done of $target books';
+ }
+
+ @override
+ String get statsGoalReached => 'Goal reached';
+
+ @override
+ String get statsChartTitle => 'Listening chart';
+
+ @override
+ String get statsChartBar => 'Bar';
+
+ @override
+ String get statsChartLine => 'Line';
+
+ @override
+ String get statsChartHeatmap => 'Heatmap';
+
+ @override
+ String get statsChartDays7 => '7 days';
+
+ @override
+ String get statsChartDays30 => '30 days';
+
+ @override
+ String get statsLast30Days => 'Last 30 days';
+
+ @override
+ String get statsThisYearTitle => 'This year';
+
+ @override
+ String get statsSectionsTitle => 'Sections';
+
+ @override
+ String get statsSectionTimePeriods => 'Time periods';
+
+ @override
+ String get statsHeatmapLess => 'Less';
+
+ @override
+ String get statsHeatmapMore => 'More';
+
@override
String get statsDaysActive => '活跃天数';
diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart
index 2600cb67..cd12503d 100644
--- a/lib/screens/settings_screen.dart
+++ b/lib/screens/settings_screen.dart
@@ -115,6 +115,17 @@ class _SettingsScreenState extends State<SettingsScreen> {
String _themeMode = 'dark';
String _language = '';
int _startScreen = 2;
+ String _statsGoalType = 'off';
+ int _statsGoalMinutes = 30;
+ int _statsBookGoal = 0;
+ String _statsChartStyle = 'bar';
+ int _statsChartRange = 7;
+ List<String> _statsSectionOrder = [];
+ Set<String> _statsHiddenSections = {};
+
+ static const _statsSectionIds = [
+ 'hero', 'goals', 'periods', 'activity', 'chart', 'top', 'sessions',
+ ];
int _streamingCacheSizeMb = 0;
bool _localServerEnabled = false;
String _localServerUrl = '';
@@ -246,6 +257,213 @@ class _SettingsScreenState extends State<SettingsScreen> {
PlayerSettings.notifySettingsChanged();
}
+ Widget _statsStepperRow(ColorScheme cs, TextTheme tt, String label, String value,
+ {VoidCallback? onMinus, VoidCallback? onPlus, VoidCallback? onTapValue}) {
+ return Row(children: [
+ Expanded(child: Text(label, style: tt.bodyMedium?.copyWith(color: cs.onSurfaceVariant))),
+ IconButton(
+ onPressed: _loaded ? onMinus : null,
+ icon: const Icon(Icons.remove_circle_outline_rounded),
+ color: cs.primary,
+ visualDensity: VisualDensity.compact,
+ ),
+ InkWell(
+ onTap: _loaded ? onTapValue : null,
+ borderRadius: BorderRadius.circular(8),
+ child: SizedBox(
+ width: 72,
+ child: Padding(
+ padding: const EdgeInsets.symmetric(vertical: 6),
+ child: Text(value,
+ textAlign: TextAlign.center,
+ style: tt.titleSmall?.copyWith(fontWeight: FontWeight.w700)),
+ ),
+ ),
+ ),
+ IconButton(
+ onPressed: _loaded ? onPlus : null,
+ icon: const Icon(Icons.add_circle_outline_rounded),
+ color: cs.primary,
+ visualDensity: VisualDensity.compact,
+ ),
+ ]);
+ }
+
+ String _statsMinutesLabel(AppLocalizations l, int minutes) {
+ final h = minutes ~/ 60;
+ final m = minutes % 60;
+ return h > 0 ? l.statsScreenDurationHm(h, m) : l.statsScreenDurationM(m);
+ }
+
+ /// Accepts plain minutes ("90") or h:mm ("1:30").
+ int? _parseGoalMinutes(String input) {
+ final t = input.trim();
+ if (t.isEmpty) return null;
+ int? minutes;
+ if (t.contains(':')) {
+ final parts = t.split(':');
+ if (parts.length != 2) return null;
+ final h = int.tryParse(parts[0].trim());
+ final m = int.tryParse(parts[1].trim());
+ if (h == null || m == null || h < 0 || m < 0 || m >= 60) return null;
+ minutes = h * 60 + m;
+ } else {
+ minutes = int.tryParse(t);
+ }
+ if (minutes == null || minutes < 1) return null;
+ return minutes.clamp(1, 1440);
+ }
+
+ Future<String?> _promptStatsValue(String hint, TextInputType keyboard) async {
+ final l = AppLocalizations.of(context)!;
+ final ctrl = TextEditingController();
+ return showDialog<String>(
+ context: context,
+ builder: (ctx) => AlertDialog(
+ title: Text(l.statsGoalEnterTitle),
+ content: TextField(
+ controller: ctrl,
+ autofocus: true,
+ keyboardType: keyboard,
+ decoration: InputDecoration(hintText: hint),
+ onSubmitted: (v) => Navigator.pop(ctx, v),
+ ),
+ actions: [
+ TextButton(onPressed: () => Navigator.pop(ctx), child: Text(l.cancel)),
+ FilledButton(onPressed: () => Navigator.pop(ctx, ctrl.text), child: Text(l.save)),
+ ],
+ ),
+ );
+ }
+
+ Future<void> _editStatsTimeTarget() async {
+ final l = AppLocalizations.of(context)!;
+ final input = await _promptStatsValue(l.statsGoalEnterTimeHint, TextInputType.datetime);
+ if (input == null) return;
+ final minutes = _parseGoalMinutes(input);
+ if (minutes == null) return;
+ setState(() => _statsGoalMinutes = minutes);
+ PlayerSettings.setStatsGoalMinutes(minutes);
+ }
+
+ Future<void> _editStatsBookTarget() async {
+ final input = await _promptStatsValue('', TextInputType.number);
+ if (input == null) return;
+ final books = int.tryParse(input.trim());
+ if (books == null || books < 0) return;
+ setState(() => _statsBookGoal = books.clamp(0, 500));
+ PlayerSettings.setStatsBookGoal(_statsBookGoal);
+ }
+
+ List<String> get _mergedStatsOrder => [
+ ..._statsSectionOrder.where(_statsSectionIds.contains),
+ ..._statsSectionIds.where((id) => !_statsSectionOrder.contains(id)),
+ ];
+
+ String _statsSectionLabel(AppLocalizations l, String id) {
+ switch (id) {
+ case 'hero': return l.statsTotalListeningTime;
+ case 'goals': return l.statsGoalTitle;
+ case 'periods': return l.statsSectionTimePeriods;
+ case 'activity': return l.statsActivity;
+ case 'chart': return l.statsChartTitle;
+ case 'top': return l.statsMostListened;
+ case 'sessions': return l.statsRecentSessions;
+ }
+ return id;
+ }
+
+ IconData _statsSectionIcon(String id) {
+ switch (id) {
+ case 'hero': return Icons.headphones_rounded;
+ case 'goals': return Icons.flag_rounded;
+ case 'periods': return Icons.date_range_rounded;
+ case 'activity': return Icons.local_fire_department_rounded;
+ case 'chart': return Icons.bar_chart_rounded;
+ case 'top': return Icons.star_outline_rounded;
+ case 'sessions': return Icons.history_rounded;
+ }
+ return Icons.widgets_outlined;
+ }
+
+ Widget _statsSectionsList(ColorScheme cs, TextTheme tt, AppLocalizations l) {
+ final order = _mergedStatsOrder;
+ return ReorderableListView.builder(
+ shrinkWrap: true,
+ physics: const NeverScrollableScrollPhysics(),
+ buildDefaultDragHandles: false,
+ itemCount: order.length,
+ onReorderStart: (_) => HapticFeedback.mediumImpact(),
+ onReorder: (oldIndex, newIndex) {
+ final list = List<String>.from(order);
+ if (newIndex > oldIndex) newIndex--;
+ final item = list.removeAt(oldIndex);
+ list.insert(newIndex, item);
+ setState(() => _statsSectionOrder = list);
+ PlayerSettings.setStatsSectionOrder(list);
+ },
+ itemBuilder: (context, index) {
+ final id = order[index];
+ final isHidden = _statsHiddenSections.contains(id);
+ return Container(
+ key: ValueKey(id),
+ margin: const EdgeInsets.symmetric(vertical: 3),
+ decoration: BoxDecoration(
+ color: cs.onSurface.withValues(alpha: isHidden ? 0.02 : 0.05),
+ borderRadius: BorderRadius.circular(12),
+ border: Border.all(color: cs.onSurface.withValues(alpha: 0.08)),
+ ),
+ child: ListTile(
+ dense: true,
+ leading: Icon(_statsSectionIcon(id), size: 18,
+ color: isHidden
+ ? cs.onSurfaceVariant.withValues(alpha: 0.3)
+ : cs.onSurfaceVariant),
+ title: Text(_statsSectionLabel(l, id),
+ style: TextStyle(
+ fontSize: 13,
+ fontWeight: FontWeight.w500,
+ color: isHidden
+ ? cs.onSurface.withValues(alpha: 0.35)
+ : cs.onSurface,
+ )),
+ trailing: Row(mainAxisSize: MainAxisSize.min, children: [
+ GestureDetector(
+ onTap: () {
+ final updated = Set<String>.from(_statsHiddenSections);
+ if (!updated.add(id)) updated.remove(id);
+ setState(() => _statsHiddenSections = updated);
+ PlayerSettings.setStatsHiddenSections(updated.toList());
+ },
+ child: Padding(
+ padding: const EdgeInsets.all(8),
+ child: Icon(
+ isHidden
+ ? Icons.visibility_off_rounded
+ : Icons.visibility_rounded,
+ size: 18,
+ color: isHidden
+ ? cs.onSurfaceVariant.withValues(alpha: 0.3)
+ : cs.onSurfaceVariant,
+ ),
+ ),
+ ),
+ ReorderableDragStartListener(
+ index: index,
+ child: Padding(
+ padding: const EdgeInsets.all(8),
+ child: Icon(Icons.drag_handle_rounded,
+ size: 18,
+ color: cs.onSurfaceVariant.withValues(alpha: 0.5)),
+ ),
+ ),
+ ]),
+ ),
+ );
+ },
+ );
+ }
+
Future<void> _loadSettings() async {
final results = await Future.wait([
AutoRewindSettings.load(), // 0
@@ -304,6 +522,13 @@ class _SettingsScreenState extends State<SettingsScreen> {
]);
final s = results[0] as AutoRewindSettings;
final progressScale = results.last as double;
+ final statsGoalType = await PlayerSettings.getStatsGoalType();
+ final statsGoalMinutes = await PlayerSettings.getStatsGoalMinutes();
+ final statsBookGoal = await PlayerSettings.getStatsBookGoal();
+ final statsChartStyle = await PlayerSettings.getStatsChartStyle();
+ final statsChartRange = await PlayerSettings.getStatsChartRange();
+ final statsSectionOrder = await PlayerSettings.getStatsSectionOrder();
+ final statsHiddenSections = await PlayerSettings.getStatsHiddenSections();
final speed = results[1] as double;
final wifiOnly = results[2] as bool;
final rollingCount = results[3] as int;
@@ -420,6 +645,13 @@ class _SettingsScreenState extends State<SettingsScreen> {
_shakeSensitivity = shakeSens;
_language = language;
_canPickDownloadLocation = !_isPlayStoreBuild;
+ _statsGoalType = statsGoalType;
+ _statsGoalMinutes = statsGoalMinutes;
+ _statsBookGoal = statsBookGoal;
+ _statsChartStyle = statsChartStyle;
+ _statsChartRange = statsChartRange;
+ _statsSectionOrder = statsSectionOrder;
+ _statsHiddenSections = statsHiddenSections.toSet();
_loaded = true;
});
@@ -913,6 +1145,152 @@ class _SettingsScreenState extends State<SettingsScreen> {
),
const SizedBox(height: 16),
+ // ── Customize Stats ──
+ CollapsibleSection(
+ key: _keyFor('Customize Stats'),
+ icon: Icons.bar_chart_rounded,
+ title: l.settingsCustomizeStats,
+ cs: cs,
+ isExpanded: _expandedSection == 'Customize Stats',
+ onExpansionChanged: (v) => _onSectionExpanded('Customize Stats', v),
+ children: [
+ Padding(
+ padding: const EdgeInsets.fromLTRB(16, 12, 16, 12),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(l.statsGoalTitle, style: tt.titleSmall),
+ const SizedBox(height: 12),
+ SizedBox(
+ width: double.infinity,
+ child: SegmentedButton<String>(
+ showSelectedIcon: false,
+ segments: [
+ ButtonSegment(value: 'off', label: FittedBox(fit: BoxFit.scaleDown, child: Text(l.statsGoalOff, maxLines: 1))),
+ ButtonSegment(value: 'daily', label: FittedBox(fit: BoxFit.scaleDown, child: Text(l.statsGoalDaily, maxLines: 1))),
+ ButtonSegment(value: 'weekly', label: FittedBox(fit: BoxFit.scaleDown, child: Text(l.statsGoalWeekly, maxLines: 1))),
+ ButtonSegment(value: 'monthly', label: FittedBox(fit: BoxFit.scaleDown, child: Text(l.statsGoalMonthly, maxLines: 1))),
+ ],
+ selected: {_statsGoalType},
+ onSelectionChanged: _loaded ? (selected) {
+ setState(() => _statsGoalType = selected.first);
+ PlayerSettings.setStatsGoalType(_statsGoalType);
+ } : null,
+ style: const ButtonStyle(visualDensity: VisualDensity.compact),
+ ),
+ ),
+ if (_statsGoalType != 'off')
+ _statsStepperRow(cs, tt, l.statsGoalTarget,
+ _statsMinutesLabel(l, _statsGoalMinutes),
+ onTapValue: _editStatsTimeTarget,
+ onMinus: _statsGoalMinutes > 5
+ ? () {
+ setState(() => _statsGoalMinutes -= 5);
+ PlayerSettings.setStatsGoalMinutes(_statsGoalMinutes);
+ }
+ : null,
+ onPlus: _statsGoalMinutes < 600
+ ? () {
+ setState(() => _statsGoalMinutes += 5);
+ PlayerSettings.setStatsGoalMinutes(_statsGoalMinutes);
+ }
+ : null),
+ ],
+ ),
+ ),
+ const Divider(height: 1, indent: 16, endIndent: 16),
+ Padding(
+ padding: const EdgeInsets.fromLTRB(16, 12, 16, 12),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(l.statsBookChallengeTitle, style: tt.titleSmall),
+ _statsStepperRow(cs, tt, l.statsBookChallengeDesc,
+ _statsBookGoal == 0 ? l.statsGoalOff : l.statsBooksShort(_statsBookGoal),
+ onTapValue: _editStatsBookTarget,
+ onMinus: _statsBookGoal > 0
+ ? () {
+ setState(() => _statsBookGoal--);
+ PlayerSettings.setStatsBookGoal(_statsBookGoal);
+ }
+ : null,
+ onPlus: _statsBookGoal < 500
+ ? () {
+ setState(() => _statsBookGoal++);
+ PlayerSettings.setStatsBookGoal(_statsBookGoal);
+ }
+ : null),
+ ],
+ ),
+ ),
+ const Divider(height: 1, indent: 16, endIndent: 16),
+ Padding(
+ padding: const EdgeInsets.fromLTRB(16, 12, 16, 12),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(l.statsChartTitle, style: tt.titleSmall),
+ const SizedBox(height: 12),
+ SizedBox(
+ width: double.infinity,
+ child: SegmentedButton<String>(
+ showSelectedIcon: false,
+ segments: [
+ ButtonSegment(value: 'bar', label: FittedBox(fit: BoxFit.scaleDown, child: Text(l.statsChartBar, maxLines: 1))),
+ ButtonSegment(value: 'line', label: FittedBox(fit: BoxFit.scaleDown, child: Text(l.statsChartLine, maxLines: 1))),
+ ButtonSegment(value: 'heatmap', label: FittedBox(fit: BoxFit.scaleDown, child: Text(l.statsChartHeatmap, maxLines: 1))),
+ ],
+ selected: {_statsChartStyle},
+ onSelectionChanged: _loaded ? (selected) {
+ setState(() => _statsChartStyle = selected.first);
+ PlayerSettings.setStatsChartStyle(_statsChartStyle);
+ } : null,
+ style: const ButtonStyle(visualDensity: VisualDensity.compact),
+ ),
+ ),
+ if (_statsChartStyle != 'heatmap') ...[
+ const SizedBox(height: 8),
+ SizedBox(
+ width: double.infinity,
+ child: SegmentedButton<int>(
+ showSelectedIcon: false,
+ segments: [
+ ButtonSegment(value: 7, label: FittedBox(fit: BoxFit.scaleDown, child: Text(l.statsChartDays7, maxLines: 1))),
+ ButtonSegment(value: 30, label: FittedBox(fit: BoxFit.scaleDown, child: Text(l.statsChartDays30, maxLines: 1))),
+ ],
+ selected: {_statsChartRange},
+ onSelectionChanged: _loaded ? (selected) {
+ setState(() => _statsChartRange = selected.first);
+ PlayerSettings.setStatsChartRange(_statsChartRange);
+ } : null,
+ style: const ButtonStyle(visualDensity: VisualDensity.compact),
+ ),
+ ),
+ ],
+ ],
+ ),
+ ),
+ const Divider(height: 1, indent: 16, endIndent: 16),
+ Padding(
+ padding: const EdgeInsets.fromLTRB(16, 12, 16, 16),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(l.statsSectionsTitle, style: tt.titleSmall),
+ const SizedBox(height: 4),
+ Text(
+ l.dragToReorderTapEye,
+ style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant),
+ ),
+ const SizedBox(height: 8),
+ _statsSectionsList(cs, tt, l),
+ ],
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: 16),
+
// ── Absorbing Cards ──
CollapsibleSection(
key: _keyFor('Absorbing Cards'),
diff --git a/lib/screens/stats_screen.dart b/lib/screens/stats_screen.dart
index 7d72a39f..f1be53f6 100644
--- a/lib/screens/stats_screen.dart
+++ b/lib/screens/stats_screen.dart
@@ -9,6 +9,7 @@ import '../providers/library_provider.dart';
import '../services/audio_player_service.dart';
import '../widgets/absorb_page_header.dart';
import '../widgets/finished_books_this_year_sheet.dart';
+import '../widgets/stats_charts.dart';
import '../widgets/absorb_wave_icon.dart';
import '../widgets/card_buttons.dart';
import '../main.dart' show oledNotifier;
@@ -30,7 +31,20 @@ class _StatsScreenState extends State<StatsScreen>
int _episodesFinished = 0;
int _booksFinishedThisYear = 0;
int _episodesFinishedThisYear = 0;
+ String _goalType = 'off';
+ int _goalMinutes = 30;
+ int _bookGoal = 0;
+ String _chartStyle = 'bar';
+ int _chartRange = 7;
+ List<String> _statsOrder = [];
+ Set<String> _statsHidden = {};
+ String? _selectedDayKey;
+ double _selectedDaySeconds = 0;
late AnimationController _animController;
+
+ static const _defaultSectionOrder = [
+ 'hero', 'goals', 'periods', 'activity', 'chart', 'top', 'sessions',
+ ];
late Animation<double> _animValue;
static const int _sessionsPerPage = 10;
@@ -47,12 +61,15 @@ class _StatsScreenState extends State<StatsScreen>
_animValue =
CurvedAnimation(parent: _animController, curve: Curves.easeOutCubic);
_scrollController.addListener(_onScroll);
+ PlayerSettings.settingsChanged.addListener(_onSettingsChanged);
_loadStats();
+ _loadGoalSettings();
}
@override
void dispose() {
_scrollController.removeListener(_onScroll);
+ PlayerSettings.settingsChanged.removeListener(_onSettingsChanged);
_scrollController.dispose();
_animController.dispose();
super.dispose();
@@ -86,6 +103,66 @@ class _StatsScreenState extends State<StatsScreen>
});
}
+ void _onSettingsChanged() => _loadGoalSettings();
+
+ Future<void> _loadGoalSettings() async {
+ final type = await PlayerSettings.getStatsGoalType();
+ final minutes = await PlayerSettings.getStatsGoalMinutes();
+ final books = await PlayerSettings.getStatsBookGoal();
+ final chartStyle = await PlayerSettings.getStatsChartStyle();
+ final chartRange = await PlayerSettings.getStatsChartRange();
+ final order = await PlayerSettings.getStatsSectionOrder();
+ final hidden = await PlayerSettings.getStatsHiddenSections();
+ if (!mounted) return;
+ setState(() {
+ if (chartStyle != _chartStyle || chartRange != _chartRange) {
+ _selectedDayKey = null;
+ }
+ _goalType = type;
+ _goalMinutes = minutes;
+ _bookGoal = books;
+ _chartStyle = chartStyle;
+ _chartRange = chartRange;
+ _statsOrder = order;
+ _statsHidden = hidden.toSet();
+ });
+ }
+
+ void _selectDay(String key, double seconds) {
+ setState(() {
+ if (_selectedDayKey == key) {
+ _selectedDayKey = null;
+ } else {
+ _selectedDayKey = key;
+ _selectedDaySeconds = seconds;
+ }
+ });
+ }
+
+ /// "Mon, Jun 5 · 1h 23m" line under the chart for the tapped day.
+ Widget _selectedDayRow(ColorScheme cs, TextTheme tt) {
+ final key = _selectedDayKey;
+ if (key == null) return const SizedBox.shrink();
+ final parts = key.split('-');
+ final date = DateTime(
+ int.parse(parts[0]), int.parse(parts[1]), int.parse(parts[2]));
+ const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
+ final l = AppLocalizations.of(context)!;
+ final label = '${_dayLabel(date, l)}, ${months[date.month - 1]} ${date.day}';
+ return Padding(
+ padding: const EdgeInsets.only(top: 10),
+ child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
+ Icon(Icons.calendar_today_rounded,
+ size: 13, color: cs.primary.withValues(alpha: 0.7)),
+ const SizedBox(width: 6),
+ Text('$label · ${_formatDuration(_selectedDaySeconds)}',
+ style: tt.bodySmall?.copyWith(
+ color: cs.onSurface.withValues(alpha: 0.7),
+ fontWeight: FontWeight.w600)),
+ ]),
+ );
+ }
+
static const _kStats = 'cached_stats';
static const _kSessions = 'cached_sessions';
@@ -242,26 +319,23 @@ class _StatsScreenState extends State<StatsScreen>
final thisMonth = _monthSeconds(dailyMap);
final streak = _currentStreak(dailyMap);
final longestStreak = _longestStreak(dailyMap);
- final weekData = _last7Days(dailyMap);
+ final chartData = _lastNDays(dailyMap, _chartRange);
final activeDays = _activeDayCount(dailyMap);
final avgDaily = _averageDailySeconds(dailyMap);
final topItems = _topItems();
- return ListView(
- controller: _scrollController,
- padding: const EdgeInsets.fromLTRB(20, 0, 20, 32),
- children: [
- AbsorbPageHeader(
- title: l.statsTitle,
- padding: const EdgeInsets.only(top: 12),
- ),
- const SizedBox(height: 24),
-
- // -- Hero stat --
+ final sections = <String, List<Widget>>{
+ 'hero': [
_heroStat(tt, cs, l, totalSeconds),
const SizedBox(height: 16),
-
- // -- Time periods --
+ ],
+ 'goals': [
+ if (_goalType != 'off' || _bookGoal > 0) ...[
+ _goalCard(cs, tt, l, today, thisWeek, thisMonth),
+ const SizedBox(height: 16),
+ ],
+ ],
+ 'periods': [
Row(children: [
Expanded(child: _periodCard(tt, cs, l.statsToday, today)),
const SizedBox(width: 8),
@@ -270,8 +344,8 @@ class _StatsScreenState extends State<StatsScreen>
Expanded(child: _periodCard(tt, cs, l.statsThisMonth, thisMonth)),
]),
const SizedBox(height: 24),
-
- // -- Activity stats --
+ ],
+ 'activity': [
_sectionTitle(tt, cs, l.statsActivity),
const SizedBox(height: 10),
Row(children: [
@@ -334,22 +408,28 @@ class _StatsScreenState extends State<StatsScreen>
_formatDuration(avgDaily), l.statsDailyAverage)),
]),
const SizedBox(height: 28),
-
- // -- Last 7 days chart --
- _sectionTitle(tt, cs, l.statsLast7Days),
+ ],
+ 'chart': [
+ _sectionTitle(
+ tt,
+ cs,
+ _chartStyle == 'heatmap'
+ ? l.statsThisYearTitle
+ : (_chartRange == 30 ? l.statsLast30Days : l.statsLast7Days)),
const SizedBox(height: 10),
- _barChart(weekData, cs, tt),
+ _chartCard(cs, tt, l, dailyMap, chartData),
+ _selectedDayRow(cs, tt),
const SizedBox(height: 28),
-
- // -- Top items --
+ ],
+ 'top': [
if (topItems.isNotEmpty) ...[
_sectionTitle(tt, cs, l.statsMostListened),
const SizedBox(height: 10),
...topItems.map((item) => _topItemCard(tt, cs, l, item)),
const SizedBox(height: 28),
],
-
- // -- Recent Sessions --
+ ],
+ 'sessions': [
if (_sessions.isNotEmpty) ...[
_sectionTitle(tt, cs, l.statsRecentSessions),
const SizedBox(height: 10),
@@ -369,6 +449,82 @@ class _StatsScreenState extends State<StatsScreen>
),
],
],
+ };
+
+ final order = [
+ ..._statsOrder.where(sections.containsKey),
+ ..._defaultSectionOrder.where((id) => !_statsOrder.contains(id)),
+ ];
+
+ return ListView(
+ controller: _scrollController,
+ padding: const EdgeInsets.fromLTRB(20, 0, 20, 32),
+ children: [
+ AbsorbPageHeader(
+ title: l.statsTitle,
+ padding: const EdgeInsets.only(top: 12),
+ ),
+ const SizedBox(height: 24),
+ for (final id in order)
+ if (!_statsHidden.contains(id)) ...sections[id]!,
+ ],
+ );
+ }
+
+ Widget _chartCard(ColorScheme cs, TextTheme tt, AppLocalizations l,
+ Map<String, dynamic> dailyMap, List<_DayData> chartData) {
+ if (_chartStyle == 'bar') {
+ return _barChart(chartData, cs, tt, dense: _chartRange > 10);
+ }
+ final deco = BoxDecoration(
+ color: cs.onSurface.withValues(alpha: 0.03),
+ borderRadius: BorderRadius.circular(16),
+ border: Border.all(color: cs.onSurface.withValues(alpha: 0.05)),
+ );
+ if (_chartStyle == 'line') {
+ return Container(
+ padding: const EdgeInsets.fromLTRB(12, 16, 12, 8),
+ decoration: deco,
+ child: StatsLineChart(
+ data: chartData
+ .map((d) => ChartDay(label: d.label, dateKey: d.fullLabel, seconds: d.seconds))
+ .toList(),
+ todayKey: _dateKey(DateTime.now()),
+ animValue: _animValue.value,
+ lineColor: cs.primary,
+ labelColor: cs.onSurface,
+ todayColor: cs.primary,
+ formatValue: _shortDuration,
+ selectedIndex: chartData.indexWhere((d) => d.fullLabel == _selectedDayKey),
+ onDaySelected: (i) => _selectDay(chartData[i].fullLabel, chartData[i].seconds),
+ ),
+ );
+ }
+ final daily = <String, double>{
+ for (final e in dailyMap.entries) e.key: _safeNum(e.value),
+ };
+ return Container(
+ padding: const EdgeInsets.fromLTRB(12, 14, 12, 10),
+ decoration: deco,
+ child: StatsHeatmap(
+ dailySeconds: daily,
+ fillColor: cs.primary,
+ emptyColor: cs.onSurface.withValues(alpha: 0.06),
+ labelColor: cs.onSurface,
+ lessLabel: l.statsHeatmapLess,
+ moreLabel: l.statsHeatmapMore,
+ dayLabels: [
+ l.statsScreenDayMon,
+ l.statsScreenDayTue,
+ l.statsScreenDayWed,
+ l.statsScreenDayThu,
+ l.statsScreenDayFri,
+ l.statsScreenDaySat,
+ l.statsScreenDaySun,
+ ],
+ selectedKey: _selectedDayKey,
+ onDaySelected: _selectDay,
+ ),
);
}
@@ -383,6 +539,114 @@ class _StatsScreenState extends State<StatsScreen>
));
}
+ // --- GOAL CARD ---
+
+ Widget _goalCard(ColorScheme cs, TextTheme tt, AppLocalizations l,
+ double today, double thisWeek, double thisMonth) {
+ final isDark = Theme.of(context).brightness == Brightness.dark;
+ final doneColor = isDark ? Colors.greenAccent[400]! : Colors.green.shade700;
+
+ final hasTimeGoal = _goalType != 'off';
+ final hasBookGoal = _bookGoal > 0;
+
+ final periodSeconds = _goalType == 'weekly'
+ ? thisWeek
+ : _goalType == 'monthly'
+ ? thisMonth
+ : today;
+ final targetSeconds = _goalMinutes * 60.0;
+ final double timeProgress =
+ targetSeconds > 0 ? (periodSeconds / targetSeconds).clamp(0.0, 1.0).toDouble() : 0.0;
+ final timeReached = hasTimeGoal && periodSeconds >= targetSeconds;
+ final goalLabel = _goalType == 'weekly'
+ ? l.statsWeeklyGoal
+ : _goalType == 'monthly'
+ ? l.statsMonthlyGoal
+ : l.statsDailyGoal;
+
+ final double bookProgress =
+ hasBookGoal ? (_booksFinishedThisYear / _bookGoal).clamp(0.0, 1.0).toDouble() : 0.0;
+ final bookReached = hasBookGoal && _booksFinishedThisYear >= _bookGoal;
+
+ return Container(
+ padding: const EdgeInsets.all(16),
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(16),
+ color: cs.onSurface.withValues(alpha: 0.03),
+ border: Border.all(color: cs.onSurface.withValues(alpha: 0.06)),
+ ),
+ child: Column(children: [
+ if (hasTimeGoal)
+ Row(children: [
+ SizedBox(
+ width: 56,
+ height: 56,
+ child: Stack(alignment: Alignment.center, children: [
+ SizedBox(
+ width: 56,
+ height: 56,
+ child: CircularProgressIndicator(
+ value: timeProgress,
+ strokeWidth: 5,
+ backgroundColor: cs.onSurface.withValues(alpha: 0.08),
+ valueColor: AlwaysStoppedAnimation(timeReached ? doneColor : cs.primary),
+ ),
+ ),
+ if (timeReached)
+ Icon(Icons.check_rounded, color: doneColor, size: 24)
+ else
+ Text('${(timeProgress * 100).round()}%',
+ style: tt.labelMedium
+ ?.copyWith(fontWeight: FontWeight.w700, color: cs.onSurface)),
+ ]),
+ ),
+ const SizedBox(width: 16),
+ Expanded(
+ child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Text(goalLabel,
+ style: tt.titleSmall
+ ?.copyWith(fontWeight: FontWeight.w700, color: cs.onSurface)),
+ const SizedBox(height: 2),
+ Text(
+ l.statsGoalProgress(
+ _formatDuration(periodSeconds), _formatDuration(targetSeconds)),
+ style: tt.bodySmall
+ ?.copyWith(color: timeReached ? doneColor : cs.onSurfaceVariant),
+ ),
+ ])),
+ ]),
+ if (hasTimeGoal && hasBookGoal) const SizedBox(height: 16),
+ if (hasBookGoal)
+ Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Row(children: [
+ Icon(Icons.auto_stories_rounded,
+ size: 16, color: bookReached ? doneColor : cs.primary),
+ const SizedBox(width: 8),
+ Expanded(
+ child: Text(l.statsBookChallengeTitle,
+ style: tt.titleSmall
+ ?.copyWith(fontWeight: FontWeight.w700, color: cs.onSurface))),
+ Text(
+ l.statsBookChallengeProgress(_booksFinishedThisYear, _bookGoal),
+ style: tt.bodySmall
+ ?.copyWith(color: bookReached ? doneColor : cs.onSurfaceVariant),
+ ),
+ ]),
+ const SizedBox(height: 8),
+ ClipRRect(
+ borderRadius: BorderRadius.circular(6),
+ child: LinearProgressIndicator(
+ value: bookProgress,
+ minHeight: 8,
+ backgroundColor: cs.onSurface.withValues(alpha: 0.08),
+ valueColor: AlwaysStoppedAnimation(bookReached ? doneColor : cs.primary),
+ ),
+ ),
+ ]),
+ ]),
+ );
+ }
+
// --- HERO STAT ---
Widget _heroStat(TextTheme tt, ColorScheme cs, AppLocalizations l, double totalSeconds) {
@@ -540,7 +804,8 @@ class _StatsScreenState extends State<StatsScreen>
// --- BAR CHART (7 days) ---
- Widget _barChart(List<_DayData> data, ColorScheme cs, TextTheme tt) {
+ Widget _barChart(List<_DayData> data, ColorScheme cs, TextTheme tt,
+ {bool dense = false}) {
final maxVal =
data.map((d) => d.seconds).fold(0.0, (a, b) => a > b ? a : b);
final barMax = maxVal > 0 ? maxVal : 1.0;
@@ -561,48 +826,60 @@ class _StatsScreenState extends State<StatsScreen>
children: data.map((d) {
final ratio = (d.seconds / barMax * anim).clamp(0.0, 1.0);
final isToday = d.fullLabel == _dateKey(DateTime.now());
+ final isSelected = d.fullLabel == _selectedDayKey;
return Expanded(
- child: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 3),
- child:
- Column(mainAxisAlignment: MainAxisAlignment.end, children: [
- if (d.seconds > 0)
- Padding(
- padding: const EdgeInsets.only(bottom: 4),
- child: Text(_shortDuration(d.seconds),
- style: TextStyle(
- color: cs.onSurface.withValues(alpha: 0.35),
- fontSize: 9,
- fontWeight: FontWeight.w600))),
- Container(
- height: max(ratio * 80, d.seconds > 0 ? 4 : 2),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(5),
- color: isToday
- ? cs.primary.withValues(alpha: 0.7)
- : cs.onSurface.withValues(alpha: 0.12),
- ),
- ),
- ]),
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => _selectDay(d.fullLabel, d.seconds),
+ child: Padding(
+ padding: EdgeInsets.symmetric(horizontal: dense ? 1 : 3),
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.end,
+ children: [
+ if ((!dense || isSelected) && d.seconds > 0)
+ Padding(
+ padding: const EdgeInsets.only(bottom: 4),
+ child: Text(_shortDuration(d.seconds),
+ style: TextStyle(
+ color: isSelected
+ ? cs.primary
+ : cs.onSurface.withValues(alpha: 0.35),
+ fontSize: 9,
+ fontWeight: FontWeight.w600))),
+ Container(
+ height: max(ratio * 80, d.seconds > 0 ? 4 : 2),
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(dense ? 2 : 5),
+ color: isSelected
+ ? cs.primary
+ : isToday
+ ? cs.primary.withValues(alpha: 0.7)
+ : cs.onSurface.withValues(alpha: 0.12),
+ ),
+ ),
+ ]),
+ ),
));
}).toList(),
),
),
const SizedBox(height: 8),
- Row(
- children: data.map((d) {
- final isToday = d.fullLabel == _dateKey(DateTime.now());
- return Expanded(
- child: Text(d.label,
- textAlign: TextAlign.center,
- style: TextStyle(
- color: isToday
- ? cs.primary.withValues(alpha: 0.8)
- : cs.onSurface.withValues(alpha: 0.25),
- fontSize: 10,
- fontWeight: isToday ? FontWeight.w600 : FontWeight.w400,
- )));
- }).toList()),
+ Row(children: [
+ for (var i = 0; i < data.length; i++)
+ Expanded(
+ child: Text(
+ dense ? (i % 5 == 0 ? data[i].label : '') : data[i].label,
+ textAlign: TextAlign.center,
+ style: TextStyle(
+ color: data[i].fullLabel == _dateKey(DateTime.now())
+ ? cs.primary.withValues(alpha: 0.8)
+ : cs.onSurface.withValues(alpha: 0.25),
+ fontSize: 10,
+ fontWeight: data[i].fullLabel == _dateKey(DateTime.now())
+ ? FontWeight.w600
+ : FontWeight.w400,
+ ))),
+ ]),
]),
);
}
@@ -921,13 +1198,13 @@ class _StatsScreenState extends State<StatsScreen>
return daysWithData > 0 ? total / daysWithData : 0;
}
- List<_DayData> _last7Days(Map<String, dynamic> dailyMap) {
+ List<_DayData> _lastNDays(Map<String, dynamic> dailyMap, int n) {
final l = AppLocalizations.of(context)!;
final now = DateTime.now();
- return List.generate(7, (i) {
- final date = now.subtract(Duration(days: 6 - i));
+ return List.generate(n, (i) {
+ final date = now.subtract(Duration(days: n - 1 - i));
return _DayData(
- label: _dayLabel(date, l),
+ label: n <= 7 ? _dayLabel(date, l) : '${date.day}',
fullLabel: _dateKey(date),
seconds: _daySeconds(dailyMap, _dateKey(date)),
);
diff --git a/lib/services/player_settings.dart b/lib/services/player_settings.dart
index 817e10d5..35204c33 100644
--- a/lib/services/player_settings.dart
+++ b/lib/services/player_settings.dart
@@ -153,6 +153,40 @@ class PlayerSettings {
static Future<int> getMaxConcurrentDownloads() => _get('maxConcurrentDownloads', 1);
static Future<void> setMaxConcurrentDownloads(int value) => _set('maxConcurrentDownloads', value);
+ // ── Stats page ──
+ // Goal period shown on the stats page: 'off' | 'daily' | 'weekly' | 'monthly'.
+ static Future<String> getStatsGoalType() => _get('stats_goal_type', 'off');
+ static Future<void> setStatsGoalType(String value) => _set('stats_goal_type', value, notify: true);
+
+ /// Target listening minutes for the active goal period.
+ static Future<int> getStatsGoalMinutes() => _get('stats_goal_minutes', 30);
+ static Future<void> setStatsGoalMinutes(int value) => _set('stats_goal_minutes', value, notify: true);
+
+ /// Yearly book-challenge target. 0 = off.
+ static Future<int> getStatsBookGoal() => _get('stats_book_goal', 0);
+ static Future<void> setStatsBookGoal(int value) => _set('stats_book_goal', value, notify: true);
+
+ /// Listening chart style on the stats page: 'bar' | 'line' | 'heatmap'.
+ static Future<String> getStatsChartStyle() => _get('stats_chart_style', 'bar');
+ static Future<void> setStatsChartStyle(String value) => _set('stats_chart_style', value, notify: true);
+
+ /// Days covered by the bar/line chart: 7 or 30. The heatmap is always a year.
+ static Future<int> getStatsChartRange() => _get('stats_chart_range', 7);
+ static Future<void> setStatsChartRange(int value) => _set('stats_chart_range', value, notify: true);
+
+ /// Stats page section layout (ids ordered / hidden), per account.
+ static Future<List<String>> getStatsSectionOrder() => ScopedPrefs.getStringList('stats_section_order');
+ static Future<void> setStatsSectionOrder(List<String> order) async {
+ await ScopedPrefs.setStringList('stats_section_order', order);
+ _notify();
+ }
+
+ static Future<List<String>> getStatsHiddenSections() => ScopedPrefs.getStringList('stats_hidden_sections');
+ static Future<void> setStatsHiddenSections(List<String> hidden) async {
+ await ScopedPrefs.setStringList('stats_hidden_sections', hidden);
+ _notify();
+ }
+
// ── Queue mode (replaces autoPlayNextBook + autoPlayNextPodcast) ──
// Values: 'off', 'manual', 'auto_next', 'playlist'
static Future<String> getQueueMode() => _get('queueMode', 'off');
diff --git a/lib/widgets/stats_charts.dart b/lib/widgets/stats_charts.dart
new file mode 100644
index 00000000..8aff9fbb
--- /dev/null
+++ b/lib/widgets/stats_charts.dart
@@ -0,0 +1,460 @@
+import 'package:flutter/material.dart';
+
+/// One day of listening for the stats charts.
+class ChartDay {
+ final String label;
+ final String dateKey;
+ final double seconds;
+ const ChartDay({required this.label, required this.dateKey, required this.seconds});
+}
+
+/// Line chart over the chart range. Colors are passed in because
+/// CustomPainters can't read Theme.of(context).
+class StatsLineChart extends StatelessWidget {
+ final List<ChartDay> data;
+ final String todayKey;
+ final double animValue;
+ final Color lineColor;
+ final Color labelColor;
+ final Color todayColor;
+ final String Function(double seconds) formatValue;
+ final int selectedIndex;
+ final void Function(int index)? onDaySelected;
+
+ const StatsLineChart({
+ super.key,
+ required this.data,
+ required this.todayKey,
+ required this.animValue,
+ required this.lineColor,
+ required this.labelColor,
+ required this.todayColor,
+ required this.formatValue,
+ this.selectedIndex = -1,
+ this.onDaySelected,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final dense = data.length > 10;
+ return Column(children: [
+ LayoutBuilder(builder: (context, constraints) {
+ return GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTapUp: onDaySelected == null || data.length < 2
+ ? null
+ : (details) {
+ final i = (details.localPosition.dx /
+ constraints.maxWidth *
+ (data.length - 1))
+ .round()
+ .clamp(0, data.length - 1);
+ onDaySelected!(i);
+ },
+ child: SizedBox(
+ height: 120,
+ width: double.infinity,
+ child: CustomPaint(
+ painter: _LinePainter(
+ values: data.map((d) => d.seconds).toList(),
+ animValue: animValue,
+ lineColor: lineColor,
+ labelColor: labelColor,
+ formatValue: formatValue,
+ selectedIndex: selectedIndex,
+ ),
+ ),
+ ),
+ );
+ }),
+ const SizedBox(height: 8),
+ Row(
+ children: [
+ for (var i = 0; i < data.length; i++)
+ Expanded(
+ child: Text(
+ dense ? (i % 5 == 0 ? data[i].label : '') : data[i].label,
+ textAlign: TextAlign.center,
+ style: TextStyle(
+ color: data[i].dateKey == todayKey
+ ? todayColor.withValues(alpha: 0.8)
+ : labelColor.withValues(alpha: 0.25),
+ fontSize: 10,
+ fontWeight:
+ data[i].dateKey == todayKey ? FontWeight.w600 : FontWeight.w400,
+ ),
+ ),
+ ),
+ ],
+ ),
+ ]);
+ }
+}
+
+class _LinePainter extends CustomPainter {
+ final List<double> values;
+ final double animValue;
+ final Color lineColor;
+ final Color labelColor;
+ final String Function(double seconds) formatValue;
+ final int selectedIndex;
+
+ _LinePainter({
+ required this.values,
+ required this.animValue,
+ required this.lineColor,
+ required this.labelColor,
+ required this.formatValue,
+ required this.selectedIndex,
+ });
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ if (values.isEmpty) return;
+ final maxVal = values.fold(0.0, (a, b) => a > b ? a : b);
+ final scale = maxVal > 0 ? maxVal : 1.0;
+ const topPad = 18.0;
+ final plotHeight = size.height - topPad;
+
+ Offset pointAt(int i) {
+ final x = values.length == 1
+ ? size.width / 2
+ : i * size.width / (values.length - 1);
+ final y = topPad + plotHeight - (values[i] / scale * plotHeight * animValue);
+ return Offset(x, y);
+ }
+
+ final path = Path()..moveTo(pointAt(0).dx, pointAt(0).dy);
+ for (var i = 1; i < values.length; i++) {
+ final p = pointAt(i);
+ path.lineTo(p.dx, p.dy);
+ }
+
+ final fillPath = Path.from(path)
+ ..lineTo(size.width, size.height)
+ ..lineTo(0, size.height)
+ ..close();
+ canvas.drawPath(
+ fillPath,
+ Paint()
+ ..shader = LinearGradient(
+ begin: Alignment.topCenter,
+ end: Alignment.bottomCenter,
+ colors: [
+ lineColor.withValues(alpha: 0.18),
+ lineColor.withValues(alpha: 0.0),
+ ],
+ ).createShader(Offset.zero & size),
+ );
+
+ canvas.drawPath(
+ path,
+ Paint()
+ ..color = lineColor.withValues(alpha: 0.75)
+ ..style = PaintingStyle.stroke
+ ..strokeWidth = 2
+ ..strokeCap = StrokeCap.round
+ ..strokeJoin = StrokeJoin.round,
+ );
+
+ final dotPaint = Paint()..color = lineColor;
+ for (var i = 0; i < values.length; i++) {
+ if (values[i] <= 0) continue;
+ canvas.drawCircle(pointAt(i), values.length > 10 ? 1.8 : 2.6, dotPaint);
+ }
+
+ if (selectedIndex >= 0 && selectedIndex < values.length) {
+ final p = pointAt(selectedIndex);
+ canvas.drawLine(
+ Offset(p.dx, topPad),
+ Offset(p.dx, size.height),
+ Paint()
+ ..color = labelColor.withValues(alpha: 0.2)
+ ..strokeWidth = 1,
+ );
+ canvas.drawCircle(p, 5, Paint()..color = lineColor.withValues(alpha: 0.25));
+ canvas.drawCircle(p, 3.2, Paint()..color = lineColor);
+ } else if (maxVal > 0) {
+ final peak = values.indexOf(maxVal);
+ final p = pointAt(peak);
+ final tp = TextPainter(
+ text: TextSpan(
+ text: formatValue(maxVal),
+ style: TextStyle(
+ color: labelColor.withValues(alpha: 0.45),
+ fontSize: 9,
+ fontWeight: FontWeight.w600,
+ ),
+ ),
+ textDirection: TextDirection.ltr,
+ )..layout();
+ final dx = (p.dx - tp.width / 2).clamp(0.0, size.width - tp.width);
+ tp.paint(canvas, Offset(dx, (p.dy - tp.height - 4).clamp(0.0, size.height)));
+ }
+ }
+
+ @override
+ bool shouldRepaint(_LinePainter old) =>
+ old.values != values ||
+ old.animValue != animValue ||
+ old.lineColor != lineColor ||
+ old.labelColor != labelColor ||
+ old.selectedIndex != selectedIndex;
+}
+
+/// GitHub-style contribution heatmap of the last 53 weeks of listening.
+/// Horizontally scrollable with a fixed cell size so it stays readable;
+/// starts scrolled to the most recent weeks.
+class StatsHeatmap extends StatelessWidget {
+ final Map<String, double> dailySeconds;
+ final Color fillColor;
+ final Color emptyColor;
+ final Color labelColor;
+ final String lessLabel;
+ final String moreLabel;
+ final List<String> dayLabels;
+ final String? selectedKey;
+ final void Function(String dateKey, double seconds)? onDaySelected;
+
+ const StatsHeatmap({
+ super.key,
+ required this.dailySeconds,
+ required this.fillColor,
+ required this.emptyColor,
+ required this.labelColor,
+ required this.lessLabel,
+ required this.moreLabel,
+ this.dayLabels = const [],
+ this.selectedKey,
+ this.onDaySelected,
+ });
+
+ static const _weeks = 53;
+ static const _gap = 2.0;
+ static const _cell = 11.0;
+ static const _labelHeight = 14.0;
+
+ static String _dateKey(DateTime d) =>
+ '${d.year}-${d.month.toString().padLeft(2, '0')}-${d.day.toString().padLeft(2, '0')}';
+
+ @override
+ Widget build(BuildContext context) {
+ final today = DateTime.now();
+ final monday = DateTime(today.year, today.month, today.day)
+ .subtract(Duration(days: today.weekday - 1));
+ final start = monday.subtract(const Duration(days: 7 * (_weeks - 1)));
+
+ var maxVal = 0.0;
+ var selW = -1;
+ var selD = -1;
+ final levels = List<List<double>>.generate(_weeks, (_) => List.filled(7, -1));
+ for (var w = 0; w < _weeks; w++) {
+ for (var d = 0; d < 7; d++) {
+ final date = start.add(Duration(days: w * 7 + d));
+ if (date.isAfter(today)) continue;
+ final key = _dateKey(date);
+ final v = dailySeconds[key] ?? 0;
+ levels[w][d] = v;
+ if (v > maxVal) maxVal = v;
+ if (key == selectedKey) {
+ selW = w;
+ selD = d;
+ }
+ }
+ }
+
+ final monthLabels = <int, String>{};
+ var lastMonth = -1;
+ for (var w = 0; w < _weeks; w++) {
+ final date = start.add(Duration(days: w * 7));
+ if (date.month != lastMonth) {
+ lastMonth = date.month;
+ monthLabels[w] = _monthShort(date.month);
+ }
+ }
+
+ final gridWidth = _weeks * _cell + (_weeks - 1) * _gap;
+ final gridHeight = 7 * _cell + 6 * _gap;
+
+ return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ if (dayLabels.length == 7)
+ Padding(
+ padding: const EdgeInsets.only(top: _labelHeight, right: 4),
+ child: Column(children: [
+ for (var d = 0; d < 7; d++)
+ SizedBox(
+ height: _cell + (d < 6 ? _gap : 0),
+ child: d.isEven
+ ? Text(dayLabels[d],
+ style: TextStyle(
+ fontSize: 7,
+ height: 1.2,
+ color: labelColor.withValues(alpha: 0.35)))
+ : null,
+ ),
+ ]),
+ ),
+ Expanded(
+ child: SingleChildScrollView(
+ scrollDirection: Axis.horizontal,
+ reverse: true,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTapUp: onDaySelected == null
+ ? null
+ : (details) {
+ final x = details.localPosition.dx;
+ final y = details.localPosition.dy - _labelHeight;
+ if (y < 0) return;
+ final w = x ~/ (_cell + _gap);
+ final d = y ~/ (_cell + _gap);
+ if (w < 0 || w >= _weeks || d < 0 || d > 6) return;
+ final v = levels[w][d];
+ if (v < 0) return;
+ final date = start.add(Duration(days: w * 7 + d));
+ onDaySelected!(_dateKey(date), v);
+ },
+ child: SizedBox(
+ width: gridWidth,
+ height: gridHeight + _labelHeight,
+ child: CustomPaint(
+ painter: _HeatmapPainter(
+ levels: levels,
+ maxVal: maxVal,
+ cell: _cell,
+ fillColor: fillColor,
+ emptyColor: emptyColor,
+ labelColor: labelColor,
+ monthLabels: monthLabels,
+ selectedWeek: selW,
+ selectedDay: selD,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ]),
+ const SizedBox(height: 6),
+ Row(mainAxisAlignment: MainAxisAlignment.end, children: [
+ Text(lessLabel,
+ style: TextStyle(fontSize: 9, color: labelColor.withValues(alpha: 0.4))),
+ const SizedBox(width: 4),
+ for (final alpha in [0.0, 0.3, 0.55, 0.8, 1.0])
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 1.5),
+ child: Container(
+ width: 8,
+ height: 8,
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(2),
+ color: alpha == 0.0
+ ? emptyColor
+ : fillColor.withValues(alpha: alpha),
+ ),
+ ),
+ ),
+ const SizedBox(width: 4),
+ Text(moreLabel,
+ style: TextStyle(fontSize: 9, color: labelColor.withValues(alpha: 0.4))),
+ ]),
+ ]);
+ }
+
+ static String _monthShort(int month) {
+ const names = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
+ return names[month - 1];
+ }
+}
+
+class _HeatmapPainter extends CustomPainter {
+ final List<List<double>> levels;
+ final double maxVal;
+ final double cell;
+ final Color fillColor;
+ final Color emptyColor;
+ final Color labelColor;
+ final Map<int, String> monthLabels;
+ final int selectedWeek;
+ final int selectedDay;
+
+ _HeatmapPainter({
+ required this.levels,
+ required this.maxVal,
+ required this.cell,
+ required this.fillColor,
+ required this.emptyColor,
+ required this.labelColor,
+ required this.monthLabels,
+ required this.selectedWeek,
+ required this.selectedDay,
+ });
+
+ static const _gap = StatsHeatmap._gap;
+ static const _labelHeight = StatsHeatmap._labelHeight;
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ final paint = Paint();
+
+ for (final entry in monthLabels.entries) {
+ final tp = TextPainter(
+ text: TextSpan(
+ text: entry.value,
+ style: TextStyle(fontSize: 8, color: labelColor.withValues(alpha: 0.35)),
+ ),
+ textDirection: TextDirection.ltr,
+ )..layout();
+ tp.paint(canvas, Offset(entry.key * (cell + _gap), 0));
+ }
+
+ for (var w = 0; w < levels.length; w++) {
+ for (var d = 0; d < 7; d++) {
+ final v = levels[w][d];
+ if (v < 0) continue;
+ if (v <= 0) {
+ paint.color = emptyColor;
+ } else {
+ final ratio = maxVal > 0 ? v / maxVal : 0.0;
+ final alpha = ratio <= 0.25
+ ? 0.3
+ : ratio <= 0.5
+ ? 0.55
+ : ratio <= 0.75
+ ? 0.8
+ : 1.0;
+ paint.color = fillColor.withValues(alpha: alpha);
+ }
+ final rect = RRect.fromRectAndRadius(
+ Rect.fromLTWH(
+ w * (cell + _gap),
+ _labelHeight + d * (cell + _gap),
+ cell,
+ cell,
+ ),
+ Radius.circular(cell / 4),
+ );
+ canvas.drawRRect(rect, paint);
+ if (w == selectedWeek && d == selectedDay) {
+ canvas.drawRRect(
+ rect,
+ Paint()
+ ..color = labelColor.withValues(alpha: 0.9)
+ ..style = PaintingStyle.stroke
+ ..strokeWidth = 1.5,
+ );
+ }
+ }
+ }
+ }
+
+ @override
+ bool shouldRepaint(_HeatmapPainter old) =>
+ old.levels != levels ||
+ old.maxVal != maxVal ||
+ old.cell != cell ||
+ old.fillColor != fillColor ||
+ old.selectedWeek != selectedWeek ||
+ old.selectedDay != selectedDay;
+}