Show date from which statistics are counting (#4517)

This commit is contained in:
asdoi 2020-10-25 19:14:59 +01:00 committed by GitHub
parent a0c604dc86
commit d732e6a5c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 45 additions and 9 deletions

View File

@ -20,8 +20,8 @@ public class DownloadStatisticsListAdapter extends StatisticsListAdapter {
}
@Override
int getHeaderCaptionResourceId() {
return R.string.total_size_downloaded_podcasts;
String getHeaderCaption() {
return context.getString(R.string.total_size_downloaded_podcasts);
}
@Override

View File

@ -4,10 +4,13 @@ import android.content.Context;
import androidx.appcompat.app.AlertDialog;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.storage.StatisticsItem;
import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.DateUtils;
import de.danoeh.antennapod.view.PieChartView;
import java.util.Date;
import java.util.List;
/**
@ -26,8 +29,14 @@ public class PlaybackStatisticsListAdapter extends StatisticsListAdapter {
}
@Override
int getHeaderCaptionResourceId() {
return R.string.total_time_listened_to_podcasts;
String getHeaderCaption() {
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

View File

@ -50,7 +50,7 @@ public abstract class StatisticsListAdapter extends RecyclerView.Adapter<Recycle
if (viewType == TYPE_HEADER) {
View view = inflater.inflate(R.layout.statistics_listitem_total, parent, false);
TextView totalText = view.findViewById(R.id.total_description);
totalText.setText(getHeaderCaptionResourceId());
totalText.setText(getHeaderCaption());
return new HeaderHolder(view);
}
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();

View File

@ -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.html.HtmlWriter;
import de.danoeh.antennapod.core.export.opml.OpmlWriter;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.storage.DatabaseExporter;
import io.reactivex.Completable;
import io.reactivex.Observable;
@ -268,6 +269,7 @@ public class ImportExportPreferencesFragment extends PreferenceFragmentCompat {
.observeOn(AndroidSchedulers.mainThread())
.subscribe(() -> {
showDatabaseImportSuccessDialog();
UserPreferences.unsetUsageCountingDate();
progressDialog.dismiss();
}, this::showExportErrorDialog);
} else if (requestCode == REQUEST_CODE_BACKUP_DATABASE) {

View File

@ -25,6 +25,7 @@ import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.PreferenceActivity;
import de.danoeh.antennapod.adapter.PlaybackStatisticsListAdapter;
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.DBWriter;
import de.danoeh.antennapod.core.storage.StatisticsItem;
@ -159,7 +160,10 @@ public class PlaybackStatisticsFragment extends Fragment {
disposable = Completable.fromFuture(DBWriter.resetStatistics())
.subscribeOn(Schedulers.io())
.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() {

View File

@ -34,6 +34,10 @@ public class PreferenceUpgrader {
private static void upgrade(int oldVersion) {
if (oldVersion == -1) {
//New installation
if (UserPreferences.getUsageCountingDateMillis() < 0) {
UserPreferences.resetUsageCountingDate();
}
return;
}
if (oldVersion < 1070196) {

View File

@ -4,7 +4,6 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Build;
import androidx.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.Log;
@ -12,6 +11,7 @@ import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.core.app.NotificationCompat;
import androidx.preference.PreferenceManager;
import org.json.JSONArray;
import org.json.JSONException;
@ -23,7 +23,7 @@ import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Calendar;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
@ -115,6 +115,7 @@ public class UserPreferences {
private static final String PREF_DATA_FOLDER = "prefDataFolder";
public static final String PREF_IMAGE_CACHE_SIZE = "prefImageCacheSize";
public static final String PREF_DELETE_REMOVES_FROM_QUEUE = "prefDeleteRemovesFromQueue";
public static final String PREF_USAGE_COUNTING_DATE = "prefUsageCounting";
// Mediaplayer
public static final String PREF_MEDIA_PLAYER = "prefMediaPlayer";
@ -1056,4 +1057,19 @@ public class UserPreferences {
.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);
}
}

View File

@ -41,6 +41,7 @@
<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_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 -->
<string name="total_size_downloaded_podcasts">Total size of episodes on the device:</string>