From df0c9511000506a66385d5dbb4a57b9c0b7ffc1d Mon Sep 17 00:00:00 2001 From: Reimar Date: Thu, 8 May 2025 11:02:04 +0200 Subject: [PATCH] Add progress bar and empty message to shopping list --- .../ui/shopping_list/ShoppingListFragment.kt | 32 +++++++++---------- .../res/layout/fragment_shopping_list.xml | 24 ++++++++++++-- app/app/src/main/res/values/strings.xml | 1 + 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/app/app/src/main/java/tech/mercantec/easyeat/ui/shopping_list/ShoppingListFragment.kt b/app/app/src/main/java/tech/mercantec/easyeat/ui/shopping_list/ShoppingListFragment.kt index ba837e6..7fd4d67 100644 --- a/app/app/src/main/java/tech/mercantec/easyeat/ui/shopping_list/ShoppingListFragment.kt +++ b/app/app/src/main/java/tech/mercantec/easyeat/ui/shopping_list/ShoppingListFragment.kt @@ -1,7 +1,6 @@ package tech.mercantec.easyeat.ui.shopping_list import android.app.AlertDialog -import android.app.Dialog import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -19,26 +18,22 @@ import tech.mercantec.easyeat.helpers.addShoppingItem import tech.mercantec.easyeat.helpers.deleteShoppingItem import tech.mercantec.easyeat.helpers.getShoppingList import tech.mercantec.easyeat.helpers.toggleShoppingItemChecked -import tech.mercantec.easyeat.models.Dish import tech.mercantec.easyeat.models.ShoppingListItem import java.util.ArrayList import kotlin.concurrent.thread class ShoppingListFragment : Fragment() { - - private var _binding: FragmentShoppingListBinding? = null - - // This property is only valid between onCreateView and - // onDestroyView. - private val binding get() = _binding!! - override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View { - _binding = FragmentShoppingListBinding.inflate(inflater, container, false) - val root: View = binding.root + val binding = FragmentShoppingListBinding.inflate(inflater, container, false) + + binding.shoppingList.visibility = View.GONE + binding.emptyShoppingList.visibility = View.GONE + binding.addToShoppingList.visibility = View.GONE + binding.loading.visibility = View.VISIBLE // Fetch shopping list items thread { @@ -48,12 +43,20 @@ class ShoppingListFragment : Fragment() { } catch (e: ApiRequestException) { activity?.runOnUiThread { Toast.makeText(context, e.message, Toast.LENGTH_LONG).show() + + binding.loading.visibility = View.GONE } return@thread } activity?.runOnUiThread { + binding.shoppingList.visibility = View.VISIBLE + binding.emptyShoppingList.visibility = View.VISIBLE + binding.addToShoppingList.visibility = View.VISIBLE + binding.loading.visibility = View.GONE + + binding.shoppingList.emptyView = binding.emptyShoppingList binding.shoppingList.adapter = ShoppingItemAdapter(requireContext(), ArrayList(items.toMutableList())) } } @@ -162,11 +165,6 @@ class ShoppingListFragment : Fragment() { dialog.findViewById(R.id.unit_selector).adapter = adapter } - return root - } - - override fun onDestroyView() { - super.onDestroyView() - _binding = null + return binding.root } } \ No newline at end of file diff --git a/app/app/src/main/res/layout/fragment_shopping_list.xml b/app/app/src/main/res/layout/fragment_shopping_list.xml index 17466ab..dab1872 100644 --- a/app/app/src/main/res/layout/fragment_shopping_list.xml +++ b/app/app/src/main/res/layout/fragment_shopping_list.xml @@ -1,10 +1,19 @@ - + + + + - + diff --git a/app/app/src/main/res/values/strings.xml b/app/app/src/main/res/values/strings.xml index e4bf2ef..3ea29e3 100644 --- a/app/app/src/main/res/values/strings.xml +++ b/app/app/src/main/res/values/strings.xml @@ -40,6 +40,7 @@ Log out Checked Delete + Your shopping list is empty g