Skip to content

[Compile Warnings As Errors] WordPress Module - Resolve Deprecated Warnings - Part.2#17287

Merged
ParaskP7 merged 18 commits intotrunkfrom
analysis/wordpress-main-deprecated-warnings-part-2
Oct 13, 2022
Merged

[Compile Warnings As Errors] WordPress Module - Resolve Deprecated Warnings - Part.2#17287
ParaskP7 merged 18 commits intotrunkfrom
analysis/wordpress-main-deprecated-warnings-part-2

Conversation

@ParaskP7
Copy link
Copy Markdown
Contributor

@ParaskP7 ParaskP7 commented Oct 7, 2022

Parent: #17173
Partially Closes: #17181

This PR resolves one part of all Deprecated related warnings for the WordPress module, and in this part, the most generic ones and specific to the main, debug, wordpress and jetpack sources:

Main Source (247 Leftovers + 118):

  • About 247 warnings x 'XYX' is deprecated. Deprecated in Java (Leftovers from part.1 PR)
  • 5 warnings x 'Xyz' is deprecated. Overrides deprecated member in 'xyz'. Deprecated in Java
  • 24 warnings x 'xyz' is deprecated. Use xyz instead.
  • 2 warnings x 'Xyz' is deprecated. This should be removed once we start receiving Xyz the source block from the backend
  • 87 warnings x 'Xyz' is deprecated. This class is being refactored, if you implement any change, please also update xyz

Debug/WordPress/Jetpack Source (11):

  • 11 warnings x 'Xyz' is deprecated. Deprecated in Java

Warnings Resolution List:

  1. Resolve kotlin stdlib's to upper case deprecated warnings.
  2. Resolve kotlin stdlib's to lower case deprecated warnings.
  3. Resolve kotlin stdlib's sum by deprecated warnings.

