Browse Source

minor clean up and refactoring

pull/22/head
Jannik 3 years ago
parent
commit
dbaf496a79
  1. 29
      app/src/main/java/org/mosad/seil0/projectlaogai/fragments/MensaFragment.kt
  2. 70
      app/src/main/java/org/mosad/seil0/projectlaogai/fragments/TimeTableFragment.kt
  3. 3
      app/src/main/res/layout/fragment_home.xml
  4. 6
      app/src/main/res/layout/fragment_mensa.xml
  5. 3
      app/src/main/res/layout/fragment_moodle.xml
  6. 7
      app/src/main/res/layout/fragment_timetable.xml

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

@ -58,7 +58,7 @@ class MensaFragment : Fragment() {
addWeek(mensaCurrentWeek, dayCurrent).get()
// add the next week
addWeek(mensaNextWeek, 0).get()
addWeek(mensaNextWeek, 0)
// TODO should we show a info if there is no more food this & next week?
@ -105,13 +105,9 @@ class MensaFragment : Fragment() {
*/
private fun refreshAction() = doAsync {
uiThread {
// set the refresh listener
refreshLayout_Mensa.setOnRefreshListener {
updateMensaScreen()
refreshLayout_Mensa.isRefreshing = false
}
}
@ -119,22 +115,25 @@ class MensaFragment : Fragment() {
/**
* refresh the mensa cache and update the mensa screen
* TODO some nice animations
*/
private fun updateMensaScreen() {
private fun updateMensaScreen() = doAsync {
// update the cache
TCoRAPIController.getMensa(context!!)
TCoRAPIController.getMensa(context!!).get() // blocking since we want the new data
CacheController.readMensa(context!!)
// remove all menus from the layout
linLayout_Mensa.removeAllViews()
uiThread {
// remove all menus from the layout
linLayout_Mensa.removeAllViews()
// add the refreshed menus
val dayCurrent = if (NotRetardedCalendar().getDayOfWeekIndex() == 6) 0 else NotRetardedCalendar().getDayOfWeekIndex()
addWeek(mensaCurrentWeek, dayCurrent).get()
// add the refreshed menus
val dayCurrent = if (NotRetardedCalendar().getDayOfWeekIndex() == 6) 0 else NotRetardedCalendar().getDayOfWeekIndex()
addWeek(mensaCurrentWeek, dayCurrent).get()
// add the next week
addWeek(mensaNextWeek, 0)
// add the next week
addWeek(mensaNextWeek, 0).get()
refreshLayout_Mensa.isRefreshing = false
}
}
}

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

@ -27,6 +27,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.afollestad.materialdialogs.MaterialDialog
import kotlinx.android.synthetic.main.fragment_timetable.*
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
@ -34,6 +35,7 @@ import org.mosad.seil0.projectlaogai.R
import org.mosad.seil0.projectlaogai.controller.CacheController.Companion.timetables
import org.mosad.seil0.projectlaogai.hsoparser.DataTypes
import org.mosad.seil0.projectlaogai.hsoparser.NotRetardedCalendar
import org.mosad.seil0.projectlaogai.hsoparser.TimetableWeek
import org.mosad.seil0.projectlaogai.uicomponents.*
import java.text.SimpleDateFormat
import java.util.*
@ -44,37 +46,51 @@ import java.util.*
*/
class TimeTableFragment : Fragment() {
private val formatter = SimpleDateFormat("E dd.MM", Locale.getDefault()) // TODO change to android call when min api is 24
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view: View = inflater.inflate(R.layout.fragment_timetable, container, false)
if (timetables[0].days.isNotEmpty() && timetables[1].days.isNotEmpty()) {
addWeeks()
addInitWeeks()
} else {
// TODO show card with error msg
MaterialDialog(context!!)
.title(R.string.error)
.message(R.string.timetable_error)
.show()
}
return view
}
/**
* add the all days with at least one lesson to the timetable screen
* add the current and next weeks lessons
*/
private fun addWeeks() = doAsync {
private fun addInitWeeks() = doAsync {
val dayIndex = NotRetardedCalendar().getDayOfWeekIndex()
val formatter = SimpleDateFormat("E dd.MM", Locale.getDefault()) // TODO change to android call when min api is 24
val calendar = Calendar.getInstance()
println(formatter.format(calendar.time))
// add current week
addWeek(dayIndex, 5, timetables[0], calendar).get()
// add next week
addWeek(0, dayIndex - 1, timetables[1], calendar)
}
private fun addWeek(dayStart: Int, dayEnd: Int, timetable: TimetableWeek, calendar: Calendar) = doAsync {
uiThread {
// add the current week
for (day in dayIndex..5) {
for (day in dayStart..dayEnd) {
var helpLesson = LessonLinearLayout(context)
val dayCardView = DayCardView(context!!)
dayCardView.setDayHeading(formatter.format(calendar.time))
println("1: $day , ${formatter.format(calendar.time)}")
// for each timeslot of the day
for ((tsIndex, timeslot) in timetables[0].days[day].timeslots.withIndex()) {
for ((tsIndex, timeslot) in timetable.days[day].timeslots.withIndex()) {
for(lesson in timeslot) {
@ -92,6 +108,8 @@ class TimeTableFragment : Fragment() {
}
}
println("2: $day , ${formatter.format(calendar.time)}")
helpLesson.disableDivider()
calendar.add(Calendar.DATE, 1)
@ -102,43 +120,7 @@ class TimeTableFragment : Fragment() {
}
calendar.add(Calendar.DATE, 1) // before this we are at a sunday (no lecture on sundays!)
// add the next week
for (day in 0..(dayIndex - 1)) {
var helpLesson = LessonLinearLayout(context!!)
val dayCardView = DayCardView(context!!)
dayCardView.setDayHeading(formatter.format(calendar.time))
// for each timeslot of the day
for ((tsIndex, timeslot) in timetables[1].days[day].timeslots.withIndex()) {
for(lesson in timeslot) {
if(lesson.lessonSubject.isNotEmpty()) {
val lessonLayout = LessonLinearLayout(context!!)
lessonLayout.setLesson(lesson, DataTypes().getTime()[tsIndex])
dayCardView.getLinLayoutDay().addView(lessonLayout)
if (lesson != timeslot.last())
lessonLayout.disableDivider()
helpLesson = lessonLayout
}
}
}
helpLesson.disableDivider()
calendar.add(Calendar.DATE, 1)
// if there are no lessons don't show the dayCardView
if (dayCardView.getLinLayoutDay().childCount > 1)
linLayout_Timetable.addView(dayCardView)
}
}
}
}

3
app/src/main/res/layout/fragment_home.xml

@ -15,7 +15,8 @@
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/linLayout_Home">
android:layout_height="wrap_content"
android:id="@+id/linLayout_Home">
</LinearLayout>
</ScrollView>

6
app/src/main/res/layout/fragment_mensa.xml

@ -16,8 +16,10 @@
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/linLayout_Mensa"
android:background="@color/themePrimary"/>
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="@color/themePrimary"
android:id="@+id/linLayout_Mensa"/>
</ScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

3
app/src/main/res/layout/fragment_moodle.xml

@ -8,6 +8,7 @@
<!-- TODO: Update blank fragment layout -->
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent" android:id="@+id/webView"/>
android:layout_height="match_parent"
android:id="@+id/webView"/>
</FrameLayout>

7
app/src/main/res/layout/fragment_timetable.xml

@ -15,9 +15,10 @@
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/linLayout_Timetable"
android:background="@color/themePrimary">
</LinearLayout>
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="@color/themePrimary"
android:id="@+id/linLayout_Timetable"/>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

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