hide the mensa card value button

This commit is contained in:
Jannik 2019-06-03 10:59:32 +02:00
parent 9c1f95ca25
commit 5e766ec126
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
4 changed files with 31 additions and 36 deletions

View File

@ -132,22 +132,13 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
override fun onNavigationItemSelected(item: MenuItem): Boolean { override fun onNavigationItemSelected(item: MenuItem): Boolean {
// Handle navigation view item clicks here. // Handle navigation view item clicks here.
when (item.itemId) { activeFragment = when(item.itemId) {
R.id.nav_home -> { R.id.nav_home -> HomeFragment()
activeFragment = HomeFragment() R.id.nav_mensa -> MensaFragment()
} R.id.nav_timetable -> TimeTableFragment()
R.id.nav_mensa -> { R.id.nav_moodle -> MoodleFragment()
activeFragment = MensaFragment() R.id.nav_settings -> SettingsFragment()
} else -> HomeFragment()
R.id.nav_timetable -> {
activeFragment = TimeTableFragment()
}
R.id.nav_moodle -> {
activeFragment = MoodleFragment()
}
R.id.nav_settings -> {
activeFragment = SettingsFragment()
}
} }
val fragmentTransaction: FragmentTransaction = supportFragmentManager.beginTransaction() val fragmentTransaction: FragmentTransaction = supportFragmentManager.beginTransaction()
@ -172,13 +163,12 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
val cal = Calendar.getInstance() val cal = Calendar.getInstance()
// TODO this will backfire if someone has to update before the server finished updating the timetable at 0001/0101
// timetable sunday workaround // timetable sunday workaround
cal.time = Date(timetableCacheTime * 1000) cal.time = Date(timetableCacheTime * 1000)
val timetableCacheDay = cal.get(Calendar.DAY_OF_WEEK)
// TODO this will backfire if someone has to update before the server finished updating the timetable at 0001/0101
// update blocking if a) it`s monday and the last cache was not on a monday or b) the cache is older than 6 days // update blocking if a) it`s monday and the last cache was not on a monday or b) the cache is older than 6 days
if((currentDay == Calendar.MONDAY && timetableCacheDay != Calendar.MONDAY) || (System.currentTimeMillis() / 1000) - timetableCacheTime > 518400) { if((currentDay == Calendar.MONDAY && cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) || currentTime - timetableCacheTime > 518400) {
println("updating timetable after sunday!") println("updating timetable after sunday!")
val jobA = TCoRAPIController.getTimetable(cCourse.courseName, 0, this) val jobA = TCoRAPIController.getTimetable(cCourse.courseName, 0, this)
val jobB = TCoRAPIController.getTimetable(cCourse.courseName, 1, this) val jobB = TCoRAPIController.getTimetable(cCourse.courseName, 1, this)
@ -188,28 +178,16 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
} }
// //mensa sunday workaround
// cal.time = Date(System.currentTimeMillis()) // reset to current time
//
// // update blocking if it's sunday after 1500
// if(currentDay == Calendar.SUNDAY && cal.get(Calendar.HOUR_OF_DAY) >= 15) {
// TCoRAPIController.getMensa(this).get()
// }
// TODO test!!
// new sunday bug fix // new sunday bug fix
CacheController.readMensa(this) CacheController.readMensa(this)
val mensaUpdateTime = Date(mensaMenu.meta.updateTime * 1000) cal.time = Date(mensaMenu.meta.updateTime * 1000)
cal.time = mensaUpdateTime
// if it's monday and the last cache update was on sunday or is older than 24hr, update blocking // if it's monday and the last cache update was on sunday or is older than 24hr, update blocking
if ((currentDay == Calendar.MONDAY && cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) || currentTime - mensaMenu.meta.updateTime > 86400) { if ((currentDay == Calendar.MONDAY && cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) || currentTime - mensaMenu.meta.updateTime > 86400) {
println("update blocking") println("update mensa blocking")
TCoRAPIController.getMensa(this).get() TCoRAPIController.getMensa(this).get()
} }
// get the cached files // get the cached files
val cache = CacheController(this) val cache = CacheController(this)
cache.readStartCache(cCourse.courseName) cache.readStartCache(cCourse.courseName)

View File

@ -22,10 +22,12 @@
package org.mosad.seil0.projectlaogai.fragments package org.mosad.seil0.projectlaogai.fragments
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ScrollView
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.google.android.material.floatingactionbutton.FloatingActionButton import com.google.android.material.floatingactionbutton.FloatingActionButton
@ -49,12 +51,14 @@ import org.mosad.seil0.projectlaogai.uicomponents.MealLinearLayout
class MensaFragment : Fragment() { class MensaFragment : Fragment() {
private lateinit var btnCardValue: FloatingActionButton private lateinit var btnCardValue: FloatingActionButton
private lateinit var scrollViewMensa: ScrollView
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view: View = inflater.inflate(R.layout.fragment_mensa, container, false) val view: View = inflater.inflate(R.layout.fragment_mensa, container, false)
btnCardValue = view.findViewById(R.id.btnCardValue) btnCardValue = view.findViewById(R.id.btnCardValue)
scrollViewMensa = view.findViewById(R.id.scrollView_Mensa)
// init actions // init actions
initActions() initActions()
@ -67,7 +71,6 @@ class MensaFragment : Fragment() {
addWeek(mensaMenu.nextWeek, 0) addWeek(mensaMenu.nextWeek, 0)
// TODO should we show a info if there is no more food this & next week? // TODO should we show a info if there is no more food this & next week?
// TODO hide the floating button if we are not on the top end of the scroll pane
return view return view
} }
@ -82,6 +85,19 @@ class MensaFragment : Fragment() {
.show() .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()
}
}
})
}
} }

View File

@ -49,7 +49,7 @@ import java.util.*
*/ */
class TimeTableFragment : Fragment() { class TimeTableFragment : Fragment() {
private val formatter = SimpleDateFormat("E dd.MM", Locale.getDefault()) // TODO change to android call when min api is 24 private val formatter = SimpleDateFormat("E dd.MM", Locale.getDefault())
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {

View File

@ -12,7 +12,7 @@
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent" android:id="@+id/scrollView_Mensa">
<LinearLayout <LinearLayout
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -22,6 +22,7 @@
android:id="@+id/linLayout_Mensa"/> android:id="@+id/linLayout_Mensa"/>
</ScrollView> </ScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout> </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton <com.google.android.material.floatingactionbutton.FloatingActionButton
android:src="@drawable/ic_local_dining_black_24dp" android:src="@drawable/ic_local_dining_black_24dp"
android:layout_width="wrap_content" android:layout_width="wrap_content"