Skip to content
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

[Nullability Annotations to Java Classes] Use Updated and Null Proof MediaModel Class (breaking) #10078

Merged
merged 11 commits into from
Nov 9, 2023

Conversation

ParaskP7
Copy link
Contributor

@ParaskP7 ParaskP7 commented Nov 1, 2023

Parent FluxC#2799
Accompanying FluxC#2886


Description

This PR accompanying the above FluxC PR, and uses an updated and null-proof MediaModel.java class.

FYI: This change is breaking, meaning that any client that depended on the MediaModel.java model should update to the new APIs (non-default constructors) as the existing API (default constructor) are now deprecated. As such, this change is inherently risky, meaning that there are compile-time changes associated with this change and thus needs testing to verify correctness, both on the library's and client's side.


@0nko I added you as the main reviewer, not so randomly (it being a continuation of FluxC#2878), since I just wanted someone from the WooCommerce mobile team to be aware of and sign-off on that change. Feel free to merge this PR directly yourself if you deem so.


FluxC Update List:

  1. Update fluxc version to pr hash (2886)
  2. Update fluxc version to pr hash (2886)
  3. Update fluxc version to trunk hash (2886)
  4. Update fluxc version to trunk hash (2886)

Deprecation Resolution List (breaking):

  1. Resolve media model constructor deprecation warnings
  2. Make media model parameter nullable on media upload exception

Nullability Checks List:

  1. Un-guard usages of non-null media model url
  2. Guard usages of nullable media model file path

Testing instructions

(REST):

  • Smoke test any media related functionality and see if everything is working as expected. For a couple of examples, you can expand and follow the inner and more explicit test steps within:

(XMLRPC):

  • Create a new self-hosted WordPress site for XMLRPC testing purposes (jurassic.ninja).
  • Smoke test any media related functionality and see if everything is working as expected. For a couple of examples, you can expand and follow the inner and more explicit test steps within:
Photos Screens [ProductDetailFragment.java + ProductImagesFragment.kt + ProductImageViewerFragment.kt]
  • Go to Products tab and tap on any product.
  • Tap on any photo on top and verify that the Photos screen is shown and functioning as expected.
  • For example try adding a new photo, select an upload method, and wait for the photo to be uploaded.
  • Tap on the photo preview and verify that the Photo Preview screen is shown and functioning as expected.
  • For example try swipe left-right to navigate between photo previews.

Merge instructions:

  1. Wait for the accompanying FluxC#2886 PR to be merged.
  2. Update fluxCVersion to point to the trunk hash that includes the above solution.
  3. Remove the status: do not merge label.
  4. Merge this PR.

  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

This 'FluxC' PR hash updates the library to that branch version
where the 'MediaModel' is updated to its new null proof version.

FluxC PR: https://github.com/wordpress-mobile/
WordPress-FluxC-Android/pull/2886

This step is required in order to check that these 'FluxC'
related changes work as expected for WCAndroid.
Warning: "'constructor MediaModel()' is deprecated. Deprecated in Java"
FYI: This change changes the logic to only checking for not blank
instead.
FYI: This change propagates to 'UploadStatus.Failed' as well.

PS: This change is not in order to avoid using an empty deprecated
'MediaModel' for no particular reason.
@ParaskP7 ParaskP7 added status: do not merge Dependent on another PR, ready for review but not ready for merge. Core Tech Debt labels Nov 1, 2023
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Nov 1, 2023

📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App Name WooCommerce Android
FlavorJalapeno
Build TypeDebug
Commit66ee06e
Direct Downloadwoocommerce-prototype-build-pr10078-66ee06e.apk

val channelResult = if (event.media?.url != null) {
WooLog.i(T.MEDIA, "MediaFilesRepository > uploaded media ${event.media?.id}")
val media = event.media
val channelResult = if (media != null && media.url.isNotBlank()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Warning (⚠️): I am not fully confident about this change here as I am not sure which check is better, the version I chose here:

if (media != null && media.url.isNotBlank()) { UploadSuccess(media) }

Or another version of it, which just checks for a nullable media, before marking this as upload success, but without checking for a blank URL:

if (media != null) { UploadSuccess(media) }

FYI: Mind the fact media.url can no longer be nullable with the updated media model.

Let me know your thoughts on this as I fear this has the potential to change the behavior somehow, on cases that we think a media is still valid even with a blank URL, thank YOU for helping! 🙏

Copy link
Contributor

Choose a reason for hiding this comment

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

I wasn't sure either so I checked for the usage of MediaModel.url and it seems like we don't use/check for the empty value anywhere, so the the 1st option should be fine. Besides, uploading an empty URL doesn't make sense anyway :).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awesome, thanks for checking, verifying and clarifying this @0nko , much appreciated! 🙇 🙏

FYI: I'll then stick with the version we have here then. 👍

@0nko 0nko self-assigned this Nov 1, 2023
Copy link
Contributor

@0nko 0nko left a comment

Choose a reason for hiding this comment

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

I've checked the code and tested both REST and XML-RPC variants and everything seems to be working fine. However, before we proceed with the merge, we'll need to also update the MediaPicker library.

Nice work @ParaskP7! 🥇

@ParaskP7
Copy link
Contributor Author

ParaskP7 commented Nov 3, 2023

Thanks you so much for review, testing and approving this and the FluxC PR @0nko , you rock! 🙇 ❤️

I've checked the code and tested both REST and XML-RPC variants and everything seems to be working fine. However, before we proceed with the merge, we'll need to also update the MediaPicker library.

Oh, I wasn't sure about that, thinking that MediaPicker will compile/work anyway (for now), just because it will be pointing to a previous version of FluxC. And also, that only when we'll need to update FluxC there that we would also need to deal with the MediaModel update. 🤔

But if you say so, I'll try to create another PR on the MediaPicker side, deal with the MediaModel update there too and update the mediapickerVersion on this PR to point to that PR hash for testing purposes. It is indeed making sense to deal with that too now, rather than later. 💯

Would you be willing to go through another round of testing afterwards? 🙏

@ParaskP7
Copy link
Contributor Author

ParaskP7 commented Nov 3, 2023

👋 @0nko !

But if you say so, I'll try to create another PR on the MediaPicker side, deal with the MediaModel update there too and update the mediapickerVersion on this PR to point to that PR hash for testing purposes. It is indeed making sense to deal with that too now, rather than later. 💯

A quick update on that! 👀

I just checked the MediaPicker library and noticed that the wordPressFluxCVersion version is pointing to develop-fa819801570505a0e9b4f7f226bb704b88ccc1d2 (😮 develop 🤷), a version which is 3 years old (commit). 😨

As such, I think it is better for me to NOT go through that change and let someone else deal with the wordPressFluxCVersion version update on MediaPicker. Update wordPressFluxCVersion version now might cause additional breaking changes, unrelated to this MediaModel update and I don't know if we should mix those 2 together. Wdyt? 🤔

@0nko
Copy link
Contributor

0nko commented Nov 3, 2023

Would you be willing to go through another round of testing afterwards? 🙏

@ParaskP7 Absolutely 👍. Thanks for handling it!

@0nko
Copy link
Contributor

0nko commented Nov 3, 2023

As such, I think it is better for me to NOT go through that change and let someone else deal with the wordPressFluxCVersion version update on MediaPicker. Update wordPressFluxCVersion version now might cause additional breaking changes, unrelated to this MediaModel update and I don't know if we should mix those 2 together. Wdyt? 🤔

Just saw your comment. OK, let's get these changes merged and I can take a look at the library afterwards.

@ParaskP7
Copy link
Contributor Author

ParaskP7 commented Nov 3, 2023

Just saw your comment. OK, let's get these changes merged and I can take a look at the library afterwards.

Great, thanks for agreeing to that @0nko and I am sorry to delegate that to you, that's wasn't my intention here. 🙏

Btw, I quickly searched for MediaModel and MediaStore within MediaPicker and didn't notice anything too breaking. This library is never constructing a MediaModel class itself, just using an existing one from the MediaStore to then construct a MediaItem from it (see here). Thus, I think MediaModel will not be too much of a breaking change on this library, or at least anything hard for you to update after first updating FluxC. 🤞

But, I do indeed worry about the FluxC library that is used there, which is 3 year old, and thus don't want to update that, as part of this work, just to deal with the MediaModel update. I hope that justifies why I suggest going this way. ☺️

@ParaskP7
Copy link
Contributor Author

ParaskP7 commented Nov 3, 2023

FYI: I'll resolve the build.gradle merge conflict when I'll be updating fluxCVersion to point to the trunk hash that includes the above solution (see Merge instructions).

@ParaskP7 ParaskP7 modified the milestones: 16.2, 16.3 Nov 7, 2023
…to analysis/use-updated-and-null-proof-media-model-class

# Conflicts:
#	build.gradle
This 'FluxC' PR hash updates the library to that branch version
where the 'MediaModel' is updated to its new null proof version.

FluxC PR: https://github.com/wordpress-mobile/
WordPress-FluxC-Android/pull/2886

This step is required in order to check that these 'FluxC'
related changes work as expected for WCAndroid.

------------------------------------------------------------------------

FYI: This change is an addition to
faf148b. This change is necessary in
order to overcome and resolve new merge conflicts.
…to analysis/use-updated-and-null-proof-media-model-class

# Conflicts:
#	build.gradle
This 'FluxC' hash updates the library to that 'trunk' version
where the 'Media' model classes are updated to their new null proof
version.

FluxC PR: https://github.com/wordpress-mobile/
WordPress-FluxC-Android/pull/2886
@0nko 0nko enabled auto-merge November 9, 2023 09:30
@0nko 0nko removed the status: do not merge Dependent on another PR, ready for review but not ready for merge. label Nov 9, 2023
…to analysis/use-updated-and-null-proof-media-model-class
@0nko 0nko added the status: do not merge Dependent on another PR, ready for review but not ready for merge. label Nov 9, 2023
This 'FluxC' hash updates the library to that 'trunk' version
where the 'Media' model classes are updated to their new null proof
version.

FluxC PR: https://github.com/wordpress-mobile/
WordPress-FluxC-Android/pull/2886

------------------------------------------------------------------------

FYI: This change is an addition to
2a44866. This change is necessary in
order to overcome and resolve new merge conflicts.
@ParaskP7 ParaskP7 removed the status: do not merge Dependent on another PR, ready for review but not ready for merge. label Nov 9, 2023
@wpmobilebot
Copy link
Collaborator

Found 1 violations:

The PR caused the following dependency changes:

expand

-+--- org.wordpress:fluxc:2890-5ca88c9aa82b96dfc9c9cb83a71eb19045437225
-|    +--- org.wordpress:wellsql:2.0.0
-|    |    +--- androidx.annotation:annotation:1.2.0 -> 1.6.0 (*)
-|    |    \--- org.wordpress.wellsql:wellsql-annotations:2.0.0
-|    +--- org.wordpress.fluxc:fluxc-annotations:2890-5ca88c9aa82b96dfc9c9cb83a71eb19045437225
-|    +--- org.greenrobot:eventbus:3.3.1 (*)
-|    +--- com.squareup.okhttp3:okhttp:4.9.0 -> 4.11.0 (*)
-|    +--- com.android.volley:volley:1.1.1 -> 1.2.0
-|    +--- androidx.paging:paging-runtime:2.1.2
-|    |    +--- androidx.paging:paging-common:2.1.2
-|    |    |    +--- androidx.annotation:annotation:1.0.0 -> 1.6.0 (*)
-|    |    |    \--- androidx.arch.core:core-common:2.0.0 -> 2.2.0 (*)
-|    |    +--- androidx.arch.core:core-runtime:2.0.0 -> 2.2.0 (*)
-|    |    +--- androidx.lifecycle:lifecycle-runtime:2.0.0 -> 2.6.2 (*)
-|    |    +--- androidx.lifecycle:lifecycle-livedata:2.0.0 -> 2.6.2 (*)
-|    |    \--- androidx.recyclerview:recyclerview:1.0.0 -> 1.2.1 (*)
-|    +--- com.goterl:lazysodium-android:5.0.2
-|    +--- net.java.dev.jna:jna:5.5.0
-|    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.20 -> 1.8.21 (*)
-|    +--- org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.6.20 -> 1.8.21
-|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.8.21 -> 1.8.22 (*)
-|    +--- androidx.appcompat:appcompat:1.0.2 -> 1.4.2 (*)
-|    +--- androidx.recyclerview:recyclerview:1.0.0 -> 1.2.1 (*)
-|    +--- androidx.exifinterface:exifinterface:1.0.0 -> 1.3.3
-|    |    \--- androidx.annotation:annotation:1.2.0 -> 1.6.0 (*)
-|    +--- androidx.security:security-crypto:1.0.0 -> 1.1.0-alpha03
-|    |    +--- androidx.annotation:annotation:1.1.0 -> 1.6.0 (*)
-|    |    +--- com.google.crypto.tink:tink-android:1.5.0
-|    |    \--- androidx.collection:collection:1.1.0 -> 1.2.0 (*)
-|    +--- com.squareup.okhttp3:okhttp-urlconnection:4.9.0
-|    |    +--- com.squareup.okhttp3:okhttp:4.9.0 -> 4.11.0 (*)
-|    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10 -> 1.8.21 (*)
-|    +--- com.google.code.gson:gson:2.8.5 -> 2.10.1
-|    +--- org.apache.commons:commons-text:1.10.0 (*)
-|    +--- androidx.room:room-runtime:2.4.2 -> 2.5.1 (*)
-|    +--- androidx.room:room-ktx:2.4.2 -> 2.5.1
-|    |    +--- androidx.room:room-common:2.5.1 (*)
-|    |    +--- androidx.room:room-runtime:2.5.1 (*)
-|    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.7.20 -> 1.8.22 (*)
-|    |    \--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4 (*)
-|    +--- com.google.dagger:dagger:2.42 -> 2.46.1
-|    |    \--- javax.inject:javax.inject:1
-|    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9 -> 1.6.4 (*)
-|    \--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9 -> 1.6.4 (*)
++--- org.wordpress:fluxc:trunk-7ea7465680431fa4df5f0433d4c8b8395055b997
+|    +--- org.wordpress:wellsql:2.0.0
+|    |    +--- androidx.annotation:annotation:1.2.0 -> 1.6.0 (*)
+|    |    \--- org.wordpress.wellsql:wellsql-annotations:2.0.0
+|    +--- org.wordpress.fluxc:fluxc-annotations:trunk-7ea7465680431fa4df5f0433d4c8b8395055b997
+|    +--- org.greenrobot:eventbus:3.3.1 (*)
+|    +--- com.squareup.okhttp3:okhttp:4.9.0 -> 4.11.0 (*)
+|    +--- com.android.volley:volley:1.1.1 -> 1.2.0
+|    +--- androidx.paging:paging-runtime:2.1.2
+|    |    +--- androidx.paging:paging-common:2.1.2
+|    |    |    +--- androidx.annotation:annotation:1.0.0 -> 1.6.0 (*)
+|    |    |    \--- androidx.arch.core:core-common:2.0.0 -> 2.2.0 (*)
+|    |    +--- androidx.arch.core:core-runtime:2.0.0 -> 2.2.0 (*)
+|    |    +--- androidx.lifecycle:lifecycle-runtime:2.0.0 -> 2.6.2 (*)
+|    |    +--- androidx.lifecycle:lifecycle-livedata:2.0.0 -> 2.6.2 (*)
+|    |    \--- androidx.recyclerview:recyclerview:1.0.0 -> 1.2.1 (*)
+|    +--- com.goterl:lazysodium-android:5.0.2
+|    +--- net.java.dev.jna:jna:5.5.0
+|    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.20 -> 1.8.21 (*)
+|    +--- org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.6.20 -> 1.8.21
+|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.8.21 -> 1.8.22 (*)
+|    +--- androidx.appcompat:appcompat:1.0.2 -> 1.4.2 (*)
+|    +--- androidx.recyclerview:recyclerview:1.0.0 -> 1.2.1 (*)
+|    +--- androidx.exifinterface:exifinterface:1.0.0 -> 1.3.3
+|    |    \--- androidx.annotation:annotation:1.2.0 -> 1.6.0 (*)
+|    +--- androidx.security:security-crypto:1.0.0 -> 1.1.0-alpha03
+|    |    +--- androidx.annotation:annotation:1.1.0 -> 1.6.0 (*)
+|    |    +--- com.google.crypto.tink:tink-android:1.5.0
+|    |    \--- androidx.collection:collection:1.1.0 -> 1.2.0 (*)
+|    +--- com.squareup.okhttp3:okhttp-urlconnection:4.9.0
+|    |    +--- com.squareup.okhttp3:okhttp:4.9.0 -> 4.11.0 (*)
+|    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10 -> 1.8.21 (*)
+|    +--- com.google.code.gson:gson:2.8.5 -> 2.10.1
+|    +--- org.apache.commons:commons-text:1.10.0 (*)
+|    +--- androidx.room:room-runtime:2.4.2 -> 2.5.1 (*)
+|    +--- androidx.room:room-ktx:2.4.2 -> 2.5.1
+|    |    +--- androidx.room:room-common:2.5.1 (*)
+|    |    +--- androidx.room:room-runtime:2.5.1 (*)
+|    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.7.20 -> 1.8.22 (*)
+|    |    \--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4 (*)
+|    +--- com.google.dagger:dagger:2.42 -> 2.46.1
+|    |    \--- javax.inject:javax.inject:1
+|    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9 -> 1.6.4 (*)
+|    \--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9 -> 1.6.4 (*)
-\--- org.wordpress.fluxc.plugins:woocommerce:2890-5ca88c9aa82b96dfc9c9cb83a71eb19045437225
-     +--- org.wordpress:wellsql:2.0.0 (*)
-     +--- org.wordpress.fluxc:fluxc-annotations:2890-5ca88c9aa82b96dfc9c9cb83a71eb19045437225
-     +--- androidx.room:room-ktx:2.4.2 -> 2.5.1 (*)
-     +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.20 -> 1.8.21 (*)
-     +--- org.wordpress:fluxc:2890-5ca88c9aa82b96dfc9c9cb83a71eb19045437225 (*)
-     +--- com.google.code.gson:gson:2.8.5 -> 2.10.1
-     +--- com.google.dagger:dagger:2.42 -> 2.46.1 (*)
-     +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9 -> 1.6.4 (*)
-     +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9 -> 1.6.4 (*)
-     \--- androidx.room:room-runtime:2.4.2 -> 2.5.1 (*)
+\--- org.wordpress.fluxc.plugins:woocommerce:trunk-7ea7465680431fa4df5f0433d4c8b8395055b997
+     +--- org.wordpress:wellsql:2.0.0 (*)
+     +--- org.wordpress.fluxc:fluxc-annotations:trunk-7ea7465680431fa4df5f0433d4c8b8395055b997
+     +--- androidx.room:room-ktx:2.4.2 -> 2.5.1 (*)
+     +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.20 -> 1.8.21 (*)
+     +--- org.wordpress:fluxc:trunk-7ea7465680431fa4df5f0433d4c8b8395055b997 (*)
+     +--- com.google.code.gson:gson:2.8.5 -> 2.10.1
+     +--- com.google.dagger:dagger:2.42 -> 2.46.1 (*)
+     +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9 -> 1.6.4 (*)
+     +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9 -> 1.6.4 (*)
+     \--- androidx.room:room-runtime:2.4.2 -> 2.5.1 (*)

Please review and act accordingly

@0nko
Copy link
Contributor

0nko commented Nov 9, 2023

@ParaskP7 I tried to update the FluxC reference and get it merged but I can't build the project. I'm getting a useless e: Could not load module <Error module> error message. I was wondering if it's because the dependency catalogue is using an old version of Kotlin (1.6). But it seems like you were more successful.

@0nko 0nko merged commit 5c5401a into trunk Nov 9, 2023
2 checks passed
@0nko 0nko deleted the analysis/use-updated-and-null-proof-media-model-class branch November 9, 2023 10:34
@ParaskP7
Copy link
Contributor Author

ParaskP7 commented Nov 9, 2023

👋 @0nko and thanks for trying to find the correct FluxC reference and then do the merge yourself. 🙇

I'm getting a useless e: Could not load module error message. I was wondering if it's because the dependency catalogue is using an old version of Kotlin (1.6).

FYI: This was most like related to this CGPNUU63E/p1699440897019819 internal discussion of our and FluxC#2890.

Let me know if that makes sense. 🙏

But it seems like you were more successful.

🎉 🚀

@hichamboushaba hichamboushaba mentioned this pull request Nov 14, 2023
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.

3 participants