Bimba.git

commit 1c14db0b4e0718f917b00624de325048d14f12b9

Author: Adam Evyčędo <git@apiote.xyz>

show snackbar in proper position in home fragment

%!v(PANIC=String method: strings: negative Repeat count)


diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/home/HomeFragment.kt b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/home/HomeFragment.kt
index 31fe93c056ed02204bf6ad61d2a870931383f264..f4dee33d49e23823cca32aab707a5956f962a5cd 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/home/HomeFragment.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/home/HomeFragment.kt
@@ -139,6 +139,15 @@ 				binding.suggestionsRecycler.updateLayoutParams {
 					leftMargin = it
 				}
 			}
+			binding.favourites.updatePadding(left = insets.left, right = insets.right)
+			binding.favourites.updateLayoutParams<ViewGroup.MarginLayoutParams> {
+				windowInsets.displayCutout?.safeInsetLeft?.let {
+					leftMargin = it + dpToPixelI(16f)
+				}
+				windowInsets.displayCutout?.safeInsetRight?.let {
+					rightMargin = it + dpToPixelI(16f)
+				}
+			}
 			windowInsets
 		}
 
@@ -163,8 +172,7 @@
 			override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
 				val (newFavourites, removedFavourite) = favouritesAdapter.delete(viewHolder.absoluteAdapterPosition)
 				this.newFavourites = newFavourites
