version 0.2.0
* the selected course is saved now
This commit is contained in:
@ -50,6 +50,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||
private var courseTTLinkList = ArrayList<CourseTTLink>()
|
||||
private var timeTableWeek = arrayOf<Array<Lesson>>()
|
||||
|
||||
private lateinit var course: CourseTTLink
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
@ -143,13 +145,22 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||
}
|
||||
|
||||
/**
|
||||
* update the gui with the data of the new selected course TODO
|
||||
* save selected course and courseTTLink TODO
|
||||
* update the gui with the data of the new selected course
|
||||
* save selected course and courseTTLink
|
||||
*/
|
||||
fun updateCourse(course: CourseTTLink) {
|
||||
println(course.course)
|
||||
println(course.courseTTLink)
|
||||
|
||||
this.course = course
|
||||
// save new selected course
|
||||
val sharedPref = getPreferences(MODE_PRIVATE) ?: return
|
||||
with (sharedPref.edit()) {
|
||||
putString(getString(R.string.save_key_course), course.course)
|
||||
putString(getString(R.string.save_key_courseTTLink), course.courseTTLink.replace("http", "https"))
|
||||
apply()
|
||||
}
|
||||
|
||||
timeTableWeek = timeTableParser.getTimeTable(course.courseTTLink.replace("http", "https"))
|
||||
}
|
||||
|
||||
@ -158,6 +169,19 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||
* TODO evaluate if we should use a timeout here
|
||||
*/
|
||||
private fun load() {
|
||||
|
||||
// load saved course
|
||||
val sharedPref = getPreferences(MODE_PRIVATE) ?: return
|
||||
course = CourseTTLink(
|
||||
sharedPref.getString(getString(R.string.save_key_courseTTLink),
|
||||
"https://www.hs-offenburg.de/index.php?id=6627&class=class&iddV=DA64F6FE-9DDB-429E-A677-05D0D40CB636&week=0")!!,
|
||||
sharedPref.getString(getString(R.string.save_key_course), "AI3")!!
|
||||
)
|
||||
|
||||
/**
|
||||
* load mensa, course timetable and courselist from the swfr/hso website
|
||||
* TODO make an API see https://git.mosad.xyz/Seil0/TheCitadelofRicks
|
||||
*/
|
||||
val time = measureTimeMillis {
|
||||
/* getting the course list should be faster than the timetable,
|
||||
* we need have time until the user opens the dialog
|
||||
@ -172,7 +196,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||
|
||||
val t2 = doAsync {
|
||||
try {
|
||||
timeTableWeek = timeTableParser.getTimeTable("https://www.hs-offenburg.de/index.php?id=6627&class=class&iddV=DA64F6FE-9DDB-429E-A677-05D0D40CB636&week=0")
|
||||
timeTableWeek = timeTableParser.getTimeTable(course.courseTTLink)
|
||||
}catch (e: Exception) {
|
||||
e.stackTrace
|
||||
}
|
||||
@ -197,4 +221,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||
return weekMenus
|
||||
}
|
||||
|
||||
fun getCourse(): CourseTTLink {
|
||||
return course
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -72,6 +72,12 @@ class SettingsFragment : Fragment() {
|
||||
return view
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
txtView_Course.text = mainActivity.getCourse().course
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize some actions for SettingsFragment elements
|
||||
*/
|
||||
|
@ -48,12 +48,13 @@ class TimeTableParser {
|
||||
fun getTimeTable(courseTTURL: String): Array<Array<Lesson>> {
|
||||
val scheduleHTML = Jsoup.connect(courseTTURL).get()
|
||||
|
||||
// val week = scheduleHTML.select("h1.timetable-caption").text()
|
||||
// println("$week successful!\n")
|
||||
//val week = scheduleHTML.select("h1.timetable-caption").text()
|
||||
//println("$week successful!\n")
|
||||
|
||||
scheduleHTML.select("table.timetable").select("td.lastcol").forEachIndexed { index, element ->
|
||||
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
|
||||
}
|
||||
|
||||
@ -69,6 +70,7 @@ class TimeTableParser {
|
||||
return courseTTLinkList
|
||||
}
|
||||
|
||||
|
||||
fun printTimeTableWeek (timeTableWeek: Array<Array<Lesson>>) {
|
||||
|
||||
for (j in 0..5) print(days[j].padEnd(25 ,' ') + " | ")
|
||||
|
Reference in New Issue
Block a user