diff options
author | Allan Wang <me@allanwang.ca> | 2018-09-09 11:59:24 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-09 11:59:24 -0400 |
commit | d540934915da26ab2cec4c897e973be35e0bfe24 (patch) | |
tree | 6f114d080c168381266a0d5d3a40b685e28b8e9a /core/src/main/kotlin | |
parent | 718a51ed00a0a5c3dc7a655e617308e82da65d1a (diff) | |
download | kau-d540934915da26ab2cec4c897e973be35e0bfe24.tar.gz kau-d540934915da26ab2cec4c897e973be35e0bfe24.tar.bz2 kau-d540934915da26ab2cec4c897e973be35e0bfe24.zip |
Clean up kotterknife (#161)
* Remove bindview implementations internally
* Remove more bindView calls
* Make config private in ElasticRecyclerActivity
* Fix recyclerview
* Update adapter
* Improve swipe destroy and add direction to swipe finish
Diffstat (limited to 'core/src/main/kotlin')
5 files changed, 81 insertions, 57 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt index 4bc216d..41cd2e0 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt @@ -33,7 +33,7 @@ internal object SwipeBackHelper { } fun onDestroy(activity: Activity) { - val page: SwipeBackPage? = this[activity] + val page: SwipeBackPage? = this[activity] ?: return pageStack.kauRemoveIf { it.activityRef.get() == null || it === page } page?.activityRef?.clear() KL.v { "KauSwipe onDestroy ${activity.localClassName}" } diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt index ae09c8a..a323e6c 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt @@ -207,9 +207,16 @@ internal class SwipeBackLayout @JvmOverloads constructor(context: Context, attrs override fun scrollToFinishActivity() { val contentView = contentViewRef.get() ?: return KL.e { "KauSwipe cannot scroll to finish as contentView is null. Is onPostCreate called?" } - val childWidth = contentView.width - val top = 0 - val left = childWidth + OVERSCROLL_DISTANCE + val swipeWidth = contentView.width + OVERSCROLL_DISTANCE + val swipeHeight = contentView.height + OVERSCROLL_DISTANCE + var top = 0 + var left = 0 + when (edgeFlag) { + SWIPE_EDGE_LEFT -> left = swipeWidth + SWIPE_EDGE_TOP -> top = swipeHeight + SWIPE_EDGE_RIGHT -> left = -swipeWidth + SWIPE_EDGE_BOTTOM -> top = -swipeHeight + } dragHelper.smoothSlideViewTo(contentView, left, top) invalidate() } 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 fdee4d8..6568bf2 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt @@ -118,7 +118,7 @@ inline fun Context.animation(@AnimRes id: Int) = AnimationUtils.loadAnimation(th inline fun Context.plural(@PluralsRes id: Int, quantity: Number) = resources.getQuantityString(id, quantity.toInt(), quantity.toInt())!! //Attr retrievers -fun Context.resolveColor(@AttrRes attr: Int, fallback: Int = 0): Int { +fun Context.resolveColor(@AttrRes attr: Int, @ColorInt fallback: Int = 0): Int { val a = theme.obtainStyledAttributes(intArrayOf(attr)) try { return a.getColor(0, fallback) 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 b0448d1..8c7c039 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt @@ -21,147 +21,133 @@ import kotlin.reflect.KProperty import android.support.v4.app.DialogFragment as SupportDialogFragment import android.support.v4.app.Fragment as SupportFragment +private const val DEPRECATION_MESSAGE = "Kotterknife will be removed in favour of the kotlin_android_extensions plugin" + +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> View.bindView(id: Int) : ReadOnlyProperty<View, V> = required(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Activity.bindView(id: Int) : ReadOnlyProperty<Activity, V> = required(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Dialog.bindView(id: Int) : ReadOnlyProperty<Dialog, V> = required(id, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindViewResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindViewResettable<V>(id)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> DialogFragment.bindView(id: Int) : ReadOnlyProperty<DialogFragment, V> = required(id, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindViewResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindViewResettable<V>(id)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportDialogFragment.bindView(id: Int) : ReadOnlyProperty<android.support.v4.app.DialogFragment, V> = required(id, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindViewResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindViewResettable<V>(id)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Fragment.bindView(id: Int) : ReadOnlyProperty<Fragment, V> = required(id, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindViewResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindViewResettable<V>(id)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportFragment.bindView(id: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, V> = required(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> ViewHolder.bindView(id: Int) : ReadOnlyProperty<ViewHolder, V> = required(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> View.bindOptionalView(id: Int) : ReadOnlyProperty<View, V?> = optional(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Activity.bindOptionalView(id: Int) : ReadOnlyProperty<Activity, V?> = optional(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Dialog.bindOptionalView(id: Int) : ReadOnlyProperty<Dialog, V?> = optional(id, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindOptionalViewResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindOptionalViewResettable<V>(id)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> DialogFragment.bindOptionalView(id: Int) : ReadOnlyProperty<DialogFragment, V?> = optional(id, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindOptionalViewResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindOptionalViewResettable<V>(id)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportDialogFragment.bindOptionalView(id: Int) : ReadOnlyProperty<android.support.v4.app.DialogFragment, V?> = optional(id, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindOptionalViewResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindOptionalViewResettable<V>(id)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Fragment.bindOptionalView(id: Int) : ReadOnlyProperty<Fragment, V?> = optional(id, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindOptionalViewResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindOptionalViewResettable<V>(id)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportFragment.bindOptionalView(id: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, V?> = optional(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> ViewHolder.bindOptionalView(id: Int) : ReadOnlyProperty<ViewHolder, V?> = optional(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> View.bindViews(vararg ids: Int) : ReadOnlyProperty<View, List<V>> = required(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Activity.bindViews(vararg ids: Int) : ReadOnlyProperty<Activity, List<V>> = required(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Dialog.bindViews(vararg ids: Int) : ReadOnlyProperty<Dialog, List<V>> = required(ids, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindViewsResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindViewsResettable<V>(*ids)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> DialogFragment.bindViews(vararg ids: Int) : ReadOnlyProperty<DialogFragment, List<V>> = required(ids, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindViewsResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindViewsResettable<V>(*ids)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportDialogFragment.bindViews(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.DialogFragment, List<V>> = required(ids, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindViewsResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindViewsResettable<V>(*ids)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Fragment.bindViews(vararg ids: Int) : ReadOnlyProperty<Fragment, List<V>> = required(ids, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindViewsResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindViewsResettable<V>(*ids)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportFragment.bindViews(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, List<V>> = required(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> ViewHolder.bindViews(vararg ids: Int) : ReadOnlyProperty<ViewHolder, List<V>> = required(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> View.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<View, List<V>> = optional(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Activity.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<Activity, List<V>> = optional(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Dialog.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<Dialog, List<V>> = optional(ids, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindOptionalViewsResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindOptionalViewsResettable<V>(*ids)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> DialogFragment.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<DialogFragment, List<V>> = optional(ids, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindOptionalViewsResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindOptionalViewsResettable<V>(*ids)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportDialogFragment.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.DialogFragment, List<V>> = optional(ids, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindOptionalViewsResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindOptionalViewsResettable<V>(*ids)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Fragment.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<Fragment, List<V>> = optional(ids, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindOptionalViewsResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindOptionalViewsResettable<V>(*ids)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportFragment.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, List<V>> = optional(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> ViewHolder.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<ViewHolder, List<V>> = optional(ids, viewFinder) @@ -223,99 +209,131 @@ private open class Lazy<in T, out V>(private val initializer: (T, KProperty<*>) * Credits to <a href="https://github.com/MichaelRocks">MichaelRocks</a> */ +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> View.bindViewResettable(id: Int) : ReadOnlyProperty<View, V> = requiredResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Activity.bindViewResettable(id: Int) : ReadOnlyProperty<Activity, V> = requiredResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Dialog.bindViewResettable(id: Int) : ReadOnlyProperty<Dialog, V> = requiredResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> DialogFragment.bindViewResettable(id: Int) : ReadOnlyProperty<DialogFragment, V> = requiredResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportDialogFragment.bindViewResettable(id: Int) : ReadOnlyProperty<android.support.v4.app.DialogFragment, V> = requiredResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Fragment.bindViewResettable(id: Int) : ReadOnlyProperty<Fragment, V> = requiredResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportFragment.bindViewResettable(id: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, V> = requiredResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> ViewHolder.bindViewResettable(id: Int) : ReadOnlyProperty<ViewHolder, V> = requiredResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> View.bindOptionalViewResettable(id: Int) : ReadOnlyProperty<View, V?> = optionalResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Activity.bindOptionalViewResettable(id: Int) : ReadOnlyProperty<Activity, V?> = optionalResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Dialog.bindOptionalViewResettable(id: Int) : ReadOnlyProperty<Dialog, V?> = optionalResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> DialogFragment.bindOptionalViewResettable(id: Int) : ReadOnlyProperty<DialogFragment, V?> = optionalResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportDialogFragment.bindOptionalViewResettable(id: Int) : ReadOnlyProperty<android.support.v4.app.DialogFragment, V?> = optionalResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Fragment.bindOptionalViewResettable(id: Int) : ReadOnlyProperty<Fragment, V?> = optionalResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportFragment.bindOptionalViewResettable(id: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, V?> = optionalResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> ViewHolder.bindOptionalViewResettable(id: Int) : ReadOnlyProperty<ViewHolder, V?> = optionalResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> View.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty<View, List<V>> = requiredResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Activity.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty<Activity, List<V>> = requiredResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Dialog.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty<Dialog, List<V>> = requiredResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> DialogFragment.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty<DialogFragment, List<V>> = requiredResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportDialogFragment.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.DialogFragment, List<V>> = requiredResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Fragment.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty<Fragment, List<V>> = requiredResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportFragment.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, List<V>> = requiredResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> ViewHolder.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty<ViewHolder, List<V>> = requiredResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> View.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty<View, List<V>> = optionalResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Activity.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty<Activity, List<V>> = optionalResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Dialog.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty<Dialog, List<V>> = optionalResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> DialogFragment.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty<DialogFragment, List<V>> = optionalResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportDialogFragment.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.DialogFragment, List<V>> = optionalResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Fragment.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty<Fragment, List<V>> = optionalResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportFragment.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, List<V>> = optionalResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> ViewHolder.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty<ViewHolder, List<V>> = optionalResettable(ids, viewFinder) @@ -345,6 +363,7 @@ private class LazyResettable<in T, out V>(initializer: (T, KProperty<*>) -> V) : } } +@Deprecated(DEPRECATION_MESSAGE) object Kotterknife { fun reset(target: Any) { KotterknifeRegistry.reset(target) 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 83b182f..28d51a4 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt @@ -11,8 +11,6 @@ import android.view.View import android.view.ViewGroup import android.widget.TextView import ca.allanwang.kau.R -import ca.allanwang.kau.utils.bindOptionalView -import ca.allanwang.kau.utils.bindView import ca.allanwang.kau.utils.materialDialog import ca.allanwang.kau.utils.use import com.afollestad.materialdialogs.MaterialDialog @@ -64,8 +62,8 @@ internal class ChangelogAdapter(val items: List<Pair<String, ChangelogType>>, @C override fun getItemCount() = items.size internal class ChangelogVH(itemView: View) : RecyclerView.ViewHolder(itemView) { - val text: TextView by bindView(R.id.kau_changelog_text) - val bullet: TextView? by bindOptionalView(R.id.kau_changelog_bullet) + val text: TextView = itemView.findViewById(R.id.kau_changelog_text) + val bullet: TextView? = itemView.findViewById(R.id.kau_changelog_bullet) } } |