Archived
WeserPlaner 1.0.2: canteen news button is now highlighted if news are available, and the news sheet will now only be shown if there are any news available. Otherwise, a toast will tell the user that no news are available.
This commit is contained in:
@@ -11,8 +11,8 @@
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"attributes": [],
|
||||
"versionCode": 4,
|
||||
"versionName": "1.0.1",
|
||||
"versionCode": 5,
|
||||
"versionName": "1.0.2",
|
||||
"outputFile": "app-release.apk"
|
||||
}
|
||||
],
|
||||
|
||||
@@ -27,7 +27,7 @@ class AppRepository(app: Application) {
|
||||
private val blankDietaryPrefs: String = DietaryPreferences.TEMPLATE_EMPTY
|
||||
|
||||
/**
|
||||
* Used to observe just to register an update of the user-set dietary preferences.
|
||||
* Used to observe whenever updates are made to the dietary preferences.
|
||||
*/
|
||||
val dietaryPreferencesUpdate: MutableLiveData<Int> = MutableLiveData(0)
|
||||
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
package com.denizk0461.weserplaner.fragment
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.fragment.app.viewModels
|
||||
import com.denizk0461.weserplaner.R
|
||||
import com.denizk0461.weserplaner.adapter.CanteenOfferPageAdapter
|
||||
import com.denizk0461.weserplaner.data.getTextSheet
|
||||
import com.denizk0461.weserplaner.data.getThemedColor
|
||||
import com.denizk0461.weserplaner.data.setRainbowProgressCircle
|
||||
import com.denizk0461.weserplaner.data.showErrorSnackBar
|
||||
import com.denizk0461.weserplaner.data.showToast
|
||||
import com.denizk0461.weserplaner.databinding.FragmentCanteenBinding
|
||||
import com.denizk0461.weserplaner.model.*
|
||||
import com.denizk0461.weserplaner.viewmodel.CanteenViewModel
|
||||
@@ -60,13 +64,53 @@ class CanteenFragment : AppFragment() {
|
||||
R.string.title_canteen_template,
|
||||
getCurrentlySelectedCanteenName(),
|
||||
)
|
||||
|
||||
// Set the title to be selected so it scrolls (marquee)
|
||||
binding.appTitleBar.isSelected = true
|
||||
|
||||
binding.buttonNotifications.setOnClickListener {
|
||||
openBottomSheet(getTextSheet(
|
||||
getString(R.string.canteen_news_sheet_title),
|
||||
contentId = TextSheetContentId.NEWS,
|
||||
))
|
||||
// Set up observer for the selected canteen
|
||||
viewModel.getCanteen().observe(viewLifecycleOwner) { canteen ->
|
||||
if (canteen == null || canteen.news.isBlank()) {
|
||||
// Set icon to show that no news are available
|
||||
binding.buttonNotifications.icon = AppCompatResources.getDrawable(
|
||||
context,
|
||||
R.drawable.notifications_none,
|
||||
)
|
||||
|
||||
// Apply default colour
|
||||
binding.buttonNotifications.iconTint = ColorStateList.valueOf(
|
||||
context.theme.getThemedColor(
|
||||
R.attr.colorOnSurfaceVariant
|
||||
)
|
||||
)
|
||||
|
||||
// Set up click listener to tell the user that no news are available
|
||||
binding.buttonNotifications.setOnClickListener {
|
||||
showToast(context, getString(R.string.text_sheet_news_empty))
|
||||
}
|
||||
|
||||
} else {
|
||||
// Set icon to show that news are available
|
||||
binding.buttonNotifications.icon = AppCompatResources.getDrawable(
|
||||
context,
|
||||
R.drawable.notifications_active,
|
||||
)
|
||||
|
||||
// Apply highlight colour
|
||||
binding.buttonNotifications.iconTint = ColorStateList.valueOf(
|
||||
context.theme.getThemedColor(
|
||||
com.google.android.material.R.attr.colorPrimary
|
||||
)
|
||||
)
|
||||
|
||||
// Set up click listener to show news sheet
|
||||
binding.buttonNotifications.setOnClickListener {
|
||||
openBottomSheet(getTextSheet(
|
||||
getString(R.string.canteen_news_sheet_title),
|
||||
contentId = TextSheetContentId.NEWS,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Assign a preference value to every button to filter for dietary preferences
|
||||
|
||||
@@ -17,6 +17,9 @@ class CanteenPageViewModel(app: Application) : AppViewModel(app) {
|
||||
fun getOffersByDay(day: Int): LiveData<List<CanteenOffer>> =
|
||||
repo.getOffersByDay(day)
|
||||
|
||||
/**
|
||||
* Used to observe whenever updates are made to the dietary preferences.
|
||||
*/
|
||||
val dietaryPreferencesUpdate: LiveData<Int> = repo.dietaryPreferencesUpdate
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,6 +42,16 @@ class CanteenViewModel(app: Application) : AppViewModel(app) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the canteen stored in the database. Should always be 0 or 1.
|
||||
*
|
||||
* @return canteen
|
||||
*/
|
||||
fun getCanteen(): LiveData<OfferCanteen> = repo.getCanteen()
|
||||
|
||||
/**
|
||||
* Register that the user has made an update to their dietary preferences.
|
||||
*/
|
||||
fun registerDietaryPreferencesUpdate() {
|
||||
repo.dietaryPreferencesUpdate.postValue(repo.dietaryPreferencesUpdate.value?.plus(1))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#000000"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M7.58,4.08L6.15,2.65C3.75,4.48 2.17,7.3 2.03,10.5h2c0.15,-2.65 1.51,-4.97 3.55,-6.42zM19.97,10.5h2c-0.15,-3.2 -1.73,-6.02 -4.12,-7.85l-1.42,1.43c2.02,1.45 3.39,3.77 3.54,6.42zM18,11c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2v-5zM12,22c0.14,0 0.27,-0.01 0.4,-0.04 0.65,-0.14 1.18,-0.58 1.44,-1.18 0.1,-0.24 0.15,-0.5 0.15,-0.78h-4c0.01,1.1 0.9,2 2.01,2z"/>
|
||||
</vector>
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#000000"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.89,2 2,2zM18,16v-5c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2z"/>
|
||||
<path android:fillColor="@android:color/white" android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.9,2 2,2zM18,16v-5c0,-3.07 -1.63,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.64,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2zM16,17L8,17v-6c0,-2.48 1.51,-4.5 4,-4.5s4,2.02 4,4.5v6z"/>
|
||||
</vector>
|
||||
@@ -49,7 +49,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minWidth="0dp"
|
||||
app:icon="@drawable/notification"
|
||||
app:icon="@drawable/notifications_none"
|
||||
app:iconPadding="0dp"
|
||||
app:layout_constraintTop_toTopOf="@id/app_title_bar"
|
||||
app:layout_constraintBottom_toBottomOf="@id/app_title_bar"
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- I am unsure whether these attrs are necessary to define -->
|
||||
<!-- <attr name="colorPrimary" type="color" />-->
|
||||
<attr name="scheduleColorDefault" type="color" />
|
||||
<attr name="colorOutlineVariant" type="color" />
|
||||
<attr name="colorOnSurfaceVariant" type="color" />
|
||||
@@ -11,7 +9,6 @@
|
||||
<attr name="colorOnSecondaryContainer" type="color" />
|
||||
<attr name="colorText" type="color" />
|
||||
<attr name="colorErrorText" type="color" />
|
||||
<!-- <attr name="colorOutline" type="color"/>-->
|
||||
|
||||
<!-- dietary preference colours -->
|
||||
<!-- fair / animal welfare -->
|
||||
|
||||
Reference in New Issue
Block a user