adeekshith / watomatic

Auto reply app helping you move away from less private messengers like WhatsApp and Facebook Messenger
https://watomatic.app
GNU General Public License v3.0
426 stars 85 forks source link

Fix language changing issues #292

Closed hegocre closed 3 years ago

hegocre commented 3 years ago

Fix for locale changing issues, possible fix #270, tested on Android Emulator API 21 (previously not working, now it does), as well as API 29 and 30 on physical devices, both working.

When creating locales, region code must be a 2 alpha character string as explained here, I imagine the r added on resource folder is an abbreviation for region and should not be used when creating Locales in code.

Also, a bug on AndroidX compat library causes the locale to be overridden to default on API versions 21 to 25 because of DayNight compatibility, so applyOverrideConfiguration must be called with the new context created.

hegocre commented 3 years ago

@adeekshith You are welcome!

I also noticed that some devices neee none, some need one and others need both patches to work correctly.

The problem I see here is that existing users will need to set their language again. Maybe changing PreferencesManager.java to remove the r before creating the locale would be lesw intrusive, but would require you to keep adding the r to new locales.

If you prefer it that way I can change this on my pull request before merging.

Cheers!

adeekshith commented 3 years ago

The problem I see here is that existing users will need to set their language again.

Oh I was thinking we were saving the key (lang_code_ca_rES) and not the value (ca-ES). I am wrong then. Thanks for catching.

Maybe changing PreferencesManager.java to remove the r before creating the locale would be lesw intrusive, but would require you to keep adding the r to new locales.

That should do but how about this solution:

  1. Change PreferencesManager::getSelectedLanguageStr() method to remove r before returning (ca-rES to ca-ES).
  2. Or even better, we can write code to migrate existing r version to the non-r version in the shared preferences PreferencesManager::init() method (init() method executed when the PreferencesManager object is created). Advantage with this method is, we can remove the migration code after a few months without affecting anyone.
adeekshith commented 3 years ago

Awesome! Your fix (186f302) looks good @hegocre Will test it in a while and merge 😃

Thank you!!

hegocre commented 3 years ago

You're welcome!

Amazing work with this app!