2023-04-16 18:19:06 +02:00
|
|
|
package com.denizk0461.studip.fragment
|
|
|
|
|
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
|
import android.view.View
|
|
|
|
|
import android.view.ViewGroup
|
2023-04-25 15:38:30 +02:00
|
|
|
import androidx.appcompat.widget.PopupMenu
|
2023-04-27 21:58:10 +02:00
|
|
|
import androidx.fragment.app.FragmentActivity
|
2023-04-16 18:19:06 +02:00
|
|
|
import androidx.fragment.app.viewModels
|
2023-04-25 15:38:30 +02:00
|
|
|
import com.denizk0461.studip.R
|
2023-04-23 17:13:48 +02:00
|
|
|
import com.denizk0461.studip.adapter.CanteenOfferItemAdapter
|
2023-04-16 21:41:46 +02:00
|
|
|
import com.denizk0461.studip.adapter.CanteenOfferPageAdapter
|
2023-04-16 18:19:06 +02:00
|
|
|
import com.denizk0461.studip.databinding.FragmentCanteenBinding
|
2023-04-20 21:35:09 +02:00
|
|
|
import com.denizk0461.studip.model.*
|
2023-04-23 17:13:48 +02:00
|
|
|
import com.denizk0461.studip.sheet.AllergenSheet
|
2023-04-25 16:55:17 +02:00
|
|
|
import com.denizk0461.studip.sheet.TextSheet
|
2023-04-16 18:19:06 +02:00
|
|
|
import com.denizk0461.studip.viewmodel.CanteenViewModel
|
2023-04-16 21:41:46 +02:00
|
|
|
import com.google.android.material.tabs.TabLayoutMediator
|
2023-04-16 18:19:06 +02:00
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
/**
|
|
|
|
|
* User-facing fragment view that displays the canteen offers from the website of the
|
|
|
|
|
* Studierendenwerk Bremen.
|
|
|
|
|
*/
|
2023-04-23 17:13:48 +02:00
|
|
|
class CanteenFragment : AppFragment(), CanteenOfferItemAdapter.OnClickListener {
|
2023-04-16 18:19:06 +02:00
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
// Nullable view binding reference
|
2023-04-16 18:19:06 +02:00
|
|
|
private var _binding: FragmentCanteenBinding? = null
|
|
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
/*
|
|
|
|
|
* Non-null reference to the view binding. This property is only valid between onCreateView and
|
|
|
|
|
* onDestroyView.
|
|
|
|
|
* BUG if the fragment is changed before the refresh is finished, the app crashes with a NPE
|
|
|
|
|
*/
|
2023-04-16 18:19:06 +02:00
|
|
|
private val binding get() = _binding!!
|
|
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
// Adapter for the view pager displaying all offers
|
2023-04-16 21:41:46 +02:00
|
|
|
private lateinit var viewPagerAdapter: CanteenOfferPageAdapter
|
2023-04-23 11:57:03 +02:00
|
|
|
|
|
|
|
|
// View model reference for providing access to the database
|
2023-04-16 18:19:06 +02:00
|
|
|
private val viewModel: CanteenViewModel by viewModels()
|
|
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
// Elements in the canteen plan
|
2023-04-20 10:17:04 +02:00
|
|
|
private var elements: List<CanteenOffer> = listOf()
|
|
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
// Count of days displayed in the canteen plan
|
|
|
|
|
private var dateSize: Int = 0
|
|
|
|
|
|
|
|
|
|
// Used if no preference has been set or none can be found
|
|
|
|
|
private val emptyPreferenceRegex: String = ".........."
|
|
|
|
|
|
2023-04-25 16:55:17 +02:00
|
|
|
private var openingHours = ""
|
|
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
// Instantiate the view binding
|
2023-04-16 18:19:06 +02:00
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
|
|
|
|
_binding = FragmentCanteenBinding.inflate(inflater, container, false)
|
|
|
|
|
return binding.root
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
|
|
|
|
|
2023-04-26 10:21:16 +02:00
|
|
|
// Open the menu for the canteen picker button
|
2023-04-25 15:38:30 +02:00
|
|
|
binding.buttonCanteenPicker.setOnClickListener {
|
|
|
|
|
PopupMenu(binding.root.context, binding.buttonCanteenPicker).apply {
|
|
|
|
|
setOnMenuItemClickListener { item ->
|
|
|
|
|
viewModel.preferenceCanteen = when (item?.itemId) {
|
|
|
|
|
R.id.mensa_uni -> 0
|
|
|
|
|
R.id.cafe_central -> 1
|
|
|
|
|
R.id.mensa_nw1 -> 2
|
|
|
|
|
R.id.cafeteria_gw2 -> 3
|
|
|
|
|
R.id.mensa_neustadt -> 4
|
|
|
|
|
R.id.mensa_werder -> 5
|
|
|
|
|
R.id.mensa_airport -> 6
|
|
|
|
|
R.id.mensa_bhv -> 7
|
|
|
|
|
R.id.cafeteria_bhv -> 8
|
|
|
|
|
R.id.mensa_hfk -> 9
|
|
|
|
|
else -> 0
|
|
|
|
|
}
|
2023-04-26 10:21:16 +02:00
|
|
|
// Set newly selected canteen to the button
|
2023-04-25 16:55:17 +02:00
|
|
|
binding.buttonCanteenPicker.text = getCurrentlySelectedCanteenName()
|
2023-04-26 10:21:16 +02:00
|
|
|
|
|
|
|
|
// Display to the user that the canteen plan will be refreshed
|
|
|
|
|
binding.swipeRefreshLayout.isRefreshing = true
|
|
|
|
|
|
|
|
|
|
// Refresh the canteen menu for the newly selected canteen
|
2023-04-25 16:55:17 +02:00
|
|
|
refresh()
|
2023-04-25 15:38:30 +02:00
|
|
|
true
|
|
|
|
|
}
|
|
|
|
|
inflate(R.menu.menu_canteens)
|
|
|
|
|
show()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-26 10:21:16 +02:00
|
|
|
// Set currently selected canteen to the button
|
|
|
|
|
binding.buttonCanteenPicker.text = getCurrentlySelectedCanteenName()
|
|
|
|
|
|
2023-04-25 16:55:17 +02:00
|
|
|
binding.buttonInfo.setOnClickListener {
|
|
|
|
|
openBottomSheet(
|
|
|
|
|
TextSheet(
|
|
|
|
|
getString(
|
|
|
|
|
R.string.canteen_opening_hours,
|
|
|
|
|
getCurrentlySelectedCanteenName()
|
|
|
|
|
),
|
|
|
|
|
openingHours
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-25 15:38:30 +02:00
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
// Assign a preference value to every button to filter for dietary preferences
|
2023-04-18 15:39:49 +02:00
|
|
|
val chipMap = mapOf(
|
2023-04-27 20:27:42 +02:00
|
|
|
binding.chipPrefFair to DietaryPreferences.WELFARE,
|
2023-04-18 10:25:45 +02:00
|
|
|
binding.chipPrefFish to DietaryPreferences.FISH,
|
|
|
|
|
binding.chipPrefPoultry to DietaryPreferences.POULTRY,
|
|
|
|
|
binding.chipPrefLamb to DietaryPreferences.LAMB,
|
|
|
|
|
binding.chipPrefVital to DietaryPreferences.VITAL,
|
|
|
|
|
binding.chipPrefBeef to DietaryPreferences.BEEF,
|
|
|
|
|
binding.chipPrefPork to DietaryPreferences.PORK,
|
|
|
|
|
binding.chipPrefVegetarian to DietaryPreferences.VEGETARIAN,
|
|
|
|
|
binding.chipPrefVegan to DietaryPreferences.VEGAN,
|
|
|
|
|
binding.chipPrefGame to DietaryPreferences.GAME,
|
|
|
|
|
)
|
|
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
// Set up every chip
|
2023-04-18 15:39:49 +02:00
|
|
|
chipMap.forEach { (chip, pref) ->
|
2023-04-23 11:57:03 +02:00
|
|
|
// Set chip to be checked if user has set this preference before
|
2023-04-18 10:25:45 +02:00
|
|
|
chip.isChecked = getPreference(pref)
|
2023-04-18 15:39:49 +02:00
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
// Set a listener for when the user clicks the chip
|
|
|
|
|
chip.setOnCheckedChangeListener { buttonView, newValue ->
|
|
|
|
|
// Save the preference change to persistent storage
|
|
|
|
|
setPreference(pref, newValue)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Force an animation on click. This is a subpar method from StackOverflow. Since
|
|
|
|
|
* it removes the view before immediately adding it back, this method causes a
|
|
|
|
|
* flicker.
|
|
|
|
|
* TODO implement a more efficient / better-looking method
|
2023-04-18 15:39:49 +02:00
|
|
|
* TODO order the chips alphabetically
|
|
|
|
|
*/
|
|
|
|
|
val index = binding.chipsPreference.indexOfChild(buttonView)
|
|
|
|
|
binding.chipsPreference.removeView(buttonView)
|
|
|
|
|
binding.chipsPreference.addView(buttonView, index)
|
2023-04-18 10:25:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
// Set up the view pager's adapter
|
2023-04-23 22:06:29 +02:00
|
|
|
viewPagerAdapter = CanteenOfferPageAdapter(
|
2023-04-27 21:58:10 +02:00
|
|
|
activity as FragmentActivity,
|
|
|
|
|
listOf(),
|
|
|
|
|
0,
|
|
|
|
|
this,
|
|
|
|
|
viewModel.preferenceAllergen,
|
2023-04-23 22:06:29 +02:00
|
|
|
)
|
2023-04-23 11:57:03 +02:00
|
|
|
|
|
|
|
|
// Assign the adapter to the view pager
|
2023-04-16 21:41:46 +02:00
|
|
|
binding.viewPager.adapter = viewPagerAdapter
|
|
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
// Create and attach the tab mediator for the view pager
|
2023-04-27 15:15:29 +02:00
|
|
|
// createTabLayoutMediator()
|
2023-04-16 21:41:46 +02:00
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
// Set up LiveData observer to refresh the view on update
|
2023-04-21 14:20:06 +02:00
|
|
|
viewModel.allOffers.observe(viewLifecycleOwner) { offers ->
|
2023-04-23 11:57:03 +02:00
|
|
|
// Update the element list stored in this fragment
|
2023-04-20 10:17:04 +02:00
|
|
|
elements = offers
|
2023-04-16 21:41:46 +02:00
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
// Group elements by category
|
2023-04-20 08:17:23 +02:00
|
|
|
val groupedElements = offers.groupElements().distinct()
|
|
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
// Find all dates stored in the database
|
2023-04-27 21:58:10 +02:00
|
|
|
// val newDates = /*groupedElements.map { it.date }.distinct() TODO */viewModel.getDates()
|
|
|
|
|
|
|
|
|
|
val newDates = groupedElements.map { it.date }.distinct()
|
2023-04-16 21:41:46 +02:00
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
// Update the date count stored in this fragment
|
2023-04-20 21:35:09 +02:00
|
|
|
dateSize = newDates.size
|
2023-04-20 10:17:04 +02:00
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
// Update the item list in the view pager's adapter
|
2023-04-20 21:35:09 +02:00
|
|
|
viewPagerAdapter.setNewItems(groupedElements, dateSize)
|
2023-04-16 21:41:46 +02:00
|
|
|
|
2023-04-25 16:55:17 +02:00
|
|
|
// Set the text for the opening hours dialogue
|
|
|
|
|
openingHours = viewModel.getCanteenOpeningHours()
|
2023-04-27 15:15:29 +02:00
|
|
|
|
|
|
|
|
binding.swipeRefreshLayout.isRefreshing = false
|
|
|
|
|
|
|
|
|
|
// createTabLayoutMediator(newDates)
|
2023-04-16 18:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
// Set up functions for when the user swipes to refresh the view
|
2023-04-16 18:19:06 +02:00
|
|
|
binding.swipeRefreshLayout.setOnRefreshListener {
|
2023-04-25 16:55:17 +02:00
|
|
|
refresh()
|
2023-04-16 18:19:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
/**
|
|
|
|
|
* Create and attach the object mediating the tabs for the view pager.
|
2023-04-25 15:38:30 +02:00
|
|
|
* TODO this is crash-prone and doesn't refresh when the dates get renewed (when the last update
|
|
|
|
|
* was from the day prior)
|
2023-04-27 15:15:29 +02:00
|
|
|
* TODO WHY DO YOU THROW AN INDEXOUTOFBOUNDSEXCEPTION????
|
2023-04-23 11:57:03 +02:00
|
|
|
*/
|
2023-04-27 15:15:29 +02:00
|
|
|
private fun createTabLayoutMediator(dates: List<OfferDate>) {
|
2023-04-23 11:57:03 +02:00
|
|
|
// Fetch all dates from the database
|
2023-04-27 15:15:29 +02:00
|
|
|
// val dates = viewModel.getDates()
|
2023-04-23 20:33:17 +02:00
|
|
|
|
2023-04-16 21:41:46 +02:00
|
|
|
if (dates.isNotEmpty()) {
|
|
|
|
|
TabLayoutMediator(binding.dayTabLayout, binding.viewPager) { tab, position ->
|
2023-04-20 21:35:09 +02:00
|
|
|
tab.text = dates[position].date
|
2023-04-16 21:41:46 +02:00
|
|
|
}.attach()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
// Invalidate the view binding
|
2023-04-16 18:19:06 +02:00
|
|
|
override fun onDestroyView() {
|
|
|
|
|
super.onDestroyView()
|
|
|
|
|
_binding = null
|
|
|
|
|
}
|
2023-04-18 10:25:45 +02:00
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
/**
|
|
|
|
|
* Updates a given preference and refreshes the view.
|
|
|
|
|
*
|
|
|
|
|
* @param pref preference to be updated
|
|
|
|
|
* @param newValue value to set the preference to
|
|
|
|
|
*/
|
2023-04-18 10:25:45 +02:00
|
|
|
private fun setPreference(pref: DietaryPreferences, newValue: Boolean) {
|
2023-04-23 11:57:03 +02:00
|
|
|
// Update the preference
|
2023-04-18 10:25:45 +02:00
|
|
|
viewModel.setPreference(pref, newValue)
|
2023-04-23 11:57:03 +02:00
|
|
|
|
|
|
|
|
// Update the view
|
2023-04-20 10:17:04 +02:00
|
|
|
viewPagerAdapter.setNewItems(elements.groupElements().distinct(), dateSize)
|
2023-04-18 10:25:45 +02:00
|
|
|
}
|
|
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
/**
|
|
|
|
|
* Retrieves a single user-specified dietary preference.
|
|
|
|
|
*
|
|
|
|
|
* @param pref the dietary preference that should be retrieved
|
|
|
|
|
* @return whether the preference needs to be met
|
|
|
|
|
*/
|
2023-04-18 10:25:45 +02:00
|
|
|
private fun getPreference(pref: DietaryPreferences): Boolean =
|
|
|
|
|
viewModel.getPreference(pref)
|
2023-04-18 15:39:49 +02:00
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
/**
|
|
|
|
|
* Retrieves the user's dietary preferences and compiles them into a regular expression that can
|
|
|
|
|
* be used to filter out items that don't fulfil the preferences. Example:
|
|
|
|
|
* .......t..|........t.
|
|
|
|
|
* This will retrieve all items that marked as either vegetarian or vegan
|
|
|
|
|
* *
|
|
|
|
|
* @return regular expression object reflecting the user's preferences
|
|
|
|
|
*/
|
2023-04-20 11:53:14 +02:00
|
|
|
private fun getPrefRegex(): Regex {
|
2023-04-23 11:57:03 +02:00
|
|
|
// Retrieve the user's dietary preference as a string
|
|
|
|
|
val prefs = viewModel.getDietaryPrefs().deconstruct()
|
2023-04-20 11:53:14 +02:00
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
// Return the 'empty' template string if no preference has been set or found
|
|
|
|
|
return if (prefs == emptyPreferenceRegex) {
|
|
|
|
|
Regex(emptyPreferenceRegex)
|
2023-04-20 11:53:14 +02:00
|
|
|
} else {
|
2023-04-23 11:57:03 +02:00
|
|
|
// Create the variable to insert the regular expression into
|
2023-04-20 11:53:14 +02:00
|
|
|
var regexString = ""
|
|
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
// Create the object to store which preferences need to be met
|
2023-04-20 11:53:14 +02:00
|
|
|
val indices = mutableListOf<Int>()
|
2023-04-23 11:57:03 +02:00
|
|
|
|
|
|
|
|
// Find all preferences that need to be met
|
2023-04-20 11:53:14 +02:00
|
|
|
prefs.forEachIndexed { index, c ->
|
2023-04-27 20:27:42 +02:00
|
|
|
if (c == DietaryPreferences.C_TRUE) indices.add(index)
|
2023-04-20 11:53:14 +02:00
|
|
|
}
|
2023-04-23 11:57:03 +02:00
|
|
|
|
|
|
|
|
// Needs to be set to correctly assemble the regular expression
|
2023-04-20 11:53:14 +02:00
|
|
|
var isFirst = true
|
2023-04-23 11:57:03 +02:00
|
|
|
|
|
|
|
|
// Iterate through every preference that has been set
|
2023-04-20 11:53:14 +02:00
|
|
|
indices.forEach { index ->
|
2023-04-23 11:57:03 +02:00
|
|
|
// Set an OR if more than one preference needs to be met
|
2023-04-20 11:53:14 +02:00
|
|
|
if (!isFirst) regexString += '|'
|
2023-04-23 11:57:03 +02:00
|
|
|
|
|
|
|
|
// Add the expression looking for the single preference to the entire string
|
|
|
|
|
regexString += emptyPreferenceRegex.substring(0 until index) +
|
2023-04-27 20:27:42 +02:00
|
|
|
DietaryPreferences.C_TRUE +
|
2023-04-23 11:57:03 +02:00
|
|
|
emptyPreferenceRegex.substring(index+1)
|
|
|
|
|
|
|
|
|
|
// Ensure that OR statements will be placed between the individual expressions
|
2023-04-20 11:53:14 +02:00
|
|
|
isFirst = false
|
|
|
|
|
}
|
2023-04-23 11:57:03 +02:00
|
|
|
|
|
|
|
|
// Compile the string to a regular expression object
|
2023-04-20 11:53:14 +02:00
|
|
|
Regex(regexString)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-20 08:17:23 +02:00
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
/**
|
|
|
|
|
* Groups [CanteenOffer] elements by their categories into [CanteenOfferGroup] elements and
|
|
|
|
|
* filters for the user's dietary preferences.
|
|
|
|
|
*
|
|
|
|
|
* @return the grouped and filtered elements
|
|
|
|
|
*/
|
2023-04-20 08:17:23 +02:00
|
|
|
private fun List<CanteenOffer>.groupElements(): List<CanteenOfferGroup> {
|
2023-04-23 11:57:03 +02:00
|
|
|
// Get dietary preference regex
|
2023-04-20 08:17:23 +02:00
|
|
|
val prefsRegex = getPrefRegex()
|
|
|
|
|
|
2023-04-27 20:27:42 +02:00
|
|
|
val filteredForPrefs = if (prefsRegex.toString() == emptyPreferenceRegex) {
|
2023-04-23 11:57:03 +02:00
|
|
|
// Show all elements and skip filtering if no preference is set
|
2023-04-20 08:17:23 +02:00
|
|
|
this
|
|
|
|
|
} else {
|
2023-04-23 11:57:03 +02:00
|
|
|
// Filter for dietary preferences
|
2023-04-20 08:17:23 +02:00
|
|
|
this.filter {
|
|
|
|
|
prefsRegex.matches(it.dietaryPreferences)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-27 20:27:42 +02:00
|
|
|
return filteredForPrefs.map { (_, date, dateId, category, _, canteen, _, _, _, _, _) ->
|
2023-04-23 11:57:03 +02:00
|
|
|
// Create new group elements to group the already filtered elements by their categories
|
2023-04-20 08:17:23 +02:00
|
|
|
CanteenOfferGroup(
|
2023-04-27 20:27:42 +02:00
|
|
|
date,
|
|
|
|
|
dateId,
|
|
|
|
|
category,
|
|
|
|
|
canteen,
|
|
|
|
|
filteredForPrefs.filter {
|
|
|
|
|
it.category == category && it.date == date && it.canteen == canteen
|
2023-04-20 08:17:23 +02:00
|
|
|
}.map {
|
2023-04-23 11:57:03 +02:00
|
|
|
// Map the individual items to their respective groups
|
2023-04-20 08:17:23 +02:00
|
|
|
CanteenOfferGroupElement(
|
|
|
|
|
it.title,
|
|
|
|
|
it.price,
|
|
|
|
|
it.dietaryPreferences,
|
2023-04-23 20:33:17 +02:00
|
|
|
it.allergens
|
2023-04-20 08:17:23 +02:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-23 17:13:48 +02:00
|
|
|
|
2023-04-25 16:55:17 +02:00
|
|
|
/**
|
|
|
|
|
* Retrieves the localised string for the canteen selected by the user.
|
|
|
|
|
*
|
|
|
|
|
* @return the localised canteen name
|
|
|
|
|
*/
|
|
|
|
|
private fun getCurrentlySelectedCanteenName(): String = getString(
|
|
|
|
|
when (viewModel.preferenceCanteen) {
|
|
|
|
|
0 -> R.string.mensa_uni
|
|
|
|
|
1 -> R.string.cafe_central
|
|
|
|
|
2 -> R.string.mensa_nw1
|
|
|
|
|
3 -> R.string.cafeteria_gw2
|
|
|
|
|
4 -> R.string.mensa_neustadt
|
|
|
|
|
5 -> R.string.mensa_werder
|
|
|
|
|
6 -> R.string.mensa_airport
|
|
|
|
|
7 -> R.string.mensa_bhv
|
|
|
|
|
8 -> R.string.cafeteria_bhv
|
|
|
|
|
9 -> R.string.mensa_hfk
|
|
|
|
|
else -> R.string.mensa_uni
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Downloads the canteen offers and refreshes them in the app.
|
2023-04-27 15:15:29 +02:00
|
|
|
* TODO handle SocketTimeoutException
|
2023-04-25 16:55:17 +02:00
|
|
|
*/
|
|
|
|
|
private fun refresh() {
|
|
|
|
|
// Retrieve new offers from the website(s)
|
|
|
|
|
viewModel.fetchOffers(viewModel.preferenceCanteen, onRefreshUpdate = { status ->
|
|
|
|
|
// TODO refresh updates
|
|
|
|
|
}, onFinish = {
|
2023-04-26 19:49:29 +02:00
|
|
|
/*
|
|
|
|
|
* Tell the swipe refresh layout to stop refreshing.
|
|
|
|
|
* TODO if an exception is raised, this will not be fired. This must be changed
|
|
|
|
|
*/
|
2023-04-25 16:55:17 +02:00
|
|
|
// binding.swipeRefreshLayout.isRefreshing = false
|
|
|
|
|
// createTabLayoutMediator()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-23 17:13:48 +02:00
|
|
|
/**
|
|
|
|
|
* Executed when an item has been clicked.
|
|
|
|
|
*
|
|
|
|
|
* @param offer item that has been clicked
|
|
|
|
|
*/
|
2023-04-24 11:21:52 +02:00
|
|
|
override fun onClick(offer: CanteenOfferGroupElement, category: String) {
|
|
|
|
|
openBottomSheet(AllergenSheet(offer, category))
|
2023-04-23 17:13:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Executed when an item has been long-pressed.
|
|
|
|
|
*
|
|
|
|
|
* @param offer item that has been long-pressed
|
|
|
|
|
* @return whether the long press was successful
|
|
|
|
|
*/
|
|
|
|
|
override fun onLongClick(offer: CanteenOfferGroupElement): Boolean {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2023-04-16 18:19:06 +02:00
|
|
|
}
|