Browse Source

added 2nd week menus & option to disable buffet in the mensa tab

* the GUI now shows a second week for Mensa menus
* you can disable the buffet in the Mensa tab now
pull/20/head
Jannik 3 years ago
parent
commit
a4eceeddc9
  1. 16
      app/src/main/java/org/mosad/seil0/projectlaogai/PreferencesController.kt
  2. 5
      app/src/main/java/org/mosad/seil0/projectlaogai/fragments/HomeFragment.kt
  3. 61
      app/src/main/java/org/mosad/seil0/projectlaogai/fragments/MensaFragment.kt
  4. 12
      app/src/main/java/org/mosad/seil0/projectlaogai/fragments/SettingsFragment.kt
  5. 16
      app/src/main/java/org/mosad/seil0/projectlaogai/hsoparser/DataTypes.kt
  6. 55
      app/src/main/java/org/mosad/seil0/projectlaogai/hsoparser/MensaParser.kt
  7. 2
      app/src/main/res/layout/fragment_mensa.xml
  8. 2
      app/src/main/res/layout/fragment_settings.xml
  9. 1
      app/src/main/res/values/strings.xml

16
app/src/main/java/org/mosad/seil0/projectlaogai/PreferencesController.kt

@ -26,7 +26,7 @@ import android.content.Context
import android.graphics.Color
import org.jetbrains.anko.defaultSharedPreferences
import org.mosad.seil0.projectlaogai.hsoparser.Course
import org.mosad.seil0.projectlaogai.hsoparser.Meal
import org.mosad.seil0.projectlaogai.hsoparser.MealWeek
import org.mosad.seil0.projectlaogai.hsoparser.TimeTable
/**
@ -37,13 +37,14 @@ class PreferencesController {
companion object {
var cCourseTTLinkList = ArrayList<Course>()
var cMenusCurrentWeek = ArrayList<Meal>()
var cMenusNextWeek = ArrayList<Meal>()
var cMenusCurrentWeek = MealWeek()
var cMenusNextWeek = MealWeek()
var cTimeTableCurrentWeek = TimeTable()
var cTimeTableNextWeek = TimeTable()
var cColorPrimary: Int = Color.BLACK
var cColorAccent: Int = Color.BLACK
var cCourse = Course("https://www.hs-offenburg.de/index.php?id=6627&class=class&iddV=DA64F6FE-9DDB-429E-A677-05D0D40CB636&week=0", "AI3")
var cShowBuffet = true
// the save function
fun save(context: Context) {
@ -68,6 +69,12 @@ class PreferencesController {
apply()
}
// save showBuffet
with (sharedPref.edit()) {
putBoolean(context.getString(R.string.save_key_showBuffet), cShowBuffet)
apply()
}
}
// the load function
@ -82,6 +89,9 @@ class PreferencesController {
// load saved colors
cColorPrimary = sharedPref.getInt(context.getString(R.string.save_key_colorPrimary), Color.BLACK)
cColorAccent = sharedPref.getInt(context.getString(R.string.save_key_colorAccent), Color.parseColor("#FF1744"))
// load showBuffet
cShowBuffet = sharedPref.getBoolean(context.getString(R.string.save_key_showBuffet), true)
}
}

5
app/src/main/java/org/mosad/seil0/projectlaogai/fragments/HomeFragment.kt

@ -71,10 +71,11 @@ class HomeFragment : Fragment() {
val dayMenus: ArrayList<Meal>
val cal = Calendar.getInstance()
if (cal.get(Calendar.HOUR_OF_DAY) < 15) {
dayMenus = MensaParser().getMensaMenuDay(cMenusCurrentWeek, cal.get(Calendar.DAY_OF_WEEK))
dayMenus = cMenusCurrentWeek.day[NotRetardedCalendar().getDayOfWeekIndex()]
} else {
dayMenus = MensaParser().getMensaMenuDay(cMenusCurrentWeek, cal.get(Calendar.DAY_OF_WEEK) + 1)
dayMenus = cMenusCurrentWeek.day[NotRetardedCalendar().getTomorrowWeekIndex()]
uiThread {
txtView_Menu1Heading.text = resources.getString(R.string.meal_1_tomorrow)
txtView_Menu2Heading.text = resources.getString(R.string.meal_2_tomorrow)

61
app/src/main/java/org/mosad/seil0/projectlaogai/fragments/MensaFragment.kt

@ -31,10 +31,13 @@ import android.widget.LinearLayout
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
import org.mosad.seil0.projectlaogai.PreferencesController.Companion.cMenusCurrentWeek
import org.mosad.seil0.projectlaogai.PreferencesController.Companion.cMenusNextWeek
import org.mosad.seil0.projectlaogai.PreferencesController.Companion.cShowBuffet
import org.mosad.seil0.projectlaogai.R
import org.mosad.seil0.projectlaogai.hsoparser.MealWeek
import org.mosad.seil0.projectlaogai.hsoparser.NotRetardedCalendar
import org.mosad.seil0.projectlaogai.uicomponents.MensaDayCardView
import org.mosad.seil0.projectlaogai.uicomponents.MenuCardView
import java.util.*
/**
* The mensa controller class
@ -50,54 +53,50 @@ class MensaFragment : Fragment() {
linLayoutMensaFragment = view.findViewById(R.id.linLayout_MensaFragment)
addCurrentWeek()
// add the current week (week starts on sunday)
val dayCurrent = if(NotRetardedCalendar().getDayOfWeekIndex() == 6) 0 else NotRetardedCalendar().getDayOfWeekIndex()
addWeek(cMenusCurrentWeek, dayCurrent)
// add the next week
addWeek(cMenusNextWeek, 0)
return view
}
private fun addCurrentWeek() {
/**
* add all menus from dayStart to Friday for a given week
*/
private fun addWeek(menusWeek: MealWeek, dayStart: Int) {
doAsync {
uiThread {
for(day in Calendar.getInstance().get(Calendar.DAY_OF_WEEK)..7) {
val strDay: String = when(day) {
Calendar.MONDAY -> "Mon"
Calendar.TUESDAY -> "Die"
Calendar.WEDNESDAY -> "Mit"
Calendar.THURSDAY -> "Don"
Calendar.FRIDAY -> "Fre"
Calendar.SATURDAY -> "Sam"
else -> "TODAY" // the app will likely crash here
}
// only add the days dayStart to Fri since the mensa is closed on Sat/Sun
for (dayIndex in dayStart..4) {
val cardViewMensaDay = MensaDayCardView(context!!, null)
var add = false
for (meal in cMenusCurrentWeek) {
//println("Day: " + meal.day)
if (meal.day.contains(strDay)) {
for (meal in menusWeek.day[dayIndex]) {
val menuViewMenu = MenuCardView(context!!, null)
menuViewMenu.setMenuHeading(meal.heading)
val menuViewMenu = MenuCardView(context!!, null)
menuViewMenu.setMenuHeading(meal.heading)
meal.parts.forEachIndexed { partIndex, part ->
menuViewMenu.getTxtViewMenu().append(part)
if(partIndex < (meal.parts.size - 2))
menuViewMenu.getTxtViewMenu().append("\n")
}
for ((i, part) in meal.parts.withIndex()) {
menuViewMenu.getTxtViewMenu().append(part)
if(i < (meal.parts.size - 2))
menuViewMenu.getTxtViewMenu().append("\n")
}
cardViewMensaDay.setDayHeading(meal.day)
cardViewMensaDay.setDayHeading(meal.day)
if(meal.heading != "Buffet" || cShowBuffet)
cardViewMensaDay.getLinLayoutMensaDay().addView(menuViewMenu)
add = true
}
}
println("$dayIndex:" + cardViewMensaDay.getLinLayoutMensaDay().childCount) // remove
if(add)
if(cardViewMensaDay.getLinLayoutMensaDay().childCount > 1)
linLayoutMensaFragment.addView(cardViewMensaDay)
}
// add a card if there are no more meals in this week
@ -107,8 +106,8 @@ class MensaFragment : Fragment() {
linLayoutMensaFragment.addView(cardViewNoMoreFood)
}
}
}
}
}

12
app/src/main/java/org/mosad/seil0/projectlaogai/fragments/SettingsFragment.kt

@ -22,12 +22,12 @@
package org.mosad.seil0.projectlaogai.fragments
import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.Switch
import androidx.fragment.app.Fragment
import com.afollestad.aesthetic.Aesthetic
import com.afollestad.materialdialogs.MaterialDialog
@ -42,6 +42,7 @@ import org.mosad.seil0.projectlaogai.PreferencesController.Companion.cColorPrima
import org.mosad.seil0.projectlaogai.PreferencesController.Companion.cColorAccent
import org.mosad.seil0.projectlaogai.PreferencesController.Companion.cCourse
import org.mosad.seil0.projectlaogai.PreferencesController.Companion.cCourseTTLinkList
import org.mosad.seil0.projectlaogai.PreferencesController.Companion.cShowBuffet
import org.mosad.seil0.projectlaogai.PreferencesController.Companion.cTimeTableCurrentWeek
import org.mosad.seil0.projectlaogai.PreferencesController.Companion.cTimeTableNextWeek
import org.mosad.seil0.projectlaogai.R
@ -60,6 +61,7 @@ class SettingsFragment : Fragment() {
private lateinit var linLayoutInfo: LinearLayout
private lateinit var linLayoutPrimaryColor: LinearLayout
private lateinit var linLayoutAccentColor: LinearLayout
private lateinit var switchBuffet: Switch
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
@ -70,6 +72,7 @@ class SettingsFragment : Fragment() {
linLayoutInfo = view.findViewById(R.id.linLayout_Info)
linLayoutPrimaryColor = view.findViewById(R.id.linLayout_PrimaryColor)
linLayoutAccentColor = view.findViewById(R.id.linLayout_AccentColor)
switchBuffet = view.findViewById(R.id.switch_buffet)
initActions()
@ -81,6 +84,7 @@ class SettingsFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)
txtView_Course.text = cCourse.courseName
switch_buffet.isChecked = cShowBuffet // init switch
}
/**
@ -170,6 +174,12 @@ class SettingsFragment : Fragment() {
.show()
}
switchBuffet.setOnClickListener {
cShowBuffet = switchBuffet.isChecked
PreferencesController.save(context!!)
println(switchBuffet.isChecked)
}
}
}

16
app/src/main/java/org/mosad/seil0/projectlaogai/hsoparser/DataTypes.kt

@ -24,6 +24,7 @@ package org.mosad.seil0.projectlaogai.hsoparser
import android.graphics.Color
import java.util.*
import kotlin.collections.ArrayList
class DataTypes {
val times = arrayOf("8.00 - 9.30", "9.45 - 11.15" ,"11.35 - 13.05", "14.00 -15.30", "15.45 - 17.15", "17.30 - 19.00")
@ -96,13 +97,26 @@ class NotRetardedCalendar {
}
}
fun getTomorrowWeekIndex(): Int {
return when(calendar.get(Calendar.DAY_OF_WEEK) + 1) {
Calendar.MONDAY -> 0
Calendar.TUESDAY -> 1
Calendar.WEDNESDAY -> 2
Calendar.THURSDAY -> 3
Calendar.FRIDAY -> 4
Calendar.SATURDAY -> 5
Calendar.SUNDAY -> 6
else -> 7
}
}
}
data class Course(val courseLink: String, val courseName: String)
data class Meal(val day: String, val heading: String, val parts: ArrayList<String>, val additives: String)
data class MealWeek(val day: Array<ArrayList<Meal>> = Array(7) { ArrayList<Meal>() })
data class Lesson(val lessonSubject: String, val lessonTeacher: String, val lessonRoom:String, val lessonRemark: String)
data class TimeTableDay( val timeslots: Array<ArrayList<Lesson>> = Array(6) { ArrayList<Lesson>()})

55
app/src/main/java/org/mosad/seil0/projectlaogai/hsoparser/MensaParser.kt

@ -24,32 +24,47 @@ package org.mosad.seil0.projectlaogai.hsoparser
import org.jsoup.Jsoup
import java.util.*
import kotlin.collections.ArrayList
class MensaParser {
/**
* returns the mensa menu for the a week
*/
fun getMensaMenu(menuLink: String): ArrayList<Meal> {
fun getMensaMenu(menuLink: String): MealWeek {
val mealList = ArrayList<Meal>()
val mealWeekList = MealWeek()
val menuHTML = Jsoup.connect(menuLink).get()
menuHTML.select("#speiseplan-tabs").select("div.tab-content").select("div.menu-tagesplan").forEachIndexed { _, element ->
val day = element.select("h3").text()
for (i in 0 .. (element.select("div.row h4").size - 1)) {
menuHTML.select("#speiseplan-tabs").select("div.tab-content").select("div.menu-tagesplan").forEachIndexed { dayIndex, day ->
val strDay = day.select("h3").text()
day.select("div.menu-info").forEachIndexed { mealIndex, meal ->
val heading = day.select("h4")[mealIndex].text()
val parts = ArrayList(meal.html().substringBefore("<br>\n").replace("<br>", " ").split("\n"))
val additives = meal.select("span.show-with-allergenes").text()
mealWeekList.day[dayIndex].add(Meal(strDay, heading, parts, additives))
}
for (i in 0 .. (day.select("div.row h4").size - 1)) {
try {
val heading = element.select("div.row h4")[i].text()
val parts = ArrayList<String>(element.select("div.row").select("div.menu-info")[i].html().substringBefore("<span").replace("<br>", " ").split("\n"))
val additives = element.select("div.row").select("div.menu-info")[i].select("span.show-with-allergenes").text()
val heading = day.select("div.row h4")[i].text()
val parts = ArrayList<String>(day.select("div.row").select("div.menu-info")[i].html().substringBefore("<span").replace("<br>", " ").split("\n"))
val additives = day.select("div.row").select("div.menu-info")[i].select("span.show-with-allergenes").text()
mealList.add(Meal(day, heading, parts, additives))
mealList.add(Meal(strDay, heading, parts, additives))
} catch (e: Exception) {
//println("Oooups! Something went wrong: ${e.printStackTrace()}")
}
}
}
return mealList
// Mon to Sat (0 - 5)
//println(mealWeekList.day[4])
return mealWeekList
}
/**
@ -60,26 +75,4 @@ class MensaParser {
return "https://www.swfr.de" + menuHTML.select("#speiseplan-tabs").select("a.next-week").attr("href")
}
/**
* return the mensa menu of a given day (Mon - Sat)
*/
fun getMensaMenuDay(mealList: ArrayList<Meal>, day: Int): ArrayList<Meal> {
val dayMenus = ArrayList<Meal>()
val strDay: String = when (day) {
Calendar.MONDAY -> "Mon"
Calendar.TUESDAY -> "Die"
Calendar.WEDNESDAY -> "Mit"
Calendar.THURSDAY -> "Don"
Calendar.FRIDAY -> "Fre"
Calendar.SATURDAY -> "Sam"
else -> "TODAY"
}
for (meal in mealList) {
if (meal.day.contains(strDay))
dayMenus.add(meal)
}
return dayMenus
}
}

2
app/src/main/res/layout/fragment_mensa.xml

@ -11,7 +11,7 @@
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent" android:background="@android:color/background_light">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"

2
app/src/main/res/layout/fragment_settings.xml

@ -14,7 +14,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"
>
android:background="@android:color/background_light">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"

1
app/src/main/res/values/strings.xml

@ -52,5 +52,6 @@
<string name="save_key_courseTTLink" translatable="false">org.mosad.seil0.projectlaogai.courseTTLink</string>
<string name="save_key_colorPrimary" translatable="false">org.mosad.seil0.projectlaogai.colorPrimary</string>
<string name="save_key_colorAccent" translatable="false">org.mosad.seil0.projectlaogai.colorAccent</string>
<string name="save_key_showBuffet" translatable="false">org.mosad.seil0.projectlaogai.showBuffet</string>
</resources>

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close