minor clean up and refactoring
This commit is contained in:
parent
77326a8ed6
commit
dbaf496a79
|
@ -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,13 +115,13 @@ 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!!)
|
||||
|
||||
uiThread {
|
||||
// remove all menus from the layout
|
||||
linLayout_Mensa.removeAllViews()
|
||||
|
||||
|
@ -134,7 +130,10 @@ class MensaFragment : Fragment() {
|
|||
addWeek(mensaCurrentWeek, dayCurrent).get()
|
||||
|
||||
// add the next week
|
||||
addWeek(mensaNextWeek, 0).get()
|
||||
addWeek(mensaNextWeek, 0)
|
||||
|
||||
refreshLayout_Mensa.isRefreshing = false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" android:id="@+id/linLayout_Home">
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/linLayout_Home">
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
|
|
|
@ -16,8 +16,10 @@
|
|||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" android:id="@+id/linLayout_Mensa"
|
||||
android:background="@color/themePrimary"/>
|
||||
android:layout_height="wrap_content"
|
||||
android:animateLayoutChanges="true"
|
||||
android:background="@color/themePrimary"
|
||||
android:id="@+id/linLayout_Mensa"/>
|
||||
</ScrollView>
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<!-- TODO: Update blank fragment layout -->
|
||||
<WebView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" android:id="@+id/webView"/>
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/webView"/>
|
||||
|
||||
</FrameLayout>
|
|
@ -15,9 +15,10 @@
|
|||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" android:id="@+id/linLayout_Timetable"
|
||||
android:background="@color/themePrimary">
|
||||
</LinearLayout>
|
||||
android:layout_height="wrap_content"
|
||||
android:animateLayoutChanges="true"
|
||||
android:background="@color/themePrimary"
|
||||
android:id="@+id/linLayout_Timetable"/>
|
||||
</ScrollView>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
|
Loading…
Reference in New Issue