Skip to content

Commit a02ae06

Browse files
committed
Add bullet comments settings fragment and resources
1 parent 015d18f commit a02ae06

6 files changed

Lines changed: 171 additions & 9 deletions

File tree

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package org.schabi.newpipe.settings;
2+
3+
import android.content.SharedPreferences;
4+
import android.os.Bundle;
5+
import androidx.preference.SeekBarPreference;
6+
import org.schabi.newpipe.R;
7+
8+
public class BulletCommentsSettingsFragment extends BasePreferenceFragment {
9+
10+
private SharedPreferences.OnSharedPreferenceChangeListener listener;
11+
12+
@Override
13+
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
14+
addPreferencesFromResourceRegistry();
15+
16+
listener = (sharedPreferences, s) -> {
17+
if (s.equals(getString(R.string.top_bottom_bullet_comments_duration_key))) {
18+
final int newSetting = sharedPreferences.getInt(s, 8);
19+
final SeekBarPreference topBottomBulletCommentsDuration = findPreference(s);
20+
if (topBottomBulletCommentsDuration != null) {
21+
topBottomBulletCommentsDuration.setSummary(newSetting + " seconds");
22+
}
23+
} else if (s.equals(getString(R.string.regular_bullet_comments_duration_key))) {
24+
final int newSetting = sharedPreferences.getInt(s, 8);
25+
final SeekBarPreference regularBulletCommentsDuration = findPreference(s);
26+
if (regularBulletCommentsDuration != null) {
27+
regularBulletCommentsDuration.setSummary(newSetting + " seconds");
28+
}
29+
} else if (s.equals(getString(R.string.max_bullet_comments_rows_top_key))
30+
|| s.equals(getString(R.string.max_bullet_comments_rows_bottom_key))
31+
|| s.equals(getString(R.string.max_bullet_comments_rows_regular_key))) {
32+
final int newSetting = sharedPreferences.getInt(s, 15);
33+
final SeekBarPreference rowsPref = findPreference(s);
34+
if (rowsPref != null) {
35+
rowsPref.setSummary(String.valueOf(newSetting));
36+
}
37+
}
38+
};
39+
40+
final SeekBarPreference regularBulletCommentsDuration =
41+
findPreference(getString(R.string.regular_bullet_comments_duration_key));
42+
if (regularBulletCommentsDuration != null) {
43+
regularBulletCommentsDuration.setMin(5);
44+
}
45+
final SeekBarPreference topBottomBulletCommentsDuration =
46+
findPreference(getString(R.string.top_bottom_bullet_comments_duration_key));
47+
if (topBottomBulletCommentsDuration != null) {
48+
topBottomBulletCommentsDuration.setMin(5);
49+
}
50+
51+
final SeekBarPreference topRowsPref =
52+
findPreference(getString(R.string.max_bullet_comments_rows_top_key));
53+
final SeekBarPreference bottomRowsPref =
54+
findPreference(getString(R.string.max_bullet_comments_rows_bottom_key));
55+
final SeekBarPreference regularRowsPref =
56+
findPreference(getString(R.string.max_bullet_comments_rows_regular_key));
57+
58+
final SharedPreferences sharedPreferences =
59+
getPreferenceManager().getSharedPreferences();
60+
if (topRowsPref != null) {
61+
topRowsPref.setSummary(String.valueOf(sharedPreferences.getInt(
62+
getString(R.string.max_bullet_comments_rows_top_key), 15)));
63+
}
64+
if (bottomRowsPref != null) {
65+
bottomRowsPref.setSummary(String.valueOf(sharedPreferences.getInt(
66+
getString(R.string.max_bullet_comments_rows_bottom_key), 15)));
67+
}
68+
if (regularRowsPref != null) {
69+
regularRowsPref.setSummary(String.valueOf(sharedPreferences.getInt(
70+
getString(R.string.max_bullet_comments_rows_regular_key), 15)));
71+
}
72+
}
73+
74+
@Override
75+
public void onResume() {
76+
super.onResume();
77+
getPreferenceManager().getSharedPreferences()
78+
.registerOnSharedPreferenceChangeListener(listener);
79+
}
80+
81+
@Override
82+
public void onPause() {
83+
super.onPause();
84+
getPreferenceManager().getSharedPreferences()
85+
.unregisterOnSharedPreferenceChangeListener(listener);
86+
}
87+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ private SettingsResourceRegistry() {
4141
add(UpdateSettingsFragment.class, R.xml.update_settings);
4242
add(VideoAudioSettingsFragment.class, R.xml.video_audio_settings);
4343
add(ExoPlayerSettingsFragment.class, R.xml.exoplayer_settings);
44+
add(BulletCommentsSettingsFragment.class, R.xml.bullet_comments_settings);
4445
add(BackupRestoreSettingsFragment.class, R.xml.backup_restore_settings);
4546
}
4647

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,4 +1513,15 @@
15131513
<item>@string/image_quality_medium_key</item>
15141514
<item>@string/image_quality_high_key</item>
15151515
</string-array>
1516+
1517+
<!-- Bullet comments -->
1518+
<string name="top_bottom_bullet_comments_duration_key">top_bottom_bullet_comments_duration_key</string>
1519+
<string name="regular_bullet_comments_duration_key">regular_bullet_comments_duration_key</string>
1520+
<string name="bullet_comments_outline_radius_key">bullet_comments_outline_radius_key</string>
1521+
<string name="bullet_comments_font_key">bullet_comments_font_key</string>
1522+
<string name="bullet_comments_opacity_key">bullet_comments_opacity_key</string>
1523+
<string name="enable_max_rows_customization_key">enable_max_rows_customization_key</string>
1524+
<string name="max_bullet_comments_rows_top_key">max_bullet_comments_rows_top_key</string>
1525+
<string name="max_bullet_comments_rows_bottom_key">max_bullet_comments_rows_bottom_key</string>
1526+
<string name="max_bullet_comments_rows_regular_key">max_bullet_comments_rows_regular_key</string>
15161527
</resources>

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -914,15 +914,6 @@
914914
<string name="kao_solution">Solution</string>
915915

