diff options
author | Allan Wang <me@allanwang.ca> | 2018-04-07 20:23:17 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-07 20:23:17 -0400 |
commit | a0377be622f21b4c6a7d8828505c1e95efab1254 (patch) | |
tree | 825760fab6f0bb1baa4e709443becefba5a8d06a /core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt | |
parent | e97db5c6529b1e12effc7141f277bd41d3fb580a (diff) | |
download | kau-a0377be622f21b4c6a7d8828505c1e95efab1254.tar.gz kau-a0377be622f21b4c6a7d8828505c1e95efab1254.tar.bz2 kau-a0377be622f21b4c6a7d8828505c1e95efab1254.zip |
Update/android studio 3.1 (#146)
* Update dependencies
* Add default invalid id value
* Extend appcompat views only
* Update migration
* Remove setTextIfValid
* Remove nosibling warning
* Add deprecation warnings to fragment view binding
* Bring back glide 4.6.1
* Use proper distribution type setter
Diffstat (limited to 'core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt')
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt | 89 |
1 files changed, 70 insertions, 19 deletions
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 f3c08bd..b0448d1 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt @@ -30,15 +30,27 @@ fun <V : View> Activity.bindView(id: Int) 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) 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) 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) 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) fun <V : View> SupportFragment.bindView(id: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, V> = required(id, viewFinder) @@ -54,15 +66,27 @@ fun <V : View> Activity.bindOptionalView(id: Int) 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) 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) 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) 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) fun <V : View> SupportFragment.bindOptionalView(id: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, V?> = optional(id, viewFinder) @@ -78,15 +102,27 @@ fun <V : View> Activity.bindViews(vararg ids: Int) 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) 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) 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) 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) fun <V : View> SupportFragment.bindViews(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, List<V>> = required(ids, viewFinder) @@ -102,15 +138,27 @@ fun <V : View> Activity.bindOptionalViews(vararg ids: Int) 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) 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) 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) 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) fun <V : View> SupportFragment.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, List<V>> = optional(ids, viewFinder) @@ -137,17 +185,19 @@ private inline val ViewHolder.viewFinder: ViewHolder.(Int) -> View? private fun viewNotFound(id: Int, desc: KProperty<*>): Nothing = throw IllegalStateException("View ID $id for '${desc.name}' not found.") -private fun <T, V : View> required(id: Int, finder: T.(Int) -> View?) - = Lazy { t: T, desc -> (t.finder(id) as V?)?.apply { } ?: viewNotFound(id, desc) } +private fun <T, V : View> required(id: Int, finder: T.(Int) -> View?) = Lazy { t: T, desc -> + (t.finder(id) as V?)?.apply { } ?: viewNotFound(id, desc) +} -private fun <T, V : View> optional(id: Int, finder: T.(Int) -> View?) - = Lazy { t: T, _ -> t.finder(id) as V? } +private fun <T, V : View> optional(id: Int, finder: T.(Int) -> View?) = Lazy { t: T, _ -> t.finder(id) as V? } -private fun <T, V : View> required(ids: IntArray, finder: T.(Int) -> View?) - = Lazy { t: T, desc -> ids.map { t.finder(it) as V? ?: viewNotFound(it, desc) } } +private fun <T, V : View> required(ids: IntArray, finder: T.(Int) -> View?) = Lazy { t: T, desc -> + ids.map { + t.finder(it) as V? ?: viewNotFound(it, desc) + } +} -private fun <T, V : View> optional(ids: IntArray, finder: T.(Int) -> View?) - = Lazy { t: T, _ -> ids.map { t.finder(it) as V? }.filterNotNull() } +private fun <T, V : View> optional(ids: IntArray, finder: T.(Int) -> View?) = Lazy { t: T, _ -> ids.map { t.finder(it) as V? }.filterNotNull() } // Like Kotlin's lazy delegate but the initializer gets the target and metadata passed to it private open class Lazy<in T, out V>(private val initializer: (T, KProperty<*>) -> V) : ReadOnlyProperty<T, V> { @@ -269,17 +319,19 @@ fun <V : View> SupportFragment.bindOptionalViewsResettable(vararg ids: Int) fun <V : View> ViewHolder.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty<ViewHolder, List<V>> = optionalResettable(ids, viewFinder) -private fun <T, V : View> requiredResettable(id: Int, finder: T.(Int) -> View?) - = LazyResettable { t: T, desc -> (t.finder(id) as V?)?.apply { } ?: viewNotFound(id, desc) } +private fun <T, V : View> requiredResettable(id: Int, finder: T.(Int) -> View?) = LazyResettable { t: T, desc -> + (t.finder(id) as V?)?.apply { } ?: viewNotFound(id, desc) +} -private fun <T, V : View> optionalResettable(id: Int, finder: T.(Int) -> View?) - = LazyResettable { t: T, _ -> t.finder(id) as V? } +private fun <T, V : View> optionalResettable(id: Int, finder: T.(Int) -> View?) = LazyResettable { t: T, _ -> t.finder(id) as V? } -private fun <T, V : View> requiredResettable(ids: IntArray, finder: T.(Int) -> View?) - = LazyResettable { t: T, desc -> ids.map { t.finder(it) as V? ?: viewNotFound(it, desc) } } +private fun <T, V : View> requiredResettable(ids: IntArray, finder: T.(Int) -> View?) = LazyResettable { t: T, desc -> + ids.map { + t.finder(it) as V? ?: viewNotFound(it, desc) + } +} -private fun <T, V : View> optionalResettable(ids: IntArray, finder: T.(Int) -> View?) - = LazyResettable { t: T, _ -> ids.map { t.finder(it) as V? }.filterNotNull() } +private fun <T, V : View> optionalResettable(ids: IntArray, finder: T.(Int) -> View?) = LazyResettable { t: T, _ -> ids.map { t.finder(it) as V? }.filterNotNull() } //Like Kotterknife's lazy delegate but is resettable private class LazyResettable<in T, out V>(initializer: (T, KProperty<*>) -> V) : Lazy<T, V>(initializer) { @@ -302,8 +354,7 @@ object Kotterknife { private object KotterknifeRegistry { private val lazyMap = WeakHashMap<Any, MutableCollection<LazyResettable<*, *>>>() - fun register(target: Any, lazy: LazyResettable<*, *>) - = lazyMap.getOrPut(target, { Collections.newSetFromMap(WeakHashMap()) }).add(lazy) + fun register(target: Any, lazy: LazyResettable<*, *>) = lazyMap.getOrPut(target, { Collections.newSetFromMap(WeakHashMap()) }).add(lazy) - fun reset(target: Any) = lazyMap[target]?.forEach { it.reset() } + fun reset(target: Any) = lazyMap[target]?.forEach(LazyResettable<*, *>::reset) }
\ No newline at end of file |