Browse Source

TimeTableFragment clean up

pull/46/head
Jannik 2 years ago
parent
commit
948f330ebe
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 73
      app/src/main/java/org/mosad/seil0/projectlaogai/fragments/TimeTableFragment.kt
  2. 9
      app/src/main/java/org/mosad/seil0/projectlaogai/uicomponents/AddLessonDialog.kt

73
app/src/main/java/org/mosad/seil0/projectlaogai/fragments/TimeTableFragment.kt

@ -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()
}
faBtnAddLesson.setOnClickListener {
//initAddLessonDialog().show()
AddLessonDialog(context!!).initAddLessonDialog().show()
}
// 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()
}
// 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
private fun addWeek(startDayIndex: Int, dayEndIndex: Int, weekIndex: Int) = GlobalScope.launch(Dispatchers.Default) {
val timetable = timetables[weekIndex].timetable
val timetableMeta = timetables[weekIndex].meta
// TODO add additional lessons
}
withContext(Dispatchers.Main) {
private fun addTimetableWeek(dayBegin: Int, dayEnd: Int, week: Int) = GlobalScope.launch(Dispatchers.Main) {
val timetable = timetables[week].timetable
val timetableMeta = timetables[week].meta
for (dayIndex in startDayIndex..dayEndIndex) {
val dayCardView = DayCardView(context!!)
for (dayIndex in dayBegin..dayEnd) {
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
}

9
app/src/main/java/org/mosad/seil0/projectlaogai/uicomponents/AddLessonDialog.kt

@ -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…
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