diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
index 69e8615..217e5c5 100644
--- a/.idea/kotlinc.xml
+++ b/.idea/kotlinc.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 628e9f3..94102ad 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -59,6 +59,7 @@ dependencies {
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01'
implementation "androidx.room:room-runtime:2.5.1"
+ implementation 'androidx.core:core-ktx:1.10.0'
kapt "androidx.room:room-compiler:2.5.1"
implementation 'androidx.preference:preference-ktx:1.2.0'
diff --git a/app/src/main/java/com/denizk0461/weserplaner/data/StwParser.kt b/app/src/main/java/com/denizk0461/weserplaner/data/StwParser.kt
index 329156f..7c17d06 100644
--- a/app/src/main/java/com/denizk0461/weserplaner/data/StwParser.kt
+++ b/app/src/main/java/com/denizk0461/weserplaner/data/StwParser.kt
@@ -8,7 +8,6 @@ import kotlinx.coroutines.withContext
import org.jsoup.Jsoup
import org.jsoup.nodes.Element
import org.jsoup.select.Elements
-import java.io.IOException
import kotlin.jvm.Throws
/**
@@ -162,7 +161,7 @@ class StwParser(application: Application) {
doc.getElementsByClass("field__items")[0]
.getElementsByTag("p")[0]
.text()
- } catch (e: IOException) {
+ } catch (e: IndexOutOfBoundsException) {
""
}
diff --git a/app/src/main/java/com/denizk0461/weserplaner/db/AppDAO.kt b/app/src/main/java/com/denizk0461/weserplaner/db/AppDAO.kt
index 977a658..de8d433 100644
--- a/app/src/main/java/com/denizk0461/weserplaner/db/AppDAO.kt
+++ b/app/src/main/java/com/denizk0461/weserplaner/db/AppDAO.kt
@@ -192,6 +192,6 @@ interface AppDAO {
*
* @return opening hours
*/
- @Query("SELECT openingHours FROM offer_canteen LIMIT 1")
- fun getCanteenOpeningHours(): String
+ @Query("SELECT openingHours, news FROM offer_canteen LIMIT 1")
+ fun getCanteenInfo(): CanteenOfferTuple
}
\ No newline at end of file
diff --git a/app/src/main/java/com/denizk0461/weserplaner/db/AppRepository.kt b/app/src/main/java/com/denizk0461/weserplaner/db/AppRepository.kt
index c51689c..f95e3a4 100644
--- a/app/src/main/java/com/denizk0461/weserplaner/db/AppRepository.kt
+++ b/app/src/main/java/com/denizk0461/weserplaner/db/AppRepository.kt
@@ -72,11 +72,11 @@ class AppRepository(app: Application) {
fun nukeEvents() { dao.nukeEvents() }
/**
- * Retrieves the opening hours of the canteen as a string.
+ * Retrieves the opening hours as well as notifications for the canteen as strings.
*
- * @return opening hours
+ * @return opening hours and notifications
*/
- fun getCanteenOpeningHours(): String = dao.getCanteenOpeningHours()
+ fun getCanteenInfo(): CanteenOfferTuple = dao.getCanteenInfo()
/**
* Retrieves all canteen offers that match given day.
diff --git a/app/src/main/java/com/denizk0461/weserplaner/fragment/CanteenFragment.kt b/app/src/main/java/com/denizk0461/weserplaner/fragment/CanteenFragment.kt
index 0e4311c..100ecc3 100644
--- a/app/src/main/java/com/denizk0461/weserplaner/fragment/CanteenFragment.kt
+++ b/app/src/main/java/com/denizk0461/weserplaner/fragment/CanteenFragment.kt
@@ -41,7 +41,13 @@ class CanteenFragment : AppFragment() {
* Locally saved opening hours to quickly access them without querying the database on every
* opening of the bottom sheet.
*/
- private var openingHours = ""
+ private var openingHours: String = ""
+
+ /**
+ * Locally saved news to quickly access them without querying the database on every opening of
+ * the corresponding bottom sheet.
+ */
+ private var news: String = ""
/**
* Locally stored dates to populate the TabLayout with.
@@ -67,6 +73,12 @@ class CanteenFragment : AppFragment() {
)
binding.appTitleBar.isSelected = true
+ binding.buttonNotifications.setOnClickListener {
+ openBottomSheet(getTextSheet(
+ getString(R.string.canteen_news_sheet_title),
+ news,
+ ))
+ }
// Assign a preference value to every button to filter for dietary preferences
val chipMap = mapOf(
@@ -167,7 +179,17 @@ class CanteenFragment : AppFragment() {
// Let the adapter know of the new amount of dates (pages) to display
viewPagerAdapter.itemCount = dates.size
- openingHours = viewModel.getCanteenOpeningHours()
+ // Retrieve further information about this canteen from the database
+ viewModel.getCanteenInfo().also { info ->
+ openingHours = info.openingHours
+ news = info.news
+
+ binding.buttonNotifications.visibility = if (news.isBlank()) {
+ View.GONE
+ } else {
+ View.VISIBLE
+ }
+ }
}
// Assign the adapter to the view pager
diff --git a/app/src/main/java/com/denizk0461/weserplaner/model/CanteenOfferTuple.kt b/app/src/main/java/com/denizk0461/weserplaner/model/CanteenOfferTuple.kt
new file mode 100644
index 0000000..4a72e0d
--- /dev/null
+++ b/app/src/main/java/com/denizk0461/weserplaner/model/CanteenOfferTuple.kt
@@ -0,0 +1,12 @@
+package com.denizk0461.weserplaner.model
+
+/**
+ * Serves to retrieve information about a specified canteen from the database using a single query.
+ *
+ * @param openingHours opening hours of the canteen
+ * @param news news that may be available for the canteen
+ */
+data class CanteenOfferTuple(
+ val openingHours: String,
+ val news: String,
+)
\ No newline at end of file
diff --git a/app/src/main/java/com/denizk0461/weserplaner/viewmodel/CanteenViewModel.kt b/app/src/main/java/com/denizk0461/weserplaner/viewmodel/CanteenViewModel.kt
index 58182b9..ab262f7 100644
--- a/app/src/main/java/com/denizk0461/weserplaner/viewmodel/CanteenViewModel.kt
+++ b/app/src/main/java/com/denizk0461/weserplaner/viewmodel/CanteenViewModel.kt
@@ -26,11 +26,11 @@ class CanteenViewModel(app: Application) : AppViewModel(app) {
fun getDates(): LiveData> = repo.getDates()
/**
- * Retrieves the opening hours of the canteen as a string.
+ * Retrieves the opening hours as well as notifications for the canteen as strings.
*
- * @return opening hours
+ * @return opening hours and notifications
*/
- fun getCanteenOpeningHours(): String = returnBlocking { repo.getCanteenOpeningHours() }
+ fun getCanteenInfo(): CanteenOfferTuple = returnBlocking { repo.getCanteenInfo() }
/**
* Fetch the canteen offers asynchronously. Updates will be provided through a LiveData object.
diff --git a/app/src/main/res/drawable/notification.xml b/app/src/main/res/drawable/notification.xml
new file mode 100644
index 0000000..1d038a4
--- /dev/null
+++ b/app/src/main/res/drawable/notification.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/app/src/main/res/layout/fragment_canteen.xml b/app/src/main/res/layout/fragment_canteen.xml
index 24f4c1d..1c5fdc7 100644
--- a/app/src/main/res/layout/fragment_canteen.xml
+++ b/app/src/main/res/layout/fragment_canteen.xml
@@ -17,23 +17,48 @@
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
-
-
+ android:layout_marginBottom="8dp">
+
+
+
+
+
+
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index 2eaff6a..320dbb4 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -63,6 +63,7 @@
Kein AngebotFür diesen Tag sind keine Angebote vorhanden
+ Neuigkeiten für diese MensaZeige ÖffnungszeitenWechsle MensaAktualisiere Angebote
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b9eb8c7..e819034 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -64,6 +64,7 @@
No offersThere are no offers available for this day
+ News for this canteenShow opening hoursSwitch canteenRefresh offers
diff --git a/build.gradle b/build.gradle
index 25ad99d..84be749 100644
--- a/build.gradle
+++ b/build.gradle
@@ -2,5 +2,5 @@
plugins {
id 'com.android.application' version '8.0.1' apply false
id 'com.android.library' version '8.0.1' apply false
- id 'org.jetbrains.kotlin.android' version '1.8.20' apply false
+ id 'org.jetbrains.kotlin.android' version '1.8.21' apply false
}
\ No newline at end of file