Skip to content

Commit 2004128

Browse files
cmaierFabtron
andauthored
Fix theming when related to shop exit and refactorings (#215)
Co-authored-by: Fabian Bender <[email protected]>
1 parent 1bb1124 commit 2004128

File tree

9 files changed

+46
-27
lines changed

9 files changed

+46
-27
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ All notable changes to this project will be documented in this file.
66
### Changed
77
### Removed
88
### Fixed
9+
10+
## [0.75.8]
11+
### Changed
12+
* ui: Refactor RemoteThemingExtensions
13+
### Fixed
914
* ui: subject dialog for external billing now works in dark mode
1015
* ui: external billing icon works with dark mode now
1116
* core: prevent SQLiteLockedException and recover from it on product database update
17+
* core: Fix theming related bug by setting restored shop in CheckInManager
1218

1319
## [0.75.7]
1420
### Added

core/src/main/java/io/snabble/sdk/Snabble.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ object Snabble {
575575
}
576576
if (shop != null) {
577577
Logger.d("Restoring last checked in shop " + shop.id + ", " + shop.name)
578-
checkedInShop = shop
578+
checkInManager.shop = shop
579579
break;
580580
}
581581
}

ui/src/main/java/io/snabble/sdk/ui/payment/PaymentCredentialsListView.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import io.snabble.sdk.payment.PaymentCredentials;
3434
import io.snabble.sdk.payment.PaymentCredentialsStore;
3535
import io.snabble.sdk.ui.R;
36-
import io.snabble.sdk.ui.remotetheme.RemoteThemingExtensionsKt;
36+
import io.snabble.sdk.ui.remotetheme.RemoteThemingHelper;
3737
import io.snabble.sdk.ui.telemetry.Telemetry;
3838
import io.snabble.sdk.ui.utils.KeyguardUtils;
3939
import io.snabble.sdk.ui.utils.OneShotClickListener;
@@ -81,8 +81,8 @@ private void inflateView() {
8181
FloatingActionButton fab = findViewById(R.id.fab);
8282

8383
final Project currentProject = Snabble.getInstance().getCheckedInProject().getLatestValue();
84-
final int primaryColor = RemoteThemingExtensionsKt.getPrimaryColorForProject(getContext(), currentProject);
85-
final int onPrimaryColor = RemoteThemingExtensionsKt.getOnPrimaryColorForProject(getContext(), currentProject);
84+
final int primaryColor = RemoteThemingHelper.primaryColorForProject(getContext(), currentProject);
85+
final int onPrimaryColor = RemoteThemingHelper.onPrimaryColorForProject(getContext(), currentProject);
8686

8787
fab.setBackgroundTintList(ColorStateList.valueOf(primaryColor));
8888
fab.setImageTintList(ColorStateList.valueOf(onPrimaryColor));
@@ -118,8 +118,8 @@ public void click() {
118118
.setCancelable(false)
119119
.show();
120120

121-
RemoteThemingExtensionsKt
122-
.setButtonColorFor(alertDialog, currentProject)
121+
RemoteThemingHelper
122+
.changeButtonColorFor(alertDialog, currentProject)
123123
.show();
124124
}
125125
}
@@ -306,8 +306,8 @@ public void onBindViewHolder(@NonNull final EntryViewHolder vh, final int positi
306306
.create();
307307
final Project currentProject = Snabble.getInstance().getCheckedInProject().getLatestValue();
308308

309-
RemoteThemingExtensionsKt
310-
.setButtonColorFor(alertDialog, currentProject)
309+
RemoteThemingHelper
310+
.changeButtonColorFor(alertDialog, currentProject)
311311
.show();
312312

313313
Telemetry.event(Telemetry.Event.PaymentMethodDeleted, e.paymentCredentials.getType());

ui/src/main/java/io/snabble/sdk/ui/payment/PaymentInputViewHelper.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import io.snabble.sdk.ui.SnabbleUI
1313
import io.snabble.sdk.ui.payment.creditcard.datatrans.ui.DatatransFragment
1414
import io.snabble.sdk.ui.payment.creditcard.fiserv.FiservInputView
1515
import io.snabble.sdk.ui.payment.externalbilling.ExternalBillingFragment.Companion.ARG_PROJECT_ID
16-
import io.snabble.sdk.ui.remotetheme.setButtonColorFor
16+
import io.snabble.sdk.ui.remotetheme.changeButtonColorFor
1717
import io.snabble.sdk.ui.utils.KeyguardUtils
1818
import io.snabble.sdk.ui.utils.UIUtils
1919
import io.snabble.sdk.utils.Logger
@@ -78,7 +78,7 @@ object PaymentInputViewHelper {
7878
val currentProject = Snabble.instance.checkedInProject.value
7979

8080
alertDialog
81-
.setButtonColorFor(currentProject)
81+
.changeButtonColorFor(currentProject)
8282
.show()
8383
}
8484
}

