-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Cleanup LocaleManager #21541
Cleanup LocaleManager #21541
Conversation
Generated by 🚫 Danger |
📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
|
📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## feature/per-app-language-prefs #21541 +/- ##
==================================================================
+ Coverage 39.44% 39.48% +0.03%
==================================================================
Files 2118 2117 -1
Lines 99550 99464 -86
Branches 15312 15296 -16
==================================================================
Hits 39269 39269
+ Misses 56800 56714 -86
Partials 3481 3481 ☔ View full report in Codecov by Sentry. |
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.
👋 @nbradbury !
I have reviewed and tested this PR as per the instructions, everything works as expected, great job Kotlinizing LocalManager
! 🌟 x 🌟 ^ 🌟
PS: I especially like the fact that you add nullability annotations on the Java side before the conversion, kudos. 💯
I have left one questions (❓), a couple of suggestions (💡) and some minor (🔍) comments for you to consider. I am going to approve this PR anyway, since none is blocking. I am NOT going to merge this PR yet to give you some time to apply any of my suggestions. However, feel free to ignore them and merge the PR yourself.
WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt
Outdated
Show resolved
Hide resolved
WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt
Outdated
Show resolved
Hide resolved
WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt
Outdated
Show resolved
Hide resolved
for (i in entryStrings.indices) { | ||
// now, we can split the sorted array to extract the display string and the language code | ||
val split = | ||
entryStrings[i].split("__".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() |
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.
- Question (❓): How come this
String[] split = entryStrings.get(i).split("__");
Java related code got replace with this Kotlin related code that seems that much more involved (toRegex()
+dropLastWhile { ... }
+toTypedArray()
). I am sure there is a good reason, I just want to understand it better... 😊 - Minor (🔍): Consider splitting this logic into multiple lines for readability purposes:
val split = entryStrings[i]
.split("__".toRegex())
.dropLastWhile { it.isEmpty() }
.toTypedArray()
WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt
Outdated
Show resolved
Hide resolved
Thanks for noticing that! I actually attempted the conversion without addressing the nullability issues and it was a disaster :) I've implemented most of your thoughtful suggestions but left some as-is because #21542 removes some of that code. |
Quality Gate passedIssues Measures |
Thanks for applying the suggestions @nbradbury and noted about #21542 ! 🥇
😄 I could imagine, Kotlin is as smart as it gets, but it isn't AI or God, the more we help it the better the result! 😄 |
This PR does two things:
LocaleManager
by removing unused code and fixing warningsLocaleMananger
to KotlinThese actions will make it easier to eventually do away with storing the app language in our shared preferences, enabling the system to be in charge of the language.
I left as much logic unchanged as possible, but I did need to make minor modifications to
createSortedLanguageDisplayStrings
to get it to work. This change can be tested two ways:Test 1:
Test 2: