making use of binding api instead of manual findviewbyid

This commit is contained in:
Adam Brown 2022-03-10 17:20:29 +00:00
parent edee6abafa
commit d89cc71eb4
2 changed files with 10 additions and 11 deletions

View file

@ -19,34 +19,33 @@ package im.vector.app.features.debug.settings
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.view.Gravity import android.view.Gravity
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.widget.AdapterView import android.widget.AdapterView
import android.widget.ArrayAdapter import android.widget.ArrayAdapter
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.widget.AppCompatSpinner
import im.vector.app.R import im.vector.app.R
import im.vector.app.databinding.ViewBooleanDropdownBinding
class OverrideDropdownView @JvmOverloads constructor( class OverrideDropdownView @JvmOverloads constructor(
context: Context, context: Context,
attrs: AttributeSet? = null attrs: AttributeSet? = null
) : LinearLayout(context, attrs) { ) : LinearLayout(context, attrs) {
private val labelView: TextView private val binding = ViewBooleanDropdownBinding.inflate(
private val optionsSpinner: AppCompatSpinner LayoutInflater.from(context),
this
)
init { init {
orientation = HORIZONTAL orientation = HORIZONTAL
gravity = Gravity.CENTER_VERTICAL gravity = Gravity.CENTER_VERTICAL
inflate(context, R.layout.view_boolean_dropdown, this)
labelView = findViewById(R.id.feature_label)
optionsSpinner = findViewById(R.id.feature_options)
} }
fun <T : OverrideOption> bind(feature: OverrideDropdown<T>, listener: Listener<T>) { fun <T : OverrideOption> bind(feature: OverrideDropdown<T>, listener: Listener<T>) {
labelView.text = feature.label binding.overrideLabel.text = feature.label
optionsSpinner.apply { binding.overrideOptions.apply {
val arrayAdapter = ArrayAdapter<String>(context, android.R.layout.simple_spinner_dropdown_item) val arrayAdapter = ArrayAdapter<String>(context, android.R.layout.simple_spinner_dropdown_item)
val options = listOf("Inactive") + feature.options.map { it.label } val options = listOf("Inactive") + feature.options.map { it.label }
arrayAdapter.addAll(options) arrayAdapter.addAll(options)

View file

@ -6,7 +6,7 @@
tools:parentTag="android.widget.LinearLayout"> tools:parentTag="android.widget.LinearLayout">
<TextView <TextView
android:id="@+id/feature_label" android:id="@+id/overrideLabel"
style="@style/Widget.Vector.TextView.Subtitle" style="@style/Widget.Vector.TextView.Subtitle"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -17,7 +17,7 @@
tools:text="Login version" /> tools:text="Login version" />
<androidx.appcompat.widget.AppCompatSpinner <androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/feature_options" android:id="@+id/overrideOptions"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" /> android:layout_weight="1" />