diff --git a/app/build.gradle b/app/build.gradle index 3439978..ac2b35f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ android { minSdkVersion 21 targetSdkVersion 28 versionCode 11 - versionName "0.3.97" + versionName "0.3.98" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" resValue "string", "build_time", buildTime() } diff --git a/app/src/main/java/org/mosad/seil0/projectlaogai/MainActivity.kt b/app/src/main/java/org/mosad/seil0/projectlaogai/MainActivity.kt index 19de5a2..67349ec 100644 --- a/app/src/main/java/org/mosad/seil0/projectlaogai/MainActivity.kt +++ b/app/src/main/java/org/mosad/seil0/projectlaogai/MainActivity.kt @@ -174,8 +174,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte cal.time = Date(timetableCacheTime * 1000) val timetableCacheDay = cal.get(Calendar.DAY_OF_WEEK) - // if the last update was on moday and now its a sunday, update before displaying the timetable - // TODO this sill backfire if someone has to update before the server finished updateing the timetable at 0001/0101 + // if the last update was on monday and now its a sunday, update before displaying the timetable + // TODO this sill backfire if someone has to update before the server finished updating the timetable at 0001/0101 if(currentDay == Calendar.MONDAY && timetableCacheDay == Calendar.SUNDAY) { println("updating timetable after sunday!") val jobA = tcor.getTimetable(cCourse.courseName, 0) diff --git a/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/HomeFragment.kt b/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/HomeFragment.kt index 715c2d5..009daf0 100644 --- a/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/HomeFragment.kt +++ b/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/HomeFragment.kt @@ -40,6 +40,7 @@ import org.mosad.seil0.projectlaogai.controller.CacheController.Companion.timeta import org.mosad.seil0.projectlaogai.hsoparser.DataTypes import org.mosad.seil0.projectlaogai.hsoparser.Meal import org.mosad.seil0.projectlaogai.hsoparser.NotRetardedCalendar +import org.mosad.seil0.projectlaogai.hsoparser.TimetableDay import org.mosad.seil0.projectlaogai.uicomponents.DayCardView import org.mosad.seil0.projectlaogai.uicomponents.LessonLinearLayout import org.mosad.seil0.projectlaogai.uicomponents.MealLinearLayout @@ -52,13 +53,13 @@ import java.util.* */ class HomeFragment : Fragment() { - val formatter = SimpleDateFormat("E dd.MM", Locale.GERMANY) + private val formatter = SimpleDateFormat("E dd.MM", Locale.getDefault()) override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view: View = inflater.inflate(R.layout.fragment_home, container, false) - addMensaMenu() + addMensaMenu().get() addTimeTable() // Inflate the layout for this fragment @@ -68,56 +69,46 @@ class HomeFragment : Fragment() { /** * add the current mensa meal to the home screens */ - private fun addMensaMenu() { - doAsync { + private fun addMensaMenu() = doAsync { - var dayMeals: ArrayList - val cal = Calendar.getInstance() - val mensaCardView = DayCardView(context!!) + var dayMeals: ArrayList + val cal = Calendar.getInstance() + val mensaCardView = DayCardView(context!!) - uiThread { + uiThread { - if (cal.get(Calendar.HOUR_OF_DAY) < 15) { - dayMeals = mensaCurrentWeek.days[NotRetardedCalendar().getDayOfWeekIndex()].meals - mensaCardView.setDayHeading(resources.getString(R.string.today_date, formatter.format(cal.time))) - } else { - dayMeals = mensaCurrentWeek.days[NotRetardedCalendar().getTomorrowWeekIndex()].meals - cal.add(Calendar.DATE, 1) - mensaCardView.setDayHeading(resources.getString(R.string.tomorrow_date, formatter.format(cal.time))) - } - - if (dayMeals.size >= 2) { - // get the index of the first meal, not a "Schneller Teller" - loop@ for ((i, meal) in dayMeals.withIndex()) { - if (meal.heading.contains("Essen")) { - - val meal1Layout = MealLinearLayout(context) - meal1Layout.setMeal(dayMeals[i]) - mensaCardView.getLinLayoutDay().addView(meal1Layout) - - val meal2Layout = MealLinearLayout(context) - meal2Layout.setMeal(dayMeals[i + 1]) - meal2Layout.disableDivider() - mensaCardView.getLinLayoutDay().addView(meal2Layout) - - break@loop - } - } - - } else { - val noFood = TextView(context) - noFood.text = resources.getString(R.string.mensa_closed) - noFood.setTextColor(ContextCompat.getColor(context!!, R.color.textPrimary)) - noFood.textSize = 18.0F - noFood.setTypeface(null, Typeface.BOLD) - noFood.textAlignment = View.TEXT_ALIGNMENT_CENTER - noFood.setPadding(7,7,7,7) - - mensaCardView.getLinLayoutDay().addView(noFood) - } - - linLayout_Home.addView(mensaCardView) + if (cal.get(Calendar.HOUR_OF_DAY) < 15) { + dayMeals = mensaCurrentWeek.days[NotRetardedCalendar().getDayOfWeekIndex()].meals + mensaCardView.setDayHeading(resources.getString(R.string.today_date, formatter.format(cal.time))) + } else { + dayMeals = mensaCurrentWeek.days[NotRetardedCalendar().getTomorrowWeekIndex()].meals + cal.add(Calendar.DATE, 1) + mensaCardView.setDayHeading(resources.getString(R.string.tomorrow_date, formatter.format(cal.time))) } + + if (dayMeals.size >= 2) { + // get the index of the first meal, not a "Schneller Teller" + loop@ for ((i, meal) in dayMeals.withIndex()) { + if (meal.heading.contains("Essen")) { + + val meal1Layout = MealLinearLayout(context) + meal1Layout.setMeal(dayMeals[i]) + mensaCardView.getLinLayoutDay().addView(meal1Layout) + + val meal2Layout = MealLinearLayout(context) + meal2Layout.setMeal(dayMeals[i + 1]) + meal2Layout.disableDivider() + mensaCardView.getLinLayoutDay().addView(meal2Layout) + + break@loop + } + } + + } else { + mensaCardView.getLinLayoutDay().addView(getNoCard(resources.getString(R.string.mensa_closed))) + } + + linLayout_Home.addView(mensaCardView) } } @@ -125,67 +116,104 @@ class HomeFragment : Fragment() { /** * add the current timetable to the home screen */ - private fun addTimeTable() { + private fun addTimeTable() = doAsync { val dayIndex = NotRetardedCalendar().getDayOfWeekIndex() - var helpLesson = LessonLinearLayout(context!!) - val dayCardView = DayCardView(context!!) - dayCardView.setDayHeading(resources.getString(R.string.today_date, formatter.format(Calendar.getInstance().time))) + val cal = Calendar.getInstance() + var dayCardView = DayCardView(context!!) - doAsync { - uiThread { + uiThread { - if (timetables[0].days.isNotEmpty() && dayIndex < 6) { + if (timetables.isNotEmpty() && dayIndex < 6) { - // for all timeslots of the day - for ((tsIndex, timeslot) in timetables[0].days[dayIndex].timeslots.withIndex()) { + // first check the current day + dayCardView = addDayTimetable(timetables[0].days[dayIndex]) + dayCardView.setDayHeading(resources.getString(R.string.today_date, formatter.format(cal.time))) - for(lesson in timeslot) { - if(lesson.lessonSubject.isNotEmpty()) { + // if there are no lessons don't show the dayCardView + if (dayCardView.getLinLayoutDay().childCount <= 1) { + // get next day with at least one lecture + var dayTimetable: TimetableDay? = null + var weekIndex = 0 + var dayIndexSearch = dayIndex + 1 + loop@ while (dayTimetable == null && weekIndex <= timetables.size) { + for (i in (dayIndexSearch) ..5) { + dayTimetable = timetables[weekIndex].days[i] + cal.add(Calendar.DATE, 1) - val lessonLayout = LessonLinearLayout(context!!) - lessonLayout.setLesson(lesson, DataTypes().getTime()[tsIndex]) - dayCardView.getLinLayoutDay().addView(lessonLayout) + // add the timetable to the card, if it contains at least one lesson break! + dayCardView = addDayTimetable(dayTimetable) + dayCardView.setDayHeading(formatter.format(cal.time)) - if (lesson != timeslot.last()) { - lessonLayout.disableDivider() - } - - helpLesson = lessonLayout - } + if (dayCardView.getLinLayoutDay().childCount > 1) + break@loop } + dayIndexSearch = 0 + weekIndex++ + cal.add(Calendar.DATE, 1) } + } - helpLesson.disableDivider() - // if there are no lessons don't show the dayCardView - if (dayCardView.getLinLayoutDay().childCount > 1) { - linLayout_Home.addView(dayCardView) - } else { - // TODO we could display the next day with a lecture - val noLesson = DayCardView(context!!) - noLesson.setDayHeading(resources.getString(R.string.no_lesson_today)) + if (dayCardView.getLinLayoutDay().childCount <= 1) + dayCardView.getLinLayoutDay().addView(getNoCard(resources.getString(R.string.no_lesson_today))) // if there is no lecture at all show the no lesson card - linLayout_Home.addView(noLesson) - } + linLayout_Home.addView(dayCardView) + } else { + if (dayIndex == 6) { + // TODO iss this necessary? + // if that's the case it's sunday + dayCardView.getLinLayoutDay().addView(getNoCard(resources.getString(R.string.no_lesson_today))) + linLayout_Home.addView(dayCardView) } else { - if (dayIndex == 6) { - // if that's the case it's sunday - val noLesson = DayCardView(context!!) - noLesson.setDayHeading(resources.getString(R.string.no_lesson_today)) - - linLayout_Home.addView(noLesson) - } else { - MaterialDialog(context!!) - .title(R.string.error) - .message(R.string.gen_tt_error) - .show() - // TODO log the error and send feedback - } - + MaterialDialog(context!!) + .title(R.string.error) + .message(R.string.gen_tt_error) + .show() + // TODO log the error and send feedback } } + } } + private fun addDayTimetable(dayTimetable: TimetableDay) : DayCardView{ + var helpLesson = LessonLinearLayout(context) + val dayCardView = DayCardView(context!!) + + for ((tsIndex, timeslot) in dayTimetable.timeslots.withIndex()) { + + for(lesson in timeslot) { + if(lesson.lessonSubject.isNotEmpty()) { + + val lessonLayout = LessonLinearLayout(context) + lessonLayout.setLesson(lesson, DataTypes().getTime()[tsIndex]) + dayCardView.getLinLayoutDay().addView(lessonLayout) + + if (lesson != timeslot.last()) { + lessonLayout.disableDivider() + } + + helpLesson = lessonLayout + } + } + } + + helpLesson.disableDivider() + + return dayCardView + } + + private fun getNoCard(text: String): TextView { + val noLesson = TextView(context) + noLesson.text = text + noLesson.setTextColor(ContextCompat.getColor(context!!, R.color.textPrimary)) + noLesson.textSize = 18.0F + noLesson.setTypeface(null, Typeface.BOLD) + noLesson.textAlignment = View.TEXT_ALIGNMENT_CENTER + noLesson.setPadding(7,7,7,7) + + return noLesson + } + } diff --git a/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/MensaFragment.kt b/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/MensaFragment.kt index 71a978d..ef6f3fd 100644 --- a/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/MensaFragment.kt +++ b/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/MensaFragment.kt @@ -56,10 +56,10 @@ class MensaFragment : Fragment() { // add the current week (week starts on sunday) val dayCurrent = if(NotRetardedCalendar().getDayOfWeekIndex() == 6) 0 else NotRetardedCalendar().getDayOfWeekIndex() - addWeek(mensaCurrentWeek, dayCurrent) + addWeek(mensaCurrentWeek, dayCurrent).get() // add the next week - addWeek(mensaNextWeek, 0) + addWeek(mensaNextWeek, 0).get() return view } @@ -67,41 +67,32 @@ class MensaFragment : Fragment() { /** * add all menus from dayStart to Friday for a given week */ - private fun addWeek(menusWeek: MensaWeek, dayStart: Int) { + private fun addWeek(menusWeek: MensaWeek, dayStart: Int) = doAsync { - doAsync { + uiThread { - uiThread { + // only add the days dayStart to Fri since the mensa is closed on Sat/Sun + for (dayIndex in dayStart..4) { + var helpMeal = MealLinearLayout(context) + val dayCardView = DayCardView(context!!) + dayCardView.setDayHeading(menusWeek.days[dayIndex].meals[0].day) - // only add the days dayStart to Fri since the mensa is closed on Sat/Sun - for (dayIndex in dayStart..4) { - var helpMeal = MealLinearLayout(context) - val dayCardView = DayCardView(context!!) - dayCardView.setDayHeading(menusWeek.days[dayIndex].meals[0].day) + for (meal in menusWeek.days[dayIndex].meals) { + val mealLayout = MealLinearLayout(context) + mealLayout.setMeal(meal) - for (meal in menusWeek.days[dayIndex].meals) { - val mealLayout = MealLinearLayout(context) - mealLayout.setMeal(meal) - - if(meal.heading != "Buffet" || cShowBuffet) { - dayCardView.getLinLayoutDay().addView(mealLayout) - helpMeal = mealLayout - } + if(meal.heading != "Buffet" || cShowBuffet) { + dayCardView.getLinLayoutDay().addView(mealLayout) + helpMeal = mealLayout } - - helpMeal.disableDivider() - - if(dayCardView.getLinLayoutDay().childCount > 1) - linLayoutMensaFragment.addView(dayCardView) } - // add a card if there are no more meals in this week - if(linLayoutMensaFragment.childCount == 0) { - val noFood = DayCardView(context!!) - noFood.setDayHeading(resources.getString(R.string.no_more_food)) - linLayout_Mensa.addView(noFood) - } + helpMeal.disableDivider() + + if(dayCardView.getLinLayoutDay().childCount > 1) + linLayout_Mensa.addView(dayCardView) } + } } diff --git a/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/TimeTableFragment.kt b/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/TimeTableFragment.kt index b9b54e5..2613508 100644 --- a/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/TimeTableFragment.kt +++ b/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/TimeTableFragment.kt @@ -60,91 +60,84 @@ class TimeTableFragment : Fragment() { /** * add the all days with at least one lesson to the timetable screen */ - private fun addWeeks() { + private fun addWeeks() = doAsync { val dayIndex = NotRetardedCalendar().getDayOfWeekIndex() val formatter = SimpleDateFormat("E dd.MM", Locale.GERMANY) // TODO change to android call when min api is 24 val calendar = Calendar.getInstance() - doAsync { + uiThread { - uiThread { + // add the current week + for (day in dayIndex..5) { + var helpLesson = LessonLinearLayout(context) + val dayCardView = DayCardView(context!!) + dayCardView.setDayHeading(formatter.format(calendar.time)) - // add the current week - for (day in dayIndex..5) { - var helpLesson = LessonLinearLayout(context) - val dayCardView = DayCardView(context!!) - dayCardView.setDayHeading(formatter.format(calendar.time)) + // for each timeslot of the day + for ((tsIndex, timeslot) in timetables[0].days[day].timeslots.withIndex()) { - // for each timeslot of the day - for ((tsIndex, timeslot) in timetables[0].days[day].timeslots.withIndex()) { + for(lesson in timeslot) { - for(lesson in timeslot) { + if(lesson.lessonSubject.isNotEmpty()) { - if(lesson.lessonSubject.isNotEmpty()) { + val lessonLayout = LessonLinearLayout(context) + lessonLayout.setLesson(lesson, DataTypes().getTime()[tsIndex]) + dayCardView.getLinLayoutDay().addView(lessonLayout) - val lessonLayout = LessonLinearLayout(context) - lessonLayout.setLesson(lesson, DataTypes().getTime()[tsIndex]) - dayCardView.getLinLayoutDay().addView(lessonLayout) + if (lesson != timeslot.last()) + lessonLayout.disableDivider() - if (lesson != timeslot.last()) { - lessonLayout.disableDivider() - } - - helpLesson = lessonLayout - } + helpLesson = lessonLayout } } - - helpLesson.disableDivider() - calendar.add(Calendar.DATE, 1) - - // if there are no lessons don't show the dayCardView - if (dayCardView.getLinLayoutDay().childCount > 1) { - linLayout_Timetable.addView(dayCardView) - } } + helpLesson.disableDivider() + calendar.add(Calendar.DATE, 1) - calendar.add(Calendar.DATE, 1) // before this we are at a sunday (no lecture on sundays!) - - // add the next week - for (day in 0..(dayIndex - 1)) { - var helpLesson = LessonLinearLayout(context!!) - val dayCardView = DayCardView(context!!) - dayCardView.setDayHeading(formatter.format(calendar.time)) - - // for each timeslot of the day - for ((tsIndex, timeslot) in timetables[1].days[day].timeslots.withIndex()) { - - for(lesson in timeslot) { - - if(lesson.lessonSubject.isNotEmpty()) { - - val lessonLayout = LessonLinearLayout(context!!) - lessonLayout.setLesson(lesson, DataTypes().getTime()[tsIndex]) - dayCardView.getLinLayoutDay().addView(lessonLayout) - - if (lesson != timeslot.last()) { - lessonLayout.disableDivider() - } - - helpLesson = lessonLayout - } - } - } - - helpLesson.disableDivider() - calendar.add(Calendar.DATE, 1) - - // if there are no lessons don't show the dayCardView - if (dayCardView.getLinLayoutDay().childCount > 1) { - linLayout_Timetable.addView(dayCardView) - } - } + // if there are no lessons don't show the dayCardView + if (dayCardView.getLinLayoutDay().childCount > 1) + linLayout_Timetable.addView(dayCardView) } + calendar.add(Calendar.DATE, 1) // before this we are at a sunday (no lecture on sundays!) + + // add the next week + for (day in 0..(dayIndex - 1)) { + var helpLesson = LessonLinearLayout(context!!) + val dayCardView = DayCardView(context!!) + dayCardView.setDayHeading(formatter.format(calendar.time)) + + // for each timeslot of the day + for ((tsIndex, timeslot) in timetables[1].days[day].timeslots.withIndex()) { + + for(lesson in timeslot) { + + if(lesson.lessonSubject.isNotEmpty()) { + + val lessonLayout = LessonLinearLayout(context!!) + lessonLayout.setLesson(lesson, DataTypes().getTime()[tsIndex]) + dayCardView.getLinLayoutDay().addView(lessonLayout) + + if (lesson != timeslot.last()) + lessonLayout.disableDivider() + + helpLesson = lessonLayout + } + } + } + + helpLesson.disableDivider() + calendar.add(Calendar.DATE, 1) + + // if there are no lessons don't show the dayCardView + if (dayCardView.getLinLayoutDay().childCount > 1) + linLayout_Timetable.addView(dayCardView) + } + } + } diff --git a/app/src/main/java/org/mosad/seil0/projectlaogai/hsoparser/DataTypes.kt b/app/src/main/java/org/mosad/seil0/projectlaogai/hsoparser/DataTypes.kt index ff68e99..db0d8eb 100644 --- a/app/src/main/java/org/mosad/seil0/projectlaogai/hsoparser/DataTypes.kt +++ b/app/src/main/java/org/mosad/seil0/projectlaogai/hsoparser/DataTypes.kt @@ -98,14 +98,14 @@ class NotRetardedCalendar { } fun getTomorrowWeekIndex(): Int { - return when(calendar.get(Calendar.DAY_OF_WEEK) + 1) { - Calendar.MONDAY -> 0 - Calendar.TUESDAY -> 1 + return when(calendar.get(Calendar.DAY_OF_WEEK)) { + Calendar.MONDAY -> 1 + Calendar.TUESDAY -> 2 Calendar.WEDNESDAY -> 2 - Calendar.THURSDAY -> 3 - Calendar.FRIDAY -> 4 - Calendar.SATURDAY -> 5 - Calendar.SUNDAY -> 6 + Calendar.THURSDAY -> 4 + Calendar.FRIDAY -> 5 + Calendar.SATURDAY -> 6 + Calendar.SUNDAY -> 0 else -> 7 } } diff --git a/app/src/main/res/drawable/background_splash.xml b/app/src/main/res/drawable/background_splash.xml index 856328b..f9df9fc 100644 --- a/app/src/main/res/drawable/background_splash.xml +++ b/app/src/main/res/drawable/background_splash.xml @@ -1,8 +1,7 @@ - + diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 107a016..0153b9f 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -1,7 +1,6 @@ diff --git a/app/src/main/res/layout/fragment_mensa.xml b/app/src/main/res/layout/fragment_mensa.xml index 7d6012b..39e0bde 100644 --- a/app/src/main/res/layout/fragment_mensa.xml +++ b/app/src/main/res/layout/fragment_mensa.xml @@ -1,6 +1,6 @@ diff --git a/app/src/main/res/layout/linearlayout_meal.xml b/app/src/main/res/layout/linearlayout_meal.xml index 5a943d7..15752aa 100644 --- a/app/src/main/res/layout/linearlayout_meal.xml +++ b/app/src/main/res/layout/linearlayout_meal.xml @@ -5,7 +5,7 @@ android:layout_height="match_parent" android:id="@+id/linLayout_Meal" android:padding="7dp"> Stundenplan Moodle Einstellungen - Essen 1 - Essen 2 + Essen Heute, %1$s Morgen, %1$s keine Essensausgabe diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6f2b99a..a5fc160 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -12,8 +12,7 @@ Moodle Settings - Meal 1 - Meal 2 + Meal Today, %1$s Tomorrow, %1$s the Mensa is closed @@ -27,7 +26,6 @@ SampleUser@stud.hs-offenburg.de SampleCourse 3 Montag, 30.02 - a lesson\na teacher\na room 0.00 – 23.59 Info @@ -46,8 +44,6 @@ "This software is made by @Seil0 and is published under the terms and conditions of GPL 3. For further information visit \ngit.mosad.xyz/Seil0/ProjectLaogai \n\n© 2018-2019 seil0@mosad.xyz " loading timetable … - %1$s\n - org.mosad.seil0.projectlaogai.course org.mosad.seil0.projectlaogai.courseTTLink org.mosad.seil0.projectlaogai.colorPrimary