fix(notifications): use app language#20747
Conversation
On API 32 and earlier, AppCompatDelegate.setApplicationLocales only works with AppCompatActivity. Work around this by manually setting the app locale Fixes 19048 Assisted-by: Claude Opus 4.6 - withAppLocale + investigation
ericli3690
left a comment
There was a problem hiding this comment.
Thank you David!! This looks great. I'll make a note to test this on the new review reminders system too once our strings are localized.
Only one major concern: this issue was originally opened when I found this to-do comment by @mikehardy in NotificationChannels:
/**
* Create or update all the notification channels for the app
*
* In Oreo and higher, you must create a channel for all notifications.
* This will create the channel if it doesn't exist, or if it exists it will update the name.
*
* Note that once a channel is created, only the name may be changed as long as the application
* is installed on the user device. All other settings are fully under user control.
*
* TODO should be called in response to [Intent.ACTION_LOCALE_CHANGED]
* @param context the context for access to localized strings for channel names
*/
fun setupNotificationChannels(context: Context) {
// ...In particular the TODO portion. Do we actually need to make setupNotificationChannels listen to Intent.ACTION_LOCALE_CHANGED, or will that no longer necessary after merging this PR? If so, please remove the above comment in NotificationChannels.
Untested, I suspect it will still be necessary |
|
If the goal is to have "all of the app" change when a language changes - either through our in-app language picker or through a system locale change, then you also must persist new notification channel names into the android system as well, implying that - yes - that notification channel setup needs to be hooked on to whatever infra we have for handling language updates, and we should be listening to system locale change broadcast |
0bb479f to
5745591
Compare
|
I'm leaving the From what I recall, the state of notification channels being semi-immutable would need some additional brainpower, whereas this is a fairly simple refactor. |
5745591 to
159da03
Compare
On API 32 and earlier, AppCompatDelegate.setApplicationLocales only works with AppCompatActivity. Work around this by manually setting the app locale Issue 19048 Assisted-by: Claude Opus 4.6 - most of the refactoring
159da03 to
b95e885
Compare
|
@ericli3690 Thanks so much! Im assuming your approval still stands, but a second look would be excellent |
ericli3690
left a comment
There was a problem hiding this comment.
Yep looks great! Thanks thanks
mikehardy
left a comment
There was a problem hiding this comment.
LGTM - it is unbelievable how much effort it takes to keep an "app language may not be system language" feature working correctly in Android across Android SDK version skew... the amount of time over the years...
|
I forgot to force push here, there will be a minor follow-up |
Follow-up for ankidroid#20747 Also a small comment change requested by David.
Follow-up for ankidroid#20747 Also a small comment change requested by David.
Follow-up for ankidroid#20747 Also a small comment change requested by David!
Follow-up for ankidroid#20747 Also a small comment change requested by David!
Note
Assisted-by: Claude Opus 4.6 - withAppLocale + investigation
Purpose / Description
On API 32 and earlier,
AppCompatDelegate.setApplicationLocalesonly works with AppCompatActivity.Fixes
Approach
Work around this by manually setting the app locale
How Has This Been Tested?
Android Version = 7.0 (SDK 24)
Learning (optional, can help others)
https://developer.android.com/reference/androidx/appcompat/app/AppCompatDelegate#setApplicationLocales(androidx.core.os.LocaleListCompat)
Checklist