Skip to content

Commit

Permalink
Merge pull request #28 from crobox/components
Browse files Browse the repository at this point in the history
Conveniences for retrieving Text and Image badges
  • Loading branch information
toztemel authored Jul 24, 2024
2 parents 86bdf18 + afba968 commit b4b93c7
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 60 deletions.
2 changes: 1 addition & 1 deletion app/src/main/kotlin/com/crobox/sdk/testapp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
Expand Down
6 changes: 3 additions & 3 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
3 changes: 1 addition & 2 deletions sdk/src/main/kotlin/com/crobox/sdk/data/api/CroboxAPI.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,5 +15,5 @@ internal interface CroboxAPI {
): Call<PromotionsResponse?>?

@GET("/socket.gif")
fun event(@QueryMap options: Map<String, String>): Call<BaseResponse?>
fun event(@QueryMap options: Map<String, String>): Call<Void?>
}
14 changes: 0 additions & 14 deletions sdk/src/main/kotlin/com/crobox/sdk/domain/BaseResponse.kt

This file was deleted.

30 changes: 24 additions & 6 deletions sdk/src/main/kotlin/com/crobox/sdk/domain/Components.kt
Original file line number Diff line number Diff line change
@@ -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?
)
val borderColor: String?,

/// Component name
override val name: String
) : PromotionContentConfig {
override val contentType: PromotionContentType = PromotionContentType.TextBadge
}
30 changes: 25 additions & 5 deletions sdk/src/main/kotlin/com/crobox/sdk/domain/PromotionContent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,44 @@ 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) }
}

/**
* Returns a Text Badge if a text component exists with the following pre-defined keys: "text", "fontColor", "backgroundColor" and "borderColor"
*/
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
)

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<BaseResponse?> {
apiInterface.event(stringParameters).enqueue(object : Callback<Void?> {
override fun onResponse(
call: Call<BaseResponse?>, response: Response<BaseResponse?>
call: Call<Void?>, response: Response<Void?>
) {
try {
if (!response.isSuccessful) {
Expand All @@ -89,7 +88,7 @@ internal class CroboxAPIPresenter(private val config: CroboxConfig) {
}
}

override fun onFailure(call: Call<BaseResponse?>, t: Throwable) {
override fun onFailure(call: Call<Void?>, t: Throwable) {
CroboxDebug.eventError(t.message.toString())
}
})
Expand Down
25 changes: 0 additions & 25 deletions sdk/src/test/java/android/util/Log.java

This file was deleted.

0 comments on commit b4b93c7

Please sign in to comment.