WIP adding filter

This commit is contained in:
Daniele Verducci (ZenPenguin) 2021-09-02 08:57:56 +02:00
parent ecdf84e488
commit 1757ee9ea1
6 changed files with 54 additions and 12 deletions

View File

@ -1,6 +1,8 @@
package it.danieleverducci.subitobeers package it.danieleverducci.subitobeers
import android.os.Bundle import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import it.danieleverducci.subitobeers.entities.Beer import it.danieleverducci.subitobeers.entities.Beer
import it.danieleverducci.subitobeers.ui.BeerDetailFragment import it.danieleverducci.subitobeers.ui.BeerDetailFragment

View File

@ -1,12 +1,10 @@
package it.danieleverducci.subitobeers.ui package it.danieleverducci.subitobeers.ui
import android.os.Bundle import android.os.Bundle
import android.view.*
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast import android.widget.Toast
import it.danieleverducci.subitobeers.BeerNavigation import it.danieleverducci.subitobeers.BeerNavigation
import it.danieleverducci.subitobeers.BeersRepository import it.danieleverducci.subitobeers.BeersRepository
@ -26,6 +24,8 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter.
inflater: LayoutInflater, container: ViewGroup?, inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
setHasOptionsMenu(true);
val view = inflater.inflate(R.layout.fragment_beers_list, container, false) val view = inflater.inflate(R.layout.fragment_beers_list, container, false)
// Set the adapter // Set the adapter
@ -53,6 +53,11 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter.
repo.getBeers(page) repo.getBeers(page)
} }
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater)
requireActivity().menuInflater.inflate(R.menu.list_menu, menu)
}
override fun onBeersObtained(beers: List<Beer>) { override fun onBeersObtained(beers: List<Beer>) {
rvAdapter.addItems(beers) rvAdapter.addItems(beers)
} }

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M4.25,5.61C6.27,8.2 10,13 10,13v6c0,0.55 0.45,1 1,1h2c0.55,0 1,-0.45 1,-1v-6c0,0 3.72,-4.8 5.74,-7.39C20.25,4.95 19.78,4 18.95,4H5.04C4.21,4 3.74,4.95 4.25,5.61z"/>
</vector>

View File

@ -1,7 +1,18 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_background">
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list" android:id="@+id/list"
android:name="it.danieleverducci.subitobeers.BeersFragment" android:name="it.danieleverducci.subitobeers.BeersFragment"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -11,3 +22,5 @@
app:layoutManager="LinearLayoutManager" app:layoutManager="LinearLayoutManager"
tools:context=".ui.BeersFragment" tools:context=".ui.BeersFragment"
tools:listitem="@layout/fragment_beers_listitem" /> tools:listitem="@layout/fragment_beers_listitem" />
</LinearLayout>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- Filter button -->
<item
android:id="@+id/action_favorite"
android:icon="@drawable/ic_action_filter"
android:title="@string/action_filter"
app:showAsAction="always"/>
</menu>

View File

@ -12,4 +12,6 @@
<string name="placeholder_firstbrewed">00/0000</string> <string name="placeholder_firstbrewed">00/0000</string>
<string name="placeholder_description">Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tristique consectetur felis vel pretium. Praesent tincidunt vestibulum lacus, molestie rhoncus lacus fermentum vel. Morbi vel pulvinar sapien, sed ultrices arcu. Vivamus gravida nulla vel ex varius, vel consequat dolor tincidunt. Fusce maximus quis mi eget tristique. Aenean sed facilisis libero. Aliquam volutpat posuere fringilla. Praesent in lorem at elit ornare congue et quis quam. Maecenas tempus et purus ac rhoncus. Donec in pulvinar ex. Aliquam ac vehicula dolor. Nam vitae tortor id nibh congue sollicitudin id in nisi. Proin lorem eros, congue at euismod et, malesuada porta nunc. Proin laoreet massa ac mi lacinia, eget tincidunt odio vestibulum. Vestibulum fermentum nunc nunc, eget ultrices nisi tempor non. Curabitur lorem leo, fringilla et pellentesque a, pharetra id magna. </string> <string name="placeholder_description">Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tristique consectetur felis vel pretium. Praesent tincidunt vestibulum lacus, molestie rhoncus lacus fermentum vel. Morbi vel pulvinar sapien, sed ultrices arcu. Vivamus gravida nulla vel ex varius, vel consequat dolor tincidunt. Fusce maximus quis mi eget tristique. Aenean sed facilisis libero. Aliquam volutpat posuere fringilla. Praesent in lorem at elit ornare congue et quis quam. Maecenas tempus et purus ac rhoncus. Donec in pulvinar ex. Aliquam ac vehicula dolor. Nam vitae tortor id nibh congue sollicitudin id in nisi. Proin lorem eros, congue at euismod et, malesuada porta nunc. Proin laoreet massa ac mi lacinia, eget tincidunt odio vestibulum. Vestibulum fermentum nunc nunc, eget ultrices nisi tempor non. Curabitur lorem leo, fringilla et pellentesque a, pharetra id magna. </string>
<!-- Menu -->
<string name="action_filter">Filter</string>
</resources> </resources>