Browse Source

the app can now display multiple lessons per time slot

* display multiple lessons per slot if needed
* material dialogs 2.0.0 -> 2.0.3
pull/20/head
Jannik 2 years ago
parent
commit
dbfdaffe99
  1. 8
      app/build.gradle
  2. 6
      app/src/main/java/org/mosad/seil0/projectlaogai/PreferencesController.kt
  3. 25
      app/src/main/java/org/mosad/seil0/projectlaogai/fragments/HomeFragment.kt
  4. 55
      app/src/main/java/org/mosad/seil0/projectlaogai/fragments/TimeTableFragment.kt
  5. 4
      app/src/main/java/org/mosad/seil0/projectlaogai/hsoparser/DataTypes.kt
  6. 40
      app/src/main/java/org/mosad/seil0/projectlaogai/hsoparser/TimeTableParser.kt
  7. 4
      app/src/main/res/values/strings.xml

8
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'

6
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<Course>()
var cWeekMenus = ArrayList<Meal>()
var cTimeTableCurrentWeek = arrayOf<Array<Lesson>>()
var cTimeTableNextWeek = arrayOf<Array<Lesson>>()
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")

25
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

55
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()) {
println(timeslot)
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)
// only add the lesson if it contains data
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)
@ -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)

4
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<Strin
data class Lesson(val lessonSubject: String, val lessonTeacher: String, val lessonRoom:String, val lessonRemark: String)
data class TimeTableDay( var timeslot: Array<ArrayList<Lesson>> = Array(6) { ArrayList<Lesson>()})
data class TimeTableDay( val timeslots: Array<ArrayList<Lesson>> = Array(6) { ArrayList<Lesson>()})
data class TimeTable(var day: Array<TimeTableDay> = Array(6) { TimeTableDay() })
data class TimeTable(val days: Array<TimeTableDay> = Array(6) { TimeTableDay() })

40
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<Array<Lesson>> {
var timeTableWeek = arrayOf<Array<Lesson>>()
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<Lesson>()
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<Array<Lesson>>) {
fun printTimeTableWeekOLD (timeTableWeek: Array<Array<Lesson>>) {
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(" | ")
}

4
app/src/main/res/values/strings.xml

@ -2,7 +2,7 @@
<string name="app_name" translatable="false">Project Laogai</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="nav_header_title" translatable="false">hso App 0.3.2</string>
<string name="nav_header_title" translatable="false">hso App 0.3.3</string>
<string name="nav_header_subtitle" translatable="false">seil0@mosad.xyz</string>
<string name="nav_header_desc" translatable="false">Project Laogai</string>
@ -37,7 +37,7 @@
<string name="primary_color">primary color</string>
<string name="main_color_desc">The primary color, default is black</string>
<string name="select">select</string>
<string name="version" translatable="false">version 0.3.2</string>
<string name="version" translatable="false">version 0.3.3</string>
<string name="about">about</string>
<string name="about_txtView" translatable="false">hso App by @Seil0</string>
<string name="about_text" translatable="false">"This software is made by @Seil0 and is published under the terms and

Loading…
Cancel
Save