diff options
author | Nils Rothaug <48482306+nproth@users.noreply.github.com> | 2022-04-09 11:54:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-09 11:54:18 +0200 |
commit | e7f23ad1c2eeac91132e03db4a213616a44483a1 (patch) | |
tree | 3ed6e59b497bca57fff170711632b0ef46e4e1ed /core/src/main/java | |
parent | 0c26eb6c04e41b6a61d0bd31ede237b5e635e0db (diff) | |
download | AntennaPod-e7f23ad1c2eeac91132e03db4a213616a44483a1.zip |
Show on-demand configuration popup for stream vs download only once (#5818)
Diffstat (limited to 'core/src/main/java')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/preferences/UsageStatistics.java | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UsageStatistics.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UsageStatistics.java index a5b00b08c..9835f9894 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UsageStatistics.java +++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UsageStatistics.java @@ -4,8 +4,6 @@ import android.content.Context; import android.content.SharedPreferences; import androidx.annotation.NonNull; -import java.util.Calendar; - /** * Collects statistics about the app usage. The statistics are used to allow on-demand configuration: * "Looks like you stream a lot. Do you want to toggle the 'Prefer streaming' setting?". @@ -22,8 +20,7 @@ public class UsageStatistics { private static final String PREF_DB_NAME = "UsageStatistics"; private static final float MOVING_AVERAGE_WEIGHT = 0.8f; private static final float MOVING_AVERAGE_BIAS_THRESHOLD = 0.1f; - private static final long ASK_AGAIN_LATER_DELAY = 1000 * 3600 * 24 * 10; // 10 days - private static final String SUFFIX_HIDDEN_UNTIL = "_hiddenUntil"; + private static final String SUFFIX_HIDDEN = "_hidden"; private static SharedPreferences prefs; public static final StatsAction ACTION_STREAM = new StatsAction("downloadVsStream", 0); @@ -49,16 +46,16 @@ public class UsageStatistics { } public static boolean hasSignificantBiasTo(StatsAction action) { - final float movingAverage = prefs.getFloat(action.type, 0.5f); - final long askAfter = prefs.getLong(action.type + SUFFIX_HIDDEN_UNTIL, 0); - return Math.abs(action.value - movingAverage) < MOVING_AVERAGE_BIAS_THRESHOLD - && Calendar.getInstance().getTimeInMillis() > askAfter; + if (prefs.getBoolean(action.type + SUFFIX_HIDDEN, false)) { + return false; + } else { + final float movingAverage = prefs.getFloat(action.type, 0.5f); + return Math.abs(action.value - movingAverage) < MOVING_AVERAGE_BIAS_THRESHOLD; + } } - public static void askAgainLater(StatsAction action) { - prefs.edit().putLong(action.type + SUFFIX_HIDDEN_UNTIL, - Calendar.getInstance().getTimeInMillis() + ASK_AGAIN_LATER_DELAY) - .apply(); + public static void doNotAskAgain(StatsAction action) { + prefs.edit().putBoolean(action.type + SUFFIX_HIDDEN, true).apply(); } public static final class StatsAction { |