Skip to content

Commit

Permalink
making use of binding api instead of manual findviewbyid
Browse files Browse the repository at this point in the history
  • Loading branch information
ouchadam committed Mar 10, 2022
1 parent 64df56b commit 7e4941b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,33 @@ package im.vector.app.features.debug.settings
import android.content.Context
import android.util.AttributeSet
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.widget.AppCompatSpinner
import im.vector.app.R
import im.vector.app.databinding.ViewBooleanDropdownBinding

class OverrideDropdownView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null
) : LinearLayout(context, attrs) {

private val labelView: TextView
private val optionsSpinner: AppCompatSpinner
private val binding = ViewBooleanDropdownBinding.inflate(
LayoutInflater.from(context),
this
)

init {
orientation = HORIZONTAL
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>) {
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 options = listOf("Inactive") + feature.options.map { it.label }
arrayAdapter.addAll(options)
Expand Down
4 changes: 2 additions & 2 deletions vector/src/debug/res/layout/view_boolean_dropdown.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
tools:parentTag="android.widget.LinearLayout">

<TextView
android:id="@+id/feature_label"
android:id="@+id/overrideLabel"
style="@style/Widget.Vector.TextView.Subtitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
Expand All @@ -17,7 +17,7 @@
tools:text="Login version" />

<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/feature_options"
android:id="@+id/overrideOptions"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
Expand Down

0 comments on commit 7e4941b

Please sign in to comment.