Archived
CanteenFragment.kt now refreshes automatically on initial launch
This commit is contained in:
@@ -69,14 +69,6 @@ class CanteenFragment : AppFragment() {
|
||||
))
|
||||
}
|
||||
|
||||
// Create badge
|
||||
// val badge = BadgeDrawable.create(context)
|
||||
//// badge.isVisible = true
|
||||
// badge.number = 1
|
||||
// badge.badgeGravity = BadgeDrawable.TOP_END
|
||||
// // Attach badge to button
|
||||
// BadgeUtils.attachBadgeDrawable(badge, binding.buttonNotifications, binding.buttonNotificationsBadgeContainer)
|
||||
|
||||
// Assign a preference value to every button to filter for dietary preferences
|
||||
val chipMap = mapOf(
|
||||
binding.chipPrefFair to DietaryPreferences.WELFARE,
|
||||
@@ -195,6 +187,18 @@ class CanteenFragment : AppFragment() {
|
||||
binding.swipeRefreshLayout.setOnRefreshListener {
|
||||
refresh()
|
||||
}
|
||||
|
||||
// Check if the user is opening the canteen fragment for the first time
|
||||
if (!viewModel.preferenceHasOpenedCanteen) {
|
||||
// Show that a refresh is in progress
|
||||
binding.swipeRefreshLayout.isRefreshing = true
|
||||
|
||||
// Refresh to fetch the first items and avoid showing an empty list
|
||||
refresh()
|
||||
|
||||
// Save that the canteen has been opened before
|
||||
viewModel.preferenceHasOpenedCanteen = true
|
||||
}
|
||||
}
|
||||
|
||||
// Invalidate the view binding
|
||||
|
||||
@@ -58,5 +58,10 @@ enum class SettingsPreferences(val key: String) {
|
||||
* The canteen the user has picked.
|
||||
*/
|
||||
CANTEEN("setting_canteen"),
|
||||
|
||||
/**
|
||||
* Whether the user has opened the canteen fragment before.
|
||||
*/
|
||||
HAS_OPENED_CANTEEN("has_opened_canteen"),
|
||||
;
|
||||
}
|
||||
@@ -70,4 +70,11 @@ class CanteenViewModel(app: Application) : AppViewModel(app) {
|
||||
var preferenceCanteen: Int
|
||||
get() = repo.getIntPreference(SettingsPreferences.CANTEEN)
|
||||
set(newValue) { repo.setPreference(SettingsPreferences.CANTEEN, newValue) }
|
||||
|
||||
/**
|
||||
* This value determines whether the user has opened the canteen fragment before.
|
||||
*/
|
||||
var preferenceHasOpenedCanteen: Boolean
|
||||
get() = repo.getBooleanPreference(SettingsPreferences.HAS_OPENED_CANTEEN)
|
||||
set(newValue) { repo.setPreference(SettingsPreferences.HAS_OPENED_CANTEEN, newValue) }
|
||||
}
|
||||
Reference in New Issue
Block a user