diff options
Diffstat (limited to 'library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemBase.kt')
-rw-r--r-- | library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemBase.kt | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemBase.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemBase.kt new file mode 100644 index 0000000..c86f3b6 --- /dev/null +++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemBase.kt @@ -0,0 +1,35 @@ +package ca.allanwang.kau.kpref.items + +import android.support.annotation.CallSuper +import android.support.annotation.StringRes +import android.util.Log +import ca.allanwang.kau.R +import com.mikepenz.iconics.typeface.IIcon + +/** + * Created by Allan Wang on 2017-06-05. + * + * Base class for pref setters that include the Shared Preference hooks + */ + +abstract class KPrefItemBase<T>(@StringRes title: Int, + @StringRes description: Int = -1, + iicon: IIcon? = null, + val enabled: Boolean = true, + private val getter: () -> T, + private val setter: (value: T) -> Unit) : KPrefItemCore(title, description, iicon) { + + var pref: T + get() = getter.invoke() + set(value) { + setter.invoke(value) + } + + @CallSuper + override fun onPostBindView(viewHolder: ViewHolder) { + viewHolder.itemView.isEnabled = enabled + viewHolder.itemView.alpha = if (enabled) 1.0f else 0.3f + } + + override final fun getLayoutRes(): Int = R.layout.kau_preference +}
\ No newline at end of file |