don't use the faBtn in MensaFragment, use it in TimetableFragment

This commit is contained in:
Jannik 2019-06-08 23:14:55 +02:00
parent 4838c9406c
commit 01db6bb451
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
5 changed files with 52 additions and 62 deletions

View File

@ -22,15 +22,11 @@
package org.mosad.seil0.projectlaogai.fragments
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
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_mensa.*
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
@ -47,21 +43,16 @@ import org.mosad.seil0.projectlaogai.uicomponents.MealLinearLayout
/**
* The mensa controller class
* contains all needed parts to display and the mensa detail screen
* TODO investigate reading the mensa card value via nfc in a background task, show value if card detected
*/
class MensaFragment : Fragment() {
private lateinit var btnCardValue: FloatingActionButton
private lateinit var scrollViewMensa: ScrollView
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view: View = inflater.inflate(R.layout.fragment_mensa, container, false)
btnCardValue = view.findViewById(R.id.btnCardValue)
scrollViewMensa = view.findViewById(R.id.scrollView_Mensa)
// init actions
initActions()
refreshAction()
// add the current week (week starts on sunday)
val dayCurrent = if(NotRetardedCalendar().getDayOfWeekIndex() == 6) 0 else NotRetardedCalendar().getDayOfWeekIndex()
@ -75,32 +66,6 @@ class MensaFragment : Fragment() {
return view
}
private fun initActions() {
refreshAction() // must be async
btnCardValue.setOnClickListener {
MaterialDialog(context!!)
.title(text = "Mensa-Karte")
.message(text = "das aktuelle Guthaben beträgt\n\n13,70€")
.show()
}
// TODO only works with android m(23) or higher
// hide the btnCardValue if the user is scrolling down
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
scrollViewMensa.setOnScrollChangeListener(object: View.OnScrollChangeListener {
override fun onScrollChange(v: View?, scrollX: Int, scrollY: Int, oldScrollX: Int, oldScrollY: Int) {
if (scrollY > oldScrollY) {
btnCardValue.hide()
} else {
btnCardValue.show()
}
}
})
}
}
/**
* add all menus from dayStart to Friday for a given week
* @param menusWeek menu of type MensaWeek you want to add

View File

@ -22,12 +22,15 @@
package org.mosad.seil0.projectlaogai.fragments
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
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 org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
@ -50,13 +53,17 @@ import java.util.*
class TimeTableFragment : Fragment() {
private val formatter = SimpleDateFormat("E dd.MM", Locale.getDefault())
private lateinit var scrollViewTimetable: ScrollView
private lateinit var faBtnAddLesson: FloatingActionButton
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view: View = inflater.inflate(R.layout.fragment_timetable, container, false)
scrollViewTimetable = view.findViewById(R.id.scrollView_Timetable)
faBtnAddLesson = view.findViewById(R.id.faBtnAddLesson)
// init actions
refreshAction()
initActions()
if (timetables[0].days.isNotEmpty() && timetables[1].days.isNotEmpty()) {
addInitWeeks()
@ -70,6 +77,38 @@ class TimeTableFragment : Fragment() {
return view
}
/**
* initialize the actions
*/
private fun initActions() = doAsync {
uiThread {
refreshLayout_Timetable.setOnRefreshListener {
updateTimetableScreen()
}
faBtnAddLesson.setOnClickListener {
MaterialDialog(context!!)
.title(text = "Vorlesung hinzufügen")
.message(text = "wähle einen Studiengang aus:\n\nWähle eine Vorlesung aus: \n\n Diese Funktion ist noch nicht verfügbar")
.show()
}
// TODO only works with android m(23) or higher
// hide the btnCardValue if the user is scrolling down
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
scrollViewTimetable.setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
if (scrollY > oldScrollY) {
faBtnAddLesson.hide()
} else {
faBtnAddLesson.show()
}
}
}
}
}
/**
* add the current and next weeks lessons
*/
@ -124,19 +163,6 @@ class TimeTableFragment : Fragment() {
}
}
/**
* initialize the refresh action
*/
private fun refreshAction() = doAsync {
uiThread {
// set the refresh listener
refreshLayout_Timetable.setOnRefreshListener {
updateTimetableScreen()
}
}
}
private fun updateTimetableScreen() = doAsync {
// update the cache
TCoRAPIController.getTimetable(cCourse.courseName, 0, context!!).get() // blocking since we want the new data

View File

@ -23,13 +23,5 @@
</ScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:src="@drawable/ic_local_dining_black_24dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true" android:id="@+id/btnCardValue" android:visibility="visible"
android:layout_gravity="bottom|center|end" android:elevation="7dp" android:focusable="true"
android:layout_marginEnd="7dp" android:layout_marginBottom="7dp"/>
</FrameLayout>

View File

@ -1,6 +1,6 @@
<?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.TimeTableFragment">
@ -12,7 +12,7 @@
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent" android:id="@+id/scrollView_Timetable">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
@ -22,4 +22,11 @@
android:id="@+id/linLayout_Timetable"/>
</ScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:src="@drawable/icon_custom_black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true" android:id="@+id/faBtnAddLesson" android:elevation="7dp"
android:visibility="visible" android:layout_gravity="bottom|center|end" android:layout_marginEnd="7dp"
android:layout_marginBottom="11dp" android:focusable="true"/>
</FrameLayout>

View File

@ -1,4 +1,4 @@
ProjectLaogai ist eine App um den Vorlesungsplan und den Mensa Speiseplan der Hochschule Offenburg anzuzeigen.
ProjectLaogai ist eine App um den Vorlesungsplan und den Mensa-Speiseplan der Hochschule Offenburg anzuzeigen.
Features:
* schaue was es diese und nächste Woche in der Mensa zu Essen gibt