minor gui updates

This commit is contained in:
Jannik 2019-03-03 20:46:51 +01:00
parent dbfdaffe99
commit 5a1a07cd42
6 changed files with 94 additions and 53 deletions

View File

@ -37,6 +37,7 @@ import org.mosad.seil0.projectlaogai.PreferencesController.Companion.cWeekMenus
import org.mosad.seil0.projectlaogai.R
import org.mosad.seil0.projectlaogai.hsoparser.*
import org.mosad.seil0.projectlaogai.uicomponents.LessonCardView
import org.mosad.seil0.projectlaogai.uicomponents.LessonTextView
import java.util.*
/**
@ -128,33 +129,42 @@ class HomeFragment : Fragment() {
// for all timeslots of the day
for ((i, timeslot) in timeTableDay.timeslots.withIndex()) {
val lessonCardView = LessonCardView(context!!, null)
lessonCardView.getTxtViewTime().text = DataTypes().getTime()[i]
for (lesson in timeslot) {
val lessonCardView = LessonCardView(context!!, null)
val lessonTxtView = LessonTextView(context!!)
lessonTxtView.setLesson(lesson)
lessonCardView.getTxtViewLesson().text = resources.getString(R.string.string_new_line, lesson.lessonSubject)
lessonCardView.getTxtViewLesson().append(lesson.lessonTeacher + "\n")
lessonCardView.getTxtViewLesson().append(lesson.lessonRoom)
lessonCardView.getTxtViewTime().text = DataTypes().getTime()[i]
if(lessonCardView.getTxtViewLesson().text.length > 2)
linLayoutTimeTable.addView(lessonCardView)
// TODO why does this exist
if (lessonTxtView.text.length > 3)
lessonCardView.getLinLayoutLesson().addView(lessonTxtView)
}
if (lessonCardView.getLinLayoutLesson().childCount > 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 lessonTxtView = LessonTextView(context!!)
lessonTxtView.setText(resources.getString(R.string.no_lesson_today))
val noLessonCardView = LessonCardView(context!!, null)
noLessonCardView.getTxtViewLesson().text = resources.getString(R.string.no_lesson_today)
noLessonCardView.getLinLayoutLesson().addView(lessonTxtView)
linLayoutTimeTable.addView(noLessonCardView)
}
} else {
if (dayIndex == 6) {
// if that's the case it's sunday
val lessonTxtView = LessonTextView(context!!)
lessonTxtView.setText(resources.getString(R.string.no_lesson_today))
val noLessonCardView = LessonCardView(context!!, null)
noLessonCardView.getTxtViewLesson().text = resources.getString(R.string.no_lesson_today)
noLessonCardView.getLinLayoutLesson().addView(lessonTxtView)
linLayoutTimeTable.addView(noLessonCardView)
} else {
MaterialDialog(context!!)

View File

@ -35,7 +35,6 @@ import com.afollestad.materialdialogs.color.colorChooser
import com.afollestad.materialdialogs.customview.customView
import com.afollestad.materialdialogs.list.listItems
import kotlinx.android.synthetic.main.fragment_settings.*
import org.jetbrains.anko.Android
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
import org.mosad.seil0.projectlaogai.PreferencesController

View File

@ -22,7 +22,6 @@
package org.mosad.seil0.projectlaogai.fragments
import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@ -37,6 +36,7 @@ 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.LessonTextView
import org.mosad.seil0.projectlaogai.uicomponents.MensaDayCardView
import java.text.SimpleDateFormat
import java.util.*
@ -83,38 +83,41 @@ class TimeTableFragment : Fragment() {
// for each timeslot of the day
for ((i, timeslot) in cTimeTableCurrentWeek.days[day].timeslots.withIndex()) {
val lessonCardView = LessonCardView(context!!, null)
lessonCardView.getTxtViewTime().text = DataTypes().getTime()[i]
println(timeslot)
//println(timeslot)
for (lesson in timeslot) {
val lessonCardView = LessonCardView(context!!, null)
lessonCardView.setBackgroundColor(Color.TRANSPARENT)
val lessonTxtView = LessonTextView(context!!)
lessonTxtView.setLesson(lesson)
lessonCardView.getTxtViewLesson().text = resources.getString(R.string.string_new_line, lesson.lessonSubject)
lessonCardView.getTxtViewLesson().append(lesson.lessonTeacher + "\n")
lessonCardView.getTxtViewLesson().append(lesson.lessonRoom)
lessonCardView.getTxtViewTime().text = DataTypes().getTime()[i]
// only add the lesson if it contains data
if (lessonCardView.getTxtViewLesson().text.length > 2)
cardViewTimeTableDay.getLinLayoutMensaDay().addView(lessonCardView)
// TODO why does this exist
if (lessonTxtView.text.length > 3)
lessonCardView.getLinLayoutLesson().addView(lessonTxtView)
}
// only add the lesson if it contains data
if (lessonCardView.getLinLayoutLesson().childCount > 1)
cardViewTimeTableDay.getLinLayoutMensaDay().addView(lessonCardView)
}
calendar.add(Calendar.DATE, 1)
// if the day contains no lessons add a text "No lesson today"
if (cardViewTimeTableDay.getLinLayoutMensaDay().childCount <= 1) {
val lessonTxtView = LessonTextView(context!!)
lessonTxtView.setText(resources.getString(R.string.no_lesson_today))
val lessonCardView = LessonCardView(context!!, null)
lessonCardView.setBackgroundColor(Color.TRANSPARENT)
lessonCardView.getTxtViewLesson().text = resources.getString(R.string.no_lesson_today)
lessonCardView.getLinLayoutLesson().addView(lessonTxtView)
cardViewTimeTableDay.getLinLayoutMensaDay().addView(lessonCardView)
}
linLayoutTTFragment.addView(cardViewTimeTableDay)
}
// TODO if there is no lesson at one day , show a no lesson card
// add next weeks days, max number = dayIndex, if timetable was loaded
if (cTimeTableNextWeek.days.isNotEmpty()) {
calendar.add(Calendar.DATE, 1) // before this we are at a sunday (no lecture on sundays!)
@ -126,23 +129,36 @@ class TimeTableFragment : Fragment() {
// for each timeslot of the day
for ((i, timeslot) in cTimeTableNextWeek.days[day].timeslots.withIndex()) {
val lessonCardView = LessonCardView(context!!, null)
lessonCardView.getTxtViewTime().text = DataTypes().getTime()[i]
for (lesson in timeslot) {
val lessonCardView = LessonCardView(context!!, null)
lessonCardView.setBackgroundColor(Color.TRANSPARENT)
val lessonTxtView = LessonTextView(context!!)
lessonTxtView.setLesson(lesson)
lessonCardView.getTxtViewLesson().text = resources.getString(R.string.string_new_line, lesson.lessonSubject)
lessonCardView.getTxtViewLesson().append(lesson.lessonTeacher + "\n")
lessonCardView.getTxtViewLesson().append(lesson.lessonRoom)
lessonCardView.getTxtViewTime().text = DataTypes().getTime()[i]
// only add the lesson if it contains data
if (lessonCardView.getTxtViewLesson().text.length > 2)
cardViewTimeTableDay.getLinLayoutMensaDay().addView(lessonCardView)
if (lessonTxtView.text.length > 3)
lessonCardView.getLinLayoutLesson().addView(lessonTxtView)
}
// only add the lesson if it contains data
if (lessonCardView.getLinLayoutLesson().childCount > 1)
cardViewTimeTableDay.getLinLayoutMensaDay().addView(lessonCardView)
}
calendar.add(Calendar.DATE, 1)
// if the day contains no lessons add a text "No lesson today"
if (cardViewTimeTableDay.getLinLayoutMensaDay().childCount <= 1) {
val lessonTxtView = LessonTextView(context!!)
lessonTxtView.setText(resources.getString(R.string.no_lesson_today))
val lessonCardView = LessonCardView(context!!, null)
lessonCardView.getLinLayoutLesson().addView(lessonTxtView)
cardViewTimeTableDay.getLinLayoutMensaDay().addView(lessonCardView)
}
linLayoutTTFragment.addView(cardViewTimeTableDay)
}
}

View File

@ -25,26 +25,27 @@ package org.mosad.seil0.projectlaogai.uicomponents
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.widget.LinearLayout
import android.widget.TextView
import org.mosad.seil0.projectlaogai.R
class LessonCardView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : androidx.cardview.widget.CardView(context, attrs){
private var txtViewLesson: TextView
private var linLayoutLesson: LinearLayout
private var txtViewTime: TextView
init {
inflate(context, R.layout.lesson_cardview,this)
txtViewLesson = findViewById(R.id.txtView_Lesson)
linLayoutLesson = findViewById(R.id.linLayout_Lesson)
txtViewTime = findViewById(R.id.txtView_Time)
// workaround to prevent a white border
this.setBackgroundColor(Color.TRANSPARENT)
}
fun getTxtViewLesson(): TextView {
return txtViewLesson
fun getLinLayoutLesson(): LinearLayout {
return linLayoutLesson
}
fun getTxtViewTime(): TextView {

View File

@ -0,0 +1,26 @@
package org.mosad.seil0.projectlaogai.uicomponents
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.widget.TextView
import org.mosad.seil0.projectlaogai.hsoparser.Lesson
class LessonTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : TextView(context, attrs) {
init {
this.setTextColor(Color.BLACK)
this.textSize = 16F
this.setPadding(0,6,0,0)
}
fun setLesson(lesson: Lesson) {
this.text = resources.getString(org.mosad.seil0.projectlaogai.R.string.string_new_line, lesson.lessonSubject)
this.append(lesson.lessonTeacher + "\n")
this.append(lesson.lessonRoom)
}
fun setText(text: String) {
this.text = text
}
}

View File

@ -9,20 +9,9 @@
app:cardUseCompatPadding="true" app:cardPreventCornerOverlap="false" app:contentPadding="5dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/txtView_Lesson"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/a_lesson"
android:textColor="@android:color/primary_text_light"
android:textSize="14sp"
android:textStyle="bold"
android:typeface="sans"/>
android:layout_height="match_parent" android:id="@+id/linLayout_Lesson">
<TextView
android:id="@+id/txtView_Time"
android:layout_width="match_parent"