From cd7aaa477db6b7ab6aa491ea7a198d8c83064dff Mon Sep 17 00:00:00 2001
From: mueller-ma <mueller-ma@users.noreply.github.com>
Date: Thu, 21 Feb 2019 19:24:27 +0100
Subject: [PATCH] Show shortcut to notification settings for Oreo and above
(#1167)
Closes #1156
Signed-off-by: mueller-ma <mueller-ma@users.noreply.github.com>
---
.../habdroid/ui/PreferencesActivity.java | 26 ++++++++++++++++---
.../org/openhab/habdroid/util/Constants.java | 2 ++
mobile/src/main/res/values/strings.xml | 1 +
mobile/src/main/res/xml/preferences.xml | 5 ++++
4 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/mobile/src/main/java/org/openhab/habdroid/ui/PreferencesActivity.java b/mobile/src/main/java/org/openhab/habdroid/ui/PreferencesActivity.java
index e3d15787..180d3822 100644
--- a/mobile/src/main/java/org/openhab/habdroid/ui/PreferencesActivity.java
+++ b/mobile/src/main/java/org/openhab/habdroid/ui/PreferencesActivity.java
@@ -22,6 +22,7 @@ import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
+import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.MenuItem;
@@ -235,6 +236,8 @@ public class PreferencesActivity extends AppCompatActivity {
final Preference ringtonePref = findPreference(Constants.PREFERENCE_TONE);
final Preference vibrationPref =
findPreference(Constants.PREFERENCE_NOTIFICATION_VIBRATION);
+ final Preference ringtoneVibrationPref =
+ findPreference(Constants.PREFERENCE_NOTIFICATION_TONE_VIBRATION);
final Preference viewLogPref = findPreference(Constants.PREFERENCE_LOG);
final SharedPreferences prefs = getPreferenceScreen().getSharedPreferences();
@@ -308,6 +311,14 @@ public class PreferencesActivity extends AppCompatActivity {
return true;
});
+ ringtoneVibrationPref.setOnPreferenceClickListener(preference -> {
+ Intent i = new Intent(android.provider.Settings.ACTION_SETTINGS);
+ i.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
+ i.putExtra(Settings.EXTRA_APP_PACKAGE, getContext().getPackageName());
+ startActivity(i);
+ return true;
+ });
+
viewLogPref.setOnPreferenceClickListener(preference -> {
Intent logIntent = new Intent(preference.getContext(), LogActivity.class);
startActivity(logIntent);
@@ -322,11 +333,20 @@ public class PreferencesActivity extends AppCompatActivity {
getParent(fullscreenPreference).removePreference(fullscreenPreference);
}
- if (!CloudMessagingHelper.isSupported()
- || Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- Log.d(TAG, "Removing notification prefs");
+ if (CloudMessagingHelper.isSupported()) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ Log.d(TAG, "Removing notification prefs for < 25");
+ getParent(ringtonePref).removePreference(ringtonePref);
+ getParent(vibrationPref).removePreference(vibrationPref);
+ } else {
+ Log.d(TAG, "Removing notification prefs for >= 25");
+ getParent(ringtoneVibrationPref).removePreference(ringtoneVibrationPref);
+ }
+ } else {
+ Log.d(TAG, "Removing all notification prefs");
getParent(ringtonePref).removePreference(ringtonePref);
getParent(vibrationPref).removePreference(vibrationPref);
+ getParent(ringtoneVibrationPref).removePreference(ringtoneVibrationPref);
}
final ServerProperties props =
diff --git a/mobile/src/main/java/org/openhab/habdroid/util/Constants.java b/mobile/src/main/java/org/openhab/habdroid/util/Constants.java
index 44c789d7..ed80044e 100644
--- a/mobile/src/main/java/org/openhab/habdroid/util/Constants.java
+++ b/mobile/src/main/java/org/openhab/habdroid/util/Constants.java
@@ -26,6 +26,8 @@ public class Constants {
public static final String PREFERENCE_TONE = "default_openhab_alertringtone";
public static final String PREFERENCE_NOTIFICATION_VIBRATION =
"default_openhab_notification_vibration";
+ public static final String PREFERENCE_NOTIFICATION_TONE_VIBRATION =
+ "default_openhab_alertringtone_vibration";
public static final String PREFERENCE_CLEAR_CACHE = "default_openhab_cleacache";
public static final String PREFERENCE_SSLCLIENTCERT = "default_openhab_sslclientcert";
public static final String PREFERENCE_DEBUG_MESSAGES = "default_openhab_debug_messages";
diff --git a/mobile/src/main/res/values/strings.xml b/mobile/src/main/res/values/strings.xml
index ea1aba40..df156f1d 100644
--- a/mobile/src/main/res/values/strings.xml
+++ b/mobile/src/main/res/values/strings.xml
@@ -68,6 +68,7 @@
<string name="settings_notification_vibration_value_short" translatable="false">short</string>
<string name="settings_notification_vibration_value_long" translatable="false">long</string>
<string name="settings_notification_vibration_value_twice" translatable="false">twice</string>
+ <string name="settings_notification_ringtone_vibration">Notification settings</string>
<string name="settings_connection_summary">Connected to %s</string>
<string name="settings_insecure_connection_summary">Insecurely connected to %s</string>
<string name="beta">Beta</string>
diff --git a/mobile/src/main/res/xml/preferences.xml b/mobile/src/main/res/xml/preferences.xml
index d17b14a9..ef6af07a 100644
--- a/mobile/src/main/res/xml/preferences.xml
+++ b/mobile/src/main/res/xml/preferences.xml
@@ -96,6 +96,11 @@
android:entries="@array/notificationVibration"
android:entryValues="@array/notificationVibrationValues"
android:icon="@drawable/ic_vibration_grey_24dp" />
+ <Preference
+ android:clickable="true"
+ android:key="default_openhab_alertringtone_vibration"
+ android:title="@string/settings_notification_ringtone_vibration"
+ android:icon="@drawable/ic_notifications_active_grey_24dp" />
<SwitchPreference
android:defaultValue="false"
android:key="default_openhab_debug_messages"
--
GitLab