ui/src/main/java/io/snabble/sdk/ui/remotetheme/RemoteThemingExtensions.kt

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:JvmName("RemoteThemingHelper")
2+
13
package io.snabble.sdk.ui.remotetheme
24

35
import android.content.Context
@@ -16,31 +18,42 @@ fun Context.getPrimaryColorForProject(project: Project?): Int {
1618
}
1719
}
1820

19-
fun Context.getOnPrimaryColorForProject(project: Project?): Int {
21+
@JvmOverloads
22+
fun Context.primaryColorForProject(project: Project?, action: ((Int) -> Unit)? = null): Int {
23+
val lightColor = project?.appTheme?.lightModeColors?.primaryColor?.asColor()
24+
val darkColor = project?.appTheme?.darkModeColors?.primaryColor?.asColor()
25+
return when {
26+
isDarkMode() -> darkColor ?: lightColor ?: getColorByAttribute(R.attr.colorPrimary)
27+
else -> lightColor ?: getColorByAttribute(R.attr.colorPrimary)
28+
}.also { action?.invoke(it) }
29+
}
30+
31+
@JvmOverloads
32+
fun Context.onPrimaryColorForProject(project: Project?, action: ((Int) -> Unit)? = null): Int {
2033
val lightColor = project?.appTheme?.lightModeColors?.onPrimaryColor?.asColor()
2134
val darkColor = project?.appTheme?.darkModeColors?.onPrimaryColor?.asColor()
2235
return when {
2336
isDarkMode() -> darkColor ?: lightColor ?: getColorByAttribute(R.attr.colorOnPrimary)
2437
else -> lightColor ?: getColorByAttribute(R.attr.colorOnPrimary)
25-
}
38+
}.also { action?.invoke(it) }
2639
}
2740

28-
fun Context.getSecondaryColorForProject(project: Project?): Int {
41+
fun Context.secondaryColorForProject(project: Project?, action: ((Int) -> Unit)? = null): Int {
2942
val lightColor = project?.appTheme?.lightModeColors?.secondaryColor?.asColor()
3043
val darkColor = project?.appTheme?.darkModeColors?.secondaryColor?.asColor()
3144
return when {
3245
isDarkMode() -> darkColor ?: lightColor ?: getColorByAttribute(R.attr.colorSecondary)
3346
else -> lightColor ?: getColorByAttribute(R.attr.colorSecondary)
34-
}
47+
}.also { action?.invoke(it) }
3548
}
3649

37-
fun Context.getOnSecondaryColorForProject(project: Project?): Int {
50+
fun Context.onSecondaryColorForProject(project: Project?, action: ((Int) -> Unit)? = null): Int {
3851
val lightColor = project?.appTheme?.lightModeColors?.onSecondaryColor?.asColor()
3952
val darkColor = project?.appTheme?.darkModeColors?.onSecondaryColor?.asColor()
4053
return when {
4154
isDarkMode() -> darkColor ?: lightColor ?: getColorByAttribute(R.attr.colorOnSecondary)
4255
else -> lightColor ?: getColorByAttribute(R.attr.colorOnSecondary)
43-
}
56+
}.also { action?.invoke(it) }
4457
}
4558

