From 359a78e23730a51b158a8323e4b85f461673122b Mon Sep 17 00:00:00 2001 From: Daniele Date: Sun, 5 Sep 2021 18:05:16 +0200 Subject: [PATCH] Italian translation, loading indicator and empty list message --- .../subitobeers/ui/BeersFragment.kt | 43 ++++++++++++------- .../main/res/layout/fragment_beers_list.xml | 16 +++++++ app/src/main/res/values-it/strings.xml | 21 +++++++++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 66 insertions(+), 15 deletions(-) create mode 100644 app/src/main/res/values-it/strings.xml diff --git a/app/src/main/java/it/danieleverducci/subitobeers/ui/BeersFragment.kt b/app/src/main/java/it/danieleverducci/subitobeers/ui/BeersFragment.kt index 9d79632..920b672 100644 --- a/app/src/main/java/it/danieleverducci/subitobeers/ui/BeersFragment.kt +++ b/app/src/main/java/it/danieleverducci/subitobeers/ui/BeersFragment.kt @@ -32,7 +32,7 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter. private val rvAdapter = BeerRecyclerAdapter() private val repo = BeersRepository() - private var binding: FragmentBeersListBinding? = null + private lateinit var binding: FragmentBeersListBinding override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -40,7 +40,7 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter. ): View? { setHasOptionsMenu(true); - if (binding == null) { + if (!this::binding.isInitialized) { // Inflate layout binding = FragmentBeersListBinding.inflate( LayoutInflater.from(container!!.context), @@ -49,12 +49,12 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter. ) // Register filter buttons listeners - binding!!.listFilterSinceBt.setOnClickListener { onFilterButtonClicked(FILTERTYPE.SINCE) } - binding!!.listFilterToBt.setOnClickListener { onFilterButtonClicked(FILTERTYPE.TO) } - binding!!.listFilterClear.setOnClickListener { onFilterButtonClicked(FILTERTYPE.CLEAR) } + binding.listFilterSinceBt.setOnClickListener { onFilterButtonClicked(FILTERTYPE.SINCE) } + binding.listFilterToBt.setOnClickListener { onFilterButtonClicked(FILTERTYPE.TO) } + binding.listFilterClear.setOnClickListener { onFilterButtonClicked(FILTERTYPE.CLEAR) } // Set the adapter - with(binding!!.list) { + with(binding.list) { layoutManager = LinearLayoutManager(context) adapter = rvAdapter } @@ -68,18 +68,18 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter. // Restore state repo.filter.brewedBefore = savedInstanceState?.getString(INSTANCESTATE_FILTER_TO) repo.filter.brewedAfter = savedInstanceState?.getString(INSTANCESTATE_FILTER_SINCE) - binding!!.listFilterDropdown.visibility = + binding.listFilterDropdown.visibility = if (savedInstanceState?.getBoolean(INSTANCESTATE_FILTER_OPEN) == true) View.VISIBLE else View.GONE // Load first page loadBeers(true) } - return binding!!.root + return binding.root } override fun onSaveInstanceState(outState: Bundle) { - outState.putBoolean(INSTANCESTATE_FILTER_OPEN, binding!!.listFilterDropdown.visibility == View.VISIBLE) + outState.putBoolean(INSTANCESTATE_FILTER_OPEN, binding.listFilterDropdown.visibility == View.VISIBLE) outState.putString(INSTANCESTATE_FILTER_SINCE, repo.filter.brewedAfter) outState.putString(INSTANCESTATE_FILTER_TO, repo.filter.brewedBefore) super.onSaveInstanceState(outState) @@ -97,10 +97,22 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter. return super.onOptionsItemSelected(item) } + /** + * Beers obtained from services callback + * @param beers List of beers + * @param more Whether there are more beers to retrieve + */ override fun onBeersObtained(beers: List, more: Boolean) { + binding.listProgress.visibility = View.GONE rvAdapter.addItems(beers, more) + + binding.listEmpty.visibility = + if (beers.isEmpty() && repo.page == 1) View.VISIBLE else View.GONE } + /** + * Unable to obtain beers from services + */ override fun onFailure() { Toast.makeText(context, R.string.network_error, Toast.LENGTH_SHORT).show() } @@ -123,8 +135,8 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter. if (type == FILTERTYPE.CLEAR) { repo.filter.clear() loadBeers(true) - binding!!.listFilterSinceBt.setText(R.string.list_filter_brewed_after) - binding!!.listFilterToBt.setText(R.string.list_filter_brewed_before) + binding.listFilterSinceBt.setText(R.string.list_filter_brewed_after) + binding.listFilterToBt.setText(R.string.list_filter_brewed_before) return } @@ -133,10 +145,10 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter. if (type == FILTERTYPE.SINCE) { repo.filter.setBrewedAfter(selMonth, selYear) - binding!!.listFilterSinceBt.setText(repo.filter.brewedAfter) + binding.listFilterSinceBt.setText(repo.filter.brewedAfter) } else { repo.filter.setBrewedBefore(selMonth, selYear) - binding!!.listFilterToBt.setText(repo.filter.brewedBefore) + binding.listFilterToBt.setText(repo.filter.brewedBefore) } // Update list @@ -168,8 +180,8 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter. * Toggles beer filter visibility */ private fun toggleFilter() { - binding!!.listFilterDropdown.visibility = - if (binding!!.listFilterDropdown.visibility == View.VISIBLE) View.GONE else View.VISIBLE + binding.listFilterDropdown.visibility = + if (binding.listFilterDropdown.visibility == View.VISIBLE) View.GONE else View.VISIBLE } /** @@ -178,6 +190,7 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter. */ private fun loadBeers(clear: Boolean) { if (clear) { + binding.listProgress.visibility = View.VISIBLE rvAdapter.clear() repo.reset() } diff --git a/app/src/main/res/layout/fragment_beers_list.xml b/app/src/main/res/layout/fragment_beers_list.xml index 3a8af27..61bd226 100644 --- a/app/src/main/res/layout/fragment_beers_list.xml +++ b/app/src/main/res/layout/fragment_beers_list.xml @@ -49,6 +49,22 @@ + + + + + + SubitoBeers + + + Impossibile ottenere le birre + Prod. dopo + Prod. prima + Nessuna birra trovata + + + + + Nome della birra + Lorem ipsum dolor sit amet + 00/0000 + 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. + + + Filtra + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b94144c..f94703f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -5,6 +5,7 @@ Unable to retrieve beers from network Brewed after Brewed before + No beers found