aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-11-12 03:46:50 -0500
committerGitHub <noreply@github.com>2017-11-12 03:46:50 -0500
commit43cd1034b3319365db52d03efdfff333822c7335 (patch)
tree6e7e5d6c6198a632e11a2855a1022feefff7b666
parent637851b6ddc4a22583797a45bdbb72eb9c6dac23 (diff)
downloadkau-43cd1034b3319365db52d03efdfff333822c7335.tar.gz
kau-43cd1034b3319365db52d03efdfff333822c7335.tar.bz2
kau-43cd1034b3319365db52d03efdfff333822c7335.zip
misc (#102)
* Update gradle * Increment android libs and add progress animator * Null check on searchview unbind, fixes #100 * Add searchview holder interface * Rename methods
-rw-r--r--build.gradle2
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt85
-rw-r--r--gradle.properties2
-rw-r--r--sample/src/main/res/xml/kau_changelog.xml5
-rw-r--r--searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt2
-rw-r--r--searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchViewHolder.kt25
6 files changed, 117 insertions, 4 deletions
diff --git a/build.gradle b/build.gradle
index 5e83087..a0087d2 100644
--- a/build.gradle
+++ b/build.gradle
@@ -6,7 +6,7 @@ buildscript {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.0.0-rc1'
+ classpath 'com.android.tools.build:gradle:3.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${KOTLIN}"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
classpath 'com.github.triplet.gradle:play-publisher:1.2.0'
diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt
new file mode 100644
index 0000000..dc10e71
--- /dev/null
+++ b/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt
@@ -0,0 +1,85 @@
+package ca.allanwang.kau.ui
+
+import android.animation.Animator
+import android.animation.AnimatorListenerAdapter
+import android.animation.ValueAnimator
+import android.view.animation.Interpolator
+
+/**
+ * Created by Allan Wang on 2017-11-10.
+ *
+ * Wrapper for value animator specifically dealing with progress values
+ * This is typically a float range of 0 to 1, but can be customized
+ * This differs in that everything can be done with simple listeners, which will be bundled
+ * and added to the backing [ValueAnimator]
+ */
+class ProgressAnimator private constructor(private vararg val values: Float) {
+
+ companion object {
+ inline fun ofFloat(crossinline builder: ProgressAnimator.() -> Unit) = ofFloat(0f, 1f) { builder() }
+
+ fun ofFloat(vararg values: Float, builder: ProgressAnimator.() -> Unit) = ProgressAnimator(*values).apply {
+ builder()
+ build()
+ }
+ }
+
+ private val animators: MutableList<(Float) -> Unit> = mutableListOf()
+ private val startActions: MutableList<() -> Unit> = mutableListOf()
+ private val endActions: MutableList<() -> Unit> = mutableListOf()
+
+ var duration: Long = -1L
+ var interpolator: Interpolator? = null
+
+ /**
+ * Add more changes to the [ValueAnimator] before running
+ */
+ var extraConfigs: ValueAnimator.() -> Unit = {}
+
+ /**
+ * Range animator. Multiples the range by the current float progress before emission
+ */
+ fun withAnimator(from: Float, to: Float, animator: (Float) -> Unit) = animators.add {
+ val range = to - from
+ animator(range * it + from)
+ }
+
+ /**
+ * Standard animator. Emits progress value as is
+ */
+ fun withAnimator(animator: (Float) -> Unit) = animators.add(animator)
+
+ /**
+ * Start action to be called once when the animator first begins
+ */
+ fun withStartAction(action: () -> Unit) = startActions.add(action)
+
+ /**
+ * End action to be called once when the animator ends
+ */
+ fun withEndAction(action: () -> Unit) = endActions.add(action)
+
+ fun build() {
+ ValueAnimator.ofFloat(*values).apply {
+ if (this@ProgressAnimator.duration > 0L)
+ duration = this@ProgressAnimator.duration
+ if (this@ProgressAnimator.interpolator != null)
+ interpolator = this@ProgressAnimator.interpolator
+ addUpdateListener {
+ val progress = it.animatedValue as Float
+ animators.forEach { it(progress) }
+ }
+ addListener(object : AnimatorListenerAdapter() {
+ override fun onAnimationStart(animation: Animator?) {
+ startActions.forEach { it() }
+ }
+
+ override fun onAnimationEnd(animation: Animator?) {
+ endActions.forEach { it() }
+ }
+ })
+ extraConfigs()
+ start()
+ }
+ }
+} \ No newline at end of file
diff --git a/gradle.properties b/gradle.properties
index 4f368a8..36a4f12 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -21,7 +21,7 @@ CORE_MIN_SDK=19
MIN_SDK=21
TARGET_SDK=26
BUILD_TOOLS=26.0.2
-ANDROID_SUPPORT_LIBS=27.0.0
+ANDROID_SUPPORT_LIBS=27.0.1
VERSION_NAME=3.5.0.0
diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml
index 4718e09..48a2644 100644
--- a/sample/src/main/res/xml/kau_changelog.xml
+++ b/sample/src/main/res/xml/kau_changelog.xml
@@ -12,7 +12,10 @@
<item text="Add Italian translations" />
<item text="Clean up unnecessary build version support" />
<item text="Optimize and refactor old code" />
- <item text="Add helper methods to enhance FastAdapter for Kotlin" />
+ <item text=":adapter: Add helper methods to enhance FastAdapter for Kotlin" />
+ <item text=":core: Create ProgressAnimator class" />
+ <item text="" />
+ <item text="" />
<item text="" />
<version title="v3.4.5" />
diff --git a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt
index dabf4bc..50e0298 100644
--- a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt
+++ b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt
@@ -316,7 +316,7 @@ class SearchView @JvmOverloads constructor(
* with the option to replace the item click listener
*/
fun unBind(replacementMenuItemClickListener: ((item: MenuItem) -> Boolean)? = null) {
- parentViewGroup.removeView(this)
+ (parent as? ViewGroup)?.removeView(this)
menuItem?.setOnMenuItemClickListener(replacementMenuItemClickListener)
menuItem = null
}
diff --git a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchViewHolder.kt b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchViewHolder.kt
new file mode 100644
index 0000000..3f81dd0
--- /dev/null
+++ b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchViewHolder.kt
@@ -0,0 +1,25 @@
+package ca.allanwang.kau.searchview
+
+import android.view.MenuItem
+
+/**
+ * Created by Allan Wang on 2017-11-12.
+ *
+ * Interface to help facilitate searchview binding and actions
+ */
+interface SearchViewHolder {
+
+ var searchView: SearchView?
+
+ fun searchViewBindIfNull(binder: () -> SearchView) {
+ if (searchView == null) searchView = binder()
+ }
+
+ fun searchViewOnBackPress() = searchView?.onBackPressed() ?: false
+
+ fun searchViewUnBind(replacementMenuItemClickListener: ((item: MenuItem) -> Boolean)? = null) {
+ searchView?.unBind(replacementMenuItemClickListener)
+ searchView = null
+ }
+
+} \ No newline at end of file