Skip to content

Commit c0b89d4

Browse files
authored
Add toolbar option for checkout activity (#121)
An optional toolbar for the gatekeeper and the option to color the status bar is now available.
1 parent 5f5f01d commit c0b89d4

File tree

16 files changed

+111
-20
lines changed

16 files changed

+111
-20
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ All notable changes to this project will be documented in this file.
44
## UNRELEASED
55
### Added
66
### Changed
7-
* ui: Show bin icon instead of minus if the quantity of the line item is 1
8-
* ui: Show the trash (minus) icon for all deletable line items
7+
* ui: Add the ability to show a header for the CheckoutActivity
98

109
### Removed
1110
### Fixed
1211

12+
## [0.68.8]
13+
### Changed
14+
* ui: Show bin icon instead of minus if the quantity of the line item is 1
15+
* ui: Show the trash (minus) icon for all deletable line items
16+
1317
## [0.69.7]
1418
### Changed
1519
* Convert all grade files to gradle.kts files

ui/src/main/java/io/snabble/sdk/ui/checkout/CheckoutActivity.kt

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package io.snabble.sdk.ui.checkout
22

3+
import android.annotation.SuppressLint
34
import android.content.Context
45
import android.content.Intent
6+
import android.graphics.Color
57
import android.os.Bundle
8+
import android.view.View
9+
import android.view.ViewGroup
10+
import android.view.WindowManager
611
import androidx.appcompat.app.AlertDialog
12+
import androidx.core.view.*
713
import androidx.fragment.app.FragmentActivity
814
import androidx.lifecycle.Observer
915
import androidx.navigation.NavController
@@ -38,8 +44,8 @@ class CheckoutActivity : FragmentActivity() {
3844
@JvmStatic
3945
fun restoreCheckoutIfNeeded(context: Context) {
4046
Snabble.initializationState.observeForever(object : Observer<InitializationState> {
41-
override fun onChanged(t: InitializationState) {
42-
if (t == InitializationState.INITIALIZED) {
47+
override fun onChanged(value: InitializationState) {
48+
if (value == InitializationState.INITIALIZED) {
4349
Snabble.initializationState.removeObserver(this)
4450
val project = Snabble.checkedInProject.value
4551
if (project?.checkout?.state?.value?.isCheckoutState == true) {
@@ -74,6 +80,7 @@ class CheckoutActivity : FragmentActivity() {
7480
val graphInflater = navHostFragment.navController.navInflater
7581
navGraph = graphInflater.inflate(R.navigation.snabble_nav_checkout)
7682
navController = navHostFragment.navController
83+
setUpToolBarAndStatusBar()
7784

7885
if (project == null) {
7986
finishWithError("Project not set")
@@ -113,6 +120,17 @@ class CheckoutActivity : FragmentActivity() {
113120
}
114121
}
115122

123+
private fun setUpToolBarAndStatusBar() {
124+
val showToolBar = resources.getBoolean(R.bool.showToolbarInCheckout)
125+
findViewById<View>(R.id.checkout_toolbar_spacer)?.isVisible = showToolBar
126+
navController.addOnDestinationChangedListener { _, destination, arguments ->
127+
findViewById<View>(R.id.checkout_toolbar)?.isVisible = arguments?.getBoolean("showToolbar", false) == true
128+
}
129+
if (showToolBar) {
130+
applyInsets()
131+
}
132+
}
133+
116134
private fun finishWithError(error: String) {
117135
Logger.e(error)
118136
finish()
@@ -176,6 +194,37 @@ class CheckoutActivity : FragmentActivity() {
176194
}
177195
}
178196

197+
private fun applyInsets() {
198+
val root = findViewById<View>(R.id.root) ?: return
199+
200+
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
201+
WindowCompat.setDecorFitsSystemWindows(window, false)
202+
val windowInsetsController = WindowInsetsControllerCompat(window, root)
203+
204+
ViewCompat.setOnApplyWindowInsetsListener(root) { view, windowInsets ->
205+
window.statusBarColor = Color.parseColor("#22000000")
206+
windowInsetsController.isAppearanceLightStatusBars = false
207+
208+
val currentInsetTypeMask = listOf(
209+
WindowInsetsCompat.Type.navigationBars(),
210+
WindowInsetsCompat.Type.ime(),
211+
WindowInsetsCompat.Type.systemBars(),
212+
WindowInsetsCompat.Type.statusBars()
213+
).fold(0) { accumulator, type -> accumulator or type }
214+
215+
@SuppressLint("WrongConstant")
216+
val insets = windowInsets.getInsets(currentInsetTypeMask)
217+
view.updateLayoutParams<ViewGroup.MarginLayoutParams> {
218+
updateMargins(insets.left, 0, insets.right, insets.bottom)
219+
}
220+
findViewById<View>(R.id.checkout_toolbar_spacer)?.apply {
221+
setPadding(0, insets.top, 0, 0)
222+
}
223+
224+
windowInsets.inset(insets.left, insets.top, insets.right, insets.bottom)
225+
}
226+
}
227+
179228
override fun onBackPressed() {
180229
// prevent user from backing out while checkout is in progress
181230
if (checkout?.state?.value == CheckoutState.PAYMENT_APPROVED) {

ui/src/main/java/io/snabble/sdk/ui/checkout/routingtargets/RoutingTargetGatekeeperView.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,11 @@ class RoutingTargetGatekeeperView @JvmOverloads constructor(
127127

128128
private fun setHelperImage(bitmap: Bitmap?) {
129129
val helperImage = helperImage
130-
if (helperImage == null) {
131-
helperTextNoImage.isVisible = false
130+
if (helperImage == null) { // Can be overridden by hosting app using R.layout.snabble_checkout_header
131+
helperTextNoImage.isVisible = false // this is not part of the layout thus needs to be hidden
132132
return
133133
}
134+
134135
if (bitmap != null) {
135136
helperImage.setImageBitmap(bitmap)
136137
helperImage.isVisible = true
Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:id="@+id/root"
45
android:layout_width="match_parent"
5-
android:layout_height="match_parent">
6+
android:layout_height="match_parent"
7+
android:orientation="vertical">
8+
9+
<!-- Workaround for alignment bug in MaterialToolbar when setting padding -->
10+
<FrameLayout
11+
android:id="@+id/checkout_toolbar_spacer"
12+
android:layout_width="match_parent"
13+
android:layout_height="wrap_content"
14+
android:background="@color/snabble_toolbar"
15+
android:visibility="gone">
16+
17+
<com.google.android.material.appbar.MaterialToolbar
18+
android:id="@+id/checkout_toolbar"
19+
style="Widget.Material3.Toolbar.Surface"
20+
android:layout_width="match_parent"
21+
android:layout_height="wrap_content"
22+
app:title="@string/Snabble.Payment.transferCart" />
23+
</FrameLayout>
24+
625
<androidx.fragment.app.FragmentContainerView
726
android:id="@+id/nav_host_container"
827
android:name="androidx.navigation.fragment.NavHostFragment"
928
android:layout_width="match_parent"
1029
android:layout_height="match_parent"
1130
app:defaultNavHost="true" />
12-
</FrameLayout>
31+
</LinearLayout>

ui/src/main/res/layout/snabble_checkout_header.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
android:layout_height="wrap_content"
1414
android:visibility="gone"
1515
tools:ignore="ContentDescription"
16-
tools:src="@drawable/snabble_ic_rating_3"
16+
tools:src="@drawable/snabble_rating_neutral"
1717
tools:visibility="visible" />
1818

1919
</merge>

ui/src/main/res/layout/snabble_view_routing_gatekeeper.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@
2525
android:layout_width="match_parent"
2626
android:layout_height="wrap_content"
2727
android:layout_gravity="center"
28+
android:layout_marginBottom="20dp"
2829
android:gravity="center"
2930
android:paddingLeft="16dp"
3031
android:paddingRight="16dp"
3132
android:text="@string/Snabble.Payment.presentCode"
32-
android:textAppearance="?attr/textAppearanceBodyLarge" />
33+
android:textAppearance="?attr/textAppearanceBodyLarge"
34+
android:visibility="gone"
35+
tools:visibility="visible" />
3336

3437
<LinearLayout
3538
android:layout_width="match_parent"

ui/src/main/res/navigation/snabble_nav_checkout.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
34
android:id="@+id/snabble_nav_checkout">
45
<fragment
56
android:id="@+id/snabble_nav_routing_gatekeeper"
67
android:name="io.snabble.sdk.ui.checkout.routingtargets.RoutingTargetGatekeeperFragment"
7-
android:label="@string/Snabble.Checkout.title" />
8+
android:label="@string/Snabble.Checkout.title">
9+
<argument
10+
android:name="showToolbar"
11+
android:defaultValue="true"
12+
app:argType="boolean" />
13+
</fragment>
814

915
<fragment
1016
android:id="@+id/snabble_nav_routing_supervisor"

ui/src/main/res/values-de/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
<string name="Snabble.Payment.SEPA.title">SEPA-Lastschrift</string>
161161
<string name="Snabble.Payment.SEPA.validIBAN">Gültige IBAN</string>
162162
<string name="Snabble.Payment.success">Vielen Dank für deinen Einkauf</string>
163+
<string name="Snabble.Payment.transferCart">Warenkorb übertragen</string>
163164
<string name="Snabble.Payment.Twint.error">Bei der Verarbeitung deines TWINT-Accounts ist ein Fehler aufgetreten</string>
164165
<string name="Snabble.Payment.usableAt">Verwendbar bei: %s</string>
165166
<string name="Snabble.Payment.waiting">Warte auf Bestätigung</string>

ui/src/main/res/values-fr-rCH/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@
164164
<string name="Snabble.Payment.SEPA.title">Débit SEPA</string>
165165
<string name="Snabble.Payment.SEPA.validIBAN">Valid IBAN</string>
166166
<string name="Snabble.Payment.success">Merci pour ton achat !</string>
167+
<string name="Snabble.Payment.transferCart">Transfer shopping cart</string>
167168
<string name="Snabble.Payment.Twint.error">Une erreur s’est produite lors du traitement de ton compte TWINT</string>
168169
<string name="Snabble.Payment.usableAt">Utilisable pour : %s</string>
169170
<string name="Snabble.Payment.waiting">Attends la confirmation</string>

ui/src/main/res/values-fr/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@
164164
<string name="Snabble.Payment.SEPA.title">Prélèvement SEPA</string>
165165
<string name="Snabble.Payment.SEPA.validIBAN">Valid IBAN</string>
166166
<string name="Snabble.Payment.success">Merci beaucoup pour votre achat</string>
167+
<string name="Snabble.Payment.transferCart">Transfer shopping cart</string>
167168
<string name="Snabble.Payment.Twint.error">Une erreur est survenue lors du traitement de votre compte TWINT.</string>
168169
<string name="Snabble.Payment.usableAt">À utiliser jusqu\'au : %s</string>
169170
<string name="Snabble.Payment.waiting">En attente de confirmation</string>

0 commit comments

Comments
 (0)