diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-09-12 22:32:47 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-09-13 17:29:36 +0200 |
commit | 46b77bf34219aa47e916f0ab980d3bd5bb05ba34 (patch) | |
tree | 0a73271b9cdea5577b7d69dbdbf525f24bcc31b7 /src/main/java/de/pixart/messenger/utils/Compatibility.java | |
parent | e50ba72e8ae024e64b1e2b2838f73faf64330adb (diff) |
initial work toward api 26+
* introduce notification channels
* always use foreground service on 26+
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/Compatibility.java | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/Compatibility.java b/src/main/java/de/pixart/messenger/utils/Compatibility.java new file mode 100644 index 000000000..95d7b4ef2 --- /dev/null +++ b/src/main/java/de/pixart/messenger/utils/Compatibility.java @@ -0,0 +1,66 @@ +package de.pixart.messenger.utils; + +import android.content.Context; +import android.content.SharedPreferences; +import android.os.Build; +import android.preference.Preference; +import android.preference.PreferenceCategory; +import android.preference.PreferenceManager; +import android.preference.PreferenceScreen; +import android.support.annotation.BoolRes; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import de.pixart.messenger.R; +import de.pixart.messenger.ui.SettingsActivity; +import de.pixart.messenger.ui.SettingsFragment; + +public class Compatibility { + private static final List<String> UNUSED_SETTINGS_POST_TWENTYSIX = Arrays.asList( + SettingsActivity.SHOW_FOREGROUND_SERVICE, + "led", + "notification_ringtone", + "notification_headsup", + "vibrate_on_notification"); + private static final List<String> UNUESD_SETTINGS_PRE_TWENTYSIX = Collections.singletonList("more_notification_settings"); + + public static boolean twentySix() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O; + } + + private static boolean getBooleanPreference(Context context, String name, @BoolRes int res) { + return getPreferences(context).getBoolean(name, context.getResources().getBoolean(res)); + } + + private static SharedPreferences getPreferences(final Context context) { + return PreferenceManager.getDefaultSharedPreferences(context); + } + + public static boolean keepForegroundService(Context context) { + return twentySix() || getBooleanPreference(context, SettingsActivity.SHOW_FOREGROUND_SERVICE, R.bool.show_foreground_service); + } + + public static void removeUnusedPreferences(SettingsFragment settingsFragment) { + List<PreferenceScreen> screens = Arrays.asList( + (PreferenceScreen) settingsFragment.findPreference("notifications")); + List<PreferenceCategory> categories = Arrays.asList( + (PreferenceCategory) settingsFragment.findPreference("general")); + for (String key : (twentySix() ? UNUSED_SETTINGS_POST_TWENTYSIX : UNUESD_SETTINGS_PRE_TWENTYSIX)) { + Preference preference = settingsFragment.findPreference(key); + if (preference != null) { + for (PreferenceScreen screen : screens) { + if (screen != null) { + screen.removePreference(preference); + } + } + for (PreferenceCategory category : categories) { + if (category != null) { + category.removePreference(preference); + } + } + } + } + } +}
\ No newline at end of file |