Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/io/snabble/sdk/Snabble.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Pair<CustomProperty, ProjectId>, Any> = mutableMapOf()

/**
* Setup the snabble SDK.
*
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/io/snabble/sdk/config/CustomProperty.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.snabble.sdk.config

@JvmInline
value class ProjectId(val id: String)

sealed interface CustomProperty

data object ExternalBillingSubjectLength : CustomProperty
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions kotlin-sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ android {
}

compileOptions {
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
Expand Down
16 changes: 15 additions & 1 deletion ui/src/main/java/io/snabble/sdk/ui/cart/CheckoutBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand Down

This file was deleted.

3 changes: 1 addition & 2 deletions ui/src/main/res/layout/snabble_subject_alert_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>

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

Expand Down