4659
fun String.asColor() = Color.parseColor(this)
@@ -51,11 +64,11 @@ fun Context.isDarkMode(): Boolean {
5164
return currentNightMode == android.content.res.Configuration.UI_MODE_NIGHT_YES
5265
}
5366

54-
fun AlertDialog.setButtonColorFor(project: Project?): AlertDialog {
55-
val primaryColor = context.getPrimaryColorForProject(project)
67+
fun AlertDialog.changeButtonColorFor(project: Project?): AlertDialog {
68+
val primaryColor = context.primaryColorForProject(project)
5669
setOnShowListener {
57-
getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(primaryColor);
58-
getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(primaryColor);
70+
getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(primaryColor)
71+
getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(primaryColor)
5972
}
6073
return this
6174
}

ui/src/main/java/io/snabble/sdk/ui/remotetheme/SnabblePrimaryButton.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class SnabblePrimaryButton @JvmOverloads constructor(
6969

7070
val colors = intArrayOf(
7171
defaultDisabledBackgroundColor ?: currentBackgroundColor,
72-
context.getPrimaryColorForProject(project)
72+
context.primaryColorForProject(project)
7373
)
7474

7575
backgroundTintList = ColorStateList(states, colors)
@@ -89,7 +89,7 @@ class SnabblePrimaryButton @JvmOverloads constructor(
8989

9090
val colors = intArrayOf(
9191
defaultDisabledTextColor,
92-
context.getOnPrimaryColorForProject(project)
92+
context.onPrimaryColorForProject(project)
9393
)
9494

9595
setTextColor(ColorStateList(states, colors))

ui/src/main/java/io/snabble/sdk/ui/remotetheme/SnabblePrimaryTextView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ class SnabblePrimaryTextView @JvmOverloads constructor(
2222

2323
private fun setProjectAppTheme() {
2424
val project = Snabble.checkedInProject.value
25-
setTextColor(context.getPrimaryColorForProject(project))
25+
setTextColor(context.primaryColorForProject(project))
2626
}
2727
}

ui/src/main/java/io/snabble/sdk/ui/remotetheme/SnabbleSecondaryButton.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class SnabbleSecondaryButton @JvmOverloads constructor(
4545

4646
val colors = intArrayOf(
4747
defaultDisabledTextColor,
48-
context.getPrimaryColorForProject(project)
48+
context.primaryColorForProject(project)
4949
)
5050

5151
setTextColor(ColorStateList(states, colors))

ui/src/main/java/io/snabble/sdk/ui/scanner/SelfScanningView.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import io.snabble.sdk.ui.R;
4747
import io.snabble.sdk.ui.SnabbleUI;
4848
import io.snabble.sdk.ui.checkout.ViolationNotificationUtils;
49-
import io.snabble.sdk.ui.remotetheme.RemoteThemingExtensionsKt;
49+
import io.snabble.sdk.ui.remotetheme.RemoteThemingHelper;
5050
import io.snabble.sdk.ui.telemetry.Telemetry;
5151
import io.snabble.sdk.ui.utils.DelayedProgressDialog;
5252
import io.snabble.sdk.ui.utils.I18nUtils;
@@ -336,8 +336,8 @@ public void searchWithBarcode() {
336336

337337
final Project currentProject = Snabble.getInstance().getCheckedInProject().getLatestValue();
338338

339-
RemoteThemingExtensionsKt
340-
.setButtonColorFor(alertDialog,currentProject)
339+
RemoteThemingHelper
340+
.changeButtonColorFor(alertDialog,currentProject)
341341
.show();
342342

343343
input.requestFocus();

0 commit comments

Comments
 (0)