-
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
[Preference Migration] Migrate Legacy Android Preference to AndroidX Preference #17962
Comments
Generated by 🚫 dangerJS |
"Thank you for the great analysis, @ParaskP7! 🤍 I also tried to find advantages of In summary, |
👋 @irfano ! That's a great question and thanks for raising it! 💯 I too wanted to suggest an extra step to all the above, which would be to move away from our current SharedPreferences (Save key-value data) solution and go for a DataStore specific solution. But, then, I stepped back and started thinking, SharedPreferences and Preference is two district things, of course they are! 😅
The above means that Preference is not going away and can be used in combination with DataStore, just like it is currently used in combination with SharedPreferences. This to me means that we shouldn't confused the 2 migrations, migrating from one UI layer solution ( Let me know if I am missing something obvious here, I for sure might... 👍 |
So, this issue is not related to |
@ParaskP7 - While reviewing #17780 I stumbled upon this ticket. Kahu is in Release team rotation, so I may have time to start digging into the following. I will post here if was able to make any progress. Would be nice if we could use compose too :P
|
👋 @zwarm !
Coolio and thank you! 💪 PS: Just don't underestimate this task, it seems (kind of) straightforward but it is not, be prepared for unknowns/blockers/interdependencies... 😅
Awesome and best of luck! 🍀
💯 😝 |
We should also remove |
Just chiming in to say that I observed the theme switch issue (invisible text like in this issue: #17780) in the Account Settings when developing the Account Closure feature.
Indeed, Compose would be great! Fyi, I've already planted a tiny "seed" of Compose in the Account Settings screen, just for the "Close Account" button, and was surprised how easy it was to integrate it with the existing UI. I was thinking it would be good to have this whole screen in Compose, so I was glad to find this idea already mentioned. 🎉 |
Hello @ParaskP7! I did the migration of Sidenote: |
👋 @07jasjeet and apologies for the late reply, I was on parental leave and just returned back to action, still catching-up on everything. Having said that, I am seeing @antonis picked this up and already helped you by reviewing this #19986 PR of yours, many thanks Antonis! 🙇 |
As part of my previous work on #17215 and #17960 I keep stumbling on the fact that on WPAndroid, instead of using the AndroidX Preference library for anything settings related, it is still using the legacy and long deprecated Android Preference library.
API 29
), the legacyandroid.preference
library, referred to as the platformandroid.preference
library, is deprecated. For consistent behavior across all devices it is recommended to use theandroidx.preference
library.Also, in addition to the above, the WPAndroid preference configuration and usage just that bit more complicated. The complication comes from the fact that WPAndroid used both
android.preference
andandroidx.preference
(see #17215).androidx.preference
is used only forPreferenceManager
related work, whileandroid.preference
is used for everything else.The above makes that bit more complicated to update the AndroidX Preference library to newer versions, and that is, because as one would need to know all the above before deciding towards the updating strategy.
For example, while working on #17960 I was tempted to also try and migrated at least one screen from
android.preference
and intoandroidx.preference
. I tried with the seemingly simpleAccountSettingsFragment.kt
class, which is related to the very simpleAccount Settings
screen, but without success, not at all. After a while, I realized that everything is interconnected in such a degree that it is impossible to complete this migration without affecting any other screen (more on that below).Technical Details
While trying to migrate
AccountSettingsFragment.kt
class toandroidx.preference
, during my work on #17960 I ended up mapping down every usage ofandroid.preference
and anything that is depending on it, via extending those classes, or using those via composition.Below is a summary of that, you can expand and see the details per class, as well as how to test each class:
1. AccountSettingsFragment.kt
Res:
account_settings.xml
Extends from:
PreferenceFragmentLifeCycleOwner.kt
Uses:
EditTextPreferenceWithValidation.java
, which extends fromSummaryEditTextPreference.java
DetailListPreference.java
To test:
Me
screen.Account Settings
button.Account Settings
screen is displayed.Account Settings
screen and verify that every setting works as expected.2. AppSettingsFragment.java
Res:
app_settings.xml
Uses:
WPActivityUtils.java
, which usesadd/removeToolbarFromDialog(...)
WPSwitchPreference.java
, which usesSummaryEditTextPreference.java
DetailListPreference.java
LearnMorePreference.java
WPPreference.java, which uses
DetailListPreference.java`WPPrefUtils.java
To test:
Me
screen.App Settings
button.App Settings
screen is displayed.App Settings
screen and verify that every setting works as expected, including the inner settings like thePrivacy Settings
andDebug Settings
screens.3. SiteSettingsFragment.java
Res:
site_settings.xml
Uses:
WPActivityUtils.java
, which usesadd/removeToolbarFromDialog(...)
WPSwitchPreference.java
, which usesSummaryEditTextPreference.java
EditTextPreferenceWithValidation.java
, which extends fromSummaryEditTextPreference.java
SummaryEditTextPreference.java
DetailListPreference.java
LearnMorePreference.java
WPPreference.java, which uses
DetailListPreference.java`WPStartOverPreference.java, which extends from WPPreference.java
WPPrefUtils.java
To test:
My Site/MENU
tab.Site Settings
button.Site Settings
screen is displayed.Site Settings
screen and verify that every setting works as expected.4. JetpackSecuritySettingsFragment.java
Res:
jetpack_settings.xml
Uses:
WPSwitchPreference.java
, which usesSummaryEditTextPreference.java
LearnMorePreference.java
WPPrefUtils.java
To test:
My Site/MENU
tab.Jetpack Settings
button.Security
setting screen is displayed.Security
settings screen and verify that every setting works as expected.5. NotificationSettingsFragment.java
Res:
notifications_settings.xml
Uses:
NotificationsSettingsDialogPreference.java
WPActivityUtils.java
, which usesadd/removeToolbarFromDialog(...)
WPSwitchPreference.java
, which usesSummaryEditTextPreference.java
To test:
Notifications
tab.Gear
setting button (top-right).Notification Settings
screen is displayed.Notification Settings
settings screen and verify that every setting works as expected.Also, consider the below usages of
android.preference
in non-setting screen related part of WPAndroid's codebase:1. EditPostActivity.java
Uses:
EditTextPreferenceWithValidation.java
, which extends fromSummaryEditTextPreference.java
To test:
Post
screen.PreferenceManager
tosetDefaultValues(...)
forAccount Settings
, add a few of the main blocks and verify that everything is workings as expected.2. MySitesPage.java (UI Test)
To test:
StatsTests
UI test suite, which uses theMySitesPage.java
class, and verify that all tests pass.From the above you will notice the below:
Account Settings
, which corresponds toAccountSettingsFragment.kt
andaccount_settings.xml
App Settings
, which corresponds toAppSettingsFragment.java
andapp_settings.xml
Site Settings
, which corresponds toSiteSettingsFragment.java
andsite_settings.xml
Jetpack Security Settings
, which corresponds toJetpackSecuritySettingsFragment.java
andjetpack_settings.xml
Notifications Settings
, which corresponds toNotificationsSettingsFragment.java
andnotifications_settings.xml
WPPreference.java, which uses
DetailListPreference.java`WPStartOverPreference.java, which extends from WPPreference.java
and only used bySiteSettingsFragment.java
WPSwitchPreference
, which usesSummaryEditTextPreference.java
SummaryEditTextPreference
EditTextPreferenceWithValidation
, which extends fromSummaryEditTextPreference
DetailListPreference
LearnMorePreference
NotificationsSettingsDialogPreference
, which is only used byNotificationSettingsFragment.java
WPPrefUtils
, which usesadd/removeToolbarFromDialog(...)
WPActivityUtils
PreferenceFragmentLifeCycleOwner
, which is extended only byAccountSettingsFragment.kt
Recommendation & Suggested Strategy
From the technical details above you will notice how interconnected everything is.
As such, my recommendation is instead of migrating all 5 settings screens, and thus, forcing us to do that change in one go, most probably even in one PR (as I am not seeing another alternative), we could create a project which will rewrite each of those screens instead. This will make this change more manageable, enable the creation of multiple PRs, each tested in isolation, and which, will target
trunk
directly, that is, without the need for a parent intermediate feature branch.Per the above, my suggested strategy would be:
androidx.preference
, along with creating any custom preference class that this screen might required to become fully operational.In more detail, I would have followed the below PR chain strategy:
Account Settings
screen, along with creating 3 new custom preference classes (SummaryEditTextPreference.kt
,EditTextPreferenceWithValidation.kt
andDetailListPreference.kt
).Jetpack Security Settings
screen, along with creating 2 new custom preference classes (WPSwitchPreference.kt
andLearnMorePreference.kt
).Notifications Settings
screen, along with creating 1 new custom preference class (NotificationsSettingsDialogPreference.kt
).App Settings
screen, along with creating 1 new custom preference class (WPPreference.kt
).Site Settings
screen, along with creating 1 new custom preference class (WPStartOverPreference
).android.preference
from anywhere else (ie.PreferenceFragmentLifeCycleOwner
,WPPrefUtils
,WPActivityUtils
,EditPostActivity
,MySitesPage
, etc)Let's discuss, let me know your thoughts on all the above! 🙇
The text was updated successfully, but these errors were encountered: