aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/ca/allanwang
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/kotlin/ca/allanwang')
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt2
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/kotlin/Zip.kt3
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt2
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeListener.kt2
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt2
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt21
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/FileUtils.kt1
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt3
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt9
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/TransitionUtils.kt12
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt1
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt60
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt3
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/xml/FAQ.kt3
14 files changed, 78 insertions, 46 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt b/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt
index 94a79ab..6576657 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt
@@ -60,7 +60,7 @@ class EmailBuilder(val email: String, val subject: String) {
.append("\nApp Version Name: ").append(appInfo.versionName)
.append("\nApp Version Code: ").append(appInfo.versionCode).append("\n")
} catch (e: PackageManager.NameNotFoundException) {
- KL.e{"EmailBuilder packageInfo not found"}
+ KL.e { "EmailBuilder packageInfo not found" }
}
}
diff --git a/core/src/main/kotlin/ca/allanwang/kau/kotlin/Zip.kt b/core/src/main/kotlin/ca/allanwang/kau/kotlin/Zip.kt
index cff520f..80cab09 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/kotlin/Zip.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/kotlin/Zip.kt
@@ -79,8 +79,7 @@ inline fun Collection<(ZipEmptyCallback) -> Unit>.zip(crossinline onFinished: ()
*/
inline fun Collection<() -> Unit>.zipAsync(crossinline onFinished: () -> Unit) {
map { synchronousFun ->
- {
- callback: ZipEmptyCallback ->
+ { callback: ZipEmptyCallback ->
doAsync {
synchronousFun()
callback()
diff --git a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt
index af5c59b..ff08e3c 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt
@@ -6,7 +6,7 @@ fun KPref.kprefSingle(key: String) = KPrefSingleDelegate(key, this)
/**
* Created by Allan Wang on 2017-06-07.
- *
+ *
* Singular KPref Delegate for booleans
* When the shared pref is not initialized, it will return true then set the pref to false
* All subsequent retrievals will be false
diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeListener.kt b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeListener.kt
index 36a4445..3ea62b5 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeListener.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeListener.kt
@@ -6,10 +6,12 @@ interface SwipeListener {
* Percent is capped at 1.0, even if there is a slight overscroll for the pages
*/
fun onScroll(percent: Float, px: Int, edgeFlag: Int)
+
/**
* Invoked when page first consumes the scroll events
*/
fun onEdgeTouch()
+
/**
* Invoked when scroll percent over the threshold for the first time
*/
diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt
index f587e60..86aba6e 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt
@@ -83,7 +83,7 @@ class RippleCanvas @JvmOverloads constructor(
if (callback != null)
animator.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationCancel(animation: Animator?) = callback()
- override fun onAnimationEnd(animation: Animator?) = callback()
+ override fun onAnimationEnd(animation: Animator?) = callback()
})
animator.start()
}
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 5cef0ac..a287cf2 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt
@@ -18,7 +18,8 @@ import android.widget.TextView
*/
@SuppressLint("NewApi")
-@KauUtils fun View.circularReveal(x: Int = 0, y: Int = 0, offset: Long = 0L, radius: Float = -1.0f, duration: Long = 500L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) {
+@KauUtils
+fun View.circularReveal(x: Int = 0, y: Int = 0, offset: Long = 0L, radius: Float = -1.0f, duration: Long = 500L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) {
if (!isAttachedToWindow) {
onStart?.invoke()
visible()
@@ -45,7 +46,8 @@ import android.widget.TextView
}
@SuppressLint("NewApi")
-@KauUtils fun View.circularHide(x: Int = 0, y: Int = 0, offset: Long = 0L, radius: Float = -1.0f, duration: Long = 500L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) {
+@KauUtils
+fun View.circularHide(x: Int = 0, y: Int = 0, offset: Long = 0L, radius: Float = -1.0f, duration: Long = 500L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) {
if (!isAttachedToWindow) {
onStart?.invoke()
invisible()
@@ -72,7 +74,8 @@ import android.widget.TextView
anim.start()
}
-@KauUtils fun View.fadeIn(offset: Long = 0L, duration: Long = 200L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) {
+@KauUtils
+fun View.fadeIn(offset: Long = 0L, duration: Long = 200L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) {
if (!isAttachedToWindow) {
onStart?.invoke()
visible()
@@ -93,7 +96,8 @@ import android.widget.TextView
startAnimation(anim)
}
-@KauUtils fun View.fadeOut(offset: Long = 0L, duration: Long = 200L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) {
+@KauUtils
+fun View.fadeOut(offset: Long = 0L, duration: Long = 200L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) {
if (!isAttachedToWindow) {
onStart?.invoke()
invisible()
@@ -117,13 +121,16 @@ import android.widget.TextView
startAnimation(anim)
}
-@KauUtils fun TextView.setTextWithFade(text: String, duration: Long = 200, onFinish: (() -> Unit)? = null) {
+@KauUtils
+fun TextView.setTextWithFade(text: String, duration: Long = 200, onFinish: (() -> Unit)? = null) {
fadeOut(duration = duration, onFinish = {
setText(text)
fadeIn(duration = duration, onFinish = onFinish)
})
}
-@KauUtils fun TextView.setTextWithFade(@StringRes textId: Int, duration: Long = 200, onFinish: (() -> Unit)? = null) = setTextWithFade(context.getString(textId), duration, onFinish)
+@KauUtils
+fun TextView.setTextWithFade(@StringRes textId: Int, duration: Long = 200, onFinish: (() -> Unit)? = null) = setTextWithFade(context.getString(textId), duration, onFinish)
-@KauUtils fun ViewPropertyAnimator.scaleXY(value: Float) = scaleX(value).scaleY(value) \ No newline at end of file
+@KauUtils
+fun ViewPropertyAnimator.scaleXY(value: Float) = scaleX(value).scaleY(value) \ No newline at end of file
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/FileUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/FileUtils.kt
index 65c28f7..b97f4aa 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/FileUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/FileUtils.kt
@@ -1,6 +1,5 @@
package ca.allanwang.kau.utils
-import android.os.Bundle
import java.io.File
import java.io.InputStream
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt
index 4c71945..a8c710e 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt
@@ -11,7 +11,8 @@ import com.mikepenz.iconics.typeface.IIcon
/**
* Created by Allan Wang on 2017-05-29.
*/
-@KauUtils fun IIcon.toDrawable(c: Context, sizeDp: Int = 24, @ColorInt color: Int = Color.WHITE, builder: IconicsDrawable.() -> Unit = {}): Drawable {
+@KauUtils
+fun IIcon.toDrawable(c: Context, sizeDp: Int = 24, @ColorInt color: Int = Color.WHITE, builder: IconicsDrawable.() -> Unit = {}): Drawable {
val state = ColorStateList.valueOf(color)
val icon = IconicsDrawable(c).icon(this).sizeDp(sizeDp).color(state)
icon.builder()
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt
index ebd7161..77750d3 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt
@@ -17,7 +17,8 @@ import android.provider.Settings
* @param packageName packageId
* @return true if installed with activity, false otherwise
*/
-@KauUtils fun Context.isAppInstalled(packageName: String): Boolean {
+@KauUtils
+fun Context.isAppInstalled(packageName: String): Boolean {
try {
packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
return true
@@ -26,7 +27,8 @@ import android.provider.Settings
}
}
-@KauUtils fun Context.isAppEnabled(packageName: String): Boolean {
+@KauUtils
+fun Context.isAppEnabled(packageName: String): Boolean {
try {
return packageManager.getApplicationInfo(packageName, 0).enabled
} catch (e: Exception) {
@@ -34,7 +36,8 @@ import android.provider.Settings
}
}
-@KauUtils fun Context.showAppInfo(packageName: String) {
+@KauUtils
+fun Context.showAppInfo(packageName: String) {
try {
//Open the specific App Info page:
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
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 1f4536b..ec206ee 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/TransitionUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/TransitionUtils.kt
@@ -23,7 +23,8 @@ class TransitionEndListener(val onEnd: (transition: Transition) -> Unit) : Trans
}
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
-@KauUtils fun Transition.addEndListener(onEnd: (transition: Transition) -> Unit) {
+@KauUtils
+fun Transition.addEndListener(onEnd: (transition: Transition) -> Unit) {
addListener(TransitionEndListener(onEnd))
}
@@ -37,18 +38,21 @@ class SupportTransitionEndListener(val onEnd: (transition: SupportTransition) ->
}
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
-@KauUtils fun SupportTransition.addEndListener(onEnd: (transition: SupportTransition) -> Unit) {
+@KauUtils
+fun SupportTransition.addEndListener(onEnd: (transition: SupportTransition) -> Unit) {
addListener(SupportTransitionEndListener(onEnd))
}
-@KauUtils fun ViewGroup.transitionAuto(builder: AutoTransition.() -> Unit = {}) {
+@KauUtils
+fun ViewGroup.transitionAuto(builder: AutoTransition.() -> Unit = {}) {
if (!buildIsLollipopAndUp) return
val transition = AutoTransition()
transition.builder()
TransitionManager.beginDelayedTransition(this, transition)
}
-@KauUtils fun ViewGroup.transitionDelayed(@TransitionRes id: Int, builder: android.support.transition.Transition.() -> Unit = {}) {
+@KauUtils
+fun ViewGroup.transitionDelayed(@TransitionRes id: Int, builder: android.support.transition.Transition.() -> Unit = {}) {
if (!buildIsLollipopAndUp) return
val transition = TransitionInflater.from(context).inflateTransition(id)
transition.builder()
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 8b32894..9a70ae7 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt
@@ -6,7 +6,6 @@ import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
-import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.support.annotation.IntRange
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt
index f6a541b..1946dbc 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt
@@ -72,11 +72,13 @@ fun View.snackbar(text: String, duration: Int = Snackbar.LENGTH_LONG, builder: S
fun View.snackbar(@StringRes textId: Int, duration: Int = Snackbar.LENGTH_LONG, builder: Snackbar.() -> Unit = {})
= snackbar(context.string(textId), duration, builder)
-@KauUtils fun TextView.setTextIfValid(@StringRes id: Int) {
+@KauUtils
+fun TextView.setTextIfValid(@StringRes id: Int) {
if (id > 0) text = context.string(id)
}
-@KauUtils fun ImageView.setIcon(icon: IIcon?, sizeDp: Int = 24, @ColorInt color: Int = Color.WHITE, builder: IconicsDrawable.() -> Unit = {}) {
+@KauUtils
+fun ImageView.setIcon(icon: IIcon?, sizeDp: Int = 24, @ColorInt color: Int = Color.WHITE, builder: IconicsDrawable.() -> Unit = {}) {
if (icon == null) return
setImageDrawable(icon.toDrawable(context, sizeDp = sizeDp, color = color, builder = builder))
}
@@ -87,42 +89,50 @@ fun FloatingActionButton.showIf(show: Boolean) = if (show) show() else hide()
fun FloatingActionButton.hideIf(hide: Boolean) = if (hide) hide() else show()
-@KauUtils fun ViewGroup.inflate(layoutId: Int, attachToRoot: Boolean = false): View = LayoutInflater.from(context).inflate(layoutId, this, attachToRoot)
+@KauUtils
+fun ViewGroup.inflate(layoutId: Int, attachToRoot: Boolean = false): View = LayoutInflater.from(context).inflate(layoutId, this, attachToRoot)
/**
* Set left margin to a value in px
*/
-@KauUtils fun View.setMarginLeft(margin: Int) = setMargins(margin, KAU_LEFT)
+@KauUtils
+fun View.setMarginLeft(margin: Int) = setMargins(margin, KAU_LEFT)
/**
* Set top margin to a value in px
*/
-@KauUtils fun View.setMarginTop(margin: Int) = setMargins(margin, KAU_TOP)
+@KauUtils
+fun View.setMarginTop(margin: Int) = setMargins(margin, KAU_TOP)
/**
* Set right margin to a value in px
*/
-@KauUtils fun View.setMarginRight(margin: Int) = setMargins(margin, KAU_RIGHT)
+@KauUtils
+fun View.setMarginRight(margin: Int) = setMargins(margin, KAU_RIGHT)
/**
* Set bottom margin to a value in px
*/
-@KauUtils fun View.setMarginBottom(margin: Int) = setMargins(margin, KAU_BOTTOM)
+@KauUtils
+fun View.setMarginBottom(margin: Int) = setMargins(margin, KAU_BOTTOM)
/**
* Set left and right margins to a value in px
*/
-@KauUtils fun View.setMarginHorizontal(margin: Int) = setMargins(margin, KAU_HORIZONTAL)
+@KauUtils
+fun View.setMarginHorizontal(margin: Int) = setMargins(margin, KAU_HORIZONTAL)
/**
* Set top and bottom margins to a value in px
*/
-@KauUtils fun View.setMarginVertical(margin: Int) = setMargins(margin, KAU_VERTICAL)
+@KauUtils
+fun View.setMarginVertical(margin: Int) = setMargins(margin, KAU_VERTICAL)
/**
* Set all margins to a value in px
*/
-@KauUtils fun View.setMargin(margin: Int) = setMargins(margin, KAU_ALL)
+@KauUtils
+fun View.setMargin(margin: Int) = setMargins(margin, KAU_ALL)
/**
* Base margin setter
@@ -142,37 +152,44 @@ fun FloatingActionButton.hideIf(hide: Boolean) = if (hide) hide() else show()
/**
* Set left padding to a value in px
*/
-@KauUtils fun View.setPaddingLeft(padding: Int) = setPadding(padding, KAU_LEFT)
+@KauUtils
+fun View.setPaddingLeft(padding: Int) = setPadding(padding, KAU_LEFT)
/**
* Set top padding to a value in px
*/
-@KauUtils fun View.setPaddingTop(padding: Int) = setPadding(padding, KAU_TOP)
+@KauUtils
+fun View.setPaddingTop(padding: Int) = setPadding(padding, KAU_TOP)
/**
* Set right padding to a value in px
*/
-@KauUtils fun View.setPaddingRight(padding: Int) = setPadding(padding, KAU_RIGHT)
+@KauUtils
+fun View.setPaddingRight(padding: Int) = setPadding(padding, KAU_RIGHT)
/**
* Set bottom padding to a value in px
*/
-@KauUtils fun View.setPaddingBottom(padding: Int) = setPadding(padding, KAU_BOTTOM)
+@KauUtils
+fun View.setPaddingBottom(padding: Int) = setPadding(padding, KAU_BOTTOM)
/**
* Set left and right padding to a value in px
*/
-@KauUtils fun View.setPaddingHorizontal(padding: Int) = setPadding(padding, KAU_HORIZONTAL)
+@KauUtils
+fun View.setPaddingHorizontal(padding: Int) = setPadding(padding, KAU_HORIZONTAL)
/**
* Set top and bottom padding to a value in px
*/
-@KauUtils fun View.setPaddingVertical(padding: Int) = setPadding(padding, KAU_VERTICAL)
+@KauUtils
+fun View.setPaddingVertical(padding: Int) = setPadding(padding, KAU_VERTICAL)
/**
* Set all padding to a value in px
*/
-@KauUtils fun View.setPadding(padding: Int) = setPadding(padding, KAU_ALL)
+@KauUtils
+fun View.setPadding(padding: Int) = setPadding(padding, KAU_ALL)
/**
* Base padding setter
@@ -186,19 +203,22 @@ fun FloatingActionButton.hideIf(hide: Boolean) = if (hide) hide() else show()
)
}
-@KauUtils fun View.hideKeyboard() {
+@KauUtils
+fun View.hideKeyboard() {
clearFocus()
(context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).hideSoftInputFromWindow(windowToken, 0)
}
-@KauUtils fun View.showKeyboard() {
+@KauUtils
+fun View.showKeyboard() {
requestFocus()
(context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).showSoftInput(this, InputMethodManager.SHOW_IMPLICIT)
}
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
-@KauUtils fun View.setRippleBackground(@ColorInt foregroundColor: Int, @ColorInt backgroundColor: Int) {
+@KauUtils
+fun View.setRippleBackground(@ColorInt foregroundColor: Int, @ColorInt backgroundColor: Int) {
background = createSimpleRippleDrawable(foregroundColor, backgroundColor)
}
diff --git a/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt b/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt
index 58f1ccc..cbebd55 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt
@@ -70,8 +70,7 @@ internal class ChangelogAdapter(val items: List<Pair<String, ChangelogType>>, @C
internal fun parse(context: Context, @XmlRes xmlRes: Int): List<Pair<String, ChangelogType>> {
val items = mutableListOf<Pair<String, ChangelogType>>()
- context.resources.getXml(xmlRes).use {
- parser: XmlResourceParser ->
+ context.resources.getXml(xmlRes).use { parser: XmlResourceParser ->
var eventType = parser.eventType
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG)
diff --git a/core/src/main/kotlin/ca/allanwang/kau/xml/FAQ.kt b/core/src/main/kotlin/ca/allanwang/kau/xml/FAQ.kt
index 07a0287..f804b70 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/xml/FAQ.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/xml/FAQ.kt
@@ -28,8 +28,7 @@ fun Context.kauParseFaq(
callback: (items: List<FaqItem>) -> Unit) {
doAsync {
val items = mutableListOf<FaqItem>()
- resources.getXml(xmlRes).use {
- parser: XmlResourceParser ->
+ resources.getXml(xmlRes).use { parser: XmlResourceParser ->
var eventType = parser.eventType
var question: Spanned? = null
var flag = -1 //-1, 0, 1 -> invalid, question, answer