-
Notifications
You must be signed in to change notification settings - Fork 37
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
Update minSdkVersion
(from 21
to 24
)
#2564
Conversation
Although the 'assemble' and 'lint' task run successfully, a quick analysis showed that updating to 'minSdkVersion = 24' added/removed the below extra warnings: Lint Warnings: - +2 x ObsoleteSdkInt (plugins:woocommerce) All these newly created warnings will be dealt with in subsequent commits. Also, any existing such warnings will be resolved too.
Warning Message: "Unnecessary; SDK_INT is always >= 24" This 'VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN' check was, and is, no longer necessary as the 'minSdkVersion' is now '24'.
Warning Message: "Unnecessary; SDK_INT is always >= 24" This 'VERSION.SDK_INT >= Build.VERSION_CODES.N' check is no longer necessary as the 'minSdkVersion' is now '24'. As such, the if condition has been simplified.
Warning Message: "Unnecessary; SDK_INT is always >= 24" Both, this '@RequiresApi(VERSION_CODES.N)' annotation and 'VERSION.SDK_INT >= Build.VERSION_CODES.N' check, are no longer necessary as the 'minSdkVersion' is now '24'.
Warning Message: "Unnecessary; SDK_INT is always >= 24" This 'assumeTrue(Build.VERSION.SDK_INT >= 23)' test assertion is no longer necessary as the 'minSdkVersion' is now '24'.
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.
Looks good, thanks @ParaskP7 for working on this.
I left one comment, but it's not blocking, so I'm pre-approving.
private fun fromHtmlWithSafeApiCall(source: String?) = source?.let { | ||
Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY) | ||
} ?: Html.fromHtml(source) |
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.
I think we can simplify this function by removing the call to the parameterless fromHtml
, as it's equivalent to the other one using FROM_HTML_MODE_LEGACY
: https://developer.android.com/reference/android/text/Html#fromHtml(java.lang.String). This was necessary before because of the takeIf
, but not anymore I think.
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.
Great, thanks for the comment @hichamboushaba ! I agree, the cleaner the better, I'll apply this change and let you know as soon as I push its commit. 🙇
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.
👋 @hichamboushaba !
This is now done, see ba0b906 and 8637d1c.
You will note that I went a bit further and tried to also resolve the Deprecated
warning, but I only could go as far as doing so for 1/3 of those. You will find further detail in the commit description itself. Let me know what you think and thank you! 🙇
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.
Thanks @ParaskP7 for making the changes 🙏 , I left some comments below.
All of this is minor, so no need for spending too much time on it 🙂.
Thank you so much for reviewing and testing this PR @hichamboushaba , you rock! 🙏 |
This 'fromHtmlWithSafeApiCall(...)' function served a purpose only when it was combined with `takeIf`. However, now that this was removed due to the 'minSdkVersion = 24' upgrade, this whole function is no longer necessary and can be replaced with a direct 'Html.fromHtml(...)' call.
Replacing 'Html.fromHtml(html)' with the 'HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_LEGACY)' compat related version is the recommended action to resolve this kind of Lint warnings. However, note that this was only possible for 'priceAmountHtmlTag'. Doing the same for the other two, 'priceAmountHtmlTag' and 'itemHtmlTag', isn't possible as those fields can end up being nullable, that is, due to the fact that the 'LeaderboardItemRow.display' constructor argument is nullable as well. As such, and because 'HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_LEGACY)' accepts a non-null String 'source', it is not possible to resolve these two Lint warnings.
@@ -84,7 +85,7 @@ class LeaderboardProductItem( | |||
?.split(";") | |||
?.filter { it.contains("&#") } | |||
?.reduce { total, new -> "$total$new" } | |||
?.run { Html.fromHtml(this) } | |||
?.run { HtmlCompat.fromHtml(this, HtmlCompat.FROM_HTML_MODE_LEGACY) } |
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.
np, you don't have to change it.
HtmlCompat
is useful only for apps with minSdk less than 24, for us, we can directly call the method that was introduced in API 24 https://developer.android.com/reference/android/text/Html#fromHtml(java.lang.String,%20int)
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.
Ah, thank you @hichamboushaba , you are totally right, I somehow got afraid of the fact that the String source
is neither marked @NonNull
nor @Nullable
on the Html.java
side and thus didn't want to make this change, but that doesn't matter, you have to trust that it works for @Nullable
just like that as it anyways defaults to using the same mechanism underneath.
Thus, done, this update seems safe and apologies for the trouble with this review (😅): 5acc19a
@@ -150,7 +150,7 @@ class LeaderboardProductItem( | |||
* using the [SpannableStringBuilder] implementation in order to parse it | |||
*/ | |||
private val link by lazy { | |||
fromHtmlWithSafeApiCall(itemHtmlTag) | |||
Html.fromHtml(itemHtmlTag) |
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.
For using the new API instead of the deprecated one, WDYT about something like this?
itemHtmlTag?.let { Html.fromHtml(it, Html.FROM_HTML_MODE_LEGACY) }
?.run { this as? SpannableStringBuilder }
...
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.
👋 @hichamboushaba !
I think maybe this change is enough for now, wdyt? 🤔
PS: I really don't want to change any of the functionality, even by that slight bit, not that it will change much, but you know, you can never be too careful, and then you need to really test that, even if you change that little bit.
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.
Good point, and I think we are safe, when the argument is null
, we were already calling Html#fromHtml(String)
which proxies the call to the same function we are using now.
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.
Exactly, once more, thank YOU Hicham ! 🙇
As correctly noted 'HtmlCompat' is only useful for apps with `minSdkVersion` less than '24', thus it is now unneeded and can be completely replaced with the direct usage of 'Html'. See discussion here: https://github.com/wordpress-mobile/ WordPress-FluxC-Android/pull/2564#discussion_r1018958379
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.
Changes LGTM 🎉
Though I wonder with regards to the existing discussion here, in WPAndroid we always use HtmlCompat
, yet minSdkVersion
is 24, isn't it then in fact not necessary? 😅
Thank you for the review and testing @ovitrif ! 🙇 ❤️ 🚀
Yeap, yeap, this is indeed the case, I just copy-pasted my solution from WCAndroid into WPAndroid, and since I used PS: Feel free to do a quick PR on it if you like, else I'll get to that at some point myself. 👍 |
…ndroid into build/update-min-sdk-version-to-24 � Conflicts: � settings.gradle
This is done once more, due to the fact that a merge conflict resulting in that update being lost.
Since the 'targetSdkVersion' has been now update to point to '31', disabling this 'ExpiredTargetSdkVersion' Lint error is no longer necessary.
This PR upgrades FluxC to
minSdkVersion
to24
. This has been unblocked because:WPAndroid
was already onminSdkVersion = 24
, for some time now (see here).WCAndroid
has been recently upgraded tominSdkVersion = 24
as well (see here).Warning (⚠️ ): This update is currently blocked by the common upgrade of
targetSdkVersion
to31
(see here).As part of this
minSdkVersion = 24
upgrade the below changes were also applied in order to fix any additional warnings that this change brought-up:Warnings Resolution List:
PS: @hichamboushaba @ovitrif I added you as the main reviewers, that is, in addition to the @wordpress-mobile/apps-infrastructure team itself, but randomly, since I just wanted someone from both, the
WordPress
andWoo Commerce
teams, to sign-off on that change for WPAndroid and WCAndroid alike.Testing instructions
FluxC Example
app and see if it works as expected.FluxC Example
app on Android 5 (API 21/22
) and Android 6 (API 23
) devices and verify that you can't (see API Levels).Merge instructions
targetSdkVersion
(from22
to31
) #2563 to be approved and merged totrunk
.trunk
.trunk
.[PR] Not Ready For Merge]
label.trunk
.