timetable week view shows the current + the following 5 days, bugfixes

*fixed always showing the same day in week timetable view
* fixed wrong date is shown in timetable week view
This commit is contained in:
2018-11-12 12:32:42 +01:00
parent e8aa09b902
commit 3cd831e72c
5 changed files with 57 additions and 21 deletions

View File

@ -50,7 +50,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
private var weekMenus = ArrayList<Meal>()
private var courseTTLinkList = ArrayList<CourseTTLink>()
private var timeTableWeek = arrayOf<Array<Lesson>>()
private var timeTableCurrentWeek = arrayOf<Array<Lesson>>()
private var timeTableNextWeek = arrayOf<Array<Lesson>>()
private lateinit var course: CourseTTLink
@ -163,7 +164,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
apply()
}
timeTableWeek = timeTableParser.getTimeTable(course.courseTTLink.replace("http", "https"))
timeTableCurrentWeek = timeTableParser.getTimeTable(course.courseTTLink.replace("http", "https"))
}
/**
@ -192,13 +193,21 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
courseTTLinkList = timeTableParser.getCourseTTLinks()
}
doAsync {
try {
timeTableNextWeek = timeTableParser.getTimeTable(course.courseTTLink.replace("week=0","week=1"))
} catch (e: Exception) {
e.stackTrace
}
}
val t1 = doAsync {
weekMenus = mensaParser.getMensaMenu()
}
val t2 = doAsync {
try {
timeTableWeek = timeTableParser.getTimeTable(course.courseTTLink)
timeTableCurrentWeek = timeTableParser.getTimeTable(course.courseTTLink)
} catch (e: Exception) {
uiThread {
@ -223,8 +232,12 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
return courseTTLinkList
}
fun getCurrentTimeTableWeek(): Array<Array<Lesson>> {
return timeTableWeek
fun getTimeTableCurrentWeek(): Array<Array<Lesson>> {
return timeTableCurrentWeek
}
fun getTimeTableNextWeek(): Array<Array<Lesson>> {
return timeTableNextWeek
}
fun getWeekMenu(): ArrayList<Meal>{

View File

@ -95,9 +95,9 @@ class HomeFragment : Fragment() {
private fun addCurrentTimeTable() {
val dayIndex = NotRetardedCalendar().getDayOfWeekIndex()
if (mainActivity.getCurrentTimeTableWeek().isNotEmpty() && dayIndex < 6) {
if (mainActivity.getTimeTableCurrentWeek().isNotEmpty() && dayIndex < 6) {
val timeTableDay = mainActivity.getCurrentTimeTableWeek()[dayIndex]
val timeTableDay = mainActivity.getTimeTableCurrentWeek()[dayIndex]
for (i in 0..5) {
val lessonCardView = LessonCardView(context!!, null)

View File

@ -62,28 +62,23 @@ class TimeTableFragment : Fragment() {
/**
* add the remaining days of the current week to the timetable screen
* TODO show the current day and the following 5 days
*/
private fun addCurrentWeek() {
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 {
println(dayIndex)
// add current weeks days
for(day in dayIndex..5) {
val formatter = SimpleDateFormat("E dd.MM", Locale.GERMANY) // TODO change to android call when min api is 24
val calendar = Calendar.getInstance()
calendar.firstDayOfWeek = Calendar.MONDAY
calendar.add(Calendar.DATE,day - Calendar.getInstance().get(Calendar.DAY_OF_WEEK))
val cardViewTimeTableDay = MensaDayCardView(context!!, null)
cardViewTimeTableDay.setDayHeading(formatter.format(calendar.time))
// for each lessen of the day
for((i, lesson) in mainActivity.getCurrentTimeTableWeek()[dayIndex].withIndex()) {
for((i, lesson) in mainActivity.getTimeTableCurrentWeek()[day].withIndex()) {
val lessonCardView = LessonCardView(context!!, null)
lessonCardView.setBackgroundColor(Color.TRANSPARENT)
@ -96,11 +91,39 @@ class TimeTableFragment : Fragment() {
cardViewTimeTableDay.getLinLayoutMensaDay().addView(lessonCardView)
}
// TODO if there is no lesson at one day , show a no lesson card
calendar.add(Calendar.DATE,1)
linLayoutTTFragment.addView(cardViewTimeTableDay)
}
// add next weeks days, max number = dayIndex, if timetable was loaded
if (mainActivity.getTimeTableNextWeek().isNotEmpty()) {
calendar.add(Calendar.DATE,1) // before this we are at a sunday (no lecture on sundays!)
for(day in 0..(dayIndex - 1)) {
val cardViewTimeTableDay = MensaDayCardView(context!!, null)
cardViewTimeTableDay.setDayHeading(formatter.format(calendar.time))
// for each lessen of the day
for((i, lesson) in mainActivity.getTimeTableNextWeek()[day].withIndex()) {
val lessonCardView = LessonCardView(context!!, null)
lessonCardView.setBackgroundColor(Color.TRANSPARENT)
lessonCardView.getTxtViewLesson().text = resources.getString(R.string.string_new_line, lesson.lessonSubject)
lessonCardView.getTxtViewLesson().append(lesson.lessonTeacher + "\n")
lessonCardView.getTxtViewLesson().append(lesson.lessonRoom)
lessonCardView.getTxtViewTime().text = DataTypes().getTime()[i]
if(lessonCardView.getTxtViewLesson().text.length > 2)
cardViewTimeTableDay.getLinLayoutMensaDay().addView(lessonCardView)
}
calendar.add(Calendar.DATE,1)
linLayoutTTFragment.addView(cardViewTimeTableDay)
}
}
// TODO if there is no lesson at one day , show a no lesson card
}
}