@ -119,7 +119,7 @@ class HomeFragment : Fragment() {
private fun addTimeTable ( ) = doAsync {
val dayIndex = NotRetardedCalendar ( ) . getDayOfWeekIndex ( )
val cal = Calendar . getInstance ( )
var dayCardView = DayCardView ( context !! )
var dayCardView : DayCardView
uiThread {
@ -129,54 +129,31 @@ class HomeFragment : Fragment() {
dayCardView = addDayTimetable ( timetables [ 0 ] . days [ dayIndex ] )
dayCardView . setDayHeading ( resources . getString ( R . string . today _date , formatter . format ( cal . time ) ) )
// if there are no lessons don't show the dayCardView
if ( dayCardView . getLinLayoutDay ( ) . childCount <= 1 ) {
// get next day with at least one lecture
var dayTimetable : TimetableDay ? = null
var weekIndex = 0
var dayIndexSearch = dayIndex + 1
loop @ while ( dayTimetable == null && weekIndex <= timetables . size ) {
for ( i in ( dayIndexSearch ) .. 5 ) {
dayTimetable = timetables [ weekIndex ] . days [ i ]
cal . add ( Calendar . DATE , 1 )
// add the timetable to the card, if it contains at least one lesson break!
dayCardView = addDayTimetable ( dayTimetable )
dayCardView . setDayHeading ( formatter . format ( cal . time ) )
if ( dayCardView . getLinLayoutDay ( ) . childCount > 1 )
break @loop
}
dayIndexSearch = 0
weekIndex ++
cal . add ( Calendar . DATE , 1 )
}
}
// if there are no lessons try to find the next day with a lesson
if ( dayCardView . getLinLayoutDay ( ) . childCount <= 1 )
dayCardView . getLinLayoutDay ( ) . addView ( getNoCard ( resources . getString ( R . string . no _lesson _today ) ) ) // if there is no lecture at all show the no lesson card
dayCardView = findNextDay ( 0 , dayIndex + 1 )
linLayout _Home . addView ( dayCardView )
} else if ( dayIndex == 6 ) {
// if that's the case it's sunday
dayCardView = findNextDay ( 1 , 0 )
linLayout _Home . addView ( dayCardView )
} else {
if ( dayIndex == 6 ) {
// TODO iss this necessary?
// if that's the case it's sunday
dayCardView . getLinLayoutDay ( ) . addView ( getNoCard ( resources . getString ( R . string . no _lesson _today ) ) )
linLayout _Home . addView ( dayCardView )
} else {
MaterialDialog ( context !! )
. title ( R . string . error )
. message ( R . string . gen _tt _error )
. show ( )
// TODO log the error and send feedback
}
MaterialDialog ( context !! )
. title ( R . string . error )
. message ( R . string . gen _tt _error )
. show ( )
// TODO log the error and send feedback
}
}
}
/ * *
* add the timetable of one day to the home - screen
* @param dayTimetable the day you wish to add
* /
private fun addDayTimetable ( dayTimetable : TimetableDay ) : DayCardView {
var helpLesson = LessonLinearLayout ( context )
val dayCardView = DayCardView ( context !! )
@ -204,6 +181,44 @@ class HomeFragment : Fragment() {
return dayCardView
}
/ * *
* find the next day with a lesson
* @param startWeekIndex the week you want to start searching
* @param startDayIndex the day index you want to start searching
* @return a DayCardView with all lessons added
* /
private fun findNextDay ( startWeekIndex : Int , startDayIndex : Int ) : DayCardView {
val cal = Calendar . getInstance ( )
var dayCardView = DayCardView ( context !! )
var dayTimetable : TimetableDay ? = null
var dayIndexSearch = startDayIndex
var weekIndexSearch = startWeekIndex
loop @ while ( dayTimetable == null && weekIndexSearch <= timetables . size ) {
for ( i in ( dayIndexSearch ) .. 5 ) {
dayTimetable = timetables [ weekIndexSearch ] . days [ i ]
cal . add ( Calendar . DATE , 1 )
// add the timetable to the card, if it contains at least one lesson break!
dayCardView = addDayTimetable ( dayTimetable )
dayCardView . setDayHeading ( formatter . format ( cal . time ) )
if ( dayCardView . getLinLayoutDay ( ) . childCount > 1 )
return dayCardView
}
dayIndexSearch = 0
weekIndexSearch ++
cal . add ( Calendar . DATE , 1 )
}
dayCardView . setDayHeading ( formatter . format ( Calendar . getInstance ( ) . time ) )
dayCardView . getLinLayoutDay ( ) . addView ( getNoCard ( resources . getString ( R . string . no _lesson _today ) ) ) // if there is no lecture at all show the no lesson card
return dayCardView
}
/ * *
* @param text the text to show on the card
* @return a TextView with the text and all needed parameters
* /
private fun getNoCard ( text : String ) : TextView {
val noLesson = TextView ( context )
noLesson . text = text