Warnings Suppression List:

  1. Suppress on activity for result deprecated warnings for java. (Associated Issue: Compiler Warnings as Errors - WordPress Module - OnActivityResult #17249)
  2. Suppress on activity for result override deprecation warnings.
  3. Suppress avatar deprecated warnings.
  4. Suppress kotlin stdlib's capitalize deprecated warning.
  5. Suppress all photo picker related deprecated warnings.
  6. Suppress on request perm. result override deprecation warns.
  7. Suppress google app client & fb instance id deprecated warns. (Associated Issue: Compiler Warnings as Errors - WordPress Module - AppInitializer - Google API Client & Firebase Instance Id #17229)
  8. Suppress connectivity manager & network info deprecated warns. (Associated Issue: Compiler Warnings as Errors - WordPress Module - Connectivity Manager & Network Info #17230)
  9. Suppress toast deprecated warnings for debug source.
  10. Suppress system ui deprecated warnings for wordpress source. (Associated Issue: Compiler Warnings as Errors - WordPress Module - WindowManager #17256)
  11. Suppress on activity created override deprecation warns.
  12. Suppress wp activity utils deprecation warns for jetpack src.

In addition to the above warning resolution list, the below Detekt warnings got resolved as well, leaving Detekt's baseline.xml file 2 entries shorter:

  1. Resolve detekt warnings by manually updating the baseline.

PS: @irfano (plus @ovitrif) I added you as the main reviewer(s), that is, in addition to @wordpress-mobile/apps-infrastructure team itself, but randomly, since I want someone from the WordPress Android team to primarily sign-off on that change. 🥇

FYI: I am going to randomly add more of you in those PRs that will follow, just so you become more aware of this change and how close we are on enabling allWarningsAsErrors by default everywhere. 🎉


To test:

  • There is nothing much to test here.
  • Verifying that all the CI checks are successful should be enough.
  • However, if you want to be thorough about reviewing this change, you could quickly smoke test both, the WordPress and Jetpack apps, and see if they are both working as expected.

Regression Notes

  1. Potential unintended areas of impact

N/A

  1. What I did to test those areas of impact (or what existing automated tests I relied on)

See To test section above.

  1. What automated tests I added (or what prevented me from doing so)

N/A


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 is an accompanying commit to a previous such commit, which was
mainly targeted Kotlin classes. As such, this commit now mainly targets
Java classes.

You will also notice that not all such Java classes are being annotated
with the '@SuppressWarnings("deprecation")'. This is due to the fact
that different versions of libraries are using different implementation
of 'onActivityResult(...)', which result to this suppression being
redundant if added, or at least seeming so. Thus, by adding that,
another set of such redundant suppression warnings are adding to the
list of overall warnings, and thus, at least for now, this is being
avoided in order to not having to then remove those again afterwards.

For more info see this commit: 103b90c
Warning Message: "'onActivityResult(Int, Int, Intent?): Unit' is
deprecated. Overrides deprecated member in
'androidx.activity.ComponentActivity'. Deprecated in Java"

Explanation: "This deprecation overrides deprecated member but not
marked as deprecated itself. This deprecation won't be inherited in
future releases. Please add @deprecated or suppress.
See https://youtrack.jetbrains.com/issue/KT-47902 for details."
Warning Message: "'toUpperCase(Locale): String' is deprecated.
Use uppercase() instead."

Replacing 'toUpperCase(...)' with 'uppercase(...)' is the recommended
action to resolve this kind of deprecated warnings.
Warning Message: "'toLowerCase(Locale): String' is deprecated.
Use lowercase() instead."

Replacing 'toLowerCase(...)' with 'lowercase(...)' is the recommended
action to resolve this kind of deprecated warnings.
Warning Message: "'AVATAR' is deprecated. Use AVATAR_WITH_BACKGROUND or
AVATAR_WITHOUT_BACKGROUND instead."

It is still unclear whether it is safe to replace 'AVATAR' with
'AVATAR_WITH_BACKGROUND', see it being suggested by the 'replaceWith'
deprecated annotation field. As such, there deprecated warnings are
suppressed, that is, instead of being resolved, since a resolution would
require a proper investigation.

For more info see:
- Issue/deprecate avatar type #8468 (Introduced In):
#8468
Warning Message: "'sumBy((T) -> Int): Int' is deprecated.
Use sumOf instead."

Replacing 'sumBy(...)' with 'sumOf(...)' is the recommended action to
resolve this kind of deprecated warnings.
Warning Messages: "'capitalize(Locale): String' is deprecated.
Use replaceFirstChar instead."

This deprecated warning is suppressed, that is, instead of it being
resolved, since using 'replaceFirstChar { ... }' is a bit complicated
and it would need a bit more thought.
Warning Messages:
- "'PhotoPickerFragment' is deprecated. This class is being refactored,
if you implement any change, please also update
{@link org.wordpress.android.ui.mediapicker.MediaPickerFragment}"
- "'PhotoPickerViewModel' is deprecated. This class is being refactored,
if you implement any change, please also update
{@link org.wordpress.android.ui.mediapicker.MediaPickerViewModel}"
- "'PhotoPickerAdapter' is deprecated. This class is being refactored,
if you implement any change, please also update
{@link org.wordpress.android.ui.mediapicker.MedaPickerAdapter}"
- "'PhotoPickerAdapterDiffCallback' is deprecated. This class is being
refactored, if you implement any change, please also update
{@link org.wordpress.android.ui.mediapicker.
MedaPickerAdapterDiffCallback}"
- "'PhotoPickerActionModeCallback' is deprecated. This class is being
refactored, if you implement any change, please also update
{@link org.wordpress.android.ui.mediapicker.
MedaPickerActionModeCallback}"
- "'PhotoPickerItem' is deprecated. This class is being refactored, if
you implement any change, please also update
{@link org.wordpress.android.ui.mediapicker.MediaItem}"
- "'PhotoPickerUiItem' is deprecated. This class is being refactored, if
you implement any change, please also update
{@link org.wordpress.android.ui.mediapicker.MedaPickerUiItem}"
- "'ThumbnailViewHolder' is deprecated. This class is being refactored,
if you implement any change, please also update
{@link org.wordpress.android.ui.mediapicker.ThumbnailViewHolder}"
- "'PhotoThumbnailViewHolder' is deprecated. This class is being
refactored, if you implement any change, please also update
{@link org.wordpress.android.ui.mediapicker.PhotoThumbnailViewHolder}"
- "'VideoThumbnailViewHolder' is deprecated. This class is being
refactored, if you implement any change, please also update
{@link org.wordpress.android.ui.mediapicker.VideoThumbnailViewHolder}"
- "'ThumbnailViewUtils' is deprecated. This class is being refactored,
if you implement any change, please also update
{@link org.wordpress.android.ui.mediapicker.ThumbnailViewUtils}"
- "'DeviceMediaListBuilder' is deprecated. This class is being
refactored, if you implement any change, please also update
{@link org.wordpress.android.ui.mediapicker.loader.DeviceListBuilder}"

These deprecated warnings are suppressed, that is, instead of being
resolved, since a resolution would require a proper migration.

You will also notice that I optimized the deprecated imports and
suppress the deprecation closer to source wherever possible, that is,
instead on suppressing it on the file level. Thus, in this change you
will also notice some refactoring related to optimizing the imports.
Only the 'EditorPhotoPicker' related deprecation got suppressed both, on
the file level and closer to the deprecation itself.

Example Explanation: See KDoc on 'PhotoPickerFragment' class.

"This class is being refactored, if you implement any change, please
also update {@link org.wordpress.android.ui.mediapicker.
MediaPickerFragment}"
Warning Message: "'onRequestPermissionsResult(Int, Array<String>,
IntArray): Unit' is deprecated. Overrides deprecated member in
'androidx.fragment.app.Fragment'. Deprecated in Java"

Explanation: "This deprecation overrides deprecated member but not
marked as deprecated itself. This deprecation won't be inherited in
future releases. Please add @deprecated or suppress.
See https://youtrack.jetbrains.com/issue/KT-47902 for details."
Warning Messages:
- "'GoogleApiClient' is deprecated. Deprecated in Java"
- "'Builder' is deprecated. Deprecated in Java"
- "'ConnectionCallbacks' is deprecated. Deprecated in Java"
- "'FirebaseInstanceId' is deprecated. Deprecated in Java"
- "'deleteInstanceId(): Unit' is deprecated. Deprecated in Java"

These deprecated warnings are suppressed, that is, instead of being
resolved, since a resolution would require a proper migration.

You will also notice that I suppressed the deprecated warning both, on
the file level and closer to the deprecation itself. I did that because
suppressing on the file level was necessary due to the
'com.google.android.gms.common.api.GoogleApiClient' and
'com.google.firebase.iid.FirebaseInstanceId' imports that can't be
suppressed any other way. But, when doing so, every deprecated warning
is suppressed as well. At which point the deprecated information is
lost. This way, adding first the '@Suppress("DEPRECATION")' closer to
source and then adding it on the file level makes sure that this
information is not lost, at least for the existing code.

For more info see:
- Compiler Warnings as Errors - WordPress Module - AppInitializer -
Google API Client & Firebase Instance Id #17229 (Issue:)
#17229
Warning Messages:
- "'CONNECTIVITY_ACTION: String' is deprecated. Deprecated in Java"
- "'getter for type: Int' is deprecated. Deprecated in Java"
- "'TYPE_WIFI: Int' is deprecated. Deprecated in Java"
- "'TYPE_MOBILE: Int' is deprecated. Deprecated in Java"
- "'getter for activeNetworkInfo: NetworkInfo?' is deprecated.
Deprecated in Java"
- "'getter for isConnected: Boolean' is deprecated.
Deprecated in Java"

These deprecated warnings are suppressed, that is, instead of being
resolved, since a resolution would require a proper migration.

For more info see:
- Compiler Warnings as Errors - WordPress Module -
Connectivity Manager & Network Info #17230 (Issue):
#17230
Warning Messages:
- "'getter for view: View?' is deprecated. Deprecated in Java"
- "'setColorFilter(Int, PorterDuff.Mode): Unit' is deprecated.
Deprecated in Java"

These deprecated warnings are suppressed, that is, instead of being
resolved, since a resolution would require a proper migration to
snackbar (from toast).

For more info see:
- android.widget.Toast.getView (Docs):
https://developer.android.com/reference/android/widget/Toast#getView()
- android.graphics.drawable.Drawable.setColorFilter (Docs):
https://developer.android.com/reference/android/graphics/drawable/
Drawable#setColorFilter(int,%20android.graphics.PorterDuff.Mode)
Warning Messages:
- "'setter for systemUiVisibility: Int' is deprecated.
Deprecated in Java"
- "'getter for systemUiVisibility: Int' is deprecated.
Deprecated in Java"
- "'SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN: Int' is deprecated.
Deprecated in Java"
- "'SYSTEM_UI_FLAG_LAYOUT_STABLE: Int' is deprecated.
Deprecated in Java"

These deprecated warnings are suppressed, that is, instead of being
resolved, since a resolution would require a proper migration.

For more info see:
- android.view.View.setSystemUiVisibility (Docs):
https://developer.android.com/reference/android/view/
View#setSystemUiVisibility(int)
- android.view.View.getSystemUiVisibility (Docs):
https://developer.android.com/reference/android/view/
View#getSystemUiVisibility()
Warning Message: "'onActivityCreated(Bundle): Unit' is deprecated.
Overrides deprecated member in 'androidx.fragment.app.Fragment'.
Deprecated in Java"

Explanation: "This deprecation overrides deprecated member but not
marked as deprecated itself. This deprecation won't be inherited in
future releases. Please add @deprecated or suppress.
See https://youtrack.jetbrains.com/issue/KT-47902 for details."
Warning Message:
- "'showFullScreen(View!): Unit' is deprecated. Deprecated in Java"
- "'setLightStatusBar(Window!, Boolean): Unit' is deprecated.
Deprecated in Java"
- "'setLightNavigationBar(Window!, Boolean): Unit' is deprecated.
Deprecated in Java"

These deprecated warnings are suppressed, that is, instead of being
resolved, since a resolution would require a proper migration.

Explanation: See Javadoc on related 'WPActivityUtils' class methods.

"Use {@link WindowExtensionsKt} instead."
After resolving some of the compile related deprecated warnings, some
Detekt baseline related warnings needed to be removed and suppressed
closer to source because the lines on those classes got changed.
@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented Oct 7, 2022

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

@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented Oct 7, 2022

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

… into analysis/wordpress-main-deprecated-warnings-part-2

� Conflicts:
�	WordPress/src/main/java/org/wordpress/android/ui/mediapicker/loader/DeviceMediaLoader.kt
@peril-wordpress-mobile
Copy link
Copy Markdown

peril-wordpress-mobile bot commented Oct 11, 2022

Warnings
⚠️ This PR is assigned to a milestone which is closing in less than 4 days Please, make sure to get it merged by then or assign it to a later expiring milestone

Generated by 🚫 dangerJS

… into analysis/wordpress-main-deprecated-warnings-part-2
@ParaskP7
Copy link
Copy Markdown
Contributor Author

👋 @ovitrif !

FYI: I am seeing @irfano is AFK this week, as such I am assigning you to this PR as well (round robin style), just in case you find some time to review it. However, this is not that urgent so please don't be too much alerted by that, meaning, please do take your time with it, as much as you need. 🙇

@ParaskP7 ParaskP7 requested a review from ovitrif October 13, 2022 07:31
Copy link
Copy Markdown
Contributor

@ovitrif ovitrif left a comment

Choose a reason for hiding this comment

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

Code changes LGTM and smoke testing both apps was without issues.

Thank you for this great work @ParaskP7 🙇 🎉 🚀

@ParaskP7
Copy link
Copy Markdown
Contributor Author

You are the best, thank you so much for reviewing and testing this PR @ovitrif ! 🙇 ❤️ 🚀

Thank you for this great work @ParaskP7 🙇 🎉 🚀

🙇 🙇 🙇 x 😊

@ParaskP7 ParaskP7 merged commit 5efa74d into trunk Oct 13, 2022
@ParaskP7 ParaskP7 deleted the analysis/wordpress-main-deprecated-warnings-part-2 branch October 13, 2022 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler Warnings as Errors - WordPress Module

3 participants