aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/ca/allanwang/kau
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/kotlin/ca/allanwang/kau')
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/internal/KauBaseActivity.kt2
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt20
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/swipe/RelativeSlider.kt20
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt11
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/BundleUtils.kt9
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt8
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt30
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/CoroutineUtils.kt4
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt4
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/TransitionUtils.kt2
10 files changed, 63 insertions, 47 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/internal/KauBaseActivity.kt b/core/src/main/kotlin/ca/allanwang/kau/internal/KauBaseActivity.kt
index 6fb8f1f..cb8f4bf 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/internal/KauBaseActivity.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/internal/KauBaseActivity.kt
@@ -19,10 +19,10 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import ca.allanwang.kau.permissions.kauOnRequestPermissionsResult
import ca.allanwang.kau.utils.ContextHelper
-import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
+import kotlin.coroutines.CoroutineContext
/**
* Created by Allan Wang on 2017-08-01.
diff --git a/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt b/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt
index a9a97b7..1475720 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt
@@ -113,14 +113,18 @@ class KauLoggerExtension(val tag: String, val logger: KauLogger) {
}
inline fun log(priority: Int, message: () -> Any?, t: Throwable? = null) =
- logger.log(priority, {
- val msg = message()?.toString()
- if (msg == null) {
- null
- } else {
- "$tag: $msg"
- }
- }, t)
+ logger.log(
+ priority,
+ {
+ val msg = message()?.toString()
+ if (msg == null) {
+ null
+ } else {
+ "$tag: $msg"
+ }
+ },
+ t
+ )
inline fun checkThread(id: Int) {
d {
diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/RelativeSlider.kt b/core/src/main/kotlin/ca/allanwang/kau/swipe/RelativeSlider.kt
index e3baa94..78bf253 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/swipe/RelativeSlider.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/RelativeSlider.kt
@@ -48,14 +48,18 @@ internal class RelativeSlider(var curPage: SwipeBackPage) : SwipeListener {
return
}
when (edgeFlag) {
- SWIPE_EDGE_LEFT -> page.swipeBackLayout.x =
- min(-offset * max(1 - percent, 0f) + DEFAULT_OFFSET, 0f)
- SWIPE_EDGE_RIGHT -> page.swipeBackLayout.x =
- min(offset * max(1 - percent, 0f) - DEFAULT_OFFSET, 0f)
- SWIPE_EDGE_TOP -> page.swipeBackLayout.y =
- min(-offset * max(1 - percent, 0f) + DEFAULT_OFFSET, 0f)
- SWIPE_EDGE_BOTTOM -> page.swipeBackLayout.y =
- min(offset * max(1 - percent, 0f) - DEFAULT_OFFSET, 0f)
+ SWIPE_EDGE_LEFT ->
+ page.swipeBackLayout.x =
+ min(-offset * max(1 - percent, 0f) + DEFAULT_OFFSET, 0f)
+ SWIPE_EDGE_RIGHT ->
+ page.swipeBackLayout.x =
+ min(offset * max(1 - percent, 0f) - DEFAULT_OFFSET, 0f)
+ SWIPE_EDGE_TOP ->
+ page.swipeBackLayout.y =
+ min(-offset * max(1 - percent, 0f) + DEFAULT_OFFSET, 0f)
+ SWIPE_EDGE_BOTTOM ->
+ page.swipeBackLayout.y =
+ min(offset * max(1 - percent, 0f) - DEFAULT_OFFSET, 0f)
}
}
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt
index c8c8b34..0c1475a 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt
@@ -166,10 +166,13 @@ fun View.fadeOut(
@KauUtils
fun TextView.setTextWithFade(text: String, duration: Long = 200, onFinish: (() -> Unit)? = null) {
- fadeOut(duration = duration, onFinish = {
- setText(text)
- fadeIn(duration = duration, onFinish = onFinish)
- })
+ fadeOut(
+ duration = duration,
+ onFinish = {
+ setText(text)
+ fadeIn(duration = duration, onFinish = onFinish)
+ }
+ )
}
@KauUtils
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/BundleUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/BundleUtils.kt
index b857eb0..6dab5cf 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/BundleUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/BundleUtils.kt
@@ -93,9 +93,12 @@ fun bundleOf(vararg params: kotlin.Pair<String, Any?>): Bundle {
* create a scene transition animation
*/
fun Bundle.withSceneTransitionAnimation(parent: View, data: Map<Int, String>) =
- withSceneTransitionAnimation(parent.context, data.mapKeys { (id, _) ->
- parent.findViewById<View>(id)
- })
+ withSceneTransitionAnimation(
+ parent.context,
+ data.mapKeys { (id, _) ->
+ parent.findViewById<View>(id)
+ }
+ )
/**
* Given a mapping of views to tags,
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt
index 0131302..29c0919 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt
@@ -89,9 +89,11 @@ fun Int.isColorVisibleOn(
@IntRange(from = 0L, to = 255L) minAlpha: Int = 50
): Boolean =
if (Color.alpha(this) < minAlpha) false
- else !(abs(Color.red(this) - Color.red(color)) < delta &&
- abs(Color.green(this) - Color.green(color)) < delta &&
- abs(Color.blue(this) - Color.blue(color)) < delta)
+ else !(
+ abs(Color.red(this) - Color.red(color)) < delta &&
+ abs(Color.green(this) - Color.green(color)) < delta &&
+ abs(Color.blue(this) - Color.blue(color)) < delta
+ )
@ColorInt
fun Context.getDisabledColor(): Int {
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 7d4a934..e797cfc 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
@@ -57,9 +57,9 @@ inline fun <reified T : Activity> Context.startActivity(
) = startActivity(T::class.java, clearStack, bundleBuilder, intentBuilder)
@Deprecated(
- "Use reified generic instead of passing class",
- ReplaceWith("startActivity<T>(clearStack, bundleBuilder, intentBuilder)"),
- DeprecationLevel.WARNING
+ "Use reified generic instead of passing class",
+ ReplaceWith("startActivity<T>(clearStack, bundleBuilder, intentBuilder)"),
+ DeprecationLevel.WARNING
)
inline fun <T : Activity> Context.startActivity(
clazz: Class<T>,
@@ -120,13 +120,13 @@ fun Context.startLink(@StringRes url: Int): Boolean = startLink(string(url))
// Toast helpers
inline fun View.toast(@StringRes id: Int, duration: Int = Toast.LENGTH_LONG, log: Boolean = false) =
- context.toast(id, duration, log)
+ context.toast(id, duration, log)
inline fun Context.toast(@StringRes id: Int, duration: Int = Toast.LENGTH_LONG, log: Boolean = false) =
- toast(this.string(id), duration, log)
+ toast(this.string(id), duration, log)
inline fun View.toast(text: String, duration: Int = Toast.LENGTH_LONG, log: Boolean = false) =
- context.toast(text, duration, log)
+ context.toast(text, duration, log)
inline fun Context.toast(text: String, duration: Int = Toast.LENGTH_LONG, log: Boolean = false) {
Toast.makeText(this, text, duration).show()
@@ -139,10 +139,10 @@ const val INVALID_ID = 0
inline fun Context.string(@StringRes id: Int): String = getString(id)
inline fun Context.string(@StringRes id: Int, fallback: String?): String? =
- if (id != INVALID_ID) string(id) else fallback
+ if (id != INVALID_ID) string(id) else fallback
inline fun Context.string(@StringRes id: Int, fallback: () -> String?): String? =
- if (id != INVALID_ID) string(id) else fallback()
+ if (id != INVALID_ID) string(id) else fallback()
inline fun Context.color(@ColorRes id: Int): Int = ContextCompat.getColor(this, id)
inline fun Context.boolean(@BoolRes id: Int): Boolean = resources.getBoolean(id)
@@ -150,13 +150,13 @@ inline fun Context.integer(@IntegerRes id: Int): Int = resources.getInteger(id)
inline fun Context.dimen(@DimenRes id: Int): Float = resources.getDimension(id)
inline fun Context.dimenPixelSize(@DimenRes id: Int): Int = resources.getDimensionPixelSize(id)
inline fun Context.drawable(@DrawableRes id: Int): Drawable = ContextCompat.getDrawable(this, id)
- ?: throw KauException("Drawable with id $id not found")
+ ?: throw KauException("Drawable with id $id not found")
inline fun Context.drawable(@DrawableRes id: Int, fallback: Drawable?): Drawable? =
- if (id != INVALID_ID) drawable(id) else fallback
+ if (id != INVALID_ID) drawable(id) else fallback
inline fun Context.drawable(@DrawableRes id: Int, fallback: () -> Drawable?): Drawable? =
- if (id != INVALID_ID) drawable(id) else fallback()
+ if (id != INVALID_ID) drawable(id) else fallback()
inline fun Context.interpolator(@InterpolatorRes id: Int) = AnimationUtils.loadInterpolator(this, id)!!
inline fun Context.animation(@AnimRes id: Int) = AnimationUtils.loadAnimation(this, id)!!
@@ -165,7 +165,7 @@ inline fun Context.animation(@AnimRes id: Int) = AnimationUtils.loadAnimation(th
* Returns plural form of res. The quantity is also passed to the formatter as an int
*/
inline fun Context.plural(@PluralsRes id: Int, quantity: Number) =
- resources.getQuantityString(id, quantity.toInt(), quantity.toInt())
+ resources.getQuantityString(id, quantity.toInt(), quantity.toInt())
// Attr retrievers
fun Context.resolveColor(@AttrRes attr: Int, @ColorInt fallback: Int = 0): Int {
@@ -221,7 +221,7 @@ inline fun Context.materialDialog(
}
fun Context.getDip(value: Float): Float =
- TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, resources.displayMetrics)
+ TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, resources.displayMetrics)
inline val Context.isRtl: Boolean
get() = resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_RTL
@@ -239,8 +239,8 @@ inline val Context.isNavBarOnBottom: Boolean
}
fun Context.hasPermission(permissions: String) = !buildIsMarshmallowAndUp || ContextCompat.checkSelfPermission(
- this,
- permissions
+ this,
+ permissions
) == PackageManager.PERMISSION_GRANTED
fun Context.copyToClipboard(text: String?, label: String = "Copied Text", showToast: Boolean = true) {
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/CoroutineUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/CoroutineUtils.kt
index 741f4e2..4d6ee54 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/CoroutineUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/CoroutineUtils.kt
@@ -19,14 +19,14 @@ import android.content.Context
import android.os.Handler
import android.os.Looper
import ca.allanwang.kau.internal.KauBaseActivity
-import kotlin.coroutines.CoroutineContext
-import kotlin.coroutines.EmptyCoroutineContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.android.asCoroutineDispatcher
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
+import kotlin.coroutines.CoroutineContext
+import kotlin.coroutines.EmptyCoroutineContext
object ContextHelper : CoroutineScope {
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt
index 7c3e3cb..fac9421 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt
@@ -34,14 +34,14 @@ import android.app.Dialog
import android.app.DialogFragment
import android.app.Fragment
import android.view.View
-import androidx.fragment.app.DialogFragment as SupportDialogFragment
-import androidx.fragment.app.Fragment as SupportFragment
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import java.util.Collections
import java.util.WeakHashMap
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
+import androidx.fragment.app.DialogFragment as SupportDialogFragment
+import androidx.fragment.app.Fragment as SupportFragment
fun <V : View> View.bindView(id: Int): ReadOnlyProperty<View, V> = required(id, viewFinder)
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/TransitionUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/TransitionUtils.kt
index 3e4a26a..523a586 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/TransitionUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/TransitionUtils.kt
@@ -21,9 +21,9 @@ import android.view.ViewGroup
import androidx.annotation.RequiresApi
import androidx.annotation.TransitionRes
import androidx.transition.AutoTransition
-import androidx.transition.Transition as SupportTransition
import androidx.transition.TransitionInflater
import androidx.transition.TransitionManager
+import androidx.transition.Transition as SupportTransition
/**
* Created by Allan Wang on 2017-06-24.