Skip to content

Commit f90d5de

Browse files
authored
Add support for custom properties (e.g. external billing, subject length) (#180)
1 parent 86c5c46 commit f90d5de

File tree

9 files changed

+44
-50
lines changed

9 files changed

+44
-50
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file.
55
### Added
66
* ui/ui-toolkit: i18n using the Lokalise
77
* Autofill support for PAYONE credit card forms
8+
* core/ui: Add support for project specific custom properties
9+
* Make the external billing subject text max length configurable
810
### Changed
911
### Removed
1012
* ui: Remove phrase for i18n

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import com.google.gson.JsonObject
1717
import io.snabble.sdk.auth.TokenRegistry
1818
import io.snabble.sdk.checkin.CheckInLocationManager
1919
import io.snabble.sdk.checkin.CheckInManager
20+
import io.snabble.sdk.config.CustomProperty
21+
import io.snabble.sdk.config.ProjectId
2022
import io.snabble.sdk.customization.IsMergeable
2123
import io.snabble.sdk.events.Events
2224
import io.snabble.sdk.extensions.getPackageInfoCompat
@@ -319,6 +321,14 @@ object Snabble {
319321
*/
320322
var formPrefillData: FormPrefillData? = null
321323

324+
/**
325+
* Set [CustomProperty]'s to override the default behavior.
326+
*
327+
* Every [CustomProperty] has to be explicitly defined and implemented beforehand
328+
* to be applicable for the given project.
329+
*/
330+
val customProperties: MutableMap<Pair<CustomProperty, ProjectId>, Any> = mutableMapOf()
331+
322332
/**
323333
* Setup the snabble SDK.
324334
*
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.snabble.sdk.config
2+
3+
@JvmInline
4+
value class ProjectId(val id: String)
5+
6+
sealed interface CustomProperty
7+
8+
data object ExternalBillingSubjectLength : CustomProperty

gradle/libs.versions.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
compileSdk = "33"
33
targetSdk = "32"
44
minSdk = "21"
5-
gradlePlugin = "8.1.4"
5+
gradlePlugin = "8.2.2"
66
desugarVersion = "1.1.5"
77
okhttpVersion = "4.10.0"
88
# @pin always, manually updated to ensure overall dependency support
9-
kotlin = "1.8.22"
9+
kotlin = "1.9.23"
1010
# @pin always, manually updated to ensure overall dependency support
11-
compose-compiler = "1.4.8"
11+
compose-compiler = "1.5.11"
1212
navigation = "2.6.0"
1313
# @pin
1414
compose_version = "1.2.1"

kotlin-sample/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ android {
3131
}
3232

3333
compileOptions {
34+
isCoreLibraryDesugaringEnabled = true
3435
sourceCompatibility = JavaVersion.VERSION_17
3536
targetCompatibility = JavaVersion.VERSION_17
3637
}

ui/src/main/java/io/snabble/sdk/ui/cart/CheckoutBar.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import io.snabble.sdk.Snabble
2828
import io.snabble.sdk.Snabble.instance
2929
import io.snabble.sdk.checkout.Checkout
3030
import io.snabble.sdk.checkout.CheckoutState
31+
import io.snabble.sdk.config.ExternalBillingSubjectLength
32+
import io.snabble.sdk.config.ProjectId
3133
import io.snabble.sdk.extensions.getApplicationInfoCompat
3234
import io.snabble.sdk.ui.Keyguard
3335
import io.snabble.sdk.ui.R
@@ -320,7 +322,7 @@ open class CheckoutBar @JvmOverloads constructor(
320322
if (entry.paymentMethod == PaymentMethod.TEGUT_EMPLOYEE_CARD) {
321323
project.checkout.pay(entry.paymentMethod, entry.paymentCredentials)
322324
} else if (entry.paymentMethod == PaymentMethod.EXTERNAL_BILLING) {
323-
SubjectAlertDialog(context)
325+
SubjectAlertDialog(context, maxSubjectLength = getMaxSubjectLength())
324326
.addMessageClickListener { message ->
325327
entry.paymentCredentials.additionalData["subject"] = message
326328
project.checkout.pay(entry.paymentMethod, entry.paymentCredentials)
@@ -471,6 +473,18 @@ open class CheckoutBar @JvmOverloads constructor(
471473
}
472474
}
473475
}
476+
477+
private fun getMaxSubjectLength(): Int? = Snabble.checkedInProject.value
478+
?.id
479+
?.let { id ->
480+
Snabble.customProperties
481+
.getOrDefault(
482+
ExternalBillingSubjectLength to ProjectId(id),
483+
defaultValue = null
484+
)
485+
?.toString()
486+
?.toInt()
487+
}
474488
}
475489

476490
fun interface CheckoutPreconditionHandler {

ui/src/main/java/io/snabble/sdk/ui/payment/externalbilling/ui/widgets/SubjectAlertDialog.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.content.Context
66
import android.graphics.Color
77
import android.graphics.drawable.ColorDrawable
88
import android.os.Bundle
9+
import android.text.InputFilter
910
import android.view.ViewGroup.LayoutParams
1011
import android.view.inputmethod.EditorInfo
1112
import android.view.inputmethod.InputMethodManager
@@ -15,7 +16,7 @@ import com.google.android.material.button.MaterialButton
1516
import com.google.android.material.textfield.TextInputLayout
1617
import io.snabble.sdk.ui.R
1718

18-
class SubjectAlertDialog(context: Context) : Dialog(context) {
19+
class SubjectAlertDialog(context: Context, private val maxSubjectLength: Int? = null) : Dialog(context) {
1920

2021
private var subjectMessageClickListener: SubjectMessageClickListener? = null
2122
private var skipClick: SubjectClickListener? = null
@@ -41,6 +42,8 @@ class SubjectAlertDialog(context: Context) : Dialog(context) {
4142
add.isEnabled = it?.isNotEmpty() == true
4243
}
4344

45+
editTextField.filters = arrayOf(InputFilter.LengthFilter(maxSubjectLength ?: 150))
46+
4447
add.setOnClickListener {
4548
subjectMessageClickListener?.onClick(input.editText?.text.toString())
4649
dismiss()

ui/src/main/java/io/snabble/sdk/ui/utils/SnackbarPushUpBehavior.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
android:id="@+id/text_edit_subject"
3636
android:layout_width="match_parent"
3737
android:layout_height="wrap_content"
38-
android:inputType="textCapSentences"
39-
android:maxLength="150" />
38+
android:inputType="textCapSentences"/>
4039

4140
</com.google.android.material.textfield.TextInputLayout>
4241

0 commit comments

Comments
 (0)