show the next day with a lecture on Sundays too

This commit is contained in:
Jannik 2019-03-24 17:23:10 +01:00
parent 750a808fbe
commit e08790aaa4
2 changed files with 59 additions and 40 deletions

View File

@ -13,7 +13,7 @@ android {
minSdkVersion 21
targetSdkVersion 28
versionCode 11
versionName "0.3.98"
versionName "0.3.99"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
resValue "string", "build_time", buildTime()
}
@ -25,6 +25,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
versionNameSuffix "-release"
}
debug {
versionNameSuffix "-debug"
}
}
compileOptions {
}

View File

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