FABs in canteen fragment now dodge away from snack bars; snack bar now used to tell the user that no news are available for a canteen

This commit is contained in:
denizk0461
2023-05-12 18:51:36 +02:00
parent 6053e8a9c4
commit 1177b8b14e
6 changed files with 51 additions and 13 deletions
@@ -145,12 +145,20 @@ class FetcherActivity : FragmentActivity() {
} catch (e: IOException) {
// Let the user know that an error occurred
theme.showErrorSnackBar(binding.rootView, getString(R.string.fetch_error_snack), binding.bottomAppBar)
theme.showErrorSnackBar(
binding.rootView,
getString(R.string.fetch_error_snack),
binding.bottomAppBar
)
}
}
} else {
// Tell the user that they must navigate to their timetable
theme.showErrorSnackBar(binding.rootView, getString(R.string.fetch_error_webpage_snack), binding.bottomAppBar)
theme.showErrorSnackBar(
binding.rootView,
getString(R.string.fetch_error_webpage_snack),
binding.bottomAppBar
)
}
}
}
@@ -55,6 +55,33 @@ fun showToast(context: Context, text: String) {
Toast.makeText(context, text, Toast.LENGTH_SHORT).show()
}
/**
* Show a snack bar. Colours will be applied according to the theme given.
*
* @receiver theme to apply colours of
* @param view view where the snack bar will be shown in
* @param text text to present in the snack bar
* @param anchor view to anchor the snack bar to
*/
fun Resources.Theme.showSnackBar(view: CoordinatorLayout, text: String, anchor: View? = null) {
val s = Snackbar.make(view, text, Snackbar.LENGTH_SHORT)
// Set colours
.setTextColor(getThemedColor(com.google.android.material.R.attr.colorOnSurfaceInverse))
.setBackgroundTint(getThemedColor(com.google.android.material.R.attr.colorSurfaceInverse))
// Set anchor view, if one has been passed
anchor?.let { a -> s.setAnchorView(a) }
s.show()
}
/**
* Show an error snack bar. Error colours will be applied according to the theme given.
*
* @receiver theme to apply colours of
* @param view view where the snack bar will be shown in
* @param text text to present in the snack bar
* @param anchor view to anchor the snack bar to
*/
fun Resources.Theme.showErrorSnackBar(view: CoordinatorLayout, text: String, anchor: View? = null) {
val s = Snackbar
.make(view, text, Snackbar.LENGTH_SHORT)
@@ -62,6 +89,7 @@ fun Resources.Theme.showErrorSnackBar(view: CoordinatorLayout, text: String, anc
.setBackgroundTint(getThemedColor(R.attr.colorErrorContainer))
.setTextColor(getThemedColor(R.attr.colorOnErrorContainer))
// Set anchor view, if one has been passed
anchor?.let { a -> s.setAnchorView(a) }
s.show()
}
@@ -14,7 +14,7 @@ import com.denizk0461.weserplaner.data.getTextSheet
import com.denizk0461.weserplaner.data.getThemedColor
import com.denizk0461.weserplaner.data.setRainbowProgressCircle
import com.denizk0461.weserplaner.data.showErrorSnackBar
import com.denizk0461.weserplaner.data.showToast
import com.denizk0461.weserplaner.data.showSnackBar
import com.denizk0461.weserplaner.databinding.FragmentCanteenBinding
import com.denizk0461.weserplaner.model.*
import com.denizk0461.weserplaner.viewmodel.CanteenViewModel
@@ -86,7 +86,8 @@ class CanteenFragment : AppFragment() {
// Set up click listener to tell the user that no news are available
binding.buttonNotifications.setOnClickListener {
showToast(context, getString(R.string.text_sheet_news_empty))
// showToast(context, getString(R.string.text_sheet_news_empty))
context.theme.showSnackBar(binding.snackbarContainer, getString(R.string.text_sheet_news_empty))
}
} else {
+4 -3
View File
@@ -247,6 +247,7 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom|end"
app:layout_dodgeInsetEdges="bottom"
app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior">
<com.google.android.material.floatingactionbutton.FloatingActionButton
@@ -256,8 +257,8 @@
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"
android:layout_gravity="center_horizontal"
tools:ignore="UnusedAttribute"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
@@ -267,9 +268,9 @@
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"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="4dp"
tools:ignore="UnusedAttribute"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton