init fragment in onViewCreated()
continuous-integration/drone/push Build is passing Details

* closes #42
* show a info text if no mensa menus where found
* the refresh spinner respects the selecte theme now
This commit is contained in:
Jannik 2020-08-17 22:30:12 +02:00
parent 953b4825a9
commit 99ba87c3f6
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
16 changed files with 183 additions and 78 deletions

View File

@ -31,6 +31,7 @@ import android.nfc.NfcManager
import android.nfc.tech.NfcA
import android.os.Bundle
import android.util.Log
import android.util.TypedValue
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.ActionBarDrawerToggle
@ -203,6 +204,13 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
apply()
}
// set theme color values
val out = TypedValue()
this.theme.resolveAttribute(R.attr.themePrimary, out, true)
Preferences.themePrimary = out.data
this.theme.resolveAttribute(R.attr.themeSecondary, out, true)
Preferences.themeSecondary = out.data
}
private fun initForegroundDispatch() {

View File

@ -45,6 +45,10 @@ object Preferences {
var cShowBuffet = true
var oGiants = false
// TODO move!
var themePrimary = 0
var themeSecondary = 0
// the save function
fun save(context: Context) {
val sharedPref = context.getSharedPreferences(

View File

@ -36,6 +36,7 @@ import kotlinx.coroutines.*
import org.mosad.seil0.projectlaogai.R
import org.mosad.seil0.projectlaogai.controller.QISPOSParser
import org.mosad.seil0.projectlaogai.controller.preferences.EncryptedPreferences
import org.mosad.seil0.projectlaogai.controller.preferences.Preferences
import org.mosad.seil0.projectlaogai.uicomponents.DayCardView
import org.mosad.seil0.projectlaogai.uicomponents.GradeLinearLayout
import org.mosad.seil0.projectlaogai.uicomponents.dialogs.LoginDialog
@ -51,19 +52,18 @@ class GradesFragment : Fragment() {
private lateinit var parser: QISPOSParser
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view: View = inflater.inflate(R.layout.fragment_grades, container, false)
refreshLayoutGrades = view.findViewById(R.id.refreshLayout_Grades)
refreshLayoutGrades.isEnabled = false // disable swipe
parser = QISPOSParser(context!!)// init the parser
return view
return inflater.inflate(R.layout.fragment_grades, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
refreshLayoutGrades = view.findViewById(R.id.refreshLayout_Grades)
refreshLayoutGrades.isEnabled = false // disable swipe
refreshLayoutGrades.setProgressBackgroundColorSchemeColor(Preferences.themeSecondary)
parser = QISPOSParser(context!!)// init the parser
if (checkCredentials() && checkQisposStatus()) {
GlobalScope.launch(Dispatchers.Default) {
addGrades()
@ -105,18 +105,21 @@ class GradesFragment : Fragment() {
private fun checkQisposStatus(): Boolean {
val statusCode = parser.checkQISPOSStatus()
val infoText = resources.getString(when(statusCode) {
503 -> R.string.qispos_unavailable
else -> R.string.qispos_generic_error
})
// show error if the status code is not 200
if (statusCode != 200) {
val infoText = resources.getString(when(statusCode) {
503 -> R.string.qispos_unavailable
else -> R.string.qispos_generic_error
})
val img = ResourcesCompat.getDrawable(resources, R.drawable.ic_error_outline_black_24dp, null)?.apply {
bounds = Rect(0, 0, 75, 75)
}
val img = ResourcesCompat.getDrawable(resources, R.drawable.ic_error_outline_black_24dp, null)?.apply {
bounds = Rect(0, 0, 75, 75)
}
txtView_Loading?.apply {
text = infoText
setCompoundDrawables(null, null, null, img)
txtView_Loading?.apply {
text = infoText
setCompoundDrawables(null, null, null, img)
}
}
return statusCode == 200

View File

@ -53,13 +53,14 @@ class HomeFragment : Fragment() {
private val formatter = SimpleDateFormat("E dd.MM", Locale.getDefault())
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view: View = inflater.inflate(R.layout.fragment_home, container, false)
return inflater.inflate(R.layout.fragment_home, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
addMensaMenu()
addTimeTable()
// Inflate the layout for this fragment
return view
}
/**

View File

@ -23,6 +23,7 @@
package org.mosad.seil0.projectlaogai.fragments
import android.os.Bundle
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -32,13 +33,16 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.mosad.seil0.projectlaogai.MainActivity
import org.mosad.seil0.projectlaogai.R
import org.mosad.seil0.projectlaogai.controller.cache.CacheController
import org.mosad.seil0.projectlaogai.controller.cache.CacheController.Companion.mensaMenu
import org.mosad.seil0.projectlaogai.controller.preferences.Preferences
import org.mosad.seil0.projectlaogai.controller.preferences.Preferences.cShowBuffet
import org.mosad.seil0.projectlaogai.util.MensaWeek
import org.mosad.seil0.projectlaogai.uicomponents.DayCardView
import org.mosad.seil0.projectlaogai.uicomponents.MealLinearLayout
import org.mosad.seil0.projectlaogai.uicomponents.TextViewInfo
import org.mosad.seil0.projectlaogai.util.MensaWeek
import org.mosad.seil0.projectlaogai.util.NotRetardedCalendar
/**
@ -48,11 +52,15 @@ import org.mosad.seil0.projectlaogai.util.NotRetardedCalendar
class MensaFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_mensa, container, false)
}
val view: View = inflater.inflate(R.layout.fragment_mensa, container, false)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// init actions
refreshAction()
refreshLayout_Mensa.setProgressBackgroundColorSchemeColor(Preferences.themeSecondary)
refreshAction() // init actions
GlobalScope.launch(Dispatchers.Default) {
val dayCurrent = if(NotRetardedCalendar.getDayOfWeekIndex() == 6) 0 else NotRetardedCalendar.getDayOfWeekIndex()
@ -62,10 +70,13 @@ class MensaFragment : Fragment() {
addWeek(mensaMenu.nextWeek, 0)
}
// TODO should we show a info if there is no more food this & next week?
return view
// show a info if there are no more menus
if (linLayout_Mensa.childCount == 0) {
val txtViewInfo = TextViewInfo(context!!).set {
txt = resources.getString(R.string.no_more_meals)
}
linLayout_Mensa.addView(txtViewInfo)
}
}
/**
@ -76,7 +87,6 @@ class MensaFragment : Fragment() {
private fun addWeek(menusWeek: MensaWeek, dayStart: Int) = GlobalScope.launch(Dispatchers.Default) {
withContext(Dispatchers.Main) {
// only add the days dayStart to Fri since the mensa is closed on Sat/Sun
for (dayIndex in dayStart..4) {
var helpMeal = MealLinearLayout(context)
@ -100,7 +110,6 @@ class MensaFragment : Fragment() {
if(dayCardView.getLinLayoutDay().childCount > 2)
linLayout_Mensa.addView(dayCardView)
}
}
}
@ -136,6 +145,14 @@ class MensaFragment : Fragment() {
addWeek(mensaMenu.nextWeek, 0)
refreshLayout_Mensa.isRefreshing = false
// show a info if there are no more menus
if (linLayout_Mensa.childCount == 0) {
val txtViewInfo = TextViewInfo(context!!).set {
txt = resources.getString(R.string.no_more_meals)
}
linLayout_Mensa.addView(txtViewInfo)
}
}
}

View File

@ -42,8 +42,11 @@ class MoodleFragment : Fragment() {
private lateinit var webSettings: WebSettings
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_moodle, container, false)
}
val view: View = inflater.inflate(R.layout.fragment_moodle, container, false)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
webView = view.findViewById(R.id.webView)
webView.loadUrl("https://elearning.hs-offenburg.de/moodle/")
@ -52,7 +55,5 @@ class MoodleFragment : Fragment() {
//webSettings.setJavaScriptEnabled(true) // Enable Javascript
webView.webViewClient = WebViewClient() // Force links and redirects to open in the WebView instead of in a browser
return view
}
}

View File

@ -80,8 +80,14 @@ class SettingsFragment : Fragment() {
private var selectedTheme = DataTypes.Theme.Light
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_settings, container, false)
}
val view: View = inflater.inflate(R.layout.fragment_settings, container, false)
/**
* initialize the settings gui
*/
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
linLayoutUser = view.findViewById(R.id.linLayout_User)
linLayoutCourse = view.findViewById(R.id.linLayout_Course)
@ -92,19 +98,13 @@ class SettingsFragment : Fragment() {
linLayoutPrimaryColor = view.findViewById(R.id.linLayout_PrimaryColor)
linLayoutAccentColor = view.findViewById(R.id.linLayout_AccentColor)
switchBuffet = view.findViewById(R.id.switch_buffet)
// if we call txtView_Course via KAE view binding it'll result in a NPE in the onDismissed call
txtViewCourse = view.findViewById(R.id.txtView_Course)
initActions()
// Inflate the layout for this fragment
return view
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// initialize the settings gui
txtView_User.text = EncryptedPreferences.email.ifEmpty { resources.getString(R.string.sample_user) }
txtView_Course.text = cCourse.courseName
txtView_AboutDesc.text = resources.getString(R.string.about_version, BuildConfig.VERSION_NAME, getString(R.string.build_time))

View File

@ -28,15 +28,16 @@ import android.view.View
import android.view.ViewGroup
import android.widget.ScrollView
import androidx.fragment.app.Fragment
import com.afollestad.materialdialogs.MaterialDialog
import com.google.android.material.floatingactionbutton.FloatingActionButton
import kotlinx.android.synthetic.main.fragment_timetable.*
import kotlinx.coroutines.*
import org.mosad.seil0.projectlaogai.R
import org.mosad.seil0.projectlaogai.controller.cache.TimetableController
import org.mosad.seil0.projectlaogai.controller.cache.TimetableController.Companion.timetable
import org.mosad.seil0.projectlaogai.controller.preferences.Preferences
import org.mosad.seil0.projectlaogai.uicomponents.dialogs.AddSubjectDialog
import org.mosad.seil0.projectlaogai.uicomponents.DayCardView
import org.mosad.seil0.projectlaogai.uicomponents.TextViewInfo
import org.mosad.seil0.projectlaogai.util.NotRetardedCalendar
/**
@ -49,26 +50,26 @@ class TimeTableFragment : Fragment() {
private lateinit var faBtnAddSubject: FloatingActionButton
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_timetable, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val view: View = inflater.inflate(R.layout.fragment_timetable, container, false)
scrollViewTimetable = view.findViewById(R.id.scrollView_Timetable)
faBtnAddSubject = view.findViewById(R.id.faBtnAddSubject)
refreshLayout_Timetable.setProgressBackgroundColorSchemeColor(Preferences.themeSecondary)
// init actions
initActions()
initActions() // init actions
if (timetable.size > 1 && timetable[0].days.isNotEmpty() && timetable[1].days.isNotEmpty()) {
initTimetable()
//println(timetable)
} else {
MaterialDialog(context!!)
.title(R.string.error)
.message(R.string.timetable_error)
.show()
val txtViewInfo = TextViewInfo(context!!).set {
txt = resources.getString(R.string.timetable_generic_error)
}.showImage()
linLayout_Timetable.addView(txtViewInfo)
}
return view
}
/**

View File

@ -65,9 +65,8 @@ class DayCardView(context: Context) : CardView(context) {
txtView_DayHeading.text = formatter.format(cal.time)
// for every timeslot of that timetable
for ((tsIndex, timeslot) in timetable.timeslots.withIndex()) {
for (lesson in timeslot) {
timetable.timeslots.forEachIndexed { tsIndex, timeslot ->
timeslot.forEach { lesson ->
if (lesson.lessonSubject.isNotEmpty()) {
val lessonLayout = LessonLinearLayout(context)
@ -81,6 +80,7 @@ class DayCardView(context: Context) : CardView(context) {
lastLesson = lessonLayout
}
}
}
lastLesson.disableDivider() // disable the divider for the last lesson of the day

View File

@ -25,7 +25,6 @@ package org.mosad.seil0.projectlaogai.uicomponents
import android.content.Context
import android.view.View
import android.widget.LinearLayout
import androidx.cardview.widget.CardView
import kotlinx.android.synthetic.main.linearlayout_grade.view.*
import org.mosad.seil0.projectlaogai.R
@ -37,7 +36,7 @@ class GradeLinearLayout(context: Context?): LinearLayout(context) {
var subGrade = ""
init {
CardView.inflate(context, R.layout.linearlayout_grade, this)
inflate(context, R.layout.linearlayout_grade, this)
}
fun set(func: GradeLinearLayout.() -> Unit): GradeLinearLayout = apply {

View File

@ -25,7 +25,6 @@ package org.mosad.seil0.projectlaogai.uicomponents
import android.content.Context
import android.view.View
import android.widget.LinearLayout
import androidx.cardview.widget.CardView
import kotlinx.android.synthetic.main.linearlayout_lesson.view.*
import org.mosad.seil0.projectlaogai.R
import org.mosad.seil0.projectlaogai.util.Lesson
@ -33,7 +32,7 @@ import org.mosad.seil0.projectlaogai.util.Lesson
class LessonLinearLayout(context: Context?) : LinearLayout(context) {
init {
CardView.inflate(context, R.layout.linearlayout_lesson, this)
inflate(context, R.layout.linearlayout_lesson, this)
}
fun setLesson(lesson: Lesson, time: String) {

View File

@ -25,7 +25,6 @@ package org.mosad.seil0.projectlaogai.uicomponents
import android.content.Context
import android.view.View
import android.widget.LinearLayout
import androidx.cardview.widget.CardView
import kotlinx.android.synthetic.main.linearlayout_meal.view.*
import org.mosad.seil0.projectlaogai.R
import org.mosad.seil0.projectlaogai.util.Meal
@ -33,7 +32,7 @@ import org.mosad.seil0.projectlaogai.util.Meal
class MealLinearLayout(context: Context?): LinearLayout(context) {
init {
CardView.inflate(context, R.layout.linearlayout_meal, this)
inflate(context, R.layout.linearlayout_meal, this)
}
fun setMeal(meal: Meal) {

View File

@ -0,0 +1,63 @@
/**
* ProjectLaogai
*
* Copyright 2019-2020 <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.uicomponents
import android.content.Context
import android.graphics.Rect
import android.view.View
import android.widget.LinearLayout
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.res.ResourcesCompat
import org.mosad.seil0.projectlaogai.R
class TextViewInfo(context: Context?): AppCompatTextView(context!!) {
var txt = ""
var txtSize = 15F
var txtAlignment = View.TEXT_ALIGNMENT_CENTER
var drawable = R.drawable.ic_error_outline_black_24dp
var params = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)
init {
params.setMargins(0,200,0,0)
}
fun set(func: TextViewInfo.() -> Unit): TextViewInfo = apply {
func()
text = txt
layoutParams = params
textSize = txtSize
textAlignment = txtAlignment
}
fun showImage(): TextViewInfo = apply {
val img = ResourcesCompat.getDrawable(resources, drawable, context.theme)?.apply {
bounds = Rect(0, 0, 75, 75)
}
setCompoundDrawables(null, null, null, img)
}
}

View File

@ -1,26 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.MensaFragment"
android:background="?themePrimary">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/refreshLayout_Mensa">
android:id="@+id/refreshLayout_Mensa"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView_Mensa">
android:id="@+id/scrollView_Mensa"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="false"
android:id="@+id/linLayout_Mensa"/>
android:id="@+id/linLayout_Mensa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="false"
android:orientation="vertical" />
</ScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

View File

@ -33,11 +33,15 @@
<string name="no_more_food">Diese Woche keine weitere Essensausgabe</string>
<string name="no_lesson_today">heute keine Vorlesung!</string>
<!-- fragment_mensa -->
<string name="no_more_meals">Für diese und nächste Woche ist der Speiseplan leer.</string>
<!-- fragment_timetable -->
<string name="add_lesson">Eine Vorlesung hinzufügen</string>
<string name="add_lesson_desc">Füge eine Vorlesung eines anderen Studiengangs zu deinem Stundenplan hinzu.</string>
<string name="courses">Studiengänge:</string>
<string name="lessons">Vorlesungen:</string>
<string name="timetable_generic_error">Beim laden des Stundenplans ist ein Fehler aufgetreten.\n</string>
<!-- fragment_grades -->
<string name="loading_from_hs">Lade Daten von den Hochschul Servern.\nDas kann eine Weile dauern.</string>
@ -78,7 +82,7 @@
<!-- errors -->
<string name="error">Fehler</string>
<string name="timetable_error">Stundenplan konnte nicht geladen werden!</string>
<string name="timetable_error">Der Stundenplan konnte nicht geladen werden.</string>
<!-- shortcuts -->
<string name="shortcut_mensa_short">Mensa</string>

View File

@ -35,11 +35,15 @@
<string name="no_more_food">No more Food this week</string>
<string name="no_lesson_today">"No lecture today!"</string>
<!-- fragment_mensa -->
<string name="no_more_meals">The menu is empty for this and the next week.</string>
<!-- fragment_timetable -->
<string name="add_lesson">Add a lesson</string>
<string name="add_lesson_desc">Add a lesson from another course to your timetable.</string>
<string name="courses">Courses:</string>
<string name="lessons">Lessons:</string>
<string name="timetable_generic_error">An error occurred while loading the timetable.\n</string>
<!-- fragment_grades -->
<string name="loading_from_hs">Loading data from the university servers.\nThis may take a while.</string>
@ -93,7 +97,7 @@
<!-- errors -->
<string name="error">Error</string>
<string name="timetable_error">Could not load timetable!"</string>
<string name="timetable_error">Could not load the timetable!"</string>
<!-- shortcuts -->
<string name="shortcut_mensa_short">Mensa</string>