Browse Source

fixed crash on days between saturday and monday, verion 0.2.1

* code clean up
pull/20/head
Jannik 4 years ago
parent
commit
03fa1eca84
  1. 4
      app/build.gradle
  2. 12
      app/src/main/java/org/mosad/seil0/projectlaogai/MainActivity.kt
  3. 28
      app/src/main/java/org/mosad/seil0/projectlaogai/fragments/HomeFragment.kt
  4. 30
      app/src/main/java/org/mosad/seil0/projectlaogai/fragments/MensaFragment.kt
  5. 9
      app/src/main/java/org/mosad/seil0/projectlaogai/fragments/TimeTableFragment.kt
  6. 21
      app/src/main/java/org/mosad/seil0/projectlaogai/hsoparser/DataTypes.kt
  7. 3
      app/src/main/res/values-de-rDE/strings.xml
  8. 11
      app/src/main/res/values/strings.xml

4
app/build.gradle

@ -10,8 +10,8 @@ android {
applicationId "org.mosad.seil0.projectlaogai"
minSdkVersion 21
targetSdkVersion 28
versionCode 5
versionName "0.2.0"
versionCode 6
versionName "0.2.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {

12
app/src/main/java/org/mosad/seil0/projectlaogai/MainActivity.kt

@ -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
}
}

28
app/src/main/java/org/mosad/seil0/projectlaogai/fragments/HomeFragment.kt

@ -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
}
}
}

30
app/src/main/java/org/mosad/seil0/projectlaogai/fragments/MensaFragment.kt

@ -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
}

9
app/src/main/java/org/mosad/seil0/projectlaogai/fragments/TimeTableFragment.kt

@ -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)

21
app/src/main/java/org/mosad/seil0/projectlaogai/hsoparser/DataTypes.kt

@ -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)

3
app/src/main/res/values-de-rDE/strings.xml

@ -12,7 +12,8 @@
<string name="no_more_food">Diese Woche keine weitere Essensausgabe</string>
<string name="no_lesson_today">heute keine Vorlesung</string>
<string name="error">Fehler</string>
<string name="nott_info">Stundenplan konnte nicht geladen werden!</string>
<string name="no_tt_error">Stundenplan konnte nicht geladen werden!</string>
<string name="gen_tt_error">Allgemeiner Stundenplan Fehler!"</string>
<string name="info">Info</string>
<string name="user">Benutzer</string>
<string name="course_desc">Tippen, um den Kurs zu ändern</string>

11
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.2.0</string>
<string name="nav_header_title" translatable="false">hso App 0.2.1</string>
<string name="nav_header_subtitle" translatable="false">seil0@mosad.xyz</string>
<string name="nav_header_desc" translatable="false">Project Laogai</string>
@ -20,7 +20,8 @@
<string name="no_lesson_today">"no lecture today "</string>
<string name="error">Error</string>
<string name="nott_info">Could not load timetabl!"</string>
<string name="no_tt_error">Could not load timetable!"</string>
<string name="gen_tt_error">There was an error with the timetable!"</string>
<string name="sample_user" translatable="false">SampleUser@stud.hs-offenburg.de</string>
<string name="sample_course" translatable="false">SampleCourse 3</string>
@ -34,7 +35,7 @@
<string name="primary_color">primary color</string>
<string name="main_color_desc">The primary color, default is indigo</string>
<string name="select">select</string>
<string name="version" translatable="false">version 0.2.0</string>
<string name="version" translatable="false">version 0.2.1</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 conditions of GPL 3. For further information visit \ngit.mosad.xyz/Seil0/ProjectLaogai \n\n© 2018 seil0@mosad.xyz "</string>
@ -44,6 +45,6 @@
<string name="hello_blank_fragment">soon ™</string>
<string name="string_new_line" translatable="false">%1$s\n</string>
<string name="save_key_course" translatable="false">org.mosag.seil0.projectlaogai.couse</string>
<string name="save_key_courseTTLink" translatable="false">org.mosag.seil0.projectlaogai.couseTTLink</string>
<string name="save_key_course" translatable="false">org.mosad.seil0.projectlaogai.course</string>
<string name="save_key_courseTTLink" translatable="false">org.mosad.seil0.projectlaogai.courseTTLink</string>
</resources>

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close