-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve handling of notification enabled setting #1264
Improve handling of notification enabled setting #1264
Conversation
This avoids the setup becoming out of date if a user changes the notification setting from another screen (like enabling notifications for a single podcast from the podcast screen).
|
||
enabledPreference?.setOnPreferenceChangeListener { _, newValue -> | ||
val checked = newValue as Boolean | ||
settings.notifyRefreshPodcast.set(checked) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from moving this entire method to be run in onResume
instead of only when the fragment was created, the only change to the logic was to add this settings.notifyRefreshPodcast.set(checked)
line so that we now persist the enabled setting. Apart from this, all the logic here is the same, just in a new location.
EDIT: With a542615, there are now some other changes to the logic here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is something slightly strange happening where you turn on "Notify me", it says "No podcasts selected", you exit the screen, come back, and now it says "All podcasts".
Screen.Recording.2023-08-10.at.5.22.05.pm.mov
@@ -445,6 +402,48 @@ class NotificationsSettingsFragment : | |||
} | |||
} | |||
|
|||
private fun setupEnabledNotifications() { | |||
launch(Dispatchers.Default) { | |||
val enabled = settings.notifyRefreshPodcast.flow.value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it's worth having a value
method that just calls flow.value
as we seem to call it lots? Feel free to ignore this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My initial thought was to intentionally not add something like that because I wanted to provide a push toward reacting to the flow instead of just fetching the latest value. There are enough places where we just get the latest value though that you're probably right that it makes sense to make it more convenient. I'll make this change in a separate PR. Thanks for bringing this up.
notifications turned on
Looks like it was a race condition, but I'm pretty sure you just brought this up to bait me into removing some RxJava 😛 . Should be fixed by a542615. Since this isn't a trivial change, I'll hold off on merging until you give this another look. |
mapOf("enabled" to checked) | ||
) | ||
|
||
lifecycleScope.launch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was surprised to find that if I used the Fragment's CouroutineScope directly here by calling launch
instead of lifecycleScope.launch
the coroutine doesn't run. I'm not sure why that is 😕, so if you have any insight, let me know.
Thanks for those changes. It worked well for me. |
Description
This PR addresses an issue where we were not using the notifications enabled setting to determine the state of the notifications enabled toggle. Instead we were checking whether any podcasts had notifications enabled. This PR updates this and makes the behavior consistent with iOS.
This issue exists on
main
and is not a result of the recent Settings refactorings.This change feels a bit tricky, so let me know if you can think of any undesireable behavior that these changes might introduce.
I am targeting the settings sync refactor branch with this change because it is easier to just include this with the other settings changes, and I anticipate that I'll be merging this branch to
main
pretty soon.Testing Instructions
Checklist
./gradlew spotlessApply
to automatically apply formatting/linting)modules/services/localization/src/main/res/values/strings.xml