Adjusted UI elements in CanteenFragment.kt to clean up the UI

This commit is contained in:
denizk0461
2023-05-13 19:45:36 +02:00
parent 2798e0ecbb
commit 2311cc46ad
5 changed files with 40 additions and 69 deletions
@@ -69,6 +69,19 @@ class CanteenFragment : AppFragment() {
// Set the title to be selected so it scrolls (marquee)
binding.appTitleBar.isSelected = true
// Set up button for viewing the opening hours
binding.buttonOpeningHours.setOnClickListener {
openBottomSheet(
getTextSheet(
getString(
R.string.canteen_opening_hours,
getCurrentlySelectedCanteenName()
),
contentId = TextSheetContentId.OPENING_HOURS,
)
)
}
// Set up observer for the selected canteen
viewModel.getCanteen().observe(viewLifecycleOwner) { canteen ->
if (canteen == null || canteen.news.isBlank()) {
@@ -140,19 +153,6 @@ class CanteenFragment : AppFragment() {
}
}
// Set up floating action button for viewing the opening hours
binding.fabOpeningHours.setOnClickListener {
openBottomSheet(
getTextSheet(
getString(
R.string.canteen_opening_hours,
getCurrentlySelectedCanteenName()
),
contentId = TextSheetContentId.OPENING_HOURS,
)
)
}
// Set up floating action button for switching the canteen
binding.fabSwitchCanteen.setOnClickListener {
PopupMenu(binding.root.context, binding.fabSwitchCanteen).apply {
@@ -188,15 +188,6 @@ class CanteenFragment : AppFragment() {
}
}
// Set up floating action button for refreshing the canteen offers
binding.fabRefreshOffers.setOnClickListener {
// Display to the user that a refresh is in progress
binding.swipeRefreshLayout.isRefreshing = true
// Refresh the offers
refresh()
}
// Set up the view pager's adapter
viewPagerAdapter = CanteenOfferPageAdapter(
childFragmentManager,
@@ -229,7 +220,7 @@ class CanteenFragment : AppFragment() {
positionOffsetPixels: Int
) {
super.onPageScrolled(position, positionOffset, positionOffsetPixels)
binding.fabRefreshOffers.extend()
binding.fabSwitchCanteen.extend()
}
})
@@ -261,14 +252,14 @@ class CanteenFragment : AppFragment() {
* Shrinks the FAB.
*/
fun shrinkFab() {
binding.fabRefreshOffers.shrink()
binding.fabSwitchCanteen.shrink()
}
/**
* Extends the FAB.
*/
fun extendFab() {
binding.fabRefreshOffers.extend()
binding.fabSwitchCanteen.extend()
}
/**
+21 -41
View File
@@ -1,7 +1,6 @@
<?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">
@@ -41,7 +40,21 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/button_notifications"/>
app:layout_constraintEnd_toStartOf="@id/button_opening_hours"/>
<com.google.android.material.button.MaterialButton
style="@style/Widget.Material3.Button.IconButton.Outlined"
android:id="@+id/button_opening_hours"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="0dp"
app:icon="@drawable/clock"
app:iconPadding="0dp"
app:strokeColor="?attr/colorOutlineVariant"
app:layout_constraintTop_toTopOf="@id/app_title_bar"
app:layout_constraintBottom_toBottomOf="@id/app_title_bar"
app:layout_constraintEnd_toStartOf="@id/button_notifications"
app:iconTint="?attr/colorOnSurfaceVariant"/>
<com.google.android.material.button.MaterialButton
style="@style/Widget.Material3.Button.IconButton.Outlined"
@@ -244,47 +257,14 @@
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<androidx.appcompat.widget.LinearLayoutCompat
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/fab_switch_canteen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:icon="@drawable/switch_arrows"
android:text="@string/canteen_fab_switch_canteen"
android:layout_gravity="bottom|end"
app:layout_dodgeInsetEdges="bottom">
<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:tooltipText="@string/canteen_fab_opening_hours_content_desc"
android:layout_gravity="end"
android:layout_marginHorizontal="24dp"
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:tooltipText="@string/canteen_fab_switch_canteen_content_desc"
android:layout_marginBottom="4dp"
android:layout_gravity="end"
android:layout_marginHorizontal="24dp"
tools:ignore="UnusedAttribute"/>
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/fab_refresh_offers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:icon="@drawable/refresh"
android:text="@string/canteen_fab_refresh_text"
android:layout_marginHorizontal="@dimen/fab_margin"
android:layout_marginBottom="@dimen/fab_margin"/>
</androidx.appcompat.widget.LinearLayoutCompat>
android:layout_marginHorizontal="@dimen/fab_margin"
android:layout_marginBottom="@dimen/fab_margin"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
+1 -1
View File
@@ -4,7 +4,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:paddingBottom="72dp"
android:paddingBottom="84dp"
android:clipToPadding="false"
android:scrollbarStyle="outsideOverlay"
android:layoutAnimation="@anim/layout_animation_fall_down"/>
+1 -1
View File
@@ -68,7 +68,7 @@
<string name="canteen_no_offer_desc">Für diesen Tag sind keine Angebote vorhanden</string>
<string name="canteen_news_sheet_title">Neuigkeiten für diese Mensa</string>
<string name="canteen_fab_opening_hours_content_desc">Zeige Öffnungszeiten</string>
<string name="canteen_fab_switch_canteen_content_desc">Wechsle Mensa</string>
<string name="canteen_fab_switch_canteen">Wechsle Mensa</string>
<string name="canteen_fab_refresh_content_desc">Aktualisiere Angebote</string>
<string name="canteen_fab_refresh_text">Aktualisieren</string>
+1 -1
View File
@@ -70,7 +70,7 @@
<string name="canteen_no_offer_desc">There are no offers available for this day</string>
<string name="canteen_news_sheet_title">News for this canteen</string>
<string name="canteen_fab_opening_hours_content_desc">Show opening hours</string>
<string name="canteen_fab_switch_canteen_content_desc">Switch canteen</string>
<string name="canteen_fab_switch_canteen">Switch canteen</string>
<string name="canteen_fab_refresh_content_desc">Refresh offers</string>
<string name="canteen_fab_refresh_text">Refresh</string>