TimeTableFragment clean up
This commit is contained in:
parent
72e9efb9e7
commit
948f330ebe
|
@ -60,7 +60,7 @@ class TimeTableFragment : Fragment() {
|
|||
initActions()
|
||||
|
||||
if (timetables[0].timetable.days.isNotEmpty() && timetables[1].timetable.days.isNotEmpty()) {
|
||||
addInitWeeks()
|
||||
initTimetable()
|
||||
} else {
|
||||
MaterialDialog(context!!)
|
||||
.title(R.string.error)
|
||||
|
@ -74,27 +74,24 @@ class TimeTableFragment : Fragment() {
|
|||
/**
|
||||
* initialize the actions
|
||||
*/
|
||||
private fun initActions() = GlobalScope.launch(Dispatchers.Default) {
|
||||
private fun initActions() = GlobalScope.launch(Dispatchers.Main) {
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
refreshLayout_Timetable.setOnRefreshListener {
|
||||
updateTimetableScreen()
|
||||
refreshLayout_Timetable.setOnRefreshListener {
|
||||
updateTimetableScreen()
|
||||
}
|
||||
|
||||
// show the AddLessonDialog if the ftaBtn is clicked
|
||||
faBtnAddLesson.setOnClickListener {
|
||||
AddLessonDialog(context!!).initAddLessonDialog().show()
|
||||
}
|
||||
|
||||
// hide the btnCardValue if the user is scrolling down
|
||||
scrollViewTimetable.setOnScrollChangeListener { _, _, scrollY, _, oldScrollY ->
|
||||
if (scrollY > oldScrollY) {
|
||||
faBtnAddLesson.hide()
|
||||
} else {
|
||||
faBtnAddLesson.show()
|
||||
}
|
||||
|
||||
faBtnAddLesson.setOnClickListener {
|
||||
//initAddLessonDialog().show()
|
||||
AddLessonDialog(context!!).initAddLessonDialog().show()
|
||||
}
|
||||
|
||||
// hide the btnCardValue if the user is scrolling down
|
||||
scrollViewTimetable.setOnScrollChangeListener { _, _, scrollY, _, oldScrollY ->
|
||||
if (scrollY > oldScrollY) {
|
||||
faBtnAddLesson.hide()
|
||||
} else {
|
||||
faBtnAddLesson.show()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -102,31 +99,30 @@ class TimeTableFragment : Fragment() {
|
|||
/**
|
||||
* add the current and next weeks lessons
|
||||
*/
|
||||
private fun addInitWeeks() = GlobalScope.launch(Dispatchers.Default) {
|
||||
private fun initTimetable() = GlobalScope.launch(Dispatchers.Default) {
|
||||
val currentDayIndex = NotRetardedCalendar.getDayOfWeekIndex()
|
||||
|
||||
addWeek(currentDayIndex, 5, 0).join() // add current week
|
||||
addWeek(0, currentDayIndex - 1, 1) // add next week
|
||||
addTimetableWeek(currentDayIndex, 5, 0).join() // add current week
|
||||
addTimetableWeek(0, currentDayIndex - 1, 1) // add next week
|
||||
|
||||
// TODO add additional lessons
|
||||
}
|
||||
|
||||
private fun addWeek(startDayIndex: Int, dayEndIndex: Int, weekIndex: Int) = GlobalScope.launch(Dispatchers.Default) {
|
||||
val timetable = timetables[weekIndex].timetable
|
||||
val timetableMeta = timetables[weekIndex].meta
|
||||
private fun addTimetableWeek(dayBegin: Int, dayEnd: Int, week: Int) = GlobalScope.launch(Dispatchers.Main) {
|
||||
val timetable = timetables[week].timetable
|
||||
val timetableMeta = timetables[week].meta
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
for (dayIndex in dayBegin..dayEnd) {
|
||||
val dayCardView = DayCardView(context!!)
|
||||
|
||||
for (dayIndex in startDayIndex..dayEndIndex) {
|
||||
val dayCardView = DayCardView(context!!)
|
||||
// some wired calendar magic, calculate the correct date to be shown ((timetable week - current week * 7) + (dayIndex - dayIndex of current week)
|
||||
val daysToAdd = (timetableMeta.weekNumberYear - NotRetardedCalendar.getWeekOfYear()) * 7 + (dayIndex - NotRetardedCalendar.getDayOfWeekIndex())
|
||||
dayCardView.addTimetableDay(timetable.days[dayIndex], daysToAdd)
|
||||
|
||||
// some wired calendar magic, calculate the correct date to be shown ((timetable week - current week * 7) + (dayIndex - dayIndex of current week)
|
||||
val daysToAdd =(timetableMeta.weekNumberYear - NotRetardedCalendar.getWeekOfYear()) * 7 + (dayIndex - NotRetardedCalendar.getDayOfWeekIndex())
|
||||
dayCardView.addTimetableDay(timetable.days[dayIndex], daysToAdd)
|
||||
// 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)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,11 +144,8 @@ class TimeTableFragment : Fragment() {
|
|||
// add the refreshed timetables
|
||||
val dayIndex = NotRetardedCalendar.getDayOfWeekIndex()
|
||||
|
||||
// add current week
|
||||
addWeek(dayIndex, 5, 0).join()
|
||||
|
||||
// add next week
|
||||
addWeek(0, dayIndex - 1, 1)
|
||||
addTimetableWeek(dayIndex, 5, 0).join() // add current week
|
||||
addTimetableWeek(0, dayIndex - 1, 1) // add next week
|
||||
|
||||
refreshLayout_Timetable.isRefreshing = false
|
||||
}
|
||||
|
|
|
@ -65,13 +65,14 @@ class AddLessonDialog(_context: Context) {
|
|||
.customView(R.layout.dialog_add_lesson)
|
||||
.setPeekHeight(900)
|
||||
.positiveButton(R.string.add) {
|
||||
println("add lesson \"$selectedCourse: $selectedSubject\"")
|
||||
// TODO call add function
|
||||
val test = runBlocking {
|
||||
val lessons = runBlocking {
|
||||
TCoRAPIController.getLessonsAsync(selectedCourse, selectedSubject, 0).await()
|
||||
}
|
||||
println("add lesson \"$selectedCourse: $selectedSubject\"")
|
||||
println(lessons.toString())
|
||||
|
||||
println(test.toString())
|
||||
// TODO save lesson
|
||||
// TODO refresh timetable (add a function to show additional lessons)
|
||||
}
|
||||
.negativeButton(R.string.cancel) { }
|
||||
|
||||
|
|
Loading…
Reference in New Issue