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
})
}