Skip to content

Commit

Permalink
DanaHistoryActivity spinner replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
MilosKozak committed Mar 19, 2022
1 parent cb1e40b commit 3212e9d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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)
}
}

Expand Down
48 changes: 24 additions & 24 deletions dana/src/main/res/layout/danar_history_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 3212e9d

Please sign in to comment.