Skip to content
Snippets Groups Projects
Commit 7d9f0a1b authored by Geoffrey Métais's avatar Geoffrey Métais Committed by Nicolas Pomepuy
Browse files

isValidUrl() String util function

parent 6187e9ea
No related branches found
No related tags found
1 merge request!128Stream clipboard
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
@UseExperimental(ExperimentalContracts::class)
fun String?.isValidUrl() : Boolean {
contract {
returns(true) implies (this@isValidUrl != null)
}
return !isNullOrEmpty() && Patterns.WEB_URL.matcher(this).matches()
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment