fixed app crash if the tt cannot be loaded

This commit is contained in:
2018-11-06 10:47:51 +01:00
parent 2d525c394b
commit 2c81c80456
6 changed files with 42 additions and 24 deletions

View File

@ -48,7 +48,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
private var weekMenus = ArrayList<Meal>()
private var courseTTLinkList = ArrayList<CourseTTLink>()
private lateinit var timeTableWeek: Array<Array<Lesson>>
private var timeTableWeek = arrayOf<Array<Lesson>>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -170,7 +170,11 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
val t2 = doAsync {
timeTableWeek = timeTableParser.getTimeTable("https://www.hs-offenburg.de/index.php?id=6627&class=class&iddV=DA64F6FE-9DDB-429E-A677-05D0D40CB636&week=0")
try {
timeTableWeek = timeTableParser.getTimeTable("https://www.hs-offenburg.de/index.php?id=6627&class=class&iddV=DA64F6FE-9DDB-429E-A677-05D0D40CB636&week=0")
}catch (e: Exception) {
e.stackTrace
}
}
t1.get()

View File

@ -28,6 +28,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.fragment.app.Fragment
import com.afollestad.materialdialogs.MaterialDialog
import kotlinx.android.synthetic.main.fragment_home.*
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
@ -94,26 +95,35 @@ class HomeFragment : Fragment() {
* add the current timetable to the home screen
*/
private fun addCurrentTimeTable() {
val timeTableDay = mainActivity.getCurrentTimeTableWeek()[Calendar.getInstance().get(Calendar.DAY_OF_WEEK) -2]
for (i in 0..5) {
val lessonCardView = LessonCardView(context!!, null)
// 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]
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 (i in 0..5) {
val lessonCardView = LessonCardView(context!!, null)
if(lessonCardView.getTxtViewLesson().text.length > 2)
linLayoutTimeTable.addView(lessonCardView)
}
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]
// add a card if there is no lesson today
if (linLayoutTimeTable.childCount == 0) {
// TODO we could display the next day with a lecture
val noLessonCardView = LessonCardView(context!!, null)
noLessonCardView.getTxtViewLesson().text = resources.getString(R.string.no_lesson_today)
linLayoutTimeTable.addView(noLessonCardView)
if(lessonCardView.getTxtViewLesson().text.length > 2)
linLayoutTimeTable.addView(lessonCardView)
}
// add a card if there is no lesson today
if (linLayoutTimeTable.childCount == 0) {
// TODO we could display the next day with a lecture
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.nott_info)
.show()
}
}