Show date from which statistics are counting (#4517)
This commit is contained in:
parent
a0c604dc86
commit
d732e6a5c1
|
@ -20,8 +20,8 @@ public class DownloadStatisticsListAdapter extends StatisticsListAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
int getHeaderCaptionResourceId() {
|
String getHeaderCaption() {
|
||||||
return R.string.total_size_downloaded_podcasts;
|
return context.getString(R.string.total_size_downloaded_podcasts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -4,10 +4,13 @@ import android.content.Context;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
import de.danoeh.antennapod.core.storage.StatisticsItem;
|
import de.danoeh.antennapod.core.storage.StatisticsItem;
|
||||||
import de.danoeh.antennapod.core.util.Converter;
|
import de.danoeh.antennapod.core.util.Converter;
|
||||||
|
import de.danoeh.antennapod.core.util.DateUtils;
|
||||||
import de.danoeh.antennapod.view.PieChartView;
|
import de.danoeh.antennapod.view.PieChartView;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,8 +29,14 @@ public class PlaybackStatisticsListAdapter extends StatisticsListAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
int getHeaderCaptionResourceId() {
|
String getHeaderCaption() {
|
||||||
return R.string.total_time_listened_to_podcasts;
|
long usageCounting = UserPreferences.getUsageCountingDateMillis();
|
||||||
|
if (usageCounting > 0) {
|
||||||
|
String date = DateUtils.formatAbbrev(context, new Date(usageCounting));
|
||||||
|
return context.getString(R.string.statistics_counting_since, date);
|
||||||
|
} else {
|
||||||
|
return context.getString(R.string.total_time_listened_to_podcasts);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -50,7 +50,7 @@ public abstract class StatisticsListAdapter extends RecyclerView.Adapter<Recycle
|
||||||
if (viewType == TYPE_HEADER) {
|
if (viewType == TYPE_HEADER) {
|
||||||
View view = inflater.inflate(R.layout.statistics_listitem_total, parent, false);
|
View view = inflater.inflate(R.layout.statistics_listitem_total, parent, false);
|
||||||
TextView totalText = view.findViewById(R.id.total_description);
|
TextView totalText = view.findViewById(R.id.total_description);
|
||||||
totalText.setText(getHeaderCaptionResourceId());
|
totalText.setText(getHeaderCaption());
|
||||||
return new HeaderHolder(view);
|
return new HeaderHolder(view);
|
||||||
}
|
}
|
||||||
return new StatisticsHolder(inflater.inflate(R.layout.statistics_listitem, parent, false));
|
return new StatisticsHolder(inflater.inflate(R.layout.statistics_listitem, parent, false));
|
||||||
|
@ -113,7 +113,7 @@ public abstract class StatisticsListAdapter extends RecyclerView.Adapter<Recycle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract int getHeaderCaptionResourceId();
|
abstract String getHeaderCaption();
|
||||||
|
|
||||||
abstract String getHeaderValue();
|
abstract String getHeaderValue();
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ import de.danoeh.antennapod.core.export.ExportWriter;
|
||||||
import de.danoeh.antennapod.core.export.favorites.FavoritesWriter;
|
import de.danoeh.antennapod.core.export.favorites.FavoritesWriter;
|
||||||
import de.danoeh.antennapod.core.export.html.HtmlWriter;
|
import de.danoeh.antennapod.core.export.html.HtmlWriter;
|
||||||
import de.danoeh.antennapod.core.export.opml.OpmlWriter;
|
import de.danoeh.antennapod.core.export.opml.OpmlWriter;
|
||||||
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
import de.danoeh.antennapod.core.storage.DatabaseExporter;
|
import de.danoeh.antennapod.core.storage.DatabaseExporter;
|
||||||
import io.reactivex.Completable;
|
import io.reactivex.Completable;
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
|
@ -268,6 +269,7 @@ public class ImportExportPreferencesFragment extends PreferenceFragmentCompat {
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(() -> {
|
.subscribe(() -> {
|
||||||
showDatabaseImportSuccessDialog();
|
showDatabaseImportSuccessDialog();
|
||||||
|
UserPreferences.unsetUsageCountingDate();
|
||||||
progressDialog.dismiss();
|
progressDialog.dismiss();
|
||||||
}, this::showExportErrorDialog);
|
}, this::showExportErrorDialog);
|
||||||
} else if (requestCode == REQUEST_CODE_BACKUP_DATABASE) {
|
} else if (requestCode == REQUEST_CODE_BACKUP_DATABASE) {
|
||||||
|
|
|
@ -25,6 +25,7 @@ import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.activity.PreferenceActivity;
|
import de.danoeh.antennapod.activity.PreferenceActivity;
|
||||||
import de.danoeh.antennapod.adapter.PlaybackStatisticsListAdapter;
|
import de.danoeh.antennapod.adapter.PlaybackStatisticsListAdapter;
|
||||||
import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
|
import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
|
||||||
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
import de.danoeh.antennapod.core.storage.DBReader;
|
import de.danoeh.antennapod.core.storage.DBReader;
|
||||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||||
import de.danoeh.antennapod.core.storage.StatisticsItem;
|
import de.danoeh.antennapod.core.storage.StatisticsItem;
|
||||||
|
@ -159,7 +160,10 @@ public class PlaybackStatisticsFragment extends Fragment {
|
||||||
disposable = Completable.fromFuture(DBWriter.resetStatistics())
|
disposable = Completable.fromFuture(DBWriter.resetStatistics())
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(this::refreshStatistics, error -> Log.e(TAG, Log.getStackTraceString(error)));
|
.subscribe(() -> {
|
||||||
|
refreshStatistics();
|
||||||
|
UserPreferences.resetUsageCountingDate();
|
||||||
|
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshStatistics() {
|
private void refreshStatistics() {
|
||||||
|
|
|
@ -34,6 +34,10 @@ public class PreferenceUpgrader {
|
||||||
|
|
||||||
private static void upgrade(int oldVersion) {
|
private static void upgrade(int oldVersion) {
|
||||||
if (oldVersion == -1) {
|
if (oldVersion == -1) {
|
||||||
|
//New installation
|
||||||
|
if (UserPreferences.getUsageCountingDateMillis() < 0) {
|
||||||
|
UserPreferences.resetUsageCountingDate();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (oldVersion < 1070196) {
|
if (oldVersion < 1070196) {
|
||||||
|
|
|
@ -4,7 +4,6 @@ import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import androidx.preference.PreferenceManager;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
@ -12,6 +11,7 @@ import androidx.annotation.IntRange;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
@ -23,7 +23,7 @@ import java.text.DecimalFormat;
|
||||||
import java.text.DecimalFormatSymbols;
|
import java.text.DecimalFormatSymbols;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Calendar;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -115,6 +115,7 @@ public class UserPreferences {
|
||||||
private static final String PREF_DATA_FOLDER = "prefDataFolder";
|
private static final String PREF_DATA_FOLDER = "prefDataFolder";
|
||||||
public static final String PREF_IMAGE_CACHE_SIZE = "prefImageCacheSize";
|
public static final String PREF_IMAGE_CACHE_SIZE = "prefImageCacheSize";
|
||||||
public static final String PREF_DELETE_REMOVES_FROM_QUEUE = "prefDeleteRemovesFromQueue";
|
public static final String PREF_DELETE_REMOVES_FROM_QUEUE = "prefDeleteRemovesFromQueue";
|
||||||
|
public static final String PREF_USAGE_COUNTING_DATE = "prefUsageCounting";
|
||||||
|
|
||||||
// Mediaplayer
|
// Mediaplayer
|
||||||
public static final String PREF_MEDIA_PLAYER = "prefMediaPlayer";
|
public static final String PREF_MEDIA_PLAYER = "prefMediaPlayer";
|
||||||
|
@ -1056,4 +1057,19 @@ public class UserPreferences {
|
||||||
.apply();
|
.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long getUsageCountingDateMillis() {
|
||||||
|
return prefs.getLong(PREF_USAGE_COUNTING_DATE, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setUsageCountingDateMillis(long value) {
|
||||||
|
prefs.edit().putLong(PREF_USAGE_COUNTING_DATE, value).apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void resetUsageCountingDate() {
|
||||||
|
setUsageCountingDateMillis(Calendar.getInstance().getTimeInMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void unsetUsageCountingDate() {
|
||||||
|
setUsageCountingDateMillis(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
<string name="statistics_speed_not_counted">Notice: Playback speed is never taken into account.</string>
|
<string name="statistics_speed_not_counted">Notice: Playback speed is never taken into account.</string>
|
||||||
<string name="statistics_reset_data">Reset statistics data</string>
|
<string name="statistics_reset_data">Reset statistics data</string>
|
||||||
<string name="statistics_reset_data_msg">This will erase the history of duration played for all episodes. Are you sure you want to proceed?</string>
|
<string name="statistics_reset_data_msg">This will erase the history of duration played for all episodes. Are you sure you want to proceed?</string>
|
||||||
|
<string name="statistics_counting_since">Since %s,\nyou played</string>
|
||||||
|
|
||||||
<!-- Download Statistics fragment -->
|
<!-- Download Statistics fragment -->
|
||||||
<string name="total_size_downloaded_podcasts">Total size of episodes on the device:</string>
|
<string name="total_size_downloaded_podcasts">Total size of episodes on the device:</string>
|
||||||
|
|
Loading…
Reference in New Issue