/** * ProjectLaogai * * Copyright 2018 * * 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 android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.LinearLayout import androidx.fragment.app.Fragment import kotlinx.android.synthetic.main.fragment_home.* import org.jetbrains.anko.doAsync import org.jetbrains.anko.uiThread import org.mosad.seil0.projectlaogai.MainActivity import org.mosad.seil0.projectlaogai.R import org.mosad.seil0.projectlaogai.hsoparser.DataTypes 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() { private lateinit var linLayoutTimeTable: LinearLayout private var mainActivity = MainActivity() 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 = MensaParser().getMensaMenuDay(mainActivity.getWeekMenu(), Calendar.getInstance().get(Calendar.DAY_OF_WEEK)) uiThread { if (dayMenus.size >= 2) { for(part in dayMenus[0].parts) { txtViewMenu1.append(part) } for(part in dayMenus[1].parts) { txtViewMenu2.append(part) } } else { txtViewMenu1.text = resources.getString(R.string.no_meal_today) txtViewMenu2.text = resources.getString(R.string.no_meal_today) } } } } private fun addCurrentTimeTable() { val timeTableDay = mainActivity.getCurrentTimeTableWeek()[Calendar.getInstance().get(Calendar.DAY_OF_WEEK) -2] for (i in 0..5) { val lessonCardView = LessonCardView(context!!, null) lessonCardView.getTxtViewLesson().text = resources.getString(R.string.string_new_line, timeTableDay[i].lessonSubject) 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) } // add a card if there is no lesson today if (linLayoutTimeTable.childCount == 0) { // TODO we could display the next day with a lecture val noLessonCardView = LessonCardView(context!!, null) noLessonCardView.getTxtViewLesson().text = resources.getString(R.string.no_lesson_today) linLayoutTimeTable.addView(noLessonCardView) } } fun setMainActivity(mainActivity: MainActivity) { this.mainActivity = mainActivity } }