From 5c45c832df044c400a76abad16a000a59d0bf54c Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 12 Aug 2017 23:07:10 -0700 Subject: Add more functions --- core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt | 5 +++++ core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt | 4 ++++ 2 files changed, 9 insertions(+) (limited to 'core') diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt index 20cec73..d561c8a 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt @@ -90,6 +90,11 @@ fun Context.startLink(vararg url: String?) { startActivity(browserIntent) } +fun Context.startLink(@StringRes url: Int) { + val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(string(url))) + startActivity(browserIntent) +} + //Toast helpers inline fun View.toast(@StringRes id: Int, duration: Int = Toast.LENGTH_LONG) = context.toast(id, duration) diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt index 9e0ad75..cdb49ea 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt @@ -7,6 +7,7 @@ import android.graphics.Canvas import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.os.Handler +import android.os.Looper import android.support.annotation.IntRange import ca.allanwang.kau.R import java.math.RoundingMode @@ -114,4 +115,7 @@ fun postDelayed(delay: Long, action: () -> Unit) { Handler().postDelayed(action, delay) } +inline val kauIsMainThread: Boolean + get() = Looper.myLooper() == Looper.getMainLooper() + class KauException(message: String) : RuntimeException(message) \ No newline at end of file -- cgit v1.2.3