Skip to content

Commit d5c29bf

Browse files
authored
Merge pull request #3160 from XiangRongLin/b3127
Hide 5, 15, 25 second seek options if inexact seek is enabled
2 parents 0a87f13 + 4bb6a14 commit d5c29bf

2 files changed

Lines changed: 56 additions & 18 deletions

File tree

app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
import android.os.Bundle;
77
import android.provider.Settings;
88

9+
import android.text.format.DateUtils;
10+
import android.widget.Toast;
911
import androidx.annotation.Nullable;
1012
import androidx.preference.ListPreference;
1113

1214
import com.google.android.material.snackbar.Snackbar;
1315

16+
import java.util.LinkedList;
17+
import java.util.List;
1418
import org.schabi.newpipe.R;
1519
import org.schabi.newpipe.util.PermissionHelper;
1620

@@ -22,23 +26,7 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment {
2226
public void onCreate(@Nullable Bundle savedInstanceState) {
2327
super.onCreate(savedInstanceState);
2428

25-
//initializing R.array.seek_duration_description to display the translation of seconds
26-
Resources res = getResources();
27-
String[] durationsValues = res.getStringArray(R.array.seek_duration_value);
28-
String[] durationsDescriptions = res.getStringArray(R.array.seek_duration_description);
29-
int currentDurationValue;
30-
for (int i = 0; i < durationsDescriptions.length; i++) {
31-
currentDurationValue = Integer.parseInt(durationsValues[i]) / 1000;
32-
try {
33-
durationsDescriptions[i] = String.format(
34-
res.getQuantityString(R.plurals.dynamic_seek_duration_description, currentDurationValue),
35-
currentDurationValue);
36-
} catch (Resources.NotFoundException ignored) {
37-
//if this happens, the translation is missing, and the english string will be displayed instead
38-
}
39-
}
40-
ListPreference durations = (ListPreference) findPreference(getString(R.string.seek_duration_key));
41-
durations.setEntries(durationsDescriptions);
29+
updateSeekOptions();
4230

4331
listener = (sharedPreferences, s) -> {
4432

@@ -58,10 +46,59 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
5846
.show();
5947

6048
}
49+
} else if (s.equals(getString(R.string.use_inexact_seek_key))) {
50+
updateSeekOptions();
6151
}
6252
};
6353
}
6454

55+
/**
56+
* Update fast-forward/-rewind seek duration options according to language and inexact seek setting.
57+
* Exoplayer can't seek 5 seconds in audio when using inexact seek.
58+
*/
59+
private void updateSeekOptions() {
60+
//initializing R.array.seek_duration_description to display the translation of seconds
61+
final Resources res = getResources();
62+
final String[] durationsValues = res.getStringArray(R.array.seek_duration_value);
63+
final List<String> displayedDurationValues = new LinkedList<>();
64+
final List<String> displayedDescriptionValues = new LinkedList<>();
65+
int currentDurationValue;
66+
final boolean inexactSeek = getPreferenceManager().getSharedPreferences()
67+
.getBoolean(res.getString(R.string.use_inexact_seek_key), false);
68+
69+
for (String durationsValue : durationsValues) {
70+
currentDurationValue =
71+
Integer.parseInt(durationsValue) / (int) DateUtils.SECOND_IN_MILLIS;
72+
if (inexactSeek && currentDurationValue % 10 == 5) {
73+
continue;
74+
}
75+
76+
displayedDurationValues.add(durationsValue);
77+
try {
78+
displayedDescriptionValues.add(String.format(
79+
res.getQuantityString(R.plurals.dynamic_seek_duration_description,
80+
currentDurationValue),
81+
currentDurationValue));
82+
} catch (Resources.NotFoundException ignored) {
83+
//if this happens, the translation is missing, and the english string will be displayed instead
84+
}
85+
}
86+
87+
final ListPreference durations = (ListPreference) findPreference(getString(R.string.seek_duration_key));
88+
durations.setEntryValues(displayedDurationValues.toArray(new CharSequence[0]));
89+
durations.setEntries(displayedDescriptionValues.toArray(new CharSequence[0]));
90+
final int selectedDuration = Integer.parseInt(durations.getValue());
91+
if (selectedDuration / (int) DateUtils.SECOND_IN_MILLIS % 10 == 5) {
92+
final int newDuration = selectedDuration / (int) DateUtils.SECOND_IN_MILLIS + 5;
93+
durations.setValue(Integer.toString(newDuration * (int) DateUtils.SECOND_IN_MILLIS));
94+
95+
Toast toast = Toast
96+
.makeText(getContext(),
97+
getString(R.string.new_seek_duration_toast, newDuration),
98+
Toast.LENGTH_LONG);
99+
toast.show();
100+
}
101+
}
65102

66103
@Override
67104
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<string name="popup_remember_size_pos_title">Remember popup size and position</string>
7272
<string name="popup_remember_size_pos_summary">Remember last size and position of popup</string>
7373
<string name="use_inexact_seek_title">Use fast inexact seek</string>
74-
<string name="use_inexact_seek_summary">Inexact seek allows the player to seek to positions faster with reduced precision</string>
74+
<string name="use_inexact_seek_summary">Inexact seek allows the player to seek to positions faster with reduced precision. Seeking for 5, 15 or 25 seconds doesn\'t work with this.</string>
7575
<string name="seek_duration_title">Fast-forward/-rewind seek duration</string>
7676
<string name="download_thumbnail_title">Load thumbnails</string>
7777
<string name="show_comments_title">Show comments</string>
@@ -593,6 +593,7 @@
593593
<string name="app_language_title">App language</string>
594594
<string name="systems_language">System default</string>
595595
<string name="dynamic_seek_duration_description">%s seconds</string>
596+
<string name="new_seek_duration_toast">Due to ExoPlayer constraints the seek duration was set to %d seconds</string>
596597
<plurals name="dynamic_seek_duration_description">
597598
<item quantity="other">%s seconds</item>
598599
</plurals>

0 commit comments

Comments
 (0)