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

111 lines
3.7 KiB
Kotlin

/**
* ProjectLaogai
*
* Copyright 2018 <seil0@mosad.xyz>
*
* 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.
*
*/
package org.mosad.seil0.projectlaogai.fragments
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import kotlinx.android.synthetic.main.fragment_home.*
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
import org.mosad.seil0.projectlaogai.R
import org.mosad.seil0.projectlaogai.hsoparser.DataTypes
import org.mosad.seil0.projectlaogai.hsoparser.Lesson
import org.mosad.seil0.projectlaogai.hsoparser.Meal
import org.mosad.seil0.projectlaogai.hsoparser.MensaParser
import org.mosad.seil0.projectlaogai.uicomponents.LessonCardView
import java.util.*
/**
* The "home" controller class
* contains all needed parts to display the apps home screen
*/
class HomeFragment : Fragment() {
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")
private lateinit var linLayoutTimeTable: LinearLayout
private lateinit var currentMenus: ArrayList<Meal>
private lateinit var timeTableWeek: Array<Array<Lesson>>
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view: View = inflater.inflate(R.layout.fragment_home, container, false)
// init UI elements
linLayoutTimeTable = view.findViewById(R.id.linLayoutTimeTable)
//setText()
addCurrentMensaMenu()
addCurrentTimeTable()
// Inflate the layout for this fragment
return view
}
private fun addCurrentMensaMenu() {
doAsync {
val dayMenus: ArrayList<Meal> = MensaParser().getMensaMenuDay(currentMenus, Calendar.getInstance().get(Calendar.DAY_OF_WEEK))
uiThread {
for(part in dayMenus[0].parts) {
txtViewMenu1.append(part)
}
for(part in dayMenus[1].parts) {
txtViewMenu2.append(part)
}
}
}
}
private fun addCurrentTimeTable() {
val timeTableDay = timeTableWeek[Calendar.getInstance().get(Calendar.DAY_OF_WEEK) -2]
for (i in 0..5) {
val lessonCardView = LessonCardView(context!!, null)
lessonCardView.getTxtViewLesson().text = timeTableDay[i].lessonSubject + "\n"
lessonCardView.getTxtViewLesson().append(timeTableDay[i].lessonTeacher + "\n")
lessonCardView.getTxtViewLesson().append(timeTableDay[i].lessonRoom)
lessonCardView.getTxtViewTime().text = DataTypes().getTime()[i]
if(lessonCardView.getTxtViewLesson().text.length > 2)
linLayoutTimeTable.addView(lessonCardView)
}
}
fun setCurrentMenu(weekMenus: ArrayList<Meal>){
this.currentMenus = weekMenus
}
fun setCurrentTimeTableWeek(timeTableWeek: Array<Array<Lesson>>) {
this.timeTableWeek = timeTableWeek
}
}