Show on-demand configuration popup for stream vs download only once (#5818)
This commit is contained in:
parent
0c26eb6c04
commit
e7f23ad1c2
|
@ -188,9 +188,9 @@ public class ItemFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void showOnDemandConfigBalloon(boolean offerStreaming) {
|
||||
boolean isLocaleRtl = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault())
|
||||
final boolean isLocaleRtl = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault())
|
||||
== View.LAYOUT_DIRECTION_RTL;
|
||||
Balloon balloon = new Balloon.Builder(getContext())
|
||||
final Balloon balloon = new Balloon.Builder(getContext())
|
||||
.setArrowOrientation(ArrowOrientation.TOP)
|
||||
.setArrowOrientationRules(ArrowOrientationRules.ALIGN_FIXED)
|
||||
.setArrowPosition(0.25f + ((isLocaleRtl ^ offerStreaming) ? 0f : 0.5f))
|
||||
|
@ -203,9 +203,9 @@ public class ItemFragment extends Fragment {
|
|||
.setDismissWhenTouchOutside(true)
|
||||
.setLifecycleOwner(this)
|
||||
.build();
|
||||
Button positiveButton = balloon.getContentView().findViewById(R.id.balloon_button_positive);
|
||||
Button negativeButton = balloon.getContentView().findViewById(R.id.balloon_button_negative);
|
||||
TextView message = balloon.getContentView().findViewById(R.id.balloon_message);
|
||||
final Button positiveButton = balloon.getContentView().findViewById(R.id.balloon_button_positive);
|
||||
final Button negativeButton = balloon.getContentView().findViewById(R.id.balloon_button_negative);
|
||||
final TextView message = balloon.getContentView().findViewById(R.id.balloon_message);
|
||||
message.setText(offerStreaming
|
||||
? R.string.on_demand_config_stream_text : R.string.on_demand_config_download_text);
|
||||
positiveButton.setOnClickListener(v1 -> {
|
||||
|
@ -217,7 +217,7 @@ public class ItemFragment extends Fragment {
|
|||
balloon.dismiss();
|
||||
});
|
||||
negativeButton.setOnClickListener(v1 -> {
|
||||
UsageStatistics.askAgainLater(UsageStatistics.ACTION_STREAM); // Type does not matter. Both are silenced.
|
||||
UsageStatistics.doNotAskAgain(UsageStatistics.ACTION_STREAM); // Type does not matter. Both are silenced.
|
||||
balloon.dismiss();
|
||||
});
|
||||
balloon.showAlignBottom(butAction1, 0, (int) (-12 * getResources().getDisplayMetrics().density));
|
||||
|
|
|
@ -56,7 +56,8 @@ public class PlaybackPreferencesFragment extends PreferenceFragmentCompat {
|
|||
findPreference(PREF_PLAYBACK_PREFER_STREAMING).setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
// Update all visible lists to reflect new streaming action button
|
||||
EventBus.getDefault().post(new UnreadItemsUpdateEvent());
|
||||
UsageStatistics.askAgainLater(UsageStatistics.ACTION_STREAM);
|
||||
// User consciously decided whether to prefer the streaming button, disable suggestion to change that
|
||||
UsageStatistics.doNotAskAgain(UsageStatistics.ACTION_STREAM);
|
||||
return true;
|
||||
});
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
<Button
|
||||
android:id="@+id/balloon_button_negative"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="36dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?attr/colorOnSecondary"
|
||||
android:text="@string/no"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton" />
|
||||
|
@ -31,7 +31,7 @@
|
|||
<Button
|
||||
android:id="@+id/balloon_button_positive"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="36dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?attr/colorOnSecondary"
|
||||
android:text="@string/yes"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton" />
|
||||
|
|
Loading…
Reference in New Issue