[Android] isValidUrl() String util function
Geoffrey Métais
git at videolan.org
Thu Nov 28 07:31:04 CET 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jun 7 17:41:50 2019 +0200| [7d9f0a1b0f13db0c94d1f8d8400bd2103552cdbc] | committer: Nicolas Pomepuy
isValidUrl() String util function
> https://code.videolan.org/videolan/vlc-android/commit/7d9f0a1b0f13db0c94d1f8d8400bd2103552cdbc
---
.../main/java/org/videolan/tools/KotlinExtensions.kt | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/tools/src/main/java/org/videolan/tools/KotlinExtensions.kt b/tools/src/main/java/org/videolan/tools/KotlinExtensions.kt
index 29cda5004..b4f4d04ab 100644
--- a/tools/src/main/java/org/videolan/tools/KotlinExtensions.kt
+++ b/tools/src/main/java/org/videolan/tools/KotlinExtensions.kt
@@ -1,5 +1,6 @@
package org.videolan.tools
+import android.util.Patterns
import android.app.ActivityManager
import android.app.ActivityManager.RunningAppProcessInfo
import android.content.ClipData
@@ -11,6 +12,14 @@ import android.view.View
import androidx.annotation.AttrRes
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
+import androidx.lifecycle.OnLifecycleEvent
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.Job
+import kotlin.contracts.ExperimentalContracts
+import kotlin.contracts.contract
+import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.actor
@@ -82,4 +91,12 @@ suspend fun Context.awaitAppIsForegroung() : Boolean {
return activityManager.isAppForeground()
}
-private fun ActivityManager.isAppForeground() = runningAppProcesses[0].importance <= RunningAppProcessInfo.IMPORTANCE_FOREGROUND
\ No newline at end of file
+private fun ActivityManager.isAppForeground() = runningAppProcesses[0].importance <= RunningAppProcessInfo.IMPORTANCE_FOREGROUND
+
+ at UseExperimental(ExperimentalContracts::class)
+fun String?.isValidUrl() : Boolean {
+ contract {
+ returns(true) implies (this at isValidUrl != null)
+ }
+ return !isNullOrEmpty() && Patterns.WEB_URL.matcher(this).matches()
+}
\ No newline at end of file
More information about the Android
mailing list