From 8e4b279ebd8a959aa0f2fd7f856d1b76866e35a9 Mon Sep 17 00:00:00 2001 From: Tayfun Oztemel Date: Wed, 24 Jul 2024 14:27:33 +0200 Subject: [PATCH 1/2] Add slf4j api for fixing missing logging impl --- sdk/build.gradle | 6 +++--- sdk/src/test/java/android/util/Log.java | 25 ------------------------- 2 files changed, 3 insertions(+), 28 deletions(-) delete mode 100644 sdk/src/test/java/android/util/Log.java diff --git a/sdk/build.gradle b/sdk/build.gradle index c7d62db..8040c1e 100644 --- a/sdk/build.gradle +++ b/sdk/build.gradle @@ -41,12 +41,12 @@ android { dependencies { implementation 'io.github.oshai:kotlin-logging-jvm:7.0.0' - testImplementation 'junit:junit:4.13.2' - testImplementation 'org.slf4j:slf4j-simple:2.0.3' + implementation 'org.slf4j:slf4j-api:2.0.7' implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-gson:2.9.0' implementation 'com.google.code.gson:gson:2.11.0' implementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.3")) implementation("com.squareup.okhttp3:okhttp") - implementation("com.squareup.okhttp3:logging-interceptor") + testImplementation 'junit:junit:4.13.2' + testImplementation 'org.slf4j:slf4j-simple:2.0.7' } \ No newline at end of file diff --git a/sdk/src/test/java/android/util/Log.java b/sdk/src/test/java/android/util/Log.java deleted file mode 100644 index a0b1072..0000000 --- a/sdk/src/test/java/android/util/Log.java +++ /dev/null @@ -1,25 +0,0 @@ -package android.util; - -public class Log { - public static int d(String tag, String msg) { - System.out.println("DEBUG: " + tag + ": " + msg); - return 0; - } - - public static int i(String tag, String msg) { - System.out.println("INFO: " + tag + ": " + msg); - return 0; - } - - public static int w(String tag, String msg) { - System.out.println("WARN: " + tag + ": " + msg); - return 0; - } - - public static int e(String tag, String msg) { - System.out.println("ERROR: " + tag + ": " + msg); - return 0; - } - - // add other methods if required... -} \ No newline at end of file From afba968d437f762ab4efe4d6bb2631c9342c1493 Mon Sep 17 00:00:00 2001 From: Tayfun Oztemel Date: Wed, 24 Jul 2024 14:32:25 +0200 Subject: [PATCH 2/2] Add conveniences for promotion contents --- .../com/crobox/sdk/testapp/MainActivity.kt | 2 +- .../com/crobox/sdk/data/api/CroboxAPI.kt | 3 +- .../com/crobox/sdk/domain/BaseResponse.kt | 14 --------- .../com/crobox/sdk/domain/Components.kt | 30 +++++++++++++++---- .../com/crobox/sdk/domain/PromotionContent.kt | 30 +++++++++++++++---- .../sdk/presenter/CroboxAPIPresenter.kt | 7 ++--- 6 files changed, 54 insertions(+), 32 deletions(-) delete mode 100644 sdk/src/main/kotlin/com/crobox/sdk/domain/BaseResponse.kt diff --git a/app/src/main/kotlin/com/crobox/sdk/testapp/MainActivity.kt b/app/src/main/kotlin/com/crobox/sdk/testapp/MainActivity.kt index c9fd87f..c23b0a7 100644 --- a/app/src/main/kotlin/com/crobox/sdk/testapp/MainActivity.kt +++ b/app/src/main/kotlin/com/crobox/sdk/testapp/MainActivity.kt @@ -225,7 +225,7 @@ class MainActivity : AppCompatActivity() { Campaign:$campaignId Variant:$variantId Msg Id:${promotion.content?.messageId} - Component:${promotion.content?.component} + Component:${promotion.content?.componentName} Msg Config:${promotion.content?.config} Image Badge:${promotion.content?.getImageBadge()} Text Badge:${promotion.content?.getTextBadge()} diff --git a/sdk/src/main/kotlin/com/crobox/sdk/data/api/CroboxAPI.kt b/sdk/src/main/kotlin/com/crobox/sdk/data/api/CroboxAPI.kt index 9ec360b..f375ab7 100644 --- a/sdk/src/main/kotlin/com/crobox/sdk/data/api/CroboxAPI.kt +++ b/sdk/src/main/kotlin/com/crobox/sdk/data/api/CroboxAPI.kt @@ -1,6 +1,5 @@ package com.crobox.sdk.data.api -import com.crobox.sdk.domain.BaseResponse import com.crobox.sdk.domain.PromotionsResponse import okhttp3.RequestBody import retrofit2.Call @@ -16,5 +15,5 @@ internal interface CroboxAPI { ): Call? @GET("/socket.gif") - fun event(@QueryMap options: Map): Call + fun event(@QueryMap options: Map): Call } \ No newline at end of file diff --git a/sdk/src/main/kotlin/com/crobox/sdk/domain/BaseResponse.kt b/sdk/src/main/kotlin/com/crobox/sdk/domain/BaseResponse.kt deleted file mode 100644 index b3411e4..0000000 --- a/sdk/src/main/kotlin/com/crobox/sdk/domain/BaseResponse.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.crobox.sdk.domain - -internal class BaseResponse(jsonData: Map) { - val data: MutableMap = mutableMapOf() - init { - data.putAll(jsonData) - } - fun getValue(key: String): String? { - return data[key] - } - fun getValue(key: String, defaultValue: String): String { - return data[key] ?: defaultValue - } -} \ No newline at end of file diff --git a/sdk/src/main/kotlin/com/crobox/sdk/domain/Components.kt b/sdk/src/main/kotlin/com/crobox/sdk/domain/Components.kt index d16811f..8dd76e3 100644 --- a/sdk/src/main/kotlin/com/crobox/sdk/domain/Components.kt +++ b/sdk/src/main/kotlin/com/crobox/sdk/domain/Components.kt @@ -1,23 +1,41 @@ package com.crobox.sdk.domain +enum class PromotionContentType { ImageBadge, TextBadge } + +interface PromotionContentConfig { + val contentType: PromotionContentType + val name: String +} + data class ImageBadge( /// Image url val image: String, /// Alternate Text - val altText: String? -) + val altText: String?, + + /// Component name + override val name: String, -data class TextBadge ( + ) : PromotionContentConfig { + override val contentType: PromotionContentType = PromotionContentType.ImageBadge +} + +data class TextBadge( /// Text message val text: String, /// Font color - val fontColor: String, + val fontColor: String?, /// Background color val backgroundColor: String?, /// Border color - val borderColor: String? -) \ No newline at end of file + val borderColor: String?, + + /// Component name + override val name: String +) : PromotionContentConfig { + override val contentType: PromotionContentType = PromotionContentType.TextBadge +} \ No newline at end of file diff --git a/sdk/src/main/kotlin/com/crobox/sdk/domain/PromotionContent.kt b/sdk/src/main/kotlin/com/crobox/sdk/domain/PromotionContent.kt index 1dda038..401979c 100644 --- a/sdk/src/main/kotlin/com/crobox/sdk/domain/PromotionContent.kt +++ b/sdk/src/main/kotlin/com/crobox/sdk/domain/PromotionContent.kt @@ -25,14 +25,29 @@ data class PromotionContent( * Component Name */ @SerializedName("component") - val component: String + val componentName: String ) { + /** + * Returns component if an Image or Text Badge is available + */ + val contentConfig: PromotionContentConfig? = + when { + config.containsKey("image") -> getImageBadge() + config.containsKey("text") -> getTextBadge() + else -> null + } + + /** + * Returns Badge type + */ + val promotionType: PromotionContentType? = contentConfig?.contentType + /** * Returns an Image Badge if an image component exists with the following pre-defined keys: "image" and "altText" */ fun getImageBadge(): ImageBadge? { - return config["image"]?.let { ImageBadge(it, config["altText"]) } + return config["image"]?.let { ImageBadge(it, config["altText"], componentName) } } /** @@ -40,9 +55,14 @@ data class PromotionContent( */ fun getTextBadge(): TextBadge? { return config["text"]?.let { text -> - config["fontColor"]?.let { fontColor -> - TextBadge(text, fontColor, config["backgroundColor"], config["borderColor"]) - } + TextBadge( + text, + config["fontColor"], + config["backgroundColor"], + config["borderColor"], + componentName + ) + } } } diff --git a/sdk/src/main/kotlin/com/crobox/sdk/presenter/CroboxAPIPresenter.kt b/sdk/src/main/kotlin/com/crobox/sdk/presenter/CroboxAPIPresenter.kt index 816a87e..02729b8 100644 --- a/sdk/src/main/kotlin/com/crobox/sdk/presenter/CroboxAPIPresenter.kt +++ b/sdk/src/main/kotlin/com/crobox/sdk/presenter/CroboxAPIPresenter.kt @@ -15,7 +15,6 @@ import com.crobox.sdk.data.model.PageViewParams import com.crobox.sdk.data.model.ProductParams import com.crobox.sdk.data.model.PurchaseParams import com.crobox.sdk.data.model.RequestQueryParams -import com.crobox.sdk.domain.BaseResponse import com.crobox.sdk.domain.PromotionsResponse import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.RequestBody @@ -76,9 +75,9 @@ internal class CroboxAPIPresenter(private val config: CroboxConfig) { val parameters = eventQuery(queryParams, additionalParams, eventType) val stringParameters = parameters.mapValues { it.value.toString() } - apiInterface.event(stringParameters).enqueue(object : Callback { + apiInterface.event(stringParameters).enqueue(object : Callback { override fun onResponse( - call: Call, response: Response + call: Call, response: Response ) { try { if (!response.isSuccessful) { @@ -89,7 +88,7 @@ internal class CroboxAPIPresenter(private val config: CroboxConfig) { } } - override fun onFailure(call: Call, t: Throwable) { + override fun onFailure(call: Call, t: Throwable) { CroboxDebug.eventError(t.message.toString()) } })