aboutsummaryrefslogtreecommitdiff
path: root/library/src/main/kotlin
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-23 17:31:58 -0700
committerAllan Wang <me@allanwang.ca>2017-06-23 17:31:58 -0700
commit0df43d971f1eb18a0e6ce7fa56fab11dfba154b8 (patch)
tree38dc2c527d5130b67a24055ae5b2afa185dae328 /library/src/main/kotlin
parent61b5d89a90964be6c41c64e9904ab7adfc0f61bb (diff)
downloadkau-0df43d971f1eb18a0e6ce7fa56fab11dfba154b8.tar.gz
kau-0df43d971f1eb18a0e6ce7fa56fab11dfba154b8.tar.bz2
kau-0df43d971f1eb18a0e6ce7fa56fab11dfba154b8.zip
Improve kpref text
Diffstat (limited to 'library/src/main/kotlin')
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt2
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBinder.kt1
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemBase.kt2
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemCore.kt11
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefText.kt11
5 files changed, 23 insertions, 4 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt
index 77bceaf..8ec95ee 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt
@@ -146,7 +146,7 @@ abstract class KPrefActivity : AppCompatActivity(), KPrefActivityContract {
else index.forEach { adapter.notifyItemChanged(it) }
}
- fun reloadByTitle(@StringRes vararg title: Int) {
+ override fun reloadByTitle(@StringRes vararg title: Int) {
if (title.isEmpty()) return
adapter.adapterItems.forEachIndexed { index, item ->
if (title.any { item.core.titleRes == it })
diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBinder.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBinder.kt
index 4904194..472c538 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBinder.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBinder.kt
@@ -47,6 +47,7 @@ class CoreAttributeBuilder : CoreAttributeContract {
interface KPrefActivityContract {
fun showNextPrefs(@StringRes toolbarTitleRes:Int, builder: KPrefAdapterBuilder.() -> Unit)
fun showPrevPrefs()
+ fun reloadByTitle(@StringRes vararg title: Int)
}
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
index 949ae59..a0718a0 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemBase.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemBase.kt
@@ -15,7 +15,7 @@ import ca.allanwang.kau.utils.resolveDrawable
abstract class KPrefItemBase<T>(val base: BaseContract<T>) : KPrefItemCore(base) {
- var pref: T
+ open var pref: T
get() = base.getter.invoke()
set(value) {
base.setter.invoke(value)
diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemCore.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemCore.kt
index faf451f..9c0ad79 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemCore.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemCore.kt
@@ -74,15 +74,24 @@ abstract class KPrefItemCore(val core: CoreContract) : AbstractItem<KPrefItemCor
val titleRes: Int
var descRes: Int
var iicon: IIcon?
+
+ /**
+ * Attempts to reload current item by identifying it with its [titleRes]
+ */
+ fun reloadSelf()
}
/**
- * Default impementation of [CoreContract]
+ * Default implementation of [CoreContract]
*/
class CoreBuilder(override val globalOptions: GlobalOptions,
override val titleRes: Int) : CoreContract {
override var descRes: Int = -1
override var iicon: IIcon? = null
+
+ override fun reloadSelf() {
+ globalOptions.reloadByTitle(titleRes)
+ }
}
class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
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 b93dbed..894f024 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
@@ -3,7 +3,6 @@ package ca.allanwang.kau.kpref.items
import android.view.View
import android.widget.TextView
import ca.allanwang.kau.R
-import ca.allanwang.kau.kpref.CoreAttributeContract
import ca.allanwang.kau.kpref.GlobalOptions
import ca.allanwang.kau.utils.toast
@@ -17,6 +16,16 @@ import ca.allanwang.kau.utils.toast
*/
class KPrefText<T>(val builder: KPrefTextContract<T>) : KPrefItemBase<T>(builder) {
+ /**
+ * Automatically reload on set
+ */
+ override var pref: T
+ get() = base.getter.invoke()
+ set(value) {
+ base.setter.invoke(value)
+ builder.reloadSelf()
+ }
+
override fun defaultOnClick(itemView: View, innerContent: View?): Boolean {
itemView.context.toast("No click function set")
return true