Scrolling ability has been added to the toolbars of the fragments, but in the process, I ducked up the canteen fragment. TODO: figure out a solution for where to put the chip group

This commit is contained in:
denizk0461
2023-05-02 16:05:33 +02:00
parent 2f4b205703
commit 51c4c9120b
7 changed files with 239 additions and 222 deletions
@@ -9,6 +9,7 @@ import android.util.TypedValue
import android.widget.Toast
import androidx.annotation.AttrRes
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.denizk0461.studip.R
import com.denizk0461.studip.exception.AcademicQuarterNotApplicableException
import com.denizk0461.studip.exception.ParcelNotFoundException
@@ -94,6 +95,19 @@ inline fun <reified T : Parcelable> Bundle?.getParcelableCompat(key: String): T
this?.getParcelable(key) as? T
} ?: throw ParcelNotFoundException()
/**
* Applies a rainbow colour effect to a progress circle of a given [SwipeRefreshLayout]. The circle
* will rotate through 4 different colours during the refresh process.
*/
fun SwipeRefreshLayout.setRainbowProgressCircle() {
setColorSchemeColors(
context.getColor(R.color.beef_light_primary),
context.getColor(R.color.fair_light_primary),
context.getColor(R.color.vital_light_primary),
context.getColor(R.color.poultry_dark_primary),
)
}
/**
* Provides a conversion method between a timestamp ending in a full hour, and one with an academic
* quarter applied.
@@ -9,6 +9,7 @@ import androidx.fragment.app.viewModels
import com.denizk0461.studip.R
import com.denizk0461.studip.adapter.CanteenOfferPageAdapter
import com.denizk0461.studip.data.getTextSheet
import com.denizk0461.studip.data.setRainbowProgressCircle
import com.denizk0461.studip.data.showErrorSnackBar
import com.denizk0461.studip.databinding.FragmentCanteenBinding
import com.denizk0461.studip.model.*
@@ -49,6 +50,9 @@ class CanteenFragment : AppFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// Set progress circle colours
binding.swipeRefreshLayout.setRainbowProgressCircle()
// Open the menu for the canteen picker button
binding.buttonCanteenPicker.setOnClickListener {
PopupMenu(binding.root.context, binding.buttonCanteenPicker).apply {
@@ -128,9 +132,9 @@ class CanteenFragment : AppFragment() {
* TODO implement a more efficient / better-looking method
* TODO order the chips alphabetically?
*/
val index = binding.chipsPreference.indexOfChild(buttonView)
binding.chipsPreference.removeView(buttonView)
binding.chipsPreference.addView(buttonView, index)
// val index = binding.chipsPreference.indexOfChild(buttonView)
// binding.chipsPreference.removeView(buttonView)
// binding.chipsPreference.addView(buttonView, index)
}
}
@@ -226,10 +230,14 @@ class CanteenFragment : AppFragment() {
binding.swipeRefreshLayout.isRefreshing = false
}, onError = {
// Tell the user that an error occurred
context.theme?.showErrorSnackBar(
binding.snackbarContainer,
getString(R.string.canteen_fetch_error)
)
/*
* Tell the swipe refresh layout to stop refreshing.
*/
binding.swipeRefreshLayout.isRefreshing = false
})
}
+1 -1
View File
@@ -21,6 +21,6 @@
android:layout_gravity="bottom|end"
android:layout_marginEnd="@dimen/fab_margin"
android:layout_marginBottom="@dimen/fab_margin"
app:srcCompat="@drawable/check" />
app:srcCompat="@drawable/save"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
+60 -60
View File
@@ -1,17 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/snackbar_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/toolbar"
android:layout_width="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
android:fitsSystemWindows="true">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
android:id="@+id/button_canteen_picker"
@@ -19,25 +28,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_gravity="start"
android:fontFamily="@font/lato_bolditalic"/>
<TextView
android:id="@+id/app_title_bar"
android:layout_width="match_parent"
android:layout_height="48dp"
android:text="@string/title_food"
android:textSize="32sp"
android:fontFamily="@font/lato_bolditalic"
android:layout_marginHorizontal="16dp"/>
<com.google.android.material.tabs.TabLayout
android:id="@+id/day_tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"/>
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.button.MaterialButton
style="@style/Widget.Material3.Button.TextButton"
android:id="@+id/button_info"
@@ -46,55 +39,22 @@
android:minWidth="0dp"
app:icon="@drawable/info"
app:iconPadding="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_gravity="end"
app:iconTint="?attr/colorOnSurfaceVariant"/>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar"
app:layout_constraintBottom_toTopOf="@+id/scroll_view_chip">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/snackbar_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/scroll_view_chip"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<HorizontalScrollView
android:id="@+id/scroll_view_chip"
android:layout_width="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
android:layout_gravity="bottom">
<com.google.android.material.chip.ChipGroup
android:id="@+id/chips_preference"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:paddingHorizontal="8dp">
<com.google.android.material.chip.Chip
@@ -221,4 +181,44 @@
</HorizontalScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/app_title_bar"
android:layout_width="match_parent"
android:layout_height="48dp"
android:text="@string/title_food"
android:textSize="32sp"
android:fontFamily="@font/lato_bolditalic"
android:layout_marginHorizontal="16dp"/>
</androidx.appcompat.widget.LinearLayoutCompat>
<com.google.android.material.tabs.TabLayout
android:id="@+id/day_tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|snap"
app:tabMode="scrollable"/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill_vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<!-- <androidx.coordinatorlayout.widget.CoordinatorLayout-->
<!-- android:id="@+id/snackbar_container"-->
<!-- android:layout_width="0dp"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_gravity="bottom"/>-->
</androidx.coordinatorlayout.widget.CoordinatorLayout>
+9 -17
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<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:layout_width="match_parent"
@@ -8,12 +8,9 @@
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/toolbar"
android:layout_width="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
android:fitsSystemWindows="true">
<TextView
android:id="@+id/app_title_bar"
@@ -21,6 +18,7 @@
android:layout_height="48dp"
android:text="@string/title_schedule"
android:textSize="32sp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fontFamily="@font/lato_bolditalic"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="16dp"/>
@@ -30,20 +28,14 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
app:layout_scrollFlags="scroll|snap"/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/view_pager"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar"
app:layout_constraintBottom_toBottomOf="parent"/>
<!-- app:layout_behavior="@string/appbar_scrolling_view_behavior"-->
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
<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"
tools:context=".fragment.SettingsFragment"
@@ -21,6 +21,7 @@
android:layout_marginTop="16dp"
android:fontFamily="@font/lato_bolditalic"
android:text="@string/title_settings"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:textSize="32sp"/>
</com.google.android.material.appbar.AppBarLayout>
@@ -28,7 +29,8 @@
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
@@ -503,5 +505,5 @@
</androidx.core.widget.NestedScrollView>
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
+1
View File
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- I am unsure whether these attrs are necessary to define -->
<!-- <attr name="colorPrimary" type="color" />-->
<attr name="scheduleColorDefault" type="color" />
<attr name="colorOutlineVariant" type="color" />
<attr name="colorOnSurfaceVariant" type="color" />