Skip to content

Commit

Permalink
Merge branch 'master' into feat/add-gaid-support
Browse files Browse the repository at this point in the history
  • Loading branch information
comfrt1k committed Jan 10, 2025
2 parents 242ad48 + 5d68371 commit ddc4352
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 5 deletions.
2 changes: 1 addition & 1 deletion personalization-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
id 'kotlin-kapt'
}

version='2.0.49'
version='2.0.50'

android {
compileSdkVersion 34
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.personalization.api.managers.ProductsManager
import com.personalization.api.managers.RecommendationManager
import com.personalization.api.managers.SearchManager
import com.personalization.api.managers.TrackEventManager
import com.personalization.api.params.ProfileParams
import com.personalization.di.AppModule
import com.personalization.di.DaggerSdkComponent
import com.personalization.features.notification.data.mapper.toNotificationData
Expand Down Expand Up @@ -222,8 +223,8 @@ open class SDK {
*
* @param data profile data
*/
fun profile(data: HashMap<String, String>, listener: OnApiCallbackListener? = null) {
sendAsync(SET_PROFILE_FIELD, JSONObject(data.toMap()), listener)
fun profile(data: ProfileParams, listener: OnApiCallbackListener? = null) {
sendAsync(SET_PROFILE_FIELD, data.toJson(), listener)
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.personalization.api.params

import org.json.JSONObject
import java.util.Date

//TODO use data loader
class ProfileParams private constructor(
private val params: JSONObject = JSONObject()
) {

class Builder {

private val params: JSONObject = JSONObject()

fun put(param: String, value: String): Builder {
params.put(param, value)
return this
}

fun put(param: String, value: Int): Builder {
params.put(param, value)
return this
}

fun put(param: String, value: Float): Builder {
params.put(param, value)
return this
}

fun put(param: String, value: Date): Builder {
params.put(param, value)
return this
}

fun put(param: String, value: Boolean): Builder {
params.put(param, value)
return this
}

fun put(param: String, value: JSONObject): Builder {
params.put(param, value)
return this
}

fun put(param: String, value: Array<String>): Builder {
params.put(param, value)
return this
}

fun put(param: String, value: Array<Int>): Builder {
params.put(param, value)
return this
}

fun put(param: String, value: Array<Float>): Builder {
params.put(param, value)
return this
}

fun put(param: String, value: Array<Date>): Builder {
params.put(param, value)
return this
}

fun put(param: String, value: Array<Boolean>): Builder {
params.put(param, value)
return this
}

fun put(param: String, value: Array<JSONObject>): Builder {
params.put(param, value)
return this
}

fun build(): ProfileParams {
return ProfileParams(params)
}
}

fun toJson(): JSONObject = params
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.core.app.ActivityCompat
import com.personalization.OnClickListener
import com.personalization.Product
import com.personalization.SDK
import com.personalization.api.params.ProfileParams
import com.personalization.stories.views.StoriesView

abstract class AbstractMainActivity<out T : SDK> internal constructor(
Expand Down Expand Up @@ -71,8 +72,9 @@ abstract class AbstractMainActivity<out T : SDK> internal constructor(

button.setOnClickListener {
if (emailEditText.text.toString().isNotEmpty()) {
val params = HashMap<String, String>()
params["email"] = emailEditText.text.toString()
val params = ProfileParams.Builder()
.put("email", emailEditText.toString())
.build()
sdk.profile(params)
Toast.makeText(applicationContext, "Email sent", Toast.LENGTH_LONG).show()
}
Expand Down

0 comments on commit ddc4352

Please sign in to comment.