1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
package de.danoeh.antennapod.fragment.preferences;
import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.collection.ArrayMap;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.PreferenceActivity;
import de.danoeh.antennapod.event.UnreadItemsUpdateEvent;
import de.danoeh.antennapod.core.preferences.UsageStatistics;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.dialog.SkipPreferenceDialog;
import de.danoeh.antennapod.dialog.VariableSpeedDialog;
import java.util.Map;
import org.greenrobot.eventbus.EventBus;
public class PlaybackPreferencesFragment extends PreferenceFragmentCompat {
private static final String PREF_PLAYBACK_SPEED_LAUNCHER = "prefPlaybackSpeedLauncher";
private static final String PREF_PLAYBACK_REWIND_DELTA_LAUNCHER = "prefPlaybackRewindDeltaLauncher";
private static final String PREF_PLAYBACK_FAST_FORWARD_DELTA_LAUNCHER = "prefPlaybackFastForwardDeltaLauncher";
private static final String PREF_PLAYBACK_PREFER_STREAMING = "prefStreamOverDownload";
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.preferences_playback);
setupPlaybackScreen();
buildSmartMarkAsPlayedPreference();
}
@Override
public void onStart() {
super.onStart();
((PreferenceActivity) getActivity()).getSupportActionBar().setTitle(R.string.playback_pref);
}
private void setupPlaybackScreen() {
final Activity activity = getActivity();
findPreference(PREF_PLAYBACK_SPEED_LAUNCHER).setOnPreferenceClickListener(preference -> {
new VariableSpeedDialog().show(getChildFragmentManager(), null);
return true;
});
findPreference(PREF_PLAYBACK_REWIND_DELTA_LAUNCHER).setOnPreferenceClickListener(preference -> {
SkipPreferenceDialog.showSkipPreference(activity, SkipPreferenceDialog.SkipDirection.SKIP_REWIND, null);
return true;
});
findPreference(PREF_PLAYBACK_FAST_FORWARD_DELTA_LAUNCHER).setOnPreferenceClickListener(preference -> {
SkipPreferenceDialog.showSkipPreference(activity, SkipPreferenceDialog.SkipDirection.SKIP_FORWARD, null);
return true;
});
findPreference(PREF_PLAYBACK_PREFER_STREAMING).setOnPreferenceChangeListener((preference, newValue) -> {
// Update all visible lists to reflect new streaming action button
EventBus.getDefault().post(new UnreadItemsUpdateEvent());
// User consciously decided whether to prefer the streaming button, disable suggestion to change that
UsageStatistics.doNotAskAgain(UsageStatistics.ACTION_STREAM);
return true;
});
buildEnqueueLocationPreference();
}
private void buildEnqueueLocationPreference() {
final Resources res = requireActivity().getResources();
final Map<String, String> options = new ArrayMap<>();
{
String[] keys = res.getStringArray(R.array.enqueue_location_values);
String[] values = res.getStringArray(R.array.enqueue_location_options);
for (int i = 0; i < keys.length; i++) {
options.put(keys[i], values[i]);
}
}
ListPreference pref = requirePreference(UserPreferences.PREF_ENQUEUE_LOCATION);
pref.setSummary(res.getString(R.string.pref_enqueue_location_sum, options.get(pref.getValue())));
pref.setOnPreferenceChangeListener((preference, newValue) -> {
if (!(newValue instanceof String)) {
return false;
}
String newValStr = (String)newValue;
pref.setSummary(res.getString(R.string.pref_enqueue_location_sum, options.get(newValStr)));
return true;
});
}
@NonNull
private <T extends Preference> T requirePreference(@NonNull CharSequence key) {
// Possibly put it to a common method in abstract base class
T result = findPreference(key);
if (result == null) {
throw new IllegalArgumentException("Preference with key '" + key + "' is not found");
}
return result;
}
private void buildSmartMarkAsPlayedPreference() {
final Resources res = getActivity().getResources();
ListPreference pref = findPreference(UserPreferences.PREF_SMART_MARK_AS_PLAYED_SECS);
String[] values = res.getStringArray(R.array.smart_mark_as_played_values);
String[] entries = new String[values.length];
for (int x = 0; x < values.length; x++) {
if(x == 0) {
entries[x] = res.getString(R.string.pref_smart_mark_as_played_disabled);
} else {
int v = Integer.parseInt(values[x]);
if(v < 60) {
entries[x] = res.getQuantityString(R.plurals.time_seconds_quantified, v, v);
} else {
v /= 60;
entries[x] = res.getQuantityString(R.plurals.time_minutes_quantified, v, v);
}
}
}
pref.setEntries(entries);
}
}
|