show the next day with a lecture on Sundays too
This commit is contained in:
parent
750a808fbe
commit
e08790aaa4
|
@ -13,7 +13,7 @@ android {
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
versionCode 11
|
versionCode 11
|
||||||
versionName "0.3.98"
|
versionName "0.3.99"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
resValue "string", "build_time", buildTime()
|
resValue "string", "build_time", buildTime()
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,10 @@ android {
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||||
versionNameSuffix "-release"
|
versionNameSuffix "-release"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug {
|
||||||
|
versionNameSuffix "-debug"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,7 @@ class HomeFragment : Fragment() {
|
||||||
private fun addTimeTable() = doAsync {
|
private fun addTimeTable() = doAsync {
|
||||||
val dayIndex = NotRetardedCalendar().getDayOfWeekIndex()
|
val dayIndex = NotRetardedCalendar().getDayOfWeekIndex()
|
||||||
val cal = Calendar.getInstance()
|
val cal = Calendar.getInstance()
|
||||||
var dayCardView = DayCardView(context!!)
|
var dayCardView: DayCardView
|
||||||
|
|
||||||
uiThread {
|
uiThread {
|
||||||
|
|
||||||
|
@ -129,54 +129,31 @@ class HomeFragment : Fragment() {
|
||||||
dayCardView = addDayTimetable(timetables[0].days[dayIndex])
|
dayCardView = addDayTimetable(timetables[0].days[dayIndex])
|
||||||
dayCardView.setDayHeading(resources.getString(R.string.today_date, formatter.format(cal.time)))
|
dayCardView.setDayHeading(resources.getString(R.string.today_date, formatter.format(cal.time)))
|
||||||
|
|
||||||
// if there are no lessons don't show the dayCardView
|
// if there are no lessons try to find the next day with a lesson
|
||||||
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 (dayCardView.getLinLayoutDay().childCount <= 1)
|
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)
|
linLayout_Home.addView(dayCardView)
|
||||||
} else {
|
} else {
|
||||||
if (dayIndex == 6) {
|
MaterialDialog(context!!)
|
||||||
// TODO iss this necessary?
|
.title(R.string.error)
|
||||||
// if that's the case it's sunday
|
.message(R.string.gen_tt_error)
|
||||||
dayCardView.getLinLayoutDay().addView(getNoCard(resources.getString(R.string.no_lesson_today)))
|
.show()
|
||||||
linLayout_Home.addView(dayCardView)
|
// TODO log the error and send feedback
|
||||||
} else {
|
|
||||||
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{
|
private fun addDayTimetable(dayTimetable: TimetableDay) : DayCardView{
|
||||||
var helpLesson = LessonLinearLayout(context)
|
var helpLesson = LessonLinearLayout(context)
|
||||||
val dayCardView = DayCardView(context!!)
|
val dayCardView = DayCardView(context!!)
|
||||||
|
@ -204,6 +181,44 @@ class HomeFragment : Fragment() {
|
||||||
return dayCardView
|
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 {
|
private fun getNoCard(text: String): TextView {
|
||||||
val noLesson = TextView(context)
|
val noLesson = TextView(context)
|
||||||
noLesson.text = text
|
noLesson.text = text
|
||||||
|
|
Loading…
Reference in New Issue