home screen redesign

This commit is contained in:
Jannik 2019-03-22 21:59:32 +01:00
parent a4eaea2918
commit e51a80b78d
5 changed files with 97 additions and 177 deletions

View File

@ -22,11 +22,13 @@
package org.mosad.seil0.projectlaogai.fragments package org.mosad.seil0.projectlaogai.fragments
import android.graphics.Typeface
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.LinearLayout import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import kotlinx.android.synthetic.main.fragment_home.* import kotlinx.android.synthetic.main.fragment_home.*
@ -40,8 +42,9 @@ import org.mosad.seil0.projectlaogai.hsoparser.Meal
import org.mosad.seil0.projectlaogai.hsoparser.NotRetardedCalendar import org.mosad.seil0.projectlaogai.hsoparser.NotRetardedCalendar
import org.mosad.seil0.projectlaogai.uicomponents.DayCardView import org.mosad.seil0.projectlaogai.uicomponents.DayCardView
import org.mosad.seil0.projectlaogai.uicomponents.LessonLinearLayout import org.mosad.seil0.projectlaogai.uicomponents.LessonLinearLayout
import org.mosad.seil0.projectlaogai.uicomponents.MealLinearLayout
import java.text.SimpleDateFormat
import java.util.* import java.util.*
import kotlin.collections.ArrayList
/** /**
* The "home" controller class * The "home" controller class
@ -49,18 +52,14 @@ import kotlin.collections.ArrayList
*/ */
class HomeFragment : Fragment() { class HomeFragment : Fragment() {
private lateinit var linLayoutTimeTable: LinearLayout val formatter = SimpleDateFormat("E dd.MM", Locale.GERMANY)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view: View = inflater.inflate(R.layout.fragment_home, container, false) val view: View = inflater.inflate(R.layout.fragment_home, container, false)
// init UI elements addMensaMenu()
linLayoutTimeTable = view.findViewById(R.id.linLayoutTimeTable) addTimeTable()
//setText()
addCurrentMensaMenu()
addCurrentTimeTable()
// Inflate the layout for this fragment // Inflate the layout for this fragment
return view return view
@ -69,54 +68,55 @@ class HomeFragment : Fragment() {
/** /**
* add the current mensa meal to the home screens * add the current mensa meal to the home screens
*/ */
private fun addCurrentMensaMenu() { private fun addMensaMenu() {
doAsync { doAsync {
val dayMeals: ArrayList<Meal>
var dayMeals: ArrayList<Meal>
val cal = Calendar.getInstance() val cal = Calendar.getInstance()
val mensaCardView = DayCardView(context!!)
if (cal.get(Calendar.HOUR_OF_DAY) < 15) {
dayMeals = mensaCurrentWeek.days[NotRetardedCalendar().getDayOfWeekIndex()].meals
} else {
dayMeals = mensaCurrentWeek.days[NotRetardedCalendar().getTomorrowWeekIndex()].meals
uiThread {
txtView_Menu1Heading.text = resources.getString(R.string.meal_1_tomorrow)
txtView_Menu2Heading.text = resources.getString(R.string.meal_2_tomorrow)
}
}
uiThread { uiThread {
if (cal.get(Calendar.HOUR_OF_DAY) < 15) {
dayMeals = mensaCurrentWeek.days[NotRetardedCalendar().getDayOfWeekIndex()].meals
mensaCardView.setDayHeading(resources.getString(R.string.today_date, formatter.format(cal.time)))
} else {
dayMeals = mensaCurrentWeek.days[NotRetardedCalendar().getTomorrowWeekIndex()].meals
cal.add(Calendar.DATE, 1)
mensaCardView.setDayHeading(resources.getString(R.string.tomorrow_date, formatter.format(cal.time)))
}
if (dayMeals.size >= 2) { if (dayMeals.size >= 2) {
// get the index of the first meal, not a "Schneller Teller" // get the index of the first meal, not a "Schneller Teller"
loop@ for ((i, meal) in dayMeals.withIndex()) { loop@ for ((i, meal) in dayMeals.withIndex()) {
if (meal.heading.contains("Essen")) { if (meal.heading.contains("Essen")) {
dayMeals[i].parts.forEachIndexed { index, part -> val meal1Layout = MealLinearLayout(context)
txtViewMenu1.append(part) meal1Layout.setMeal(dayMeals[i])
if (index < (dayMeals[i].parts.size - 1)) mensaCardView.getLinLayoutDay().addView(meal1Layout)
txtViewMenu1.append("\n")
}
dayMeals[i + 1].parts.forEachIndexed { index, part -> val meal2Layout = MealLinearLayout(context)
txtViewMenu2.append(part) meal2Layout.setMeal(dayMeals[i + 1])
if (index < (dayMeals[i + 1].parts.size - 1)) meal2Layout.disableDivider()
txtViewMenu2.append("\n") mensaCardView.getLinLayoutDay().addView(meal2Layout)
}
break@loop break@loop
} }
} }
} else { } else {
if (txtView_Menu1Heading.text == resources.getString(R.string.meal_1_tomorrow)) { val noFood = TextView(context)
txtViewMenu1.text = resources.getString(R.string.no_meal_tomorrow) noFood.text = resources.getString(R.string.mensa_closed)
txtViewMenu2.text = resources.getString(R.string.no_meal_tomorrow) noFood.setTextColor(ContextCompat.getColor(context!!, R.color.textPrimary))
} else { noFood.textSize = 18.0F
txtViewMenu1.text = resources.getString(R.string.no_meal_today) noFood.setTypeface(null, Typeface.BOLD)
txtViewMenu2.text = resources.getString(R.string.no_meal_today) noFood.textAlignment = View.TEXT_ALIGNMENT_CENTER
} noFood.setPadding(7,7,7,7)
mensaCardView.getLinLayoutDay().addView(noFood)
} }
linLayout_Home.addView(mensaCardView)
} }
} }
@ -125,60 +125,67 @@ class HomeFragment : Fragment() {
/** /**
* add the current timetable to the home screen * add the current timetable to the home screen
*/ */
private fun addCurrentTimeTable() { private fun addTimeTable() {
val dayIndex = NotRetardedCalendar().getDayOfWeekIndex() val dayIndex = NotRetardedCalendar().getDayOfWeekIndex()
var helpLesson = LessonLinearLayout(context!!) var helpLesson = LessonLinearLayout(context!!)
val dayCardView = DayCardView(context!!) val dayCardView = DayCardView(context!!)
dayCardView.setDayHeading("Heute") dayCardView.setDayHeading(resources.getString(R.string.today_date, formatter.format(Calendar.getInstance().time)))
if (timetables[0].days.isNotEmpty() && dayIndex < 6) { doAsync {
uiThread {
// for all timeslots of the day if (timetables[0].days.isNotEmpty() && dayIndex < 6) {
for ((tsIndex, timeslot) in timetables[0].days[dayIndex].timeslots.withIndex()) {
for(lesson in timeslot) { // for all timeslots of the day
if(lesson.lessonSubject.isNotEmpty()) { for ((tsIndex, timeslot) in timetables[0].days[dayIndex].timeslots.withIndex()) {
val lessonLayout = LessonLinearLayout(context!!) for(lesson in timeslot) {
lessonLayout.setLesson(lesson, DataTypes().getTime()[tsIndex]) if(lesson.lessonSubject.isNotEmpty()) {
dayCardView.getLinLayoutDay().addView(lessonLayout)
if (lesson != timeslot.last()) { val lessonLayout = LessonLinearLayout(context!!)
lessonLayout.disableDivider() lessonLayout.setLesson(lesson, DataTypes().getTime()[tsIndex])
dayCardView.getLinLayoutDay().addView(lessonLayout)
if (lesson != timeslot.last()) {
lessonLayout.disableDivider()
}
helpLesson = lessonLayout
}
} }
helpLesson = lessonLayout
} }
helpLesson.disableDivider()
// if there are no lessons don't show the dayCardView
if (dayCardView.getLinLayoutDay().childCount > 1) {
linLayout_Home.addView(dayCardView)
} else {
// TODO we could display the next day with a lecture
val noLesson = DayCardView(context!!)
noLesson.setDayHeading(resources.getString(R.string.no_lesson_today))
linLayout_Home.addView(noLesson)
}
} else {
if (dayIndex == 6) {
// if that's the case it's sunday
val noLesson = DayCardView(context!!)
noLesson.setDayHeading(resources.getString(R.string.no_lesson_today))
linLayout_Home.addView(noLesson)
} else {
MaterialDialog(context!!)
.title(R.string.error)
.message(R.string.gen_tt_error)
.show()
// TODO log the error and send feedback
}
} }
} }
helpLesson.disableDivider()
// if there are no lessons don't show the dayCardView
if (dayCardView.getLinLayoutDay().childCount > 1) {
linLayoutTimeTable.addView(dayCardView)
} else {
// TODO we could display the next day with a lecture
val noLesson = DayCardView(context!!)
noLesson.setDayHeading(resources.getString(R.string.no_lesson_today))
linLayoutTimeTable.addView(noLesson)
}
} else {
if (dayIndex == 6) {
// if that's the case it's sunday
val noLesson = DayCardView(context!!)
noLesson.setDayHeading(resources.getString(R.string.no_lesson_today))
linLayoutTimeTable.addView(noLesson)
} else {
MaterialDialog(context!!)
.title(R.string.error)
.message(R.string.gen_tt_error)
.show()
// TODO log the error and send feedback
}
} }
} }
} }

View File

@ -26,7 +26,6 @@ import android.content.Context
import android.view.View import android.view.View
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.cardview.widget.CardView import androidx.cardview.widget.CardView
import kotlinx.android.synthetic.main.linearlayout_lesson.view.*
import kotlinx.android.synthetic.main.linearlayout_meal.view.* import kotlinx.android.synthetic.main.linearlayout_meal.view.*
import org.mosad.seil0.projectlaogai.R import org.mosad.seil0.projectlaogai.R
import org.mosad.seil0.projectlaogai.hsoparser.Meal import org.mosad.seil0.projectlaogai.hsoparser.Meal

View File

@ -10,97 +10,13 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:id="@+id/cardView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="3dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="3dp"
android:clickable="false"
android:maxHeight="125dp"
app:cardUseCompatPadding="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" android:elevation="5dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_marginBottom="2dp">
<TextView
android:text="@string/meal_1"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/txtView_Menu1Heading"
android:textStyle="bold" android:textAlignment="center" android:textSize="16sp"
android:typeface="sans" android:fontFamily="sans-serif" android:paddingBottom="5dp"/>
<TextView
android:id="@+id/txtViewMenu1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:textAlignment="center"
android:textSize="16sp"
android:textStyle="bold"
android:typeface="sans"
android:textIsSelectable="true"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="@+id/cardView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:cardUseCompatPadding="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cardView" android:elevation="5dp"
android:layout_marginEnd="3dp" android:layout_marginStart="3dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_marginBottom="2dp">
<TextView
android:text="@string/meal_2"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/txtView_Menu2Heading"
android:textAlignment="center" android:textStyle="bold" android:textSize="16sp"
android:typeface="sans" android:fontFamily="sans-serif" android:paddingBottom="5dp"/>
<TextView
android:id="@+id/txtViewMenu2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:textAlignment="center"
android:textSize="16sp"
android:textStyle="bold"
android:typeface="sans"
android:textIsSelectable="true"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<ScrollView <ScrollView
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="match_parent">
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cardView2" android:id="@+id/scrollViewTimeTable"
android:background="@color/md_divider_dark_theme" android:paddingTop="6dp"
android:layout_marginTop="5dp">
<LinearLayout <LinearLayout
android:id="@+id/linLayoutTimeTable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent" android:layout_width="match_parent"
app:layout_constraintEnd_toEndOf="parent" android:layout_height="wrap_content" android:id="@+id/linLayout_Home">
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cardView2">
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

View File

@ -7,10 +7,9 @@
<string name="settings">Einstellungen</string> <string name="settings">Einstellungen</string>
<string name="meal_1">Essen 1</string> <string name="meal_1">Essen 1</string>
<string name="meal_2">Essen 2</string> <string name="meal_2">Essen 2</string>
<string name="meal_1_tomorrow">Essen 1, Morgen</string> <string name="today_date">Heute, %1$s</string>
<string name="meal_2_tomorrow">Essen 1, Morgen</string> <string name="tomorrow_date">Morgen, %1$s</string>
<string name="no_meal_today">heute keine Essensausgabe</string> <string name="mensa_closed">keine Essensausgabe</string>
<string name="no_meal_tomorrow">morgen keine Essensausgabe</string>
<string name="no_more_food">Diese Woche keine weitere Essensausgabe</string> <string name="no_more_food">Diese Woche keine weitere Essensausgabe</string>
<string name="no_lesson_today">heute keine Vorlesung!</string> <string name="no_lesson_today">heute keine Vorlesung!</string>
<string name="error">Fehler</string> <string name="error">Fehler</string>

View File

@ -14,10 +14,9 @@
<string name="meal_1">Meal 1</string> <string name="meal_1">Meal 1</string>
<string name="meal_2">Meal 2</string> <string name="meal_2">Meal 2</string>
<string name="meal_1_tomorrow">Meal 1, tomorrow</string> <string name="today_date">Today, %1$s</string>
<string name="meal_2_tomorrow">Meal 2, tomorrow</string> <string name="tomorrow_date">Tomorrow, %1$s</string>
<string name="no_meal_today">Mensa closed today</string> <string name="mensa_closed">the Mensa is closed</string>
<string name="no_meal_tomorrow">Mensa closed tomorrow</string>
<string name="no_more_food">No more Food this week</string> <string name="no_more_food">No more Food this week</string>
<string name="no_lesson_today">"No lecture today!"</string> <string name="no_lesson_today">"No lecture today!"</string>