diff --git a/app/build.gradle b/app/build.gradle index 665e8a1..a092bf5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,8 @@ android { applicationId "org.mosad.seil0.projectlaogai" minSdkVersion 21 targetSdkVersion 28 - versionCode 10 - versionName "0.3.2" + versionCode 11 + versionName "0.3.3" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { @@ -36,8 +36,8 @@ dependencies { implementation 'org.jsoup:jsoup:1.11.3' implementation 'org.jetbrains.anko:anko-commons:0.10.8' implementation 'com.afollestad:aesthetic:1.0.0-beta05' - implementation 'com.afollestad.material-dialogs:core:2.0.0' - implementation 'com.afollestad.material-dialogs:color:2.0.0' + implementation 'com.afollestad.material-dialogs:core:2.0.3' + implementation 'com.afollestad.material-dialogs:color:2.0.3' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.1' diff --git a/app/src/main/java/org/mosad/seil0/projectlaogai/PreferencesController.kt b/app/src/main/java/org/mosad/seil0/projectlaogai/PreferencesController.kt index 1ca889b..70b2b80 100644 --- a/app/src/main/java/org/mosad/seil0/projectlaogai/PreferencesController.kt +++ b/app/src/main/java/org/mosad/seil0/projectlaogai/PreferencesController.kt @@ -26,8 +26,8 @@ import android.content.Context import android.graphics.Color import org.jetbrains.anko.defaultSharedPreferences import org.mosad.seil0.projectlaogai.hsoparser.Course -import org.mosad.seil0.projectlaogai.hsoparser.Lesson import org.mosad.seil0.projectlaogai.hsoparser.Meal +import org.mosad.seil0.projectlaogai.hsoparser.TimeTable /** * The PreferencesController class @@ -38,8 +38,8 @@ class PreferencesController { companion object { var cCourseTTLinkList = ArrayList() var cWeekMenus = ArrayList() - var cTimeTableCurrentWeek = arrayOf>() - var cTimeTableNextWeek = arrayOf>() + var cTimeTableCurrentWeek = TimeTable() + var cTimeTableNextWeek = TimeTable() var cColor: Int = Color.BLACK var cCourse = Course("https://www.hs-offenburg.de/index.php?id=6627&class=class&iddV=DA64F6FE-9DDB-429E-A677-05D0D40CB636&week=0", "AI3") diff --git a/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/HomeFragment.kt b/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/HomeFragment.kt index 537ca02..e761de5 100644 --- a/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/HomeFragment.kt +++ b/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/HomeFragment.kt @@ -122,20 +122,25 @@ class HomeFragment : Fragment() { private fun addCurrentTimeTable() { val dayIndex = NotRetardedCalendar().getDayOfWeekIndex() - if (cTimeTableCurrentWeek.isNotEmpty() && dayIndex < 6) { + if (cTimeTableCurrentWeek.days.isNotEmpty() && dayIndex < 6) { - val timeTableDay = cTimeTableCurrentWeek[dayIndex] + val timeTableDay = cTimeTableCurrentWeek.days[dayIndex] - for (i in 0..5) { - val lessonCardView = LessonCardView(context!!, null) + // for all timeslots of the day + for ((i, timeslot) in timeTableDay.timeslots.withIndex()) { - lessonCardView.getTxtViewLesson().text = resources.getString(R.string.string_new_line, timeTableDay[i].lessonSubject) - lessonCardView.getTxtViewLesson().append(timeTableDay[i].lessonTeacher + "\n") - lessonCardView.getTxtViewLesson().append(timeTableDay[i].lessonRoom) - lessonCardView.getTxtViewTime().text = DataTypes().getTime()[i] + for (lesson in timeslot) { + val lessonCardView = LessonCardView(context!!, null) + + 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) + linLayoutTimeTable.addView(lessonCardView) + } - if(lessonCardView.getTxtViewLesson().text.length > 2) - linLayoutTimeTable.addView(lessonCardView) } // add a card if there is no lesson today diff --git a/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/TimeTableFragment.kt b/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/TimeTableFragment.kt index c6977f4..92cd16f 100644 --- a/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/TimeTableFragment.kt +++ b/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/TimeTableFragment.kt @@ -55,7 +55,7 @@ class TimeTableFragment : Fragment() { linLayoutTTFragment = view.findViewById(R.id.linLayout_TTFragment) - if (cTimeTableCurrentWeek.isNotEmpty()) { + if (cTimeTableCurrentWeek.days.isNotEmpty()) { addCurrentWeek() } else { // TODO show card with error msg @@ -81,19 +81,24 @@ class TimeTableFragment : Fragment() { val cardViewTimeTableDay = MensaDayCardView(context!!, null) cardViewTimeTableDay.setDayHeading(formatter.format(calendar.time)) - // for each lessen of the day - for ((i, lesson) in cTimeTableCurrentWeek[day].withIndex()) { - val lessonCardView = LessonCardView(context!!, null) - lessonCardView.setBackgroundColor(Color.TRANSPARENT) + // for each timeslot of the day + for ((i, timeslot) in cTimeTableCurrentWeek.days[day].timeslots.withIndex()) { - 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] + println(timeslot) - // only add the lesson if it contains data - if (lessonCardView.getTxtViewLesson().text.length > 2) - cardViewTimeTableDay.getLinLayoutMensaDay().addView(lessonCardView) + for (lesson in timeslot) { + 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] + + // only add the lesson if it contains data + if (lessonCardView.getTxtViewLesson().text.length > 2) + cardViewTimeTableDay.getLinLayoutMensaDay().addView(lessonCardView) + } } calendar.add(Calendar.DATE, 1) @@ -111,7 +116,7 @@ class TimeTableFragment : Fragment() { // TODO if there is no lesson at one day , show a no lesson card // add next weeks days, max number = dayIndex, if timetable was loaded - if (cTimeTableNextWeek.isNotEmpty()) { + if (cTimeTableNextWeek.days.isNotEmpty()) { calendar.add(Calendar.DATE, 1) // before this we are at a sunday (no lecture on sundays!) for (day in 0..(dayIndex - 1)) { @@ -119,18 +124,22 @@ class TimeTableFragment : Fragment() { val cardViewTimeTableDay = MensaDayCardView(context!!, null) cardViewTimeTableDay.setDayHeading(formatter.format(calendar.time)) - // for each lessen of the day - for ((i, lesson) in cTimeTableNextWeek[day].withIndex()) { - val lessonCardView = LessonCardView(context!!, null) - lessonCardView.setBackgroundColor(Color.TRANSPARENT) + // for each timeslot of the day + for ((i, timeslot) in cTimeTableNextWeek.days[day].timeslots.withIndex()) { - 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] + for (lesson in timeslot) { + val lessonCardView = LessonCardView(context!!, null) + lessonCardView.setBackgroundColor(Color.TRANSPARENT) - if (lessonCardView.getTxtViewLesson().text.length > 2) - cardViewTimeTableDay.getLinLayoutMensaDay().addView(lessonCardView) + 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] + + // only add the lesson if it contains data + if (lessonCardView.getTxtViewLesson().text.length > 2) + cardViewTimeTableDay.getLinLayoutMensaDay().addView(lessonCardView) + } } calendar.add(Calendar.DATE, 1) diff --git a/app/src/main/java/org/mosad/seil0/projectlaogai/hsoparser/DataTypes.kt b/app/src/main/java/org/mosad/seil0/projectlaogai/hsoparser/DataTypes.kt index b2e8cd3..50f72b4 100644 --- a/app/src/main/java/org/mosad/seil0/projectlaogai/hsoparser/DataTypes.kt +++ b/app/src/main/java/org/mosad/seil0/projectlaogai/hsoparser/DataTypes.kt @@ -62,6 +62,6 @@ data class Meal(val day: String, val heading: String, val parts: ArrayList> = Array(6) { ArrayList()}) +data class TimeTableDay( val timeslots: Array> = Array(6) { ArrayList()}) -data class TimeTable(var day: Array = Array(6) { TimeTableDay() }) \ No newline at end of file +data class TimeTable(val days: Array = Array(6) { TimeTableDay() }) \ No newline at end of file diff --git a/app/src/main/java/org/mosad/seil0/projectlaogai/hsoparser/TimeTableParser.kt b/app/src/main/java/org/mosad/seil0/projectlaogai/hsoparser/TimeTableParser.kt index 26fabcd..0dbc43c 100644 --- a/app/src/main/java/org/mosad/seil0/projectlaogai/hsoparser/TimeTableParser.kt +++ b/app/src/main/java/org/mosad/seil0/projectlaogai/hsoparser/TimeTableParser.kt @@ -33,24 +33,23 @@ class TimeTableParser { * the timetable is organised per row not per column; * Mon 1, Tue 1, Wed 1, Thur 1, Fri 1, Sat 1, Mon 2 and so on */ - fun getTimeTable(courseTTURL: String): Array> { - var timeTableWeek = arrayOf>() + fun getTimeTable(courseTTURL: String): TimeTable { + var timeTableWeek = TimeTable() // this must be a var! val scheduleHTML = Jsoup.connect(courseTTURL).get() // create the timetable array - for (i in 0..5) { +/* for (i in 0..5) { var timeTableDay = arrayOf() for (j in 0..5) { timeTableDay += Lesson("", "","","") } timeTableWeek += timeTableDay - } + }*/ //val week = scheduleHTML.select("h1.timetable-caption").text() //println("$week successful!\n") val rows= scheduleHTML.select("table.timetable").select("tr[scope=\"row\"]") - var timeTableWeekTEST = TimeTable() var sDay = -1 var sRow = -1 var sLesson = Lesson("", "", "", "") @@ -68,7 +67,7 @@ class TimeTableParser { // if there is a lecture with rowspan="2", we need to shift everything by one to the left. This is stupid and ugly there needs to bee an API if ((sDay > -1 && sRow > -1) && (sDay == day && ((sRow + 1) == rowIndex))) { // we found a lecture that is longer than 1 lesson - timeTableWeekTEST.day[day].timeslot[rowIndex].add(sLesson) // this just works if there is one lecture per slot + timeTableWeek.days[day].timeslots[rowIndex].add(sLesson) // this just works if there is one lecture per slot // adjust the following slot sDay++ @@ -76,18 +75,18 @@ class TimeTableParser { // adjust the slot directly as we don't get there anymore if(sDay == 5) { - timeTableWeekTEST.day[day + 1].timeslot[rowIndex].add(sLesson) + timeTableWeek.days[day + 1].timeslots[rowIndex].add(sLesson) } } else { - timeTableWeekTEST.day[day].timeslot[rowIndex].add(Lesson(element.select("div.lesson-subject").text(), element.select("div.lesson-teacher").text(), element.select("div.lesson-room").text(), element.select("div.lesson-remark").text())) + timeTableWeek.days[day].timeslots[rowIndex].add(Lesson(element.select("div.lesson-subject").text(), element.select("div.lesson-teacher").text(), element.select("div.lesson-room").text(), element.select("div.lesson-remark").text())) } // we found a lecture with rowspan="2", save day, row and lesson for later adjustment if(element.toString().contains("rowspan=\"2\"")) { sDay = day sRow = rowIndex - sLesson = timeTableWeekTEST.day[day].timeslot[rowIndex].get(index = 0) + sLesson = timeTableWeek.days[day].timeslots[rowIndex].get(index = 0) } if(element.hasClass("lastcol")) day++ @@ -95,12 +94,12 @@ class TimeTableParser { } - printTimeTableWeekNew(timeTableWeekTEST) + printTimeTableWeek(timeTableWeek) - scheduleHTML.select("table.timetable").select("td.lastcol").forEachIndexed { index, element -> + /*scheduleHTML.select("table.timetable").select("td.lastcol").forEachIndexed { index, element -> //println("Index: " + index + " lesson: " + element.select("div.lesson-subject").text() + ", " + element.select("div.lesson-teacher").text()) timeTableWeek[index % 6][index / 6] = Lesson(element.select("div.lesson-subject").text(), element.select("div.lesson-teacher").text(), element.select("div.lesson-room").text(), element.select("div.lesson-remark").text()) - } + }*/ return timeTableWeek } @@ -118,7 +117,7 @@ class TimeTableParser { } @Suppress("unused") - fun printTimeTableWeek (timeTableWeek: Array>) { + fun printTimeTableWeekOLD (timeTableWeek: Array>) { for (j in 0..5) print(days[j].padEnd(25 ,' ') + " | ") println() @@ -138,7 +137,8 @@ class TimeTableParser { println(" \n") } - fun printTimeTableWeekNew(timetable: TimeTable) { + @Suppress("unused") + fun printTimeTableWeek(timetable: TimeTable) { for (j in 0..5) print(days[j].padEnd(75 ,' ') + " | ") println() for (j in 0..5) print("-".padEnd(76 + (j.toFloat().div(j).toInt()), '-') + "+") @@ -148,27 +148,27 @@ class TimeTableParser { for (i in 0..5) { for (j in 0..5) { - val ldiff = if (timetable.day[j].timeslot[i].size == 0) 1 else timetable.day[j].timeslot[i].size + val ldiff = if (timetable.days[j].timeslots[i].size == 0) 1 else timetable.days[j].timeslots[i].size - for (lesson in timetable.day[j].timeslot[i]) print(lesson.lessonSubject.padEnd(75/ldiff ,' ')) + for (lesson in timetable.days[j].timeslots[i]) print(lesson.lessonSubject.padEnd(75/ldiff ,' ')) if (ldiff == 2) print(" ") print(" | ") } println() for (j in 0..5) { - val ldiff = if (timetable.day[j].timeslot[i].size == 0) 1 else timetable.day[j].timeslot[i].size + val ldiff = if (timetable.days[j].timeslots[i].size == 0) 1 else timetable.days[j].timeslots[i].size - for (lesson in timetable.day[j].timeslot[i]) print(lesson.lessonTeacher.padEnd(75/ldiff ,' ')) + for (lesson in timetable.days[j].timeslots[i]) print(lesson.lessonTeacher.padEnd(75/ldiff ,' ')) if (ldiff == 2) print(" ") print(" | ") } println() for (j in 0..5) { - val ldiff = if (timetable.day[j].timeslot[i].size == 0) 1 else timetable.day[j].timeslot[i].size + val ldiff = if (timetable.days[j].timeslots[i].size == 0) 1 else timetable.days[j].timeslots[i].size - for (lesson in timetable.day[j].timeslot[i]) print(lesson.lessonRoom.padEnd(75/ldiff ,' ')) + for (lesson in timetable.days[j].timeslots[i]) print(lesson.lessonRoom.padEnd(75/ldiff ,' ')) if (ldiff == 2) print(" ") print(" | ") } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 62a13c6..ab7bce3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2,7 +2,7 @@ Project Laogai Open navigation drawer Close navigation drawer - hso App 0.3.2 + hso App 0.3.3 seil0@mosad.xyz Project Laogai @@ -37,7 +37,7 @@ primary color The primary color, default is black select - version 0.3.2 + version 0.3.3 about hso App by @Seil0 "This software is made by @Seil0 and is published under the terms and