fixed crash on days between saturday and monday, verion 0.2.1
* code clean up
This commit is contained in:
@ -29,10 +29,12 @@ import androidx.appcompat.app.ActionBarDrawerToggle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.GravityCompat
|
||||
import androidx.fragment.app.FragmentTransaction
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.google.android.material.navigation.NavigationView
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import kotlinx.android.synthetic.main.app_bar_main.*
|
||||
import org.jetbrains.anko.doAsync
|
||||
import org.jetbrains.anko.uiThread
|
||||
import org.mosad.seil0.projectlaogai.fragments.HomeFragment
|
||||
import org.mosad.seil0.projectlaogai.fragments.MensaFragment
|
||||
import org.mosad.seil0.projectlaogai.fragments.SettingsFragment
|
||||
@ -197,7 +199,15 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||
val t2 = doAsync {
|
||||
try {
|
||||
timeTableWeek = timeTableParser.getTimeTable(course.courseTTLink)
|
||||
}catch (e: Exception) {
|
||||
} catch (e: Exception) {
|
||||
|
||||
uiThread {
|
||||
MaterialDialog(this@MainActivity)
|
||||
.title(R.string.error)
|
||||
.message(R.string.no_tt_error)
|
||||
.show()
|
||||
}
|
||||
|
||||
e.stackTrace
|
||||
}
|
||||
}
|
||||
|
@ -34,9 +34,7 @@ import org.jetbrains.anko.doAsync
|
||||
import org.jetbrains.anko.uiThread
|
||||
import org.mosad.seil0.projectlaogai.MainActivity
|
||||
import org.mosad.seil0.projectlaogai.R
|
||||
import org.mosad.seil0.projectlaogai.hsoparser.DataTypes
|
||||
import org.mosad.seil0.projectlaogai.hsoparser.Meal
|
||||
import org.mosad.seil0.projectlaogai.hsoparser.MensaParser
|
||||
import org.mosad.seil0.projectlaogai.hsoparser.*
|
||||
import org.mosad.seil0.projectlaogai.uicomponents.LessonCardView
|
||||
import java.util.*
|
||||
|
||||
@ -95,10 +93,11 @@ class HomeFragment : Fragment() {
|
||||
* add the current timetable to the home screen
|
||||
*/
|
||||
private fun addCurrentTimeTable() {
|
||||
val dayIndex = NotRetardedCalendar().getDayOfWeekIndex()
|
||||
|
||||
// TODO this needs to be reworked, currently we display the waring if there is no lecture at all not only if we're unable to load the tt
|
||||
if (mainActivity.getCurrentTimeTableWeek().isNotEmpty()) {
|
||||
val timeTableDay = mainActivity.getCurrentTimeTableWeek()[Calendar.getInstance().get(Calendar.DAY_OF_WEEK) -2]
|
||||
if (mainActivity.getCurrentTimeTableWeek().isNotEmpty() && dayIndex < 6) {
|
||||
|
||||
val timeTableDay = mainActivity.getCurrentTimeTableWeek()[dayIndex]
|
||||
|
||||
for (i in 0..5) {
|
||||
val lessonCardView = LessonCardView(context!!, null)
|
||||
@ -120,10 +119,19 @@ class HomeFragment : Fragment() {
|
||||
linLayoutTimeTable.addView(noLessonCardView)
|
||||
}
|
||||
} else {
|
||||
MaterialDialog(context!!)
|
||||
.title(R.string.error)
|
||||
.message(R.string.nott_info)
|
||||
.show()
|
||||
if (dayIndex == 6) {
|
||||
// if that's the case it's sunday
|
||||
val noLessonCardView = LessonCardView(context!!, null)
|
||||
noLessonCardView.getTxtViewLesson().text = resources.getString(R.string.no_lesson_today)
|
||||
linLayoutTimeTable.addView(noLessonCardView)
|
||||
} else {
|
||||
MaterialDialog(context!!)
|
||||
.title(R.string.error)
|
||||
.message(R.string.gen_tt_error)
|
||||
.show()
|
||||
// TODO log the error and send feedback
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,6 @@ import org.jetbrains.anko.doAsync
|
||||
import org.jetbrains.anko.uiThread
|
||||
import org.mosad.seil0.projectlaogai.MainActivity
|
||||
import org.mosad.seil0.projectlaogai.R
|
||||
import org.mosad.seil0.projectlaogai.hsoparser.Meal
|
||||
import org.mosad.seil0.projectlaogai.hsoparser.MensaParser
|
||||
import org.mosad.seil0.projectlaogai.uicomponents.MensaDayCardView
|
||||
import org.mosad.seil0.projectlaogai.uicomponents.MenuCardView
|
||||
import java.util.*
|
||||
@ -112,34 +110,6 @@ class MensaFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
fun addDay(day: Int) {
|
||||
val cardViewMensaDay = MensaDayCardView(context!!, null)
|
||||
|
||||
doAsync {
|
||||
val mensaParser = MensaParser()
|
||||
val dayMenus: ArrayList<Meal> = mensaParser.getMensaMenuDay(mensaParser.getMensaMenu(), day)
|
||||
|
||||
uiThread {
|
||||
|
||||
for (meal in dayMenus) {
|
||||
val menuViewMenu = MenuCardView(context!!, null)
|
||||
menuViewMenu.setMenuHeading(meal.heading)
|
||||
|
||||
for(part in meal.parts) {
|
||||
menuViewMenu.getTxtViewMenu().append(part)
|
||||
}
|
||||
|
||||
cardViewMensaDay.setDayHeading(meal.day) //TODO move this out of the first for loop, performance!!
|
||||
cardViewMensaDay.getLinLayoutMensaDay().addView(menuViewMenu)
|
||||
}
|
||||
|
||||
linLayoutMensaFragment.addView(cardViewMensaDay)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun setMainActivity(mainActivity: MainActivity) {
|
||||
this.mainActivity = mainActivity
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ import org.jetbrains.anko.uiThread
|
||||
import org.mosad.seil0.projectlaogai.MainActivity
|
||||
import org.mosad.seil0.projectlaogai.R
|
||||
import org.mosad.seil0.projectlaogai.hsoparser.DataTypes
|
||||
import org.mosad.seil0.projectlaogai.hsoparser.NotRetardedCalendar
|
||||
import org.mosad.seil0.projectlaogai.uicomponents.LessonCardView
|
||||
import org.mosad.seil0.projectlaogai.uicomponents.MensaDayCardView
|
||||
import java.text.SimpleDateFormat
|
||||
@ -61,13 +62,17 @@ class TimeTableFragment : Fragment() {
|
||||
|
||||
/**
|
||||
* add the remaining days of the current week to the timetable screen
|
||||
* TODO show the current day and the following 5 days
|
||||
*/
|
||||
private fun addCurrentWeek() {
|
||||
val dayIndex = NotRetardedCalendar().getDayOfWeekIndex()
|
||||
|
||||
doAsync {
|
||||
|
||||
uiThread {
|
||||
|
||||
for(day in Calendar.getInstance().get(Calendar.DAY_OF_WEEK)..7) {
|
||||
println(dayIndex)
|
||||
for(day in dayIndex..5) {
|
||||
|
||||
val formatter = SimpleDateFormat("E dd.MM", Locale.GERMANY) // TODO change to android call when min api is 24
|
||||
val calendar = Calendar.getInstance()
|
||||
@ -78,7 +83,7 @@ class TimeTableFragment : Fragment() {
|
||||
cardViewTimeTableDay.setDayHeading(formatter.format(calendar.time))
|
||||
|
||||
// for each lessen of the day
|
||||
for((i, lesson) in mainActivity.getCurrentTimeTableWeek()[day - 2].withIndex()) {
|
||||
for((i, lesson) in mainActivity.getCurrentTimeTableWeek()[dayIndex].withIndex()) {
|
||||
val lessonCardView = LessonCardView(context!!, null)
|
||||
lessonCardView.setBackgroundColor(Color.TRANSPARENT)
|
||||
|
||||
|
@ -22,6 +22,8 @@
|
||||
|
||||
package org.mosad.seil0.projectlaogai.hsoparser
|
||||
|
||||
import java.util.*
|
||||
|
||||
class DataTypes {
|
||||
val times = arrayOf("8.00 - 9.30", "9.45 - 11.15" ,"11.35 - 13.05", "14.00 -15.30", "15.45 - 17.15", "17.30 - 19.00")
|
||||
|
||||
@ -35,6 +37,25 @@ class DataTypes {
|
||||
|
||||
}
|
||||
|
||||
class NotRetardedCalendar {
|
||||
private val calendar = Calendar.getInstance()!!
|
||||
|
||||
fun getDayOfWeekIndex(): Int {
|
||||
return when(calendar.get(Calendar.DAY_OF_WEEK)) {
|
||||
Calendar.MONDAY -> 0
|
||||
Calendar.TUESDAY -> 1
|
||||
Calendar.WEDNESDAY -> 2
|
||||
Calendar.THURSDAY -> 3
|
||||
Calendar.FRIDAY -> 4
|
||||
Calendar.SATURDAY -> 5
|
||||
Calendar.SUNDAY -> 6
|
||||
else -> 7
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
data class Lesson(val lessonSubject: String, val lessonTeacher: String, val lessonRoom:String, val lessonRemark: String)
|
||||
|
||||
data class CourseTTLink(val courseTTLink: String, val course: String)
|
||||
|
Reference in New Issue
Block a user