From 31a293c5c0c11d62e04262edb598261e1b0382dd Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Sun, 5 Jan 2020 23:42:35 +0100 Subject: [PATCH] [Extensions] Add trigger extension instead of using performClick on checkboxes. --- app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt | 7 +++++-- .../ui/modules/login/LoginSummaryProfileAdapter.kt | 7 ++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt index 69d7cf1b..3a1992ff 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt @@ -23,6 +23,7 @@ import android.util.LongSparseArray import android.util.SparseArray import android.util.TypedValue import android.view.View +import android.widget.CheckBox import android.widget.CompoundButton import android.widget.TextView import androidx.annotation.* @@ -506,7 +507,7 @@ fun CharSequence.asSpannable(vararg spans: Any, substring: String? = null, ignor spans.forEach { spannable.setSpan(it, index, index + substring.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) } - index = indexOf(substring, startIndex = index + 1, ignoreCase = ignoreCase); + index = indexOf(substring, startIndex = index + 1, ignoreCase = ignoreCase) } } return spannable @@ -841,7 +842,7 @@ fun Int.toColorStateList(): ColorStateList { this ) - return ColorStateList(states, colors); + return ColorStateList(states, colors) } fun SpannableStringBuilder.appendText(text: CharSequence): SpannableStringBuilder { @@ -888,3 +889,5 @@ fun String.base64Decode(): ByteArray { fun String.base64DecodeToString(): String { return Base64.decode(this, Base64.DEFAULT).toString(Charset.defaultCharset()) } + +fun CheckBox.trigger() { isChecked = !isChecked } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginSummaryProfileAdapter.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginSummaryProfileAdapter.kt index b0d33e71..7cea592e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginSummaryProfileAdapter.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginSummaryProfileAdapter.kt @@ -9,13 +9,10 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView -import pl.szczodrzynski.edziennik.App -import pl.szczodrzynski.edziennik.R +import pl.szczodrzynski.edziennik.* import pl.szczodrzynski.edziennik.data.api.* import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile import pl.szczodrzynski.edziennik.databinding.RowLoginProfileListItemBinding -import pl.szczodrzynski.edziennik.joinNotNullStrings -import pl.szczodrzynski.edziennik.onClick class LoginSummaryProfileAdapter( val context: Context, @@ -68,7 +65,7 @@ class LoginSummaryProfileAdapter( ) b.root.onClick { - b.checkBox.performClick() + b.checkBox.trigger() } b.checkBox.setOnCheckedChangeListener { _, isChecked -> item.isSelected = isChecked