aboutsummaryrefslogtreecommitdiff
path: root/kpref-activity/src
diff options
context:
space:
mode:
Diffstat (limited to 'kpref-activity/src')
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefBinder.kt20
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefItemActions.kt11
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt5
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemBase.kt13
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemCore.kt10
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt5
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefText.kt9
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefTimePicker.kt7
8 files changed, 46 insertions, 34 deletions
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefBinder.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefBinder.kt
index cf2a12f..ec3c69f 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefBinder.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefBinder.kt
@@ -82,8 +82,8 @@ class KPrefAdapterBuilder(val globalOptions: GlobalOptions) {
@KPrefMarker
fun checkbox(
@StringRes title: Int,
- getter: (() -> Boolean),
- setter: ((value: Boolean) -> Unit),
+ getter: KPrefItemActions.() -> Boolean,
+ setter: KPrefItemActions.(value: Boolean) -> Unit,
builder: KPrefItemBase.BaseContract<Boolean>.() -> Unit = {}
) = list.add(
KPrefCheckbox(KPrefItemBase.BaseBuilder(globalOptions, title, getter, setter)
@@ -93,8 +93,8 @@ class KPrefAdapterBuilder(val globalOptions: GlobalOptions) {
@KPrefMarker
fun colorPicker(
@StringRes title: Int,
- getter: (() -> Int),
- setter: ((value: Int) -> Unit),
+ getter: KPrefItemActions.() -> Int,
+ setter: KPrefItemActions.(value: Int) -> Unit,
builder: KPrefColorPicker.KPrefColorContract.() -> Unit = {}
) = list.add(
KPrefColorPicker(KPrefColorPicker.KPrefColorBuilder(globalOptions, title, getter, setter)
@@ -104,8 +104,8 @@ class KPrefAdapterBuilder(val globalOptions: GlobalOptions) {
@KPrefMarker
fun <T> text(
@StringRes title: Int,
- getter: (() -> T),
- setter: ((value: T) -> Unit),
+ getter: KPrefItemActions.() -> T,
+ setter: KPrefItemActions.(value: T) -> Unit,
builder: KPrefText.KPrefTextContract<T>.() -> Unit = {}
) = list.add(
KPrefText(KPrefText.KPrefTextBuilder(globalOptions, title, getter, setter)
@@ -134,8 +134,8 @@ class KPrefAdapterBuilder(val globalOptions: GlobalOptions) {
@KPrefMarker
fun seekbar(
@StringRes title: Int,
- getter: (() -> Int),
- setter: ((value: Int) -> Unit),
+ getter: KPrefItemActions.() -> Int,
+ setter: KPrefItemActions.(value: Int) -> Unit,
builder: KPrefSeekbar.KPrefSeekbarContract.() -> Unit = {}
) = list.add(
KPrefSeekbar(KPrefSeekbar.KPrefSeekbarBuilder(globalOptions, title, getter, setter)
@@ -145,8 +145,8 @@ class KPrefAdapterBuilder(val globalOptions: GlobalOptions) {
@KPrefMarker
fun timePicker(
@StringRes title: Int,
- getter: (() -> Int),
- setter: ((value: Int) -> Unit),
+ getter: KPrefItemActions.() -> Int,
+ setter: KPrefItemActions.(value: Int) -> Unit,
builder: KPrefTimePicker.KPrefTimeContract.() -> Unit = {}
) = list.add(
KPrefTimePicker(KPrefTimePicker.KPrefTimeBuilder(globalOptions, title, getter, setter)
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefItemActions.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefItemActions.kt
new file mode 100644
index 0000000..e28bac6
--- /dev/null
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefItemActions.kt
@@ -0,0 +1,11 @@
+package ca.allanwang.kau.kpref.activity
+
+/**
+ * Applicable actions
+ */
+interface KPrefItemActions {
+ /**
+ * Attempts to reload current item by identifying it with its titleId
+ */
+ fun reloadSelf()
+} \ No newline at end of file
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt
index 675e387..07a6bbf 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt
@@ -21,6 +21,7 @@ import ca.allanwang.kau.colorpicker.ColorContract
import ca.allanwang.kau.colorpicker.colorPickerDialog
import ca.allanwang.kau.kpref.activity.GlobalOptions
import ca.allanwang.kau.kpref.activity.KClick
+import ca.allanwang.kau.kpref.activity.KPrefItemActions
import ca.allanwang.kau.kpref.activity.R
/**
@@ -71,8 +72,8 @@ open class KPrefColorPicker(open val builder: KPrefColorContract) : KPrefItemBas
class KPrefColorBuilder(
globalOptions: GlobalOptions,
titleId: Int,
- getter: () -> Int,
- setter: (value: Int) -> Unit
+ getter: KPrefItemActions.() -> Int,
+ setter: KPrefItemActions.(value: Int) -> Unit
) : KPrefColorContract, BaseContract<Int> by BaseBuilder(globalOptions, titleId, getter, setter),
ColorContract by ColorBuilder() {
override var showPreview: Boolean = true
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemBase.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemBase.kt
index 6690574..a445de5 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemBase.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemBase.kt
@@ -19,6 +19,7 @@ import android.view.View
import androidx.annotation.CallSuper
import ca.allanwang.kau.kpref.activity.GlobalOptions
import ca.allanwang.kau.kpref.activity.KClick
+import ca.allanwang.kau.kpref.activity.KPrefItemActions
import ca.allanwang.kau.kpref.activity.R
import ca.allanwang.kau.utils.resolveDrawable
@@ -30,9 +31,9 @@ import ca.allanwang.kau.utils.resolveDrawable
abstract class KPrefItemBase<T>(protected val base: BaseContract<T>) : KPrefItemCore(base) {
open var pref: T
- get() = base.getter()
+ get() = base.getter(this)
set(value) {
- base.setter(value)
+ base.setter(this, value)
}
private var _enabled: Boolean = true
@@ -92,8 +93,8 @@ abstract class KPrefItemBase<T>(protected val base: BaseContract<T>) : KPrefItem
var enabler: () -> Boolean
var onClick: (KClick<T>.() -> Unit)?
var onDisabledClick: (KClick<T>.() -> Unit)?
- val getter: () -> T
- val setter: (value: T) -> Unit
+ val getter: KPrefItemActions.() -> T
+ val setter: KPrefItemActions.(value: T) -> Unit
}
/**
@@ -102,8 +103,8 @@ abstract class KPrefItemBase<T>(protected val base: BaseContract<T>) : KPrefItem
class BaseBuilder<T>(
globalOptions: GlobalOptions,
titleId: Int,
- override val getter: () -> T,
- override val setter: (value: T) -> Unit
+ override val getter: KPrefItemActions.() -> T,
+ override val setter: KPrefItemActions.(value: T) -> Unit
) : CoreContract by CoreBuilder(globalOptions, titleId), BaseContract<T> {
override var enabler: () -> Boolean = { true }
override var onClick: (KClick<T>.() -> Unit)? = null
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemCore.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemCore.kt
index fc632ce..36bf670 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemCore.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemCore.kt
@@ -30,6 +30,7 @@ import androidx.recyclerview.widget.RecyclerView
import ca.allanwang.kau.adapters.ThemableIItem
import ca.allanwang.kau.adapters.ThemableIItemDelegate
import ca.allanwang.kau.kpref.activity.GlobalOptions
+import ca.allanwang.kau.kpref.activity.KPrefItemActions
import ca.allanwang.kau.kpref.activity.KPrefMarker
import ca.allanwang.kau.kpref.activity.R
import ca.allanwang.kau.utils.INVALID_ID
@@ -47,7 +48,7 @@ import com.mikepenz.iconics.typeface.IIcon
* Core class containing nothing but the view items
*/
-abstract class KPrefItemCore(val core: CoreContract) : AbstractItem<KPrefItemCore, KPrefItemCore.ViewHolder>(),
+abstract class KPrefItemCore(val core: CoreContract) : AbstractItem<KPrefItemCore, KPrefItemCore.ViewHolder>(), KPrefItemActions by core,
ThemableIItem by ThemableIItemDelegate() {
final override fun getViewHolder(v: View) = ViewHolder(v)
@@ -119,7 +120,7 @@ abstract class KPrefItemCore(val core: CoreContract) : AbstractItem<KPrefItemCor
* Core values for all kpref items
*/
@KPrefMarker
- interface CoreContract {
+ interface CoreContract : KPrefItemActions {
val globalOptions: GlobalOptions
val titleId: Int
var titleFun: () -> Int
@@ -128,11 +129,6 @@ abstract class KPrefItemCore(val core: CoreContract) : AbstractItem<KPrefItemCor
var descFun: () -> Int
var iicon: IIcon?
var visible: () -> Boolean
-
- /**
- * Attempts to reload current item by identifying it with its [id]
- */
- fun reloadSelf()
}
/**
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt
index e70a374..d49fe16 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt
@@ -19,6 +19,7 @@ import android.widget.SeekBar
import android.widget.TextView
import ca.allanwang.kau.kpref.activity.GlobalOptions
import ca.allanwang.kau.kpref.activity.KClick
+import ca.allanwang.kau.kpref.activity.KPrefItemActions
import ca.allanwang.kau.kpref.activity.R
import ca.allanwang.kau.utils.tint
@@ -84,8 +85,8 @@ open class KPrefSeekbar(val builder: KPrefSeekbarContract) : KPrefItemBase<Int>(
class KPrefSeekbarBuilder(
globalOptions: GlobalOptions,
titleId: Int,
- getter: () -> Int,
- setter: (value: Int) -> Unit
+ getter: KPrefItemActions.() -> Int,
+ setter: KPrefItemActions.(value: Int) -> Unit
) : KPrefSeekbarContract, BaseContract<Int> by BaseBuilder(globalOptions, titleId, getter, setter) {
override var min: Int = 0
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefText.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefText.kt
index ac8416d..5f6eefa 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefText.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefText.kt
@@ -18,6 +18,7 @@ package ca.allanwang.kau.kpref.activity.items
import android.widget.TextView
import ca.allanwang.kau.kpref.activity.GlobalOptions
import ca.allanwang.kau.kpref.activity.KClick
+import ca.allanwang.kau.kpref.activity.KPrefItemActions
import ca.allanwang.kau.kpref.activity.R
import ca.allanwang.kau.utils.toast
@@ -35,9 +36,9 @@ open class KPrefText<T>(open val builder: KPrefTextContract<T>) : KPrefItemBase<
* Automatically reload on set
*/
override var pref: T
- get() = base.getter()
+ get() = base.getter(this)
set(value) {
- base.setter(value)
+ base.setter(this, value)
builder.reloadSelf()
}
@@ -65,8 +66,8 @@ open class KPrefText<T>(open val builder: KPrefTextContract<T>) : KPrefItemBase<
class KPrefTextBuilder<T>(
globalOptions: GlobalOptions,
titleId: Int,
- getter: () -> T,
- setter: (value: T) -> Unit
+ getter: KPrefItemActions.() -> T,
+ setter: KPrefItemActions.(value: T) -> Unit
) : KPrefTextContract<T>, BaseContract<T> by BaseBuilder<T>(globalOptions, titleId, getter, setter) {
override var textGetter: (T) -> String? = { it?.toString() }
}
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefTimePicker.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefTimePicker.kt
index 7242bbe..f2824a7 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefTimePicker.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefTimePicker.kt
@@ -19,6 +19,7 @@ import android.app.TimePickerDialog
import android.widget.TimePicker
import ca.allanwang.kau.kpref.activity.GlobalOptions
import ca.allanwang.kau.kpref.activity.KClick
+import ca.allanwang.kau.kpref.activity.KPrefItemActions
import ca.allanwang.kau.kpref.activity.R
import java.util.Locale
@@ -47,9 +48,9 @@ open class KPrefTimePicker(override val builder: KPrefTimeContract) : KPrefText<
class KPrefTimeBuilder(
globalOptions: GlobalOptions,
titleId: Int,
- getter: () -> Int,
- setter: (value: Int) -> Unit
- ) : KPrefTimeContract, BaseContract<Int> by BaseBuilder<Int>(globalOptions, titleId, getter, setter) {
+ getter: KPrefItemActions.() -> Int,
+ setter: KPrefItemActions.(value: Int) -> Unit
+ ) : KPrefTimeContract, BaseContract<Int> by BaseBuilder(globalOptions, titleId, getter, setter) {
override var use24HourFormat: Boolean = false