aboutsummaryrefslogtreecommitdiff
path: root/library/src/main/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'library/src/main/kotlin')
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt6
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefCheckbox.kt5
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefHeader.kt1
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemBase.kt12
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemCore.kt14
5 files changed, 17 insertions, 21 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 c441782..13407db 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt
@@ -34,14 +34,14 @@ abstract class KPrefActivity : AppCompatActivity() {
fun reload(vararg index: Int) {
if (index.isEmpty()) adapter.notifyAdapterDataSetChanged()
- else index.forEach { adapter.notifyItemChanged(it) }
+ else index.forEach { adapter.notifyItemChanged(it, null) }
}
- fun reloadByTitle(@StringRes vararg title:Int){
+ fun reloadByTitle(@StringRes vararg title: Int) {
if (title.isEmpty()) return
adapter.adapterItems.forEachIndexed { index, item ->
if (title.any { item.title == it })
- adapter.notifyItemChanged(index)
+ adapter.notifyItemChanged(index, null)
}
}
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 75b480f..e09e245 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
@@ -33,9 +33,8 @@ class KPrefCheckbox(builder: KPrefAdapterBuilder,
super.onPostBindView(viewHolder, textColor, accentColor)
val checkbox = viewHolder.bindInnerView<CheckBox>(R.layout.kau_preference_checkbox)
if (accentColor != null) checkbox.tint(accentColor)
- checkbox.isChecked = pref //Checkbox tick needs to be delayed since notifyDataSetChanged will cancel the animation
- //It seems to work well here
-// checkbox.jumpDrawablesToCurrentState()
+ checkbox.isChecked = pref
+ checkbox.jumpDrawablesToCurrentState() //Cancel the animation
}
override fun getType(): Int = R.id.kau_item_pref_checkbox
diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefHeader.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefHeader.kt
index 0cd5901..94ef745 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefHeader.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefHeader.kt
@@ -16,7 +16,6 @@ class KPrefHeader(builder: KPrefAdapterBuilder, @StringRes title: Int) : KPrefIt
override fun getLayoutRes(): Int = R.layout.kau_preference_header
override fun onPostBindView(viewHolder: ViewHolder, textColor: Int?, accentColor: Int?) {
- viewHolder.itemView.isClickable = false
if (accentColor != null) viewHolder.title.setTextColor(accentColor)
}
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 3c62b43..459166e 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
@@ -30,19 +30,17 @@ abstract class KPrefItemBase<T>(builder: KPrefAdapterBuilder,
@CallSuper
override fun onPostBindView(viewHolder: ViewHolder, textColor: Int?, accentColor: Int?) {
val enabled = enabler.invoke()
- with(viewHolder){
- itemView.isEnabled = enabled
- itemView.alpha = if (enabled) 1.0f else 0.3f
- SL.d("Alpha ${itemView.isEnabled} ${itemView.alpha}")
+ with(viewHolder) {
+ container?.isEnabled = enabled
+ container?.alpha = if (enabled) 1.0f else 0.3f
}
}
override fun unbindView(holder: ViewHolder) {
super.unbindView(holder)
with(holder) {
-// itemView.isEnabled = true
-// itemView.alpha = 1.0f
- SL.d("Unset alpha ${itemView.isEnabled} ${itemView.alpha}")
+ container?.isEnabled = true
+ container?.alpha = 1.0f
}
}
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 169c716..2a03746 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
@@ -7,6 +7,7 @@ import android.support.annotation.StringRes
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
+import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
@@ -17,6 +18,7 @@ import ca.allanwang.kau.logging.SL
import ca.allanwang.kau.utils.*
import com.mikepenz.fastadapter.items.AbstractItem
import com.mikepenz.iconics.typeface.IIcon
+import java.util.*
/**
* Created by Allan Wang on 2017-06-05.
@@ -34,7 +36,6 @@ abstract class KPrefItemCore(val builder: KPrefAdapterBuilder,
@CallSuper
override fun bindView(viewHolder: ViewHolder, payloads: List<Any>) {
super.bindView(viewHolder, payloads)
- SL.d("BINDVIEW")
with(viewHolder) {
val context = itemView.context
title.text = context.string(this@KPrefItemCore.title)
@@ -42,10 +43,8 @@ abstract class KPrefItemCore(val builder: KPrefAdapterBuilder,
desc?.visible()?.setText(description)
else
desc?.gone()
- if (iicon != null) {
- iconFrame?.visible()
- icon?.setIcon(iicon, 48)
- } else iconFrame?.gone()
+ if (iicon != null) icon?.visible()?.setIcon(iicon, 48)
+ else icon?.gone()
innerFrame?.removeAllViews()
val textColor = builder.textColor?.invoke()
if (textColor != null) {
@@ -66,7 +65,6 @@ abstract class KPrefItemCore(val builder: KPrefAdapterBuilder,
override fun unbindView(holder: ViewHolder) {
super.unbindView(holder)
- SL.d("UNBINDVIEW")
with(holder) {
title.text = null
desc?.text = null
@@ -77,9 +75,9 @@ abstract class KPrefItemCore(val builder: KPrefAdapterBuilder,
class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
val title: TextView by bindView(R.id.kau_pref_title)
+ val container: ViewGroup? by bindOptionalView(R.id.kau_pref_container)
val desc: TextView? by bindOptionalView(R.id.kau_pref_desc)
val icon: ImageView? by bindOptionalView(R.id.kau_pref_icon)
- val iconFrame: LinearLayout? by bindOptionalView(R.id.kau_pref_icon_frame)
val innerFrame: LinearLayout? by bindOptionalView(R.id.kau_pref_inner_frame)
val innerContent: View?
get() = itemView.findViewById(R.id.kau_pref_inner_content)
@@ -93,6 +91,8 @@ abstract class KPrefItemCore(val builder: KPrefAdapterBuilder,
if (innerContent !is T) {
innerFrame!!.removeAllViews()
LayoutInflater.from(innerFrame!!.context).inflate(id, innerFrame)
+ } else {
+ SL.d("Inner view still attached")
}
return innerContent as T
}