DanaHistoryActivity spinner replacement

This commit is contained in:
Milos Kozak 2022-03-19 17:32:07 +01:00
parent cb1e40bd90
commit 3212e9d906
2 changed files with 31 additions and 37 deletions

View file

@ -83,6 +83,7 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() {
super.onCreate(savedInstanceState)
binding = DanarHistoryActivityBinding.inflate(layoutInflater)
setContentView(binding.root)
setTheme(R.style.AppTheme)
binding.recyclerview.setHasFixedSize(true)
binding.recyclerview.layoutManager = LinearLayoutManager(this)
@ -108,11 +109,10 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() {
typeList.add(TypeList(RecordTypes.RECORD_TYPE_REFILL, rh.gs(R.string.danar_history_refill)))
typeList.add(TypeList(RecordTypes.RECORD_TYPE_SUSPEND, rh.gs(R.string.danar_history_syspend)))
}
binding.spinner.adapter = ArrayAdapter(this, R.layout.spinner_centered, typeList)
binding.typeList.setAdapter(ArrayAdapter(this, R.layout.spinner_centered, typeList))
binding.reload.setOnClickListener {
val selected = binding.spinner.selectedItem as TypeList?
?: return@setOnClickListener
val selected = typeList.firstOrNull { it.name == binding.typeList.text.toString() } ?: return@setOnClickListener
binding.reload.visibility = View.GONE
binding.status.visibility = View.VISIBLE
clearCardView()
@ -126,16 +126,10 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() {
}
})
}
binding.spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
val selected = typeList[position]
swapAdapter(selected.type)
showingType = selected.type
}
override fun onNothingSelected(parent: AdapterView<*>?) {
clearCardView()
}
binding.typeList.onItemClickListener = AdapterView.OnItemClickListener { _, _, position, _ ->
val selected = typeList[position]
showingType = selected.type
swapAdapter(selected.type)
}
}

View file

@ -16,7 +16,7 @@
android:background="?attr/activity_title_backgroundColor"
android:orientation="horizontal"
android:padding="5dp"
app:layout_constraintBottom_toTopOf="@+id/spinner"
app:layout_constraintBottom_toTopOf="@+id/typeListLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
@ -49,29 +49,29 @@
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:id="@+id/typeListLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="20dp"
android:text="@string/eventtype"
android:textAppearance="?android:attr/textAppearanceSmall"
app:layout_constraintBottom_toBottomOf="@+id/spinner"
app:layout_constraintEnd_toStartOf="@+id/spinner"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/spinner" />
<Spinner
android:id="@+id/spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:hint="@string/eventtype"
app:boxStrokeColor="@color/list_delimiter"
app:layout_constraintBottom_toTopOf="@+id/status"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/header" />
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/header">
<androidx.appcompat.widget.AppCompatAutoCompleteTextView
android:id="@+id/typeList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:enabled="false"
tools:ignore="KeyboardInaccessibleWidget" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/status"
@ -83,7 +83,7 @@
app:layout_constraintBottom_toTopOf="@+id/recyclerview"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
app:layout_constraintTop_toBottomOf="@+id/typeListLayout" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview"
@ -100,9 +100,9 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:text="@string/reload"
app:icon="@drawable/ic_actions_refill"
app:iconTint="@color/ic_actions_refill"
android:text="@string/reload"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"