916916
<!-- Bullet comments -->
917-
<string name="top_bottom_bullet_comments_duration_key">top_bottom_bullet_comments_duration_key</string>
918-
<string name="regular_bullet_comments_duration_key">regular_bullet_comments_duration_key</string>
919-
<string name="bullet_comments_outline_radius_key">bullet_comments_outline_radius_key</string>
920-
<string name="bullet_comments_font_key">bullet_comments_font_key</string>
921-
<string name="bullet_comments_opacity_key">bullet_comments_opacity_key</string>
922-
<string name="enable_max_rows_customization_key">enable_max_rows_customization_key</string>
923-
<string name="max_bullet_comments_rows_top_key">max_bullet_comments_rows_top_key</string>
924-
<string name="max_bullet_comments_rows_bottom_key">max_bullet_comments_rows_bottom_key</string>
925-
<string name="max_bullet_comments_rows_regular_key">max_bullet_comments_rows_regular_key</string>
926917
<string name="settings_category_bullet_comments_title">Bullet comments</string>
927918
<string name="settings_category_bullet_comments_summary">Configure live chat overlay</string>
928919
<string name="regular_bullet_comments_duration_title">Regular comments duration</string>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:title="@string/settings_category_bullet_comments_title">
5+
6+
<SeekBarPreference
7+
android:defaultValue="8"
8+
android:key="@string/regular_bullet_comments_duration_key"
9+
android:max="20"
10+
android:summary="@string/regular_bullet_comments_duration_summary"
11+
android:title="@string/regular_bullet_comments_duration_title"
12+
app:showSeekBarValue="true" />
13+
14+
<SeekBarPreference
15+
android:defaultValue="8"
16+
android:key="@string/top_bottom_bullet_comments_duration_key"
17+
android:max="20"
18+
android:summary="@string/top_bottom_bullet_comments_duration_summary"
19+
android:title="@string/top_bottom_bullet_comments_duration_title"
20+
app:showSeekBarValue="true" />
21+
22+
<SeekBarPreference
23+
android:defaultValue="2"
24+
android:key="@string/bullet_comments_outline_radius_key"
25+
android:max="10"
26+
android:title="@string/bullet_comments_outline_radius_title"
27+
app:showSeekBarValue="true" />
28+
29+
<SeekBarPreference
30+
android:defaultValue="255"
31+
android:key="@string/bullet_comments_opacity_key"
32+
android:max="255"
33+
android:title="@string/bullet_comments_opacity_title"
34+
app:showSeekBarValue="true" />
35+
36+
<SwitchPreferenceCompat
37+
android:defaultValue="false"
38+
android:key="@string/enable_max_rows_customization_key"
39+
android:title="@string/enable_max_rows_customization_title" />
40+
41+
<SeekBarPreference
42+
android:defaultValue="15"
43+
android:dependency="@string/enable_max_rows_customization_key"
44+
android:key="@string/max_bullet_comments_rows_top_key"
45+
android:max="50"
46+
android:title="@string/max_bullet_comments_rows_top_title"
47+
app:showSeekBarValue="true" />
48+
49+
<SeekBarPreference
50+
android:defaultValue="15"
51+
android:dependency="@string/enable_max_rows_customization_key"
52+
android:key="@string/max_bullet_comments_rows_bottom_key"
53+
android:max="50"
54+
android:title="@string/max_bullet_comments_rows_bottom_title"
55+
app:showSeekBarValue="true" />
56+
57+
<SeekBarPreference
58+
android:defaultValue="15"
59+
android:dependency="@string/enable_max_rows_customization_key"
60+
android:key="@string/max_bullet_comments_rows_regular_key"
61+
android:max="50"
62+
android:title="@string/max_bullet_comments_rows_regular_title"
63+
app:showSeekBarValue="true" />
64+
65+
</PreferenceScreen>

app/src/main/res/xml/main_settings.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
android:title="@string/settings_category_video_audio_title"
1111
app:iconSpaceReserved="false" />
1212

13+
<PreferenceScreen
14+
android:fragment="org.schabi.newpipe.settings.BulletCommentsSettingsFragment"
15+
android:icon="@drawable/ic_comment"
16+
android:title="@string/settings_category_bullet_comments_title"
17+
android:summary="@string/settings_category_bullet_comments_summary"
18+
app:iconSpaceReserved="false" />
19+
1320
<PreferenceScreen
1421
android:fragment="org.schabi.newpipe.settings.DownloadSettingsFragment"
1522
android:icon="@drawable/ic_file_download"

0 commit comments

Comments
 (0)