aboutsummaryrefslogtreecommitdiff
path: root/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefCheckbox.kt
diff options
context:
space:
mode:
Diffstat (limited to 'library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefCheckbox.kt')
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefCheckbox.kt16
1 files changed, 9 insertions, 7 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefCheckbox.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefCheckbox.kt
index 9961df9..474c3e5 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefCheckbox.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefCheckbox.kt
@@ -5,11 +5,15 @@ import android.view.View
import android.widget.CheckBox
import ca.allanwang.kau.R
import ca.allanwang.kau.kpref.KPrefAdapterBuilder
+import ca.allanwang.kau.logging.SL
import ca.allanwang.kau.utils.tint
import com.mikepenz.iconics.typeface.IIcon
/**
* Created by Allan Wang on 2017-06-07.
+ *
+ * Checkbox preference
+ * When clicked, will toggle the preference and the apply the result to the checkbox
*/
class KPrefCheckbox(builder: KPrefAdapterBuilder,
@StringRes title: Int,
@@ -19,11 +23,6 @@ class KPrefCheckbox(builder: KPrefAdapterBuilder,
getter: () -> Boolean,
setter: (value: Boolean) -> Unit) : KPrefItemBase<Boolean>(builder, title, description, iicon, enabled, getter, setter) {
- override fun onPostBindView(viewHolder: KPrefItemCore.ViewHolder) {
- super.onPostBindView(viewHolder)
- viewHolder.addInnerView(R.layout.kau_preference_checkbox)
- (viewHolder[R.id.kau_pref_checkbox] as CheckBox).isChecked = pref
- }
override fun onClick(itemView: View): Boolean {
val checkbox = itemView.findViewById(R.id.kau_pref_checkbox) as CheckBox
@@ -32,11 +31,14 @@ class KPrefCheckbox(builder: KPrefAdapterBuilder,
return true
}
- override fun setColors(viewHolder: ViewHolder, builder: KPrefAdapterBuilder) {
- super.setColors(viewHolder, builder)
+ override fun onPostBindView(viewHolder: ViewHolder, builder: KPrefAdapterBuilder) {
+ super.onPostBindView(viewHolder, builder)
+ viewHolder.addInnerView(R.layout.kau_preference_checkbox)
if (builder.accentColor != null) {
val checkbox = viewHolder.itemView.findViewById(R.id.kau_pref_checkbox) as CheckBox
checkbox.tint(builder.accentColor!!)
+ checkbox.isChecked = pref //Checkbox tick needs to be delayed since notifyDataSetChanged will cancel the animation
+ //It seems to work well here
}
}