CanteenFragment.kt: replaced buttons for opening hours and canteen switch embedded in the app bar with floating action buttons; implemented a possible fix for the app crashing after refreshing the canteen plan. This may have been caused by accessing the view/context of the fragment to let the user know that the refresh succeeded or encountered an error. Reference will be null by the time the fragment is inactive, causing a NullPointerException

This commit is contained in:
denizk0461
2023-05-04 15:09:10 +02:00
parent 5ca5788899
commit e17a81e604
14 changed files with 165 additions and 142 deletions
+51 -45
View File
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/snackbar_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
@@ -17,48 +18,21 @@
android:orientation="vertical"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<com.google.android.material.button.MaterialButton
android:id="@+id/button_canteen_picker"
style="@style/Widget.Material3.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_gravity="start"
android:layout_marginStart="8dp"
android:fontFamily="@font/lato_bolditalic"/>
<androidx.constraintlayout.widget.ConstraintLayout
<TextView
android:id="@+id/app_title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp">
<TextView
android:id="@+id/app_title_bar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/title_food"
android:textSize="32sp"
android:fontFamily="@font/lato_bolditalic"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/button_info"/>
<com.google.android.material.button.MaterialButton
style="@style/Widget.Material3.Button.TextButton"
android:id="@+id/button_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="0dp"
app:icon="@drawable/info"
app:iconPadding="0dp"
android:layout_gravity="center_vertical|end"
app:iconTint="?attr/colorOnSurfaceVariant"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
android:text="@string/title_food"
android:textSize="28sp"
android:fontFamily="@font/lato_bolditalic"
android:layout_marginTop="16dp"
android:layout_marginHorizontal="16dp"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"/>
<HorizontalScrollView
android:id="@+id/scroll_view_chip"
@@ -222,16 +196,48 @@
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_refresh_offers"
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/refresh"
android:contentDescription="@string/canteen_fab_refresh_content_desc"
android:orientation="vertical"
android:layout_gravity="bottom|end"
android:layout_marginEnd="@dimen/fab_margin"
android:layout_marginBottom="@dimen/fab_margin"
app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior"/>
app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior">
<com.google.android.material.floatingactionbutton.FloatingActionButton
style="?attr/floatingActionButtonSmallStyle"
android:id="@+id/fab_opening_hours"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/clock"
android:contentDescription="@string/canteen_fab_opening_hours_content_desc"
android:layout_gravity="center_horizontal"
android:tooltipText="@string/canteen_fab_opening_hours_content_desc"
tools:ignore="UnusedAttribute"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
style="?attr/floatingActionButtonSmallStyle"
android:id="@+id/fab_switch_canteen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/switch_arrows"
android:contentDescription="@string/canteen_fab_switch_canteen_content_desc"
android:layout_marginBottom="8dp"
android:layout_gravity="center_horizontal"
android:tooltipText="@string/canteen_fab_switch_canteen_content_desc"
tools:ignore="UnusedAttribute"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_refresh_offers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/refresh"
android:contentDescription="@string/canteen_fab_refresh_content_desc"
android:tooltipText="@string/canteen_fab_refresh_content_desc"
tools:ignore="UnusedAttribute"/>
</androidx.appcompat.widget.LinearLayoutCompat>
<!-- <androidx.coordinatorlayout.widget.CoordinatorLayout-->
<!-- android:id="@+id/snackbar_container"-->