aboutsummaryrefslogtreecommitdiff
path: root/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefText.kt
diff options
context:
space:
mode:
Diffstat (limited to 'library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefText.kt')
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefText.kt27
1 files changed, 17 insertions, 10 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefText.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefText.kt
index b7091a6..0daa054 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefText.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefText.kt
@@ -1,10 +1,9 @@
package ca.allanwang.kau.kpref.items
-import android.support.annotation.StringRes
import android.view.View
import android.widget.TextView
import ca.allanwang.kau.R
-import ca.allanwang.kau.kpref.KPrefAdapterBuilder
+import ca.allanwang.kau.kpref.CoreAttributeContract
import ca.allanwang.kau.utils.toast
/**
@@ -15,10 +14,7 @@ import ca.allanwang.kau.utils.toast
* This is still a generic preference
*
*/
-class KPrefText<T>(adapterBuilder: KPrefAdapterBuilder,
- @StringRes title: Int,
- val builder: KPrefTextContract<T>
-) : KPrefItemBase<T>(adapterBuilder, title, builder) {
+class KPrefText<T>(val builder: KPrefTextContract<T>) : KPrefItemBase<T>(builder) {
override fun defaultOnClick(itemView: View, innerContent: View?): Boolean {
itemView.context.toast("No click function set")
@@ -32,14 +28,25 @@ class KPrefText<T>(adapterBuilder: KPrefAdapterBuilder,
textview.text = builder.textGetter.invoke(pref)
}
- class KPrefTextBuilder<T> : KPrefTextContract<T>, BaseContract<T> by BaseBuilder<T>() {
- override var textGetter: (T) -> String? = { it?.toString() }
- }
-
+ /**
+ * Extension of the base contract with an optional text getter
+ */
interface KPrefTextContract<T> : BaseContract<T> {
var textGetter: (T) -> String?
}
+ /**
+ * Default implementation of [KPrefTextContract]
+ */
+ class KPrefTextBuilder<T>(
+ attributes: CoreAttributeContract,
+ titleRes: Int,
+ getter: () -> T,
+ setter: (value: T) -> Unit
+ ) : KPrefTextContract<T>, BaseContract<T> by BaseBuilder<T>(attributes, titleRes, getter, setter) {
+ override var textGetter: (T) -> String? = { it?.toString() }
+ }
+
override fun getType(): Int = R.id.kau_item_pref_checkbox
} \ No newline at end of file