Filter buttons

This commit is contained in:
Daniele Verducci (ZenPenguin) 2021-09-04 08:54:12 +02:00
parent 1757ee9ea1
commit 4b4e2b6b3c
5 changed files with 70 additions and 10 deletions

View File

@ -9,6 +9,7 @@ import android.widget.Toast
import it.danieleverducci.subitobeers.BeerNavigation
import it.danieleverducci.subitobeers.BeersRepository
import it.danieleverducci.subitobeers.R
import it.danieleverducci.subitobeers.databinding.FragmentBeersListBinding
import it.danieleverducci.subitobeers.entities.Beer
/**
@ -18,6 +19,7 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter.
private val rvAdapter = BeerRecyclerAdapter()
private val repo = BeersRepository()
lateinit var binding: FragmentBeersListBinding
private var page = 1
override fun onCreateView(
@ -26,20 +28,22 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter.
): View? {
setHasOptionsMenu(true);
val view = inflater.inflate(R.layout.fragment_beers_list, container, false)
binding = FragmentBeersListBinding.inflate(
LayoutInflater.from(container!!.context),
container,
false
)
// Set the adapter
if (view is RecyclerView) {
with(view) {
layoutManager = LinearLayoutManager(context)
adapter = rvAdapter
}
with(binding.list) {
layoutManager = LinearLayoutManager(context)
adapter = rvAdapter
}
// Register for recyclerview adapter events
rvAdapter.listener = this
return view
return binding.root
}
override fun onStart() {
@ -58,6 +62,12 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter.
requireActivity().menuInflater.inflate(R.menu.list_menu, menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == R.id.action_filter)
toggleFilter()
return super.onOptionsItemSelected(item)
}
override fun onBeersObtained(beers: List<Beer>) {
rvAdapter.addItems(beers)
}
@ -85,4 +95,9 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter.
repo.getBeers(page)
}
private fun toggleFilter() {
binding.listFilterDropdown.visibility =
if (binding.listFilterDropdown.visibility == View.VISIBLE) View.GONE else View.VISIBLE
}
}

View File

@ -0,0 +1,11 @@
package it.danieleverducci.subitobeers.ui.views
import android.app.DatePickerDialog
import android.content.Context
/**
* Here I extend DatePickerDialog to hide the Day picker
*/
class CustomMonthPickerDialog(context: Context) : DatePickerDialog(context) {
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/accent_200"/>
<corners android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
</shape>
</item>
</selector>

View File

@ -3,12 +3,33 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/list_filter_dropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_background">
android:background="@drawable/filter_dropdown_rounded_background"
android:padding="10dp"
android:visibility="gone">
<Button
android:id="@+id/list_filter_since_bt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="10dp"
android:text="00/0000"
android:drawableLeft="@drawable/ic_firstbrewed"/>
<Button
android:id="@+id/list_filter_to_bt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="00/0000"
android:drawableLeft="@drawable/ic_firstbrewed"/>
</LinearLayout>

View File

@ -3,7 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- Filter button -->
<item
android:id="@+id/action_favorite"
android:id="@+id/action_filter"
android:icon="@drawable/ic_action_filter"
android:title="@string/action_filter"
app:showAsAction="always"/>