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

Update minSdkVersion (from 21 to 24) #2564

Merged
merged 11 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package org.wordpress.android.fluxc.mocked

import android.os.Build
import com.yarolegovich.wellsql.WellSql
import org.greenrobot.eventbus.Subscribe
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Assume.assumeTrue
import org.junit.Test
import org.wordpress.android.fluxc.Dispatcher
import org.wordpress.android.fluxc.TestUtils
Expand Down Expand Up @@ -55,11 +53,6 @@ class MockedStack_WCBaseStoreTest : MockedStack_Base() {
// stubbed in a unit test environment, giving results inconsistent with a normal running app
@Test
fun testGetLocalizedCurrencySymbolForCode() {
assumeTrue(
"Requires API 23 or higher due to localized currency values differing on older versions",
Build.VERSION.SDK_INT >= 23
)

Locale("en", "US").let { localeEnUS ->
assertEquals("$", WCCurrencyUtils.getLocalizedCurrencySymbolForCode("USD", localeEnUS))
assertEquals("CA$", WCCurrencyUtils.getLocalizedCurrencySymbolForCode("CAD", localeEnUS))
Expand All @@ -84,11 +77,6 @@ class MockedStack_WCBaseStoreTest : MockedStack_Base() {

@Test
fun testGetSiteCurrency() {
assumeTrue(
"Requires API 23 or higher due to localized currency values differing on older versions",
Build.VERSION.SDK_INT >= 23
)

// Override device locale and use en_US so currency symbols can be predicted
TestUtils.updateLocale(mAppContext, Locale("en", "US"))

Expand Down Expand Up @@ -175,11 +163,6 @@ class MockedStack_WCBaseStoreTest : MockedStack_Base() {

@Test
fun testFormatCurrencyForDisplay() {
assumeTrue(
"Requires API 23 or higher due to localized currency values differing on older versions",
Build.VERSION.SDK_INT >= 23
)

// Override device locale and use en_US so currency symbols can be predicted
TestUtils.updateLocale(mAppContext, Locale("en", "US"))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.wordpress.android.fluxc.network;

import android.os.Build;

import androidx.annotation.NonNull;

import java.io.IOException;
Expand Down Expand Up @@ -83,7 +81,7 @@ public OpenJdkCookieManager(CookieStore store,
if (pathMatches(path, cookie.getPath()) &&
(secureLink || !cookie.getSecure())) {
// Enforce httponly attribute
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && cookie.isHttpOnly()) {
if (cookie.isHttpOnly()) {
String s = uri.getScheme();
if (!"http".equalsIgnoreCase(s) && !"https".equalsIgnoreCase(s)) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package org.wordpress.android.fluxc.persistence

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.os.Build
import android.preference.PreferenceManager
import android.view.Gravity
import android.widget.Toast
Expand Down Expand Up @@ -1918,13 +1917,8 @@ open class WellSqlConfig : DefaultWellConfig {
}
}

@Suppress("CheckStyle")
override fun onConfigure(db: SQLiteDatabase, helper: WellTableManager?) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
db.setForeignKeyConstraintsEnabled(true)
} else {
db.execSQL("PRAGMA foreign_keys=ON")
}
db.setForeignKeyConstraintsEnabled(true)
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.wordpress.android.fluxc.network.rest.wpcom.wc.leaderboards

import android.annotation.TargetApi
import android.os.Build
import android.text.Html
import android.text.SpannableStringBuilder
import android.text.style.URLSpan
Expand Down Expand Up @@ -86,7 +84,7 @@ class LeaderboardProductItem(
?.split(";")
?.filter { it.contains("&#") }
?.reduce { total, new -> "$total$new" }
?.run { fromHtmlWithSafeApiCall(this) }
?.run { Html.fromHtml(this) }
?: plainTextCurrency
}

Expand All @@ -107,7 +105,7 @@ class LeaderboardProductItem(
* Output: DKK
*/
@Suppress("MaxLineLength") private val plainTextCurrency by lazy {
fromHtmlWithSafeApiCall(priceAmountHtmlTag)
Html.fromHtml(priceAmountHtmlTag)
.toString()
.replace(Regex("[0-9.,]"), "")
}
Expand Down Expand Up @@ -152,7 +150,7 @@ class LeaderboardProductItem(
* using the [SpannableStringBuilder] implementation in order to parse it
*/
private val link by lazy {
fromHtmlWithSafeApiCall(itemHtmlTag)
Html.fromHtml(itemHtmlTag)
Copy link
Member

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 }
                 ...

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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 ! 🙇

.run { this as? SpannableStringBuilder }
?.spansAsList()
?.firstOrNull()
Expand All @@ -175,12 +173,6 @@ class LeaderboardProductItem(
getSpans(0, length, URLSpan::class.java)
.toList()

@TargetApi(Build.VERSION_CODES.N)
private fun fromHtmlWithSafeApiCall(source: String?) = source
?.takeIf { Build.VERSION.SDK_INT >= Build.VERSION_CODES.N }?.let {
Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY)
} ?: Html.fromHtml(source)

/**
* Returns the second object of the Top Performer Item Array if exists
*/
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ include ':fluxc',
':tests:api'

gradle.ext {
minSdkVersion = 21
minSdkVersion = 24
compileSdkVersion = 31
targetSdkVersion = 31
}