aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--library/src/main/res/layout/kau_preference.xml82
-rw-r--r--library/src/main/res/values/strings.xml1
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt2
8 files changed, 68 insertions, 55 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
}
diff --git a/library/src/main/res/layout/kau_preference.xml b/library/src/main/res/layout/kau_preference.xml
index 265015a..5123b27 100644
--- a/library/src/main/res/layout/kau_preference.xml
+++ b/library/src/main/res/layout/kau_preference.xml
@@ -1,68 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:baselineAligned="false"
android:clipToPadding="false"
- android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
+ android:orientation="horizontal"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingStart="?android:attr/listPreferredItemPaddingStart">
- <LinearLayout
- android:id="@+id/kau_pref_icon_frame"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="-4dp"
- android:gravity="start|center_vertical"
- android:minWidth="60dp"
- android:orientation="horizontal"
- android:paddingBottom="4dp"
- android:paddingEnd="12dp"
- android:paddingTop="4dp">
+ <android.support.constraint.ConstraintLayout
+ android:id="@+id/kau_pref_container"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
<ImageView
android:id="@+id/kau_pref_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:layout_marginBottom="4dp"
+ android:layout_marginTop="4dp"
+ android:contentDescription="@string/kau_pref_icon"
android:maxHeight="48dp"
- android:maxWidth="48dp" />
- </LinearLayout>
+ android:maxWidth="48dp"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintVertical_bias="0.5"
+ tools:layout_editor_absoluteX="0dp" />
- <RelativeLayout
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:paddingBottom="16dp"
- android:paddingTop="16dp">
+ <LinearLayout
+ android:id="@+id/kau_pref_inner_frame"
+ android:layout_width="wrap_content"
+ android:layout_height="0dp"
+ android:layout_marginStart="16dp"
+ android:gravity="center_vertical|end"
+ android:orientation="horizontal"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintHorizontal_bias="1.0"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintVertical_bias="0.5"
+ tools:layout_editor_absoluteX="1dp" />
<TextView
android:id="@+id/kau_pref_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:layout_marginTop="16dp"
android:ellipsize="marquee"
+ android:textAppearance="?android:attr/textAppearanceListItem"
android:textColor="?android:attr/textColorPrimary"
- android:textAppearance="?android:attr/textAppearanceListItem" />
+ app:layout_constraintBottom_toTopOf="@+id/kau_pref_desc"
+ app:layout_constraintEnd_toStartOf="@id/kau_pref_inner_frame"
+ app:layout_constraintHorizontal_bias="0"
+ app:layout_constraintStart_toEndOf="@id/kau_pref_icon"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_goneMarginBottom="16dp"
+ tools:layout_editor_absoluteX="-175dp" />
<TextView
- android:id="@+id/kau_pref_desc"
+ android:id="@id/kau_pref_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_alignStart="@id/kau_pref_title"
- android:layout_below="@id/kau_pref_title"
+ android:layout_marginBottom="16dp"
android:ellipsize="end"
android:maxLines="10"
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
- android:textColor="?android:attr/textColorSecondary" />
-
- </RelativeLayout>
+ android:textColor="?android:attr/textColorSecondary"
+ android:visibility="gone"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toStartOf="@id/kau_pref_inner_frame"
+ app:layout_constraintHorizontal_bias="0"
+ app:layout_constraintStart_toEndOf="@id/kau_pref_icon"
+ app:layout_constraintTop_toBottomOf="@+id/kau_pref_title"
+ tools:layout_editor_absoluteX="-175dp" />
- <LinearLayout android:id="@+id/kau_pref_inner_frame"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:gravity="end|center_vertical"
- android:paddingLeft="16dp"
- android:orientation="vertical" />
+ </android.support.constraint.ConstraintLayout>
</LinearLayout> \ No newline at end of file
diff --git a/library/src/main/res/values/strings.xml b/library/src/main/res/values/strings.xml
index 10a73b9..ed939fa 100644
--- a/library/src/main/res/values/strings.xml
+++ b/library/src/main/res/values/strings.xml
@@ -14,4 +14,5 @@
<string name="kau_md_color_palette">Color Palette</string>
<string name="kau_kpref_title_placeholder">Title Placeholder</string>
+ <string name="kau_pref_icon">Pref Icon</string>
</resources>
diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
index 914fff8..cb1cd77 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
@@ -20,7 +20,7 @@ class MainActivity : KPrefActivity() {
checkbox(title = R.string.checkbox_1, description = R.string.desc,
getter = { KPrefSample.check1 }, setter = { KPrefSample.check1 = it })
checkbox(title = R.string.checkbox_2,
- getter = { KPrefSample.check2 }, setter = { KPrefSample.check2 = it; reloadByTitle(R.string.checkbox_3) })
+ getter = { KPrefSample.check2 }, setter = { KPrefSample.check2 = it; reload(3) })
checkbox(title = R.string.checkbox_3, description = R.string.desc_dependent, enabler = { KPrefSample.check2 },
getter = { KPrefSample.check3 }, setter = { KPrefSample.check3 = it })
colorPicker(title = R.string.text_color, description = R.string.color_custom,