Skip to content

Apply user language selected in WordPress app to Jetpack app during migration - #17768

Merged
ovitrif merged 20 commits into
trunkfrom
issue/17685-migration-apply-user-language
Jan 18, 2023
Merged

Apply user language selected in WordPress app to Jetpack app during migration#17768
ovitrif merged 20 commits into
trunkfrom
issue/17685-migration-apply-user-language

Conversation

@ovitrif

@ovitrif ovitrif commented Jan 16, 2023

Copy link
Copy Markdown
Contributor

Fixes #17685

This PR enhances the implementation of the Jetpack Content Migration Flow by applying the interface language set by the user in the WordPress app to the Migration screens.

Note:
During implementation I experimented with the widely popular approach of inheriting from LocaleAwareActivity in the JetpackMigrationActivity, but it did not work correctly in cases when the WordPress app theme is also customized by the user:
ℹ️ More specifically upon navigating to another non-migration specific screen (Help / My Site / Login), if the user changes the system theme to be different than the custom app theme migrated from the WordPress app (system theme = light, Jetpack app theme = dark) the next screen could end up not translated into the user language.
ℹ️ On top of this issue, using LocaleAwareActivity is not working correctly with Compose, or at least not for the JetpackMigrationActivity, where recreating the fragment is avoided in order fix the error when changing the device settings mid-flow.
🚀 As a solution to these issues I introduced the new LocaleAwareComposable utility that listens to language changes and synchronizes the local configuration inside its content composable when needed.

To test:

  1. Build, install, launch the WordPress app and login
  2. Go to MeApp SettingsAppearance and Set the WordPress app theme to Dark mode (or the opposite of the system default)
  3. Go to Interface Language and change the app language to Arabic (or a language you know, Arabic helps to verify the RTL texts)
  4. Build and install the Jetpack app of the same flavor
  5. Open Jetpack app and expect that the migration Welcome screen is shown
  6. Verify on the migration welcome screen:
    • The app theme is in Dark mode (or whatever was manually set in WordPress)
    • The language is Arabic (or whatever was manually set in WordPress)
    • The layout direction is RTL mode if Arabic/ LTR if in a LTR language
  7. Explore the different options to interrupt & resume the flow, eg:
    • Tap back to end up on Login Screen, force close & restart the app
    • Tap Need help?Log out, force close & restart the app
    • Complete the migration flow by tapping on the primary green button
      • On My Site tap on the card with the WordPress logo (to open "Please Delete WordPress.." screen)
    • Eventually set the system theme to dark mode, then to light mode and navigate to another screen (there was an issue with this behavior and specific fixes were needed for this)
  8. Verify the app theme, language and layout direction are persisted (same as on Welcome Screen)

🎬 Video recording preview

(click to expand)
app_language_transfer.mp4

Regression Notes

  1. Potential unintended areas of impact
    Migration of user language and theme from WordPress to Jetpack app.

  2. What I did to test those areas of impact (or what existing automated tests I relied on)
    Manual testing & unit tests from JetpackMigrationViewModelTest.

  3. What automated tests I added (or what prevented me from doing so)
    Added unit tests to JetpackMigrationViewModelTest for the updated language transfer logic.

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

This was already handled by the application callbacks and therefore not needed.
This fix was needed to address possible issues when the language and the app theme is set manually by the user in the WordPress app.
This fix was needed to address possible issues when the language and the app theme is set manually by the user in the WordPress app.
# Conflicts:
#	WordPress/src/main/java/org/wordpress/android/localcontentmigration/LocalMigrationResult.kt
#	WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModel.kt
@ovitrif ovitrif added this to the 21.6 milestone Jan 16, 2023
@ovitrif
ovitrif requested review from antonis and mkevins January 16, 2023 18:13
@wpmobilebot

Copy link
Copy Markdown
Contributor
Jetpack📲 You can test these changes on Jetpack by downloading jetpack-installable-build-pr17768-11e73fa.apk
💡 Scan this QR code with your Android phone to download and install the APK directly on it.
AppJetpack
Build FlavorJalapeno
Build TypeDebug
Commit11e73fa
Note: This installable build uses the JalapenoDebug build flavor, and does not support Google Login.

@wpmobilebot

Copy link
Copy Markdown
Contributor
WordPress📲 You can test these changes on WordPress by downloading wordpress-installable-build-pr17768-11e73fa.apk
💡 Scan this QR code with your Android phone to download and install the APK directly on it.
AppWordPress
Build FlavorJalapeno
Build TypeDebug
Commit11e73fa
Note: This installable build uses the JalapenoDebug build flavor, and does not support Google Login.

* @param locale The locale to be used in the [LocalContext] configuration override.
* @param onLocaleChange Callback to be invoked when the locale is overridden, useful to update other app components.
* @param content The Composable function to be rendered with the overridden locale.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for documenting this properly 🙇

@antonis antonis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @ovitrif 👍
I've tested the implementation on a Pixel 5 (Android 13) and everything worked as described for me. The code changes also look good to me

🚀 As a solution to these issues I introduced the new LocaleAwareComposable utility that listens to language changes and synchronizes the local configuration inside its content composable when needed.

I also validated that this case is cover too 🎉

I'll restrain from merging in case @mkevins has any more feedback 🙇

Comment on lines +167 to +174
private fun emitLanguageRefreshIfNeeded(languageCode: String) {
if (languageCode.isNotEmpty()) {
val shouldEmitLanguageRefresh = !localeManagerWrapper.isSameLanguage(languageCode)
if (shouldEmitLanguageRefresh) {
_refreshAppLanguage.value = languageCode
}
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not suggesting a change here, but wanted to note that my first thought here was if we could instead use:

val refreshAppLanguage: LiveData<String> = _refreshAppLanguage.distinct()

but I guess this could result in one unnecessary refresh at the start compared to the approach used here, since this way compares to the locale set in the current context. 🤷‍♂️

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, it would be nice if this idempotency was intrinsic to the implementation, so we wouldn't need to worry about it at the call site, but that's out of scope for this PR 😅 .

@ovitrif ovitrif Jan 18, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, it would be nice if this idempotency was intrinsic to the implementation, so we wouldn't need to worry about it at the call site

Top idea 👏 , totally agreeing with you on this one, that would add to the reusability of the code 🚀

I've added a card on our team's private GitHub project to further pursue this when there's time for technical improvements 🙇 . On the other hand, it's possible we won't need this at all if we add support for the Android 13 Per-app language preferences mechanism soon 🤔

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, this could all become moot in the future 😄 👍

@mkevins

mkevins commented Jan 18, 2023

Copy link
Copy Markdown
Contributor

I tested all flows described on a Pixel 3a (physical device) and it is working as expected. Great work on this Ovi! Also, the code looks good! 👍

@mkevins mkevins left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, LGTM!

@ovitrif

ovitrif commented Jan 18, 2023

Copy link
Copy Markdown
Contributor Author

Thank you both @antonis & @mkevins for reviewing, testing & validating the changes 🙇

I'll proceed to merge this PR 🚀

@ovitrif
ovitrif merged commit 06bf582 into trunk Jan 18, 2023
@ovitrif
ovitrif deleted the issue/17685-migration-apply-user-language branch January 18, 2023 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android - Investigate applying the language setting on the migration screens

4 participants