diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c0129c6e2..f197387321 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file. ### Added * ui/ui-toolkit: i18n using the Lokalise * Autofill support for PAYONE credit card forms +* core/ui: Add support for project specific custom properties + * Make the external billing subject text max length configurable ### Changed ### Removed * ui: Remove phrase for i18n diff --git a/core/src/main/java/io/snabble/sdk/Snabble.kt b/core/src/main/java/io/snabble/sdk/Snabble.kt index 65b5493b16..d908edbb5f 100644 --- a/core/src/main/java/io/snabble/sdk/Snabble.kt +++ b/core/src/main/java/io/snabble/sdk/Snabble.kt @@ -17,6 +17,8 @@ import com.google.gson.JsonObject import io.snabble.sdk.auth.TokenRegistry import io.snabble.sdk.checkin.CheckInLocationManager import io.snabble.sdk.checkin.CheckInManager +import io.snabble.sdk.config.CustomProperty +import io.snabble.sdk.config.ProjectId import io.snabble.sdk.customization.IsMergeable import io.snabble.sdk.events.Events import io.snabble.sdk.extensions.getPackageInfoCompat @@ -319,6 +321,14 @@ object Snabble { */ var formPrefillData: FormPrefillData? = null + /** + * Set [CustomProperty]'s to override the default behavior. + * + * Every [CustomProperty] has to be explicitly defined and implemented beforehand + * to be applicable for the given project. + */ + val customProperties: MutableMap, Any> = mutableMapOf() + /** * Setup the snabble SDK. * diff --git a/core/src/main/java/io/snabble/sdk/config/CustomProperty.kt b/core/src/main/java/io/snabble/sdk/config/CustomProperty.kt new file mode 100644 index 0000000000..e4d930e22c --- /dev/null +++ b/core/src/main/java/io/snabble/sdk/config/CustomProperty.kt @@ -0,0 +1,8 @@ +package io.snabble.sdk.config + +@JvmInline +value class ProjectId(val id: String) + +sealed interface CustomProperty + +data object ExternalBillingSubjectLength : CustomProperty diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 950d6d5f30..5cb686aa23 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,13 +2,13 @@ compileSdk = "33" targetSdk = "32" minSdk = "21" -gradlePlugin = "8.1.4" +gradlePlugin = "8.2.2" desugarVersion = "1.1.5" okhttpVersion = "4.10.0" # @pin always, manually updated to ensure overall dependency support -kotlin = "1.8.22" +kotlin = "1.9.23" # @pin always, manually updated to ensure overall dependency support -compose-compiler = "1.4.8" +compose-compiler = "1.5.11" navigation = "2.6.0" # @pin compose_version = "1.2.1" diff --git a/kotlin-sample/build.gradle.kts b/kotlin-sample/build.gradle.kts index 6bfe118a71..b318b3d73d 100644 --- a/kotlin-sample/build.gradle.kts +++ b/kotlin-sample/build.gradle.kts @@ -31,6 +31,7 @@ android { } compileOptions { + isCoreLibraryDesugaringEnabled = true sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } diff --git a/ui/src/main/java/io/snabble/sdk/ui/cart/CheckoutBar.kt b/ui/src/main/java/io/snabble/sdk/ui/cart/CheckoutBar.kt index 7c30555f94..e783c81072 100644 --- a/ui/src/main/java/io/snabble/sdk/ui/cart/CheckoutBar.kt +++ b/ui/src/main/java/io/snabble/sdk/ui/cart/CheckoutBar.kt @@ -28,6 +28,8 @@ import io.snabble.sdk.Snabble import io.snabble.sdk.Snabble.instance import io.snabble.sdk.checkout.Checkout import io.snabble.sdk.checkout.CheckoutState +import io.snabble.sdk.config.ExternalBillingSubjectLength +import io.snabble.sdk.config.ProjectId import io.snabble.sdk.extensions.getApplicationInfoCompat import io.snabble.sdk.ui.Keyguard import io.snabble.sdk.ui.R @@ -320,7 +322,7 @@ open class CheckoutBar @JvmOverloads constructor( if (entry.paymentMethod == PaymentMethod.TEGUT_EMPLOYEE_CARD) { project.checkout.pay(entry.paymentMethod, entry.paymentCredentials) } else if (entry.paymentMethod == PaymentMethod.EXTERNAL_BILLING) { - SubjectAlertDialog(context) + SubjectAlertDialog(context, maxSubjectLength = getMaxSubjectLength()) .addMessageClickListener { message -> entry.paymentCredentials.additionalData["subject"] = message project.checkout.pay(entry.paymentMethod, entry.paymentCredentials) @@ -471,6 +473,18 @@ open class CheckoutBar @JvmOverloads constructor( } } } + + private fun getMaxSubjectLength(): Int? = Snabble.checkedInProject.value + ?.id + ?.let { id -> + Snabble.customProperties + .getOrDefault( + ExternalBillingSubjectLength to ProjectId(id), + defaultValue = null + ) + ?.toString() + ?.toInt() + } } fun interface CheckoutPreconditionHandler { diff --git a/ui/src/main/java/io/snabble/sdk/ui/payment/externalbilling/ui/widgets/SubjectAlertDialog.kt b/ui/src/main/java/io/snabble/sdk/ui/payment/externalbilling/ui/widgets/SubjectAlertDialog.kt index ecc8a37213..5af11e558d 100644 --- a/ui/src/main/java/io/snabble/sdk/ui/payment/externalbilling/ui/widgets/SubjectAlertDialog.kt +++ b/ui/src/main/java/io/snabble/sdk/ui/payment/externalbilling/ui/widgets/SubjectAlertDialog.kt @@ -6,6 +6,7 @@ import android.content.Context import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle +import android.text.InputFilter import android.view.ViewGroup.LayoutParams import android.view.inputmethod.EditorInfo import android.view.inputmethod.InputMethodManager @@ -15,7 +16,7 @@ import com.google.android.material.button.MaterialButton import com.google.android.material.textfield.TextInputLayout import io.snabble.sdk.ui.R -class SubjectAlertDialog(context: Context) : Dialog(context) { +class SubjectAlertDialog(context: Context, private val maxSubjectLength: Int? = null) : Dialog(context) { private var subjectMessageClickListener: SubjectMessageClickListener? = null private var skipClick: SubjectClickListener? = null @@ -41,6 +42,8 @@ class SubjectAlertDialog(context: Context) : Dialog(context) { add.isEnabled = it?.isNotEmpty() == true } + editTextField.filters = arrayOf(InputFilter.LengthFilter(maxSubjectLength ?: 150)) + add.setOnClickListener { subjectMessageClickListener?.onClick(input.editText?.text.toString()) dismiss() diff --git a/ui/src/main/java/io/snabble/sdk/ui/utils/SnackbarPushUpBehavior.java b/ui/src/main/java/io/snabble/sdk/ui/utils/SnackbarPushUpBehavior.java deleted file mode 100644 index 06f70a8c2a..0000000000 --- a/ui/src/main/java/io/snabble/sdk/ui/utils/SnackbarPushUpBehavior.java +++ /dev/null @@ -1,43 +0,0 @@ -package io.snabble.sdk.ui.utils; - -import android.content.Context; -import android.util.AttributeSet; -import android.view.View; - -import androidx.annotation.NonNull; -import androidx.coordinatorlayout.widget.CoordinatorLayout; - -import com.google.android.material.snackbar.Snackbar; - -public class SnackbarPushUpBehavior extends CoordinatorLayout.Behavior { - public SnackbarPushUpBehavior() { - - } - - public SnackbarPushUpBehavior(Context context, AttributeSet attrs) { - super(context, attrs); - } - - @Override - public boolean layoutDependsOn(@NonNull CoordinatorLayout parent, - @NonNull View child, - @NonNull View dependency) { - return dependency instanceof Snackbar.SnackbarLayout; - } - - @Override - public void onDependentViewRemoved(@NonNull CoordinatorLayout parent, - View child, - @NonNull View dependency) { - child.setTranslationY(0); - } - - @Override - public boolean onDependentViewChanged(@NonNull CoordinatorLayout parent, - View child, - View dependency) { - float translationY = Math.min(0, dependency.getTranslationY() - dependency.getHeight()); - child.setTranslationY(translationY); - return true; - } -} diff --git a/ui/src/main/res/layout/snabble_subject_alert_dialog.xml b/ui/src/main/res/layout/snabble_subject_alert_dialog.xml index 747f6eef0f..d42bdbc833 100644 --- a/ui/src/main/res/layout/snabble_subject_alert_dialog.xml +++ b/ui/src/main/res/layout/snabble_subject_alert_dialog.xml @@ -35,8 +35,7 @@ android:id="@+id/text_edit_subject" android:layout_width="match_parent" android:layout_height="wrap_content" - android:inputType="textCapSentences" - android:maxLength="150" /> + android:inputType="textCapSentences"/>