-				// FIXME snackbar should appear above FAB (and be in CoordinatorLayout)
-				Snackbar.make(binding.fragmentContent, R.string.favourite_deleted, Snackbar.LENGTH_LONG)
+				Snackbar.make(binding.fragmentRoot, R.string.favourite_deleted, Snackbar.LENGTH_LONG)
 					.setAction(R.string.undo) {
 						this.newFavourites = favouritesAdapter.insert(removedFavourite)
 						viewModel.saveFavourites(this.newFavourites, requireContext())




diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml
index 1cc4250cb72b7dc1b0fbc2ad9635620d6d48ffe1..925487e2b450251a216845ce8573e76fb1c4acb8 100644
--- a/app/src/main/res/layout/fragment_home.xml
+++ b/app/src/main/res/layout/fragment_home.xml
@@ -6,82 +6,87 @@
 SPDX-License-Identifier: GPL-3.0-or-later
 -->
 
-<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:tool="http://schemas.android.com/tools"
+	android:id="@+id/fragment_root"
 	android:layout_width="match_parent"
 	android:layout_height="match_parent"
-	android:id="@+id/fragment_content"
 	android:tag="@string/title_home"
 	tool:context="xyz.apiote.bimba.czwek.dashboard.ui.home.HomeFragment">
 
-	<com.google.android.material.search.SearchBar
-		android:id="@+id/search_bar"
+	<androidx.constraintlayout.widget.ConstraintLayout
 		android:layout_width="match_parent"
-		android:layout_height="wrap_content"
-		android:layout_marginStart="8dp"
-		android:layout_marginTop="8dp"
-		android:layout_marginEnd="8dp"
-		android:hint="@string/search_placeholder"
-		app:layout_constraintEnd_toEndOf="parent"
-		app:layout_constraintStart_toStartOf="parent"
-		app:layout_constraintTop_toTopOf="parent"
-		app:navigationIcon="@drawable/menu"
-		app:useDrawerArrowDrawable="true" />
+		android:layout_height="match_parent">
 
-	<com.google.android.material.search.SearchView
-		android:id="@+id/search_view"
-		android:layout_width="match_parent"
-		android:layout_height="match_parent"
-		app:layout_constraintEnd_toEndOf="parent"
-		app:layout_constraintStart_toStartOf="parent"
-		app:layout_constraintTop_toTopOf="parent"
-		app:layout_constraintBottom_toBottomOf="parent"
-		android:hint="@string/search_placeholder"
-		app:layout_anchor="@id/search_bar">
+		<com.google.android.material.search.SearchBar
+			android:id="@+id/search_bar"
+			android:layout_width="match_parent"
+			android:layout_height="wrap_content"
+			android:layout_marginStart="8dp"
+			android:layout_marginTop="8dp"
+			android:layout_marginEnd="8dp"
+			android:hint="@string/search_placeholder"
+			app:layout_constraintEnd_toEndOf="parent"
+			app:layout_constraintStart_toStartOf="parent"
+			app:layout_constraintTop_toTopOf="parent"
+			app:navigationIcon="@drawable/menu"
+			app:useDrawerArrowDrawable="true" />
 
-		<androidx.recyclerview.widget.RecyclerView
-			android:id="@+id/suggestions_recycler"
+		<com.google.android.material.search.SearchView
+			android:id="@+id/search_view"
 			android:layout_width="match_parent"
-			android:layout_height="match_parent" />
-	</com.google.android.material.search.SearchView>
+			android:layout_height="match_parent"
+			android:hint="@string/search_placeholder"
+			app:layout_anchor="@id/search_bar"
+			app:layout_constraintBottom_toBottomOf="parent"
+			app:layout_constraintEnd_toEndOf="parent"
+			app:layout_constraintStart_toStartOf="parent"
+			app:layout_constraintTop_toTopOf="parent">
+
+			<androidx.recyclerview.widget.RecyclerView
+				android:id="@+id/suggestions_recycler"
+				android:layout_width="match_parent"
+				android:layout_height="match_parent" />
+		</com.google.android.material.search.SearchView>
 
-	<ImageView
-		android:id="@+id/inari"
-		android:layout_width="0dp"
-		android:layout_height="0dp"
-		android:layout_marginStart="16dp"
-		android:layout_marginEnd="16dp"
-		android:layout_marginTop="16dp"
-		android:layout_marginBottom="16dp"
-		android:alpha="0.25"
-		android:src="@drawable/inari"
-		app:layout_constraintBottom_toBottomOf="parent"
-		app:layout_constraintEnd_toEndOf="parent"
-		app:layout_constraintStart_toStartOf="parent"
-		app:layout_constraintTop_toTopOf="parent"
-		tool:ignore="ContentDescription,ImageContrastCheck" />
+		<ImageView
+			android:id="@+id/inari"
+			android:layout_width="0dp"
+			android:layout_height="0dp"
+			android:layout_marginStart="16dp"
+			android:layout_marginTop="16dp"
+			android:layout_marginEnd="16dp"
+			android:layout_marginBottom="16dp"
+			android:alpha="0.25"
+			android:src="@drawable/inari"
+			app:layout_constraintBottom_toBottomOf="parent"
+			app:layout_constraintEnd_toEndOf="parent"
+			app:layout_constraintStart_toStartOf="parent"
+			app:layout_constraintTop_toTopOf="parent"
+			tool:ignore="ContentDescription,ImageContrastCheck" />
 
-	<androidx.recyclerview.widget.RecyclerView
-		android:id="@+id/favourites"
-		android:layout_width="0dp"
-		android:layout_height="0dp"
-		android:layout_marginStart="16dp"
-		android:layout_marginTop="16dp"
-		android:layout_marginEnd="16dp"
-		app:layout_constraintBottom_toBottomOf="@id/inari"
-		app:layout_constraintEnd_toEndOf="parent"
-		app:layout_constraintStart_toStartOf="parent"
-		app:layout_constraintTop_toBottomOf="@id/search_bar" />
+		<androidx.recyclerview.widget.RecyclerView
+			android:id="@+id/favourites"
+			android:layout_width="0dp"
+			android:layout_height="0dp"
+			android:layout_marginStart="16dp"
+			android:layout_marginTop="16dp"
+			android:layout_marginEnd="16dp"
+			app:layout_constraintBottom_toBottomOf="@id/inari"
+			app:layout_constraintEnd_toEndOf="parent"
+			app:layout_constraintStart_toStartOf="parent"
+			app:layout_constraintTop_toBottomOf="@id/search_bar" />
+	</androidx.constraintlayout.widget.ConstraintLayout>
 
 	<com.google.android.material.floatingactionbutton.FloatingActionButton
 		android:id="@+id/floating_action_button"
 		android:layout_width="wrap_content"
 		android:layout_height="wrap_content"
+		android:layout_gravity="bottom|end"
 		android:layout_margin="16dp"
 		android:contentDescription="@string/home_fab_description"
 		android:src="@drawable/gps_black"
-		app:layout_constraintBottom_toBottomOf="parent"
-		app:layout_constraintEnd_toEndOf="parent"
+		app:layout_behavior="com.google.android.material.floatingactionbutton.FloatingActionButton$Behavior"
 		tool:ignore="ImageContrastCheck" />
-</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
+</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file