Commit 6341e10c authored by Tiger Oakes's avatar Tiger Oakes Committed by Tiger Oakes
Browse files

Replace String.toUri with Android KTX

parent b12f2558
......@@ -32,6 +32,7 @@ dependencies {
implementation project(':support-ktx')
implementation project(':support-utils')
implementation Dependencies.androidx_core_ktx
implementation Dependencies.kotlin_stdlib
implementation Dependencies.kotlin_coroutines
......
......@@ -42,6 +42,7 @@ import android.webkit.WebViewClient
import android.widget.FrameLayout
import androidx.annotation.VisibleForTesting
import androidx.annotation.VisibleForTesting.PRIVATE
import androidx.core.net.toUri
import kotlinx.coroutines.runBlocking
import mozilla.components.browser.engine.system.matcher.UrlMatcher
import mozilla.components.browser.engine.system.permission.SystemPermissionRequest
......@@ -55,7 +56,6 @@ import mozilla.components.concept.engine.prompt.PromptRequest
import mozilla.components.concept.engine.request.RequestInterceptor.InterceptionResponse
import mozilla.components.concept.storage.VisitType
import mozilla.components.support.ktx.android.view.getRectWithViewLocation
import mozilla.components.support.ktx.kotlin.toUri
import mozilla.components.support.utils.DownloadUtils
import java.util.Date
......@@ -294,7 +294,7 @@ class SystemEngineView @JvmOverloads constructor(
val session = session ?: return handler.cancel()
val formattedUrl = session.currentUrl.toUri().let { uri ->
(uri.scheme ?: "http") + "://" + (uri.host ?: host)
"${uri.scheme ?: "http"}://${uri.host ?: host}"
}
// Trim obnoxiously long realms.
......
......@@ -40,6 +40,7 @@ dependencies {
implementation project(':browser-session')
implementation Dependencies.androidx_annotation
implementation Dependencies.androidx_core_ktx
implementation Dependencies.androidx_palette
implementation Dependencies.kotlin_stdlib
implementation Dependencies.kotlin_coroutines
......
......@@ -8,6 +8,7 @@ import android.content.Context
import android.os.SystemClock
import android.util.LruCache
import androidx.annotation.VisibleForTesting
import androidx.core.net.toUri
import mozilla.components.browser.icons.Icon
import mozilla.components.browser.icons.IconRequest
import mozilla.components.concept.fetch.Client
......@@ -16,7 +17,6 @@ import mozilla.components.concept.fetch.Response
import mozilla.components.concept.fetch.isSuccess
import mozilla.components.support.base.log.logger.Logger
import mozilla.components.support.ktx.android.net.isHttpOrHttps
import mozilla.components.support.ktx.kotlin.toUri
import java.io.IOException
import java.util.concurrent.TimeUnit
......
......@@ -6,12 +6,12 @@ package mozilla.components.browser.icons.preparer
import android.content.Context
import android.content.res.AssetManager
import androidx.core.net.toUri
import mozilla.components.browser.icons.IconRequest
import mozilla.components.support.base.log.Log
import mozilla.components.support.ktx.android.net.hostWithoutCommonPrefixes
import mozilla.components.support.ktx.android.net.isHttpOrHttps
import mozilla.components.support.ktx.android.org.json.asSequence
import mozilla.components.support.ktx.kotlin.toUri
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
......
......@@ -43,6 +43,7 @@ dependencies {
implementation project(':ui-icons')
implementation project(':support-ktx')
implementation Dependencies.androidx_core_ktx
implementation Dependencies.androidx_room_runtime
kapt Dependencies.androidx_room_compiler
implementation Dependencies.androidx_paging
......
......@@ -5,6 +5,7 @@
package mozilla.components.feature.sitepermissions.db
import android.content.Context
import androidx.core.net.toUri
import androidx.room.Room
import androidx.room.testing.MigrationTestHelper
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory
......@@ -12,7 +13,6 @@ import androidx.test.core.app.ApplicationProvider
import androidx.test.platform.app.InstrumentationRegistry
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.feature.sitepermissions.SitePermissionsStorage
import mozilla.components.support.ktx.kotlin.toUri
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
......
......@@ -5,12 +5,12 @@
package mozilla.components.feature.sitepermissions.db
import android.content.Context
import androidx.core.net.toUri
import androidx.room.Room
import androidx.test.core.app.ApplicationProvider
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.feature.sitepermissions.SitePermissions.Status.ALLOWED
import mozilla.components.feature.sitepermissions.SitePermissions.Status.BLOCKED
import mozilla.components.support.ktx.kotlin.toUri
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
......
......@@ -11,6 +11,7 @@ import android.content.pm.PackageManager
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.core.net.toUri
import androidx.fragment.app.FragmentManager
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
......@@ -37,7 +38,6 @@ import mozilla.components.support.base.feature.LifecycleAwareFeature
import mozilla.components.support.base.feature.OnNeedToRequestPermissions
import mozilla.components.support.base.feature.PermissionsFeature
import mozilla.components.support.ktx.android.content.isPermissionGranted
import mozilla.components.support.ktx.kotlin.toUri
import java.security.InvalidParameterException
internal const val FRAGMENT_TAG = "mozac_feature_sitepermissions_prompt_dialog"
......
......@@ -32,6 +32,7 @@ dependencies {
implementation project(':support-utils')
implementation project(':support-ktx')
implementation Dependencies.androidx_core_ktx
implementation Dependencies.kotlin_stdlib
implementation Dependencies.kotlin_coroutines
......
......@@ -7,6 +7,7 @@ package mozilla.components.feature.toolbar.internal
import android.text.SpannableStringBuilder
import android.text.style.ForegroundColorSpan
import androidx.annotation.VisibleForTesting
import androidx.core.net.toUri
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
......@@ -15,7 +16,6 @@ import kotlinx.coroutines.channels.sendBlocking
import kotlinx.coroutines.launch
import mozilla.components.concept.toolbar.Toolbar
import mozilla.components.feature.toolbar.ToolbarFeature
import mozilla.components.support.ktx.kotlin.toUri
/**
* Asynchronous URL renderer.
......
......@@ -22,6 +22,7 @@ android {
}
dependencies {
implementation Dependencies.androidx_core_ktx
implementation Dependencies.kotlin_stdlib
implementation project(':support-ktx')
......
......@@ -5,7 +5,7 @@
package mozilla.components.service.pocket
import android.net.Uri
import mozilla.components.support.ktx.kotlin.toUri
import androidx.core.net.toUri
// When upgrading to production endpoint, ensure this is HTTPS.
private const val STAGE_SERVER_BASE = "http://scout-stage.herokuapp.com"
......
......@@ -7,7 +7,7 @@ package mozilla.components.service.pocket
import android.net.Uri
import androidx.annotation.VisibleForTesting
import androidx.annotation.VisibleForTesting.PRIVATE
import mozilla.components.support.ktx.kotlin.toUri
import androidx.core.net.toUri
private const val CDN_BASE = "https://getpocket.cdn.mozilla.net/v3/firefox"
......
......@@ -4,6 +4,7 @@
package mozilla.components.service.pocket
import androidx.core.net.toUri
import androidx.test.ext.junit.runners.AndroidJUnit4
import mozilla.components.concept.fetch.Client
import mozilla.components.concept.fetch.Headers.Names.USER_AGENT
......@@ -12,7 +13,6 @@ import mozilla.components.service.pocket.helpers.MockResponses
import mozilla.components.service.pocket.helpers.assertRequestParams
import mozilla.components.service.pocket.helpers.assertResponseIsClosed
import mozilla.components.service.pocket.helpers.assertSuccessfulRequestReturnsResponseBody
import mozilla.components.support.ktx.kotlin.toUri
import mozilla.components.support.test.any
import mozilla.components.support.test.mock
import org.junit.Assert.assertEquals
......
......@@ -4,6 +4,7 @@
package mozilla.components.service.pocket
import androidx.core.net.toUri
import androidx.test.ext.junit.runners.AndroidJUnit4
import mozilla.components.concept.fetch.Client
import mozilla.components.concept.fetch.Headers.Names.CONTENT_TYPE
......@@ -16,7 +17,6 @@ import mozilla.components.service.pocket.helpers.MockResponses
import mozilla.components.service.pocket.helpers.assertRequestParams
import mozilla.components.service.pocket.helpers.assertResponseIsClosed
import mozilla.components.service.pocket.helpers.assertSuccessfulRequestReturnsResponseBody
import mozilla.components.support.ktx.kotlin.toUri
import mozilla.components.support.test.any
import mozilla.components.support.test.mock
import org.junit.Assert.assertEquals
......
......@@ -10,14 +10,15 @@ import java.security.MessageDigest
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import kotlin.text.RegexOption.IGNORE_CASE
/**
* A collection of regular expressions used in the `is*` methods below.
*/
private val re = object {
val phoneish = "^\\s*tel:\\S?\\d+\\S*\\s*$".toRegex(RegexOption.IGNORE_CASE)
val emailish = "^\\s*mailto:\\w+\\S*\\s*$".toRegex(RegexOption.IGNORE_CASE)
val geoish = "^\\s*geo:\\S*\\d+\\S*\\s*$".toRegex(RegexOption.IGNORE_CASE)
val phoneish = "^\\s*tel:\\S?\\d+\\S*\\s*$".toRegex(IGNORE_CASE)
val emailish = "^\\s*mailto:\\w+\\S*\\s*$".toRegex(IGNORE_CASE)
val geoish = "^\\s*geo:\\S*\\d+\\S*\\s*$".toRegex(IGNORE_CASE)
}
/**
......@@ -52,6 +53,7 @@ fun String.toDate(format: String, locale: Locale = Locale.ROOT): Date {
/**
* Converts a [String] to a [Uri] object.
*/
@Deprecated("Use Android KTX instead", ReplaceWith("toUri()", "androidx.core.net.toUri"))
fun String.toUri() = Uri.parse(this)
/**
......
......@@ -4,7 +4,7 @@
package mozilla.components.support.ktx.android.net
import mozilla.components.support.ktx.kotlin.toUri
import androidx.core.net.toUri
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
......
......@@ -84,6 +84,7 @@ class StringTest {
assertTrue("Geo:1,-1".isGeoLocation())
}
@Suppress("Deprecation")
@Test
fun toUri() {
assertEquals(
......
......@@ -32,6 +32,7 @@ permalink: /changelog/
* Added `FetchDownloadManager`, an alternate download manager that uses a fetch `Client` instead of the native Android `DownloadManager`.
* **support-ktx**
* Deprecated `String.toUri()` in favour of Android Core KTX.
* Added `putCompoundDrawablesRelative` and `putCompoundDrawablesRelativeWithIntrinsicBounds`, aliases of `setCompoundDrawablesRelative` that use Kotlin named and default arguments.
* **feature-prompts**
......@@ -200,8 +201,8 @@ permalink: /changelog/
* ⚠️ **This is a breaking change**: Added `url` parameter to `Session.Observer.onLoadRequest()`.
* **support-ktx**
* Removed `Drawable.toBitmap()` in favour of the Android Core KTX version.
* Removed `Context.systemService()` in favour of the Android Core KTX version.
* ⚠️ **This is a breaking change**: Removed `Drawable.toBitmap()` in favour of the Android Core KTX version.
* ⚠️ **This is a breaking change**: Removed `Context.systemService()` in favour of the Android Core KTX version.
* **browser-session**
* Added `Session.hasParentSession` to indicate whether a `Session` was opened from a parent `Session` such as opening a new tab from a link context menu ("Open in new tab").
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment