From 222709bc15ace77ebf03e5a8e17e0bf026520970 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 24 Oct 2021 17:45:09 -0700 Subject: Many version bumps --- .../kotlin/ca/allanwang/kau/utils/AnimUtils.kt | 11 +++++--- .../kotlin/ca/allanwang/kau/utils/BundleUtils.kt | 9 ++++--- .../kotlin/ca/allanwang/kau/utils/ColorUtils.kt | 8 +++--- .../kotlin/ca/allanwang/kau/utils/ContextUtils.kt | 30 +++++++++++----------- .../ca/allanwang/kau/utils/CoroutineUtils.kt | 4 +-- .../kotlin/ca/allanwang/kau/utils/Kotterknife.kt | 4 +-- .../ca/allanwang/kau/utils/TransitionUtils.kt | 2 +- 7 files changed, 38 insertions(+), 30 deletions(-) (limited to 'core/src/main/kotlin/ca/allanwang/kau/utils') 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): Bundle { * create a scene transition animation */ fun Bundle.withSceneTransitionAnimation(parent: View, data: Map) = - withSceneTransitionAnimation(parent.context, data.mapKeys { (id, _) -> - parent.findViewById(id) - }) + withSceneTransitionAnimation( + parent.context, + data.mapKeys { (id, _) -> + parent.findViewById(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 Context.startActivity( ) = startActivity(T::class.java, clearStack, bundleBuilder, intentBuilder) @Deprecated( - "Use reified generic instead of passing class", - ReplaceWith("startActivity(clearStack, bundleBuilder, intentBuilder)"), - DeprecationLevel.WARNING + "Use reified generic instead of passing class", + ReplaceWith("startActivity(clearStack, bundleBuilder, intentBuilder)"), + DeprecationLevel.WARNING ) inline fun Context.startActivity( clazz: Class, @@ -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 View.bindView(id: Int): ReadOnlyProperty = 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. -- cgit v1.2.3