From 619f60e780bbdab2f1c44c9171544825575b6ec0 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 8 Sep 2022 18:40:41 +0200 Subject: [PATCH] Fix issue #298 - Change distributor in settings --- .../FragmentNotificationsSettings.java | 28 ++++++++++++++++++- app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/pref_notifications.xml | 7 +++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentNotificationsSettings.java b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentNotificationsSettings.java index 04c575eb..e7baefef 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentNotificationsSettings.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentNotificationsSettings.java @@ -30,6 +30,11 @@ import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceScreen; +import org.unifiedpush.android.connector.UnifiedPush; + +import java.util.ArrayList; +import java.util.List; + import app.fedilab.android.R; import app.fedilab.android.helper.Helper; import app.fedilab.android.helper.PushHelper; @@ -96,17 +101,33 @@ public class FragmentNotificationsSettings extends PreferenceFragmentCompat impl if (SET_NOTIFICATION_DELAY_VALUE != null) { preferenceScreen.removePreferenceRecursively("SET_NOTIFICATION_DELAY_VALUE"); } + ListPreference SET_PUSH_DISTRIBUTOR = findPreference("SET_PUSH_DISTRIBUTOR"); + if (SET_PUSH_DISTRIBUTOR != null) { + preferenceScreen.removePreferenceRecursively("SET_PUSH_DISTRIBUTOR"); + } return; } else if (SET_NOTIFICATION_TYPE != null && SET_NOTIFICATION_TYPE.getValue().equals(notificationValues[1])) { ListPreference SET_NOTIFICATION_DELAY_VALUE = findPreference(getString(R.string.SET_NOTIFICATION_DELAY_VALUE)); if (SET_NOTIFICATION_DELAY_VALUE != null) { SET_NOTIFICATION_DELAY_VALUE.getContext().setTheme(Helper.dialogStyle()); } + ListPreference SET_PUSH_DISTRIBUTOR = findPreference("SET_PUSH_DISTRIBUTOR"); + if (SET_PUSH_DISTRIBUTOR != null) { + preferenceScreen.removePreferenceRecursively("SET_PUSH_DISTRIBUTOR"); + } } else { ListPreference SET_NOTIFICATION_DELAY_VALUE = findPreference("SET_NOTIFICATION_DELAY_VALUE"); if (SET_NOTIFICATION_DELAY_VALUE != null) { preferenceScreen.removePreferenceRecursively("SET_NOTIFICATION_DELAY_VALUE"); } + ListPreference SET_PUSH_DISTRIBUTOR = findPreference(getString(R.string.SET_PUSH_DISTRIBUTOR)); + if (SET_PUSH_DISTRIBUTOR != null) { + SET_PUSH_DISTRIBUTOR.getContext().setTheme(Helper.dialogStyle()); + List distributors = UnifiedPush.getDistributors(requireActivity(), new ArrayList<>()); + SET_PUSH_DISTRIBUTOR.setValue(UnifiedPush.getDistributor(requireActivity())); + SET_PUSH_DISTRIBUTOR.setEntries(distributors.toArray(new String[0])); + SET_PUSH_DISTRIBUTOR.setEntryValues(distributors.toArray(new String[0])); + } } Preference button_mention = findPreference("button_mention"); @@ -198,13 +219,18 @@ public class FragmentNotificationsSettings extends PreferenceFragmentCompat impl } if (key.compareToIgnoreCase(getString(R.string.SET_LED_COLOUR_VAL)) == 0) { try { - int value = Integer.parseInt(key); + int value = sharedPreferences.getInt(key, 0); sharedPreferences.edit().putInt(getString(R.string.SET_LED_COLOUR_VAL), value).apply(); } catch (NumberFormatException e) { e.printStackTrace(); } } + if (key.compareToIgnoreCase(getString(R.string.SET_PUSH_DISTRIBUTOR)) == 0) { + String distributor = sharedPreferences.getString(key, ""); + UnifiedPush.saveDistributor(requireActivity(), distributor); + PushHelper.startStreaming(requireActivity()); + } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 48024e44..8b7c1b41 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -770,6 +770,7 @@ SET_NSFW_TIMEOUT SET_NOTIFICATION_TYPE SET_NOTIFICATION_DELAY_VALUE + SET_PUSH_DISTRIBUTOR PUSH_NOTIFICATIONS @@ -1438,4 +1439,5 @@ Import settings Permission not granted! Load exported settings + Push distributor diff --git a/app/src/main/res/xml/pref_notifications.xml b/app/src/main/res/xml/pref_notifications.xml index 42a17cdf..d9a4738a 100644 --- a/app/src/main/res/xml/pref_notifications.xml +++ b/app/src/main/res/xml/pref_notifications.xml @@ -26,6 +26,13 @@ app:summary="@string/set_push_notifications_delay" app:title="@string/type_of_notifications_delay_title" app:useSimpleSummaryProvider="true" /> + +