|
| 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 | +} |
0 commit comments