2018-10-25 16:44:36 +02:00
/ * *
* ProjectLaogai
*
2020-01-15 15:00:05 +01:00
* Copyright 2019 - 2020 < seil0 @mosad . xyz >
2018-10-25 16:44:36 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston ,
* MA 02110 - 1301 , USA .
*
* /
2018-10-29 13:04:20 +01:00
package org.mosad.seil0.projectlaogai.uicomponents
2018-10-24 18:22:05 +02:00
import android.content.Context
2019-03-19 19:51:58 +01:00
import android.graphics.Color
2018-10-29 13:04:20 +01:00
import android.widget.LinearLayout
2019-03-20 21:33:55 +01:00
import androidx.cardview.widget.CardView
import kotlinx.android.synthetic.main.cardview_day.view.*
2018-10-27 14:11:47 +02:00
import org.mosad.seil0.projectlaogai.R
2019-09-22 20:51:36 +02:00
import org.mosad.seil0.projectlaogai.hsoparser.DataTypes
import org.mosad.seil0.projectlaogai.hsoparser.TimetableDay
import java.text.SimpleDateFormat
import java.util.*
2018-10-25 16:44:36 +02:00
2019-03-20 21:33:55 +01:00
class DayCardView ( context : Context ) : CardView ( context ) {
2018-10-24 18:22:05 +02:00
2019-09-22 20:51:36 +02:00
private val formatter = SimpleDateFormat ( " E dd.MM " , Locale . getDefault ( ) )
2018-10-24 18:22:05 +02:00
init {
2019-03-20 21:33:55 +01:00
inflate ( context , R . layout . cardview _day , this )
2018-10-25 16:44:36 +02:00
// workaround to prevent a white border
2019-03-19 19:51:58 +01:00
this . setBackgroundColor ( Color . TRANSPARENT )
2018-10-25 16:44:36 +02:00
}
2019-03-20 21:33:55 +01:00
fun getLinLayoutDay ( ) : LinearLayout {
return linLayout _Day
2018-10-25 16:44:36 +02:00
}
2018-10-24 18:22:05 +02:00
2018-10-29 13:04:20 +01:00
fun setDayHeading ( heading : String ) {
2019-03-20 21:33:55 +01:00
txtView _DayHeading . text = heading
2018-10-24 18:22:05 +02:00
}
2018-10-29 13:04:20 +01:00
2019-09-22 20:51:36 +02:00
/ * *
* add the lessons of one day to the dayCardView
* @param timetable a timetable containing the day ( and it ' s lessons ) to be added
* /
fun addTimetableDay ( timetable : TimetableDay , daysToAdd : Int ) {
var lastLesson = LessonLinearLayout ( context )
// set the heading
val cal = Calendar . getInstance ( )
cal . add ( Calendar . DATE , daysToAdd )
txtView _DayHeading . text = formatter . format ( cal . time )
// for every timeslot of that timetable
for ( ( tsIndex , timeslot ) in timetable . timeslots . withIndex ( ) ) {
for ( lesson in timeslot ) {
if ( lesson . lessonSubject . isNotEmpty ( ) ) {
val lessonLayout = LessonLinearLayout ( context )
lessonLayout . setLesson ( lesson , DataTypes ( ) . getTime ( ) [ tsIndex ] )
linLayout _Day . addView ( lessonLayout )
if ( lesson != timeslot . last ( ) ) {
lessonLayout . disableDivider ( )
}
lastLesson = lessonLayout
}
}
}
lastLesson . disableDivider ( ) // disable the divider for the last lesson of the day
}
2018-10-24 18:22:05 +02:00
}