Skip to content

Commit 692dafa

Browse files
committed
Disable notifications sound and frequency if not enabled
1 parent e9ac7e6 commit 692dafa

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

app/src/main/java/com/javiersantos/whatsappbetaupdater/activity/SettingsActivity.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,29 @@ protected void onCreate(Bundle savedInstanceState) {
4545
}
4646

4747
private void setPreferenceView() {
48+
Preference prefLicense = (Preference) findPreference("prefLicense");
49+
Preference prefVersion = (Preference) findPreference("prefVersion");
4850
prefEnableNotifications = (CheckBoxPreference) findPreference("prefEnableNotifications");
4951
prefSoundNotification = (Preference) findPreference("prefSoundNotification");
50-
initPrefSoundNotification(prefSoundNotification);
5152
prefHoursNotification = (ListPreference) findPreference("prefHoursNotification");
53+
54+
initPrefEnableNotifications(appPreferences.getEnableNotifications());
55+
initPrefSoundNotification(prefSoundNotification);
5256
initPrefHoursNotification(prefHoursNotification);
53-
Preference prefLicense = (Preference) findPreference("prefLicense");
5457
initPrefLicense(prefLicense);
55-
Preference prefVersion = (Preference) findPreference("prefVersion");
5658
initPrefVersion(prefVersion);
5759
}
5860

61+
private void initPrefEnableNotifications(Boolean enable) {
62+
if (enable) {
63+
prefSoundNotification.setEnabled(true);
64+
prefHoursNotification.setEnabled(true);
65+
} else {
66+
prefSoundNotification.setEnabled(false);
67+
prefHoursNotification.setEnabled(false);
68+
}
69+
}
70+
5971
private void initPrefSoundNotification(Preference preference) {
6072
preference.setSummary(RingtoneManager.getRingtone(this, appPreferences.getSoundNotification()).getTitle(this));
6173
preference.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
@@ -76,7 +88,6 @@ public boolean onPreferenceClick(android.preference.Preference preference) {
7688
private void initPrefHoursNotification(ListPreference listPreference) {
7789
listPreference.setEntries(getResources().getStringArray(R.array.notification_hours));
7890
listPreference.setEntryValues(getResources().getStringArray(R.array.notification_hours_values));
79-
8091
listPreference.setSummary(String.format(getResources().getString(R.string.settings_interval_description), appPreferences.getHoursNotification()));
8192
}
8293

@@ -113,13 +124,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
113124
Preference preference = (Preference) findPreference(key);
114125

115126
if (preference == prefEnableNotifications) {
116-
if (prefEnableNotifications.isChecked()) {
117-
prefSoundNotification.setEnabled(true);
118-
prefHoursNotification.setEnabled(true);
119-
} else {
120-
prefSoundNotification.setEnabled(false);
121-
prefHoursNotification.setEnabled(false);
122-
}
127+
initPrefEnableNotifications(prefEnableNotifications.isChecked());
123128
} else if (preference == prefSoundNotification) {
124129
preference.setSummary(RingtoneManager.getRingtone(this, appPreferences.getSoundNotification()).getTitle(this));
125130
} else if (preference == prefHoursNotification) {

0 commit comments

Comments
 (0)