|
@@ -4,6 +4,7 @@ import android.animation.ObjectAnimator
|
|
|
import android.app.Activity
|
|
import android.app.Activity
|
|
|
import android.content.Context
|
|
import android.content.Context
|
|
|
import android.content.Intent
|
|
import android.content.Intent
|
|
|
|
|
+import android.net.Uri
|
|
|
import android.support.annotation.IdRes
|
|
import android.support.annotation.IdRes
|
|
|
import android.support.annotation.LayoutRes
|
|
import android.support.annotation.LayoutRes
|
|
|
import android.support.annotation.StringRes
|
|
import android.support.annotation.StringRes
|
|
@@ -25,6 +26,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers
|
|
|
import io.reactivex.schedulers.Schedulers
|
|
import io.reactivex.schedulers.Schedulers
|
|
|
|
|
|
|
|
private const val TAG = "Knigopis"
|
|
private const val TAG = "Knigopis"
|
|
|
|
|
+private val HTTP_SCHEMES = setOf("http", "https")
|
|
|
|
|
|
|
|
fun Context.startActivityOrElse(intent: Intent, onError: () -> Unit) {
|
|
fun Context.startActivityOrElse(intent: Intent, onError: () -> Unit) {
|
|
|
if (packageManager.resolveActivity(intent, 0) == null) {
|
|
if (packageManager.resolveActivity(intent, 0) == null) {
|
|
@@ -110,4 +112,10 @@ fun Activity.hideKeyboard() {
|
|
|
(getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager)
|
|
(getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager)
|
|
|
.hideSoftInputFromWindow(view.windowToken, 0)
|
|
.hideSoftInputFromWindow(view.windowToken, 0)
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+fun String.toUriOrNull() =
|
|
|
|
|
+ Uri.parse(this).takeIf(Uri::isValidHttpLink)
|
|
|
|
|
+
|
|
|
|
|
+private fun Uri.isValidHttpLink() =
|
|
|
|
|
+ scheme in HTTP_SCHEMES && !host.isNullOrBlank()
|