diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2024-08-24 09:37:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-24 09:37:16 +0200 |
commit | 02ec30e7e225fb8892b2ad02633589f5f7259225 (patch) | |
tree | c2b12f83b38fe53e5ce20405d3d8251e022bb45b | |
parent | eff3208b86f1bcad1a78e4b6e718d87302d703e0 (diff) | |
download | AntennaPod-02ec30e7e225fb8892b2ad02633589f5f7259225.zip |
Directly enable notifications when permission was granted (#7336)
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/ui/screen/feed/preferences/FeedSettingsFragment.java | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/ui/screen/feed/preferences/FeedSettingsFragment.java b/app/src/main/java/de/danoeh/antennapod/ui/screen/feed/preferences/FeedSettingsFragment.java index d657ed675..d723a5579 100644 --- a/app/src/main/java/de/danoeh/antennapod/ui/screen/feed/preferences/FeedSettingsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/ui/screen/feed/preferences/FeedSettingsFragment.java @@ -107,14 +107,15 @@ public class FeedSettingsFragment extends Fragment { } public static class FeedSettingsPreferenceFragment extends PreferenceFragmentCompat { - private static final CharSequence PREF_EPISODE_FILTER = "episodeFilter"; - private static final CharSequence PREF_SCREEN = "feedSettingsScreen"; - private static final CharSequence PREF_AUTHENTICATION = "authentication"; - private static final CharSequence PREF_AUTO_DELETE = "autoDelete"; - private static final CharSequence PREF_CATEGORY_AUTO_DOWNLOAD = "autoDownloadCategory"; - private static final CharSequence PREF_NEW_EPISODES_ACTION = "feedNewEpisodesAction"; + private static final String PREF_EPISODE_FILTER = "episodeFilter"; + private static final String PREF_SCREEN = "feedSettingsScreen"; + private static final String PREF_AUTHENTICATION = "authentication"; + private static final String PREF_AUTO_DELETE = "autoDelete"; + private static final String PREF_CATEGORY_AUTO_DOWNLOAD = "autoDownloadCategory"; + private static final String PREF_NEW_EPISODES_ACTION = "feedNewEpisodesAction"; private static final String PREF_FEED_PLAYBACK_SPEED = "feedPlaybackSpeed"; private static final String PREF_AUTO_SKIP = "feedAutoSkip"; + private static final String PREF_NOTIFICATION = "episodeNotification"; private static final String PREF_TAGS = "tags"; private Feed feed; @@ -130,9 +131,12 @@ public class FeedSettingsFragment extends Fragment { } boolean notificationPermissionDenied = false; - private final ActivityResultLauncher<String> requestPermissionLauncher = + private final ActivityResultLauncher<String> enableNotificationsRequestPermissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { if (isGranted) { + SwitchPreferenceCompat pref = findPreference(PREF_NOTIFICATION); + pref.setChecked(true); + pref.callChangeListener(true); return; } if (notificationPermissionDenied) { @@ -506,16 +510,16 @@ public class FeedSettingsFragment extends Fragment { } private void setupEpisodeNotificationPreference() { - SwitchPreferenceCompat pref = findPreference("episodeNotification"); + SwitchPreferenceCompat pref = findPreference(PREF_NOTIFICATION); pref.setChecked(feedPreferences.getShowEpisodeNotification()); pref.setOnPreferenceChangeListener((preference, newValue) -> { - if (Build.VERSION.SDK_INT >= 33 && ContextCompat.checkSelfPermission(getContext(), + boolean checked = Boolean.TRUE.equals(newValue); + if (checked && Build.VERSION.SDK_INT >= 33 && ContextCompat.checkSelfPermission(getContext(), Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { - requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS); + enableNotificationsRequestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS); return false; } - boolean checked = Boolean.TRUE.equals(newValue); feedPreferences.setShowEpisodeNotification(checked); DBWriter.setFeedPreferences(feedPreferences); pref.setChecked(checked); |