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 335c6b0..774ddf5 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 @@ -58,7 +58,7 @@ class MensaFragment : Fragment() { addWeek(mensaCurrentWeek, dayCurrent).get() // add the next week - addWeek(mensaNextWeek, 0).get() + addWeek(mensaNextWeek, 0) // TODO should we show a info if there is no more food this & next week? @@ -105,13 +105,9 @@ class MensaFragment : Fragment() { */ private fun refreshAction() = doAsync { uiThread { - // set the refresh listener refreshLayout_Mensa.setOnRefreshListener { - updateMensaScreen() - refreshLayout_Mensa.isRefreshing = false - } } @@ -119,22 +115,25 @@ class MensaFragment : Fragment() { /** * refresh the mensa cache and update the mensa screen - * TODO some nice animations */ - private fun updateMensaScreen() { + private fun updateMensaScreen() = doAsync { // update the cache - TCoRAPIController.getMensa(context!!) + TCoRAPIController.getMensa(context!!).get() // blocking since we want the new data CacheController.readMensa(context!!) - // remove all menus from the layout - linLayout_Mensa.removeAllViews() + uiThread { + // remove all menus from the layout + linLayout_Mensa.removeAllViews() - // add the refreshed menus - val dayCurrent = if (NotRetardedCalendar().getDayOfWeekIndex() == 6) 0 else NotRetardedCalendar().getDayOfWeekIndex() - addWeek(mensaCurrentWeek, dayCurrent).get() + // add the refreshed menus + val dayCurrent = if (NotRetardedCalendar().getDayOfWeekIndex() == 6) 0 else NotRetardedCalendar().getDayOfWeekIndex() + addWeek(mensaCurrentWeek, dayCurrent).get() - // add the next week - addWeek(mensaNextWeek, 0).get() + // add the next week + addWeek(mensaNextWeek, 0) + + refreshLayout_Mensa.isRefreshing = false + } } } 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 54515fb..2e026e5 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 @@ -27,6 +27,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment +import com.afollestad.materialdialogs.MaterialDialog import kotlinx.android.synthetic.main.fragment_timetable.* import org.jetbrains.anko.doAsync import org.jetbrains.anko.uiThread @@ -34,6 +35,7 @@ import org.mosad.seil0.projectlaogai.R import org.mosad.seil0.projectlaogai.controller.CacheController.Companion.timetables import org.mosad.seil0.projectlaogai.hsoparser.DataTypes import org.mosad.seil0.projectlaogai.hsoparser.NotRetardedCalendar +import org.mosad.seil0.projectlaogai.hsoparser.TimetableWeek import org.mosad.seil0.projectlaogai.uicomponents.* import java.text.SimpleDateFormat import java.util.* @@ -44,37 +46,51 @@ import java.util.* */ class TimeTableFragment : Fragment() { + private val formatter = SimpleDateFormat("E dd.MM", Locale.getDefault()) // TODO change to android call when min api is 24 + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view: View = inflater.inflate(R.layout.fragment_timetable, container, false) if (timetables[0].days.isNotEmpty() && timetables[1].days.isNotEmpty()) { - addWeeks() + addInitWeeks() } else { - // TODO show card with error msg + MaterialDialog(context!!) + .title(R.string.error) + .message(R.string.timetable_error) + .show() } return view } /** - * add the all days with at least one lesson to the timetable screen + * add the current and next weeks lessons */ - private fun addWeeks() = doAsync { + private fun addInitWeeks() = doAsync { val dayIndex = NotRetardedCalendar().getDayOfWeekIndex() - val formatter = SimpleDateFormat("E dd.MM", Locale.getDefault()) // TODO change to android call when min api is 24 val calendar = Calendar.getInstance() + println(formatter.format(calendar.time)) + + // add current week + addWeek(dayIndex, 5, timetables[0], calendar).get() + + // add next week + addWeek(0, dayIndex - 1, timetables[1], calendar) + } + + private fun addWeek(dayStart: Int, dayEnd: Int, timetable: TimetableWeek, calendar: Calendar) = doAsync { uiThread { - // add the current week - for (day in dayIndex..5) { + for (day in dayStart..dayEnd) { var helpLesson = LessonLinearLayout(context) val dayCardView = DayCardView(context!!) dayCardView.setDayHeading(formatter.format(calendar.time)) + println("1: $day , ${formatter.format(calendar.time)}") // for each timeslot of the day - for ((tsIndex, timeslot) in timetables[0].days[day].timeslots.withIndex()) { + for ((tsIndex, timeslot) in timetable.days[day].timeslots.withIndex()) { for(lesson in timeslot) { @@ -92,6 +108,8 @@ class TimeTableFragment : Fragment() { } } + println("2: $day , ${formatter.format(calendar.time)}") + helpLesson.disableDivider() calendar.add(Calendar.DATE, 1) @@ -102,43 +120,7 @@ class TimeTableFragment : Fragment() { } 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/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 0153b9f..7d10427 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -15,7 +15,8 @@ + android:layout_height="wrap_content" + android:id="@+id/linLayout_Home"> diff --git a/app/src/main/res/layout/fragment_mensa.xml b/app/src/main/res/layout/fragment_mensa.xml index a9440bd..f37da0f 100644 --- a/app/src/main/res/layout/fragment_mensa.xml +++ b/app/src/main/res/layout/fragment_mensa.xml @@ -16,8 +16,10 @@ + android:layout_height="wrap_content" + android:animateLayoutChanges="true" + android:background="@color/themePrimary" + android:id="@+id/linLayout_Mensa"/> diff --git a/app/src/main/res/layout/fragment_moodle.xml b/app/src/main/res/layout/fragment_moodle.xml index f153eb0..b8a0b9a 100644 --- a/app/src/main/res/layout/fragment_moodle.xml +++ b/app/src/main/res/layout/fragment_moodle.xml @@ -8,6 +8,7 @@ + android:layout_height="match_parent" + android:id="@+id/webView"/> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_timetable.xml b/app/src/main/res/layout/fragment_timetable.xml index b678da5..e5abf01 100644 --- a/app/src/main/res/layout/fragment_timetable.xml +++ b/app/src/main/res/layout/fragment_timetable.xml @@ -15,9 +15,10 @@ - + android:layout_height="wrap_content" + android:animateLayoutChanges="true" + android:background="@color/themePrimary" + android:id="@+id/linLayout_Timetable"/>