Skip to content

Commit

Permalink
moshi to kotlin serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahroz16 committed Oct 16, 2023
1 parent c3ee83f commit aad9a11
Show file tree
Hide file tree
Showing 34 changed files with 448 additions and 343 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import okhttp3.mockwebserver.SocketPolicy

fun <F : Any> F.toResponseBody(jsonAdapter: JsonAdapter): ResponseBody {
inline fun <reified F : Any> F.toResponseBody(jsonAdapter: JsonAdapter): ResponseBody {
return jsonAdapter.toJson(this).toResponseBody("application/json".toMediaType())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import dagger.hilt.android.HiltAndroidApp
import io.customer.android.sample.kotlin_compose.data.models.setValuesFromBuilder
import io.customer.android.sample.kotlin_compose.data.repositories.PreferenceRepository
import io.customer.android.sample.kotlin_compose.data.sdk.InAppMessageEventListener
import io.customer.datapipeline.DataPipelineModuleConfig
import io.customer.datapipeline.ModuleDataPipeline
import io.customer.messaginginapp.MessagingInAppModuleConfig
import io.customer.messaginginapp.ModuleMessagingInApp
import io.customer.messagingpush.ModuleMessagingPushFCM
Expand Down Expand Up @@ -41,11 +39,6 @@ class MainApplication : Application() {
)
)
addCustomerIOModule(ModuleMessagingPushFCM())
addCustomerIOModule(
ModuleDataPipeline(
DataPipelineModuleConfig.Builder("API-KEY").build()
)
)

build()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.customer.android.sample.kotlin_compose.data.sdk

import io.customer.android.sample.kotlin_compose.util.Logger
import io.customer.datapipeline.di.dataPipeline
import io.customer.messaginginapp.type.InAppEventListener
import io.customer.messaginginapp.type.InAppMessage
import io.customer.sdk.CustomerIO
Expand Down Expand Up @@ -52,7 +51,7 @@ class InAppMessageEventListener(private val logger: Logger = Logger()) : InAppEv
message: InAppMessage,
arguments: Map<String, String>?
) {
CustomerIO.instance().dataPipeline().track(
CustomerIO.instance().track(
"in-app message action",
HashMap<String, String>().apply {
arguments?.let { putAll(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import io.customer.android.sample.kotlin_compose.ui.components.ActionButton
import io.customer.android.sample.kotlin_compose.ui.components.BackButton
import io.customer.android.sample.kotlin_compose.ui.components.HeaderText
import io.customer.android.sample.kotlin_compose.ui.components.TrackScreenLifecycle
import io.customer.datapipeline.di.dataPipeline
import io.customer.sdk.CustomerIO
import kotlinx.coroutines.launch

Expand All @@ -46,7 +45,7 @@ fun CustomAttributeRoute(
val context = LocalContext.current

TrackScreenLifecycle(lifecycleOwner = LocalLifecycleOwner.current, onScreenEnter = {
CustomerIO.instance().dataPipeline()
CustomerIO.instance()
.screen("Custom ${attributeType.replaceFirstChar { it.uppercase() }} Attribute")
})

Expand Down Expand Up @@ -99,7 +98,7 @@ fun CustomAttributeRoute(
Pair(
stringResource(R.string.send_profile_attribute)
) {
CustomerIO.instance().dataPipeline().identify(mapOf(attributeName to attributeValue))
CustomerIO.instance().identify("", mapOf(attributeName to attributeValue))
}
} else {
Pair(stringResource(R.string.send_device_attribute)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import io.customer.android.sample.kotlin_compose.ui.components.ActionButton
import io.customer.android.sample.kotlin_compose.ui.components.BackButton
import io.customer.android.sample.kotlin_compose.ui.components.HeaderText
import io.customer.android.sample.kotlin_compose.ui.components.TrackScreenLifecycle
import io.customer.datapipeline.di.dataPipeline
import io.customer.sdk.CustomerIO
import kotlinx.coroutines.launch

Expand All @@ -45,7 +44,7 @@ fun CustomEventRoute(
val context = LocalContext.current

TrackScreenLifecycle(lifecycleOwner = LocalLifecycleOwner.current, onScreenEnter = {
CustomerIO.instance().dataPipeline().screen("Custom Event")
CustomerIO.instance().screen("Custom Event")
})

Column(
Expand Down Expand Up @@ -102,9 +101,9 @@ fun CustomEventRoute(
text = stringResource(R.string.send_event),
modifier = Modifier.testTag(stringResource(id = R.string.acd_send_event_button)),
onClick = {
CustomerIO.instance().dataPipeline().track(
CustomerIO.instance().track(
name = eventName,
properties = if (propertyName.isEmpty()) emptyMap() else mapOf(propertyName to propertyValue)
attributes = if (propertyName.isEmpty()) emptyMap() else mapOf(propertyName to propertyValue)
)
scope.launch {
snackbarHostState.showSnackbar(message = context.getString(R.string.event_sent_successfully))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import io.customer.android.sample.kotlin_compose.ui.components.HeaderText
import io.customer.android.sample.kotlin_compose.ui.components.SettingsIcon
import io.customer.android.sample.kotlin_compose.ui.components.TrackScreenLifecycle
import io.customer.android.sample.kotlin_compose.ui.components.VersionText
import io.customer.datapipeline.di.dataPipeline
import io.customer.sdk.CustomerIO
import kotlinx.coroutines.launch

Expand All @@ -46,7 +45,7 @@ fun DashboardRoute(
val userState = viewModel.uiState.collectAsState()

TrackScreenLifecycle(lifecycleOwner = LocalLifecycleOwner.current, onScreenEnter = {
CustomerIO.instance().dataPipeline().screen("Dashboard")
CustomerIO.instance().screen("Dashboard")
})

DashboardScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import io.customer.android.sample.kotlin_compose.data.models.User
import io.customer.android.sample.kotlin_compose.data.repositories.UserRepository
import io.customer.datapipeline.di.dataPipeline
import io.customer.sdk.CustomerIO
import java.util.Calendar
import java.util.Random
Expand Down Expand Up @@ -47,19 +46,19 @@ class DashboardViewModel @Inject constructor(
fun sendRandomEvent() {
when (Random().nextInt(2)) {
0 -> {
CustomerIO.instance().dataPipeline().track("Order Purchased")
CustomerIO.instance().track("Order Purchased")
}

1 -> {
val attributes = mapOf("movie_name" to "The Incredibles")
CustomerIO.instance().dataPipeline().track("movie_watched", attributes)
CustomerIO.instance().track("movie_watched", attributes)
}

2 -> {
val sevenDaysLater =
Calendar.getInstance().apply { add(Calendar.DAY_OF_YEAR, 7) }.time
val attributes = mapOf("appointmentTime" to sevenDaysLater)
CustomerIO.instance().dataPipeline().track("appointmentScheduled", attributes)
CustomerIO.instance().track("appointmentScheduled", attributes)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import io.customer.android.sample.kotlin_compose.ui.components.HeaderText
import io.customer.android.sample.kotlin_compose.ui.components.SettingsIcon
import io.customer.android.sample.kotlin_compose.ui.components.TrackScreenLifecycle
import io.customer.android.sample.kotlin_compose.ui.components.VersionText
import io.customer.datapipeline.di.dataPipeline
import io.customer.sdk.CustomerIO

@Composable
Expand All @@ -47,7 +46,7 @@ fun LoginRoute(
TrackScreenLifecycle(
lifecycleOwner = LocalLifecycleOwner.current,
onScreenEnter = {
CustomerIO.instance().dataPipeline().screen("Login")
CustomerIO.instance().screen("Login")
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import io.customer.android.sample.kotlin_compose.R
import io.customer.android.sample.kotlin_compose.data.models.User
import io.customer.android.sample.kotlin_compose.data.repositories.UserRepository
import io.customer.datapipeline.di.dataPipeline
import io.customer.sdk.CustomerIO
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -67,15 +66,15 @@ class LoginViewModel @Inject constructor(
identifier = email,
attributes = mapOf("name" to name, "is_guest" to isGuest, "cio_source" to "track API")
)
CustomerIO.instance().dataPipeline().identify(
userId = email,
traits = mapOf("name" to name, "is_guest" to isGuest, "cio_source" to "data pipeline")
CustomerIO.instance().identify(
identifier = email,
attributes = mapOf("name" to name, "is_guest" to isGuest, "cio_source" to "data pipeline")
)
CustomerIO.instance().dataPipeline().track(
CustomerIO.instance().track(
name = "login",
properties = mapOf("name" to name, "email" to email)
attributes = mapOf("name" to name, "email" to email)
)
CustomerIO.instance().dataPipeline().group("kotlin-data-pipeline")
// CustomerIO.instance().group("kotlin-data-pipeline")
withContext(Dispatchers.Main) {
onLoginSuccess.invoke()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import androidx.hilt.navigation.compose.hiltViewModel
import io.customer.android.sample.kotlin_compose.R
import io.customer.android.sample.kotlin_compose.data.models.Configuration
import io.customer.android.sample.kotlin_compose.ui.components.TrackScreenLifecycle
import io.customer.datapipeline.di.dataPipeline
import io.customer.sdk.CustomerIO

@Composable
Expand All @@ -62,7 +61,7 @@ fun SettingsRoute(
val state by settingsViewModel.uiState.collectAsState()

TrackScreenLifecycle(lifecycleOwner = LocalLifecycleOwner.current, onScreenEnter = {
CustomerIO.instance().dataPipeline().screen("Settings")
CustomerIO.instance().screen("Settings")
})

SettingsScreen(
Expand Down
31 changes: 23 additions & 8 deletions sdk/api/sdk.api
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,17 @@ public final class io/customer/sdk/CustomerIOShared$Companion {
}

public final class io/customer/sdk/data/model/EventType : java/lang/Enum {
public static final field Companion Lio/customer/sdk/data/model/EventType$Companion;
public static final field event Lio/customer/sdk/data/model/EventType;
public static final field screen Lio/customer/sdk/data/model/EventType;
public static fun valueOf (Ljava/lang/String;)Lio/customer/sdk/data/model/EventType;
public static fun values ()[Lio/customer/sdk/data/model/EventType;
}

public final class io/customer/sdk/data/model/EventType$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public abstract class io/customer/sdk/data/model/Region {
public static final field Companion Lio/customer/sdk/data/model/Region$Companion;
public synthetic fun <init> (Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
Expand All @@ -192,6 +197,8 @@ public final class io/customer/sdk/data/model/Region$US : io/customer/sdk/data/m
}

public final class io/customer/sdk/data/request/Device {
public static final field Companion Lio/customer/sdk/data/request/Device$Companion;
public synthetic fun <init> (ILjava/lang/String;Ljava/lang/String;Ljava/util/Date;Ljava/util/Map;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/util/Date;Ljava/util/Map;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/util/Date;Ljava/util/Map;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/lang/String;
Expand All @@ -207,15 +214,22 @@ public final class io/customer/sdk/data/request/Device {
public final fun getToken ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
public static final fun write$Self (Lio/customer/sdk/data/request/Device;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V
}

public final class io/customer/sdk/data/request/DeviceJsonAdapter : com/squareup/moshi/JsonAdapter {
public fun <init> (Lcom/squareup/moshi/Moshi;)V
public fun fromJson (Lcom/squareup/moshi/JsonReader;)Lio/customer/sdk/data/request/Device;
public synthetic fun fromJson (Lcom/squareup/moshi/JsonReader;)Ljava/lang/Object;
public fun toJson (Lcom/squareup/moshi/JsonWriter;Lio/customer/sdk/data/request/Device;)V
public synthetic fun toJson (Lcom/squareup/moshi/JsonWriter;Ljava/lang/Object;)V
public fun toString ()Ljava/lang/String;
public final class io/customer/sdk/data/request/Device$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
public static final field INSTANCE Lio/customer/sdk/data/request/Device$$serializer;
public fun childSerializers ()[Lkotlinx/serialization/KSerializer;
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lio/customer/sdk/data/request/Device;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lio/customer/sdk/data/request/Device;)V
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
}

public final class io/customer/sdk/data/request/Device$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public final class io/customer/sdk/data/request/MetricEvent : java/lang/Enum {
Expand All @@ -230,6 +244,7 @@ public final class io/customer/sdk/data/request/MetricEvent : java/lang/Enum {

public final class io/customer/sdk/data/request/MetricEvent$Companion {
public final fun getEvent (Ljava/lang/String;)Lio/customer/sdk/data/request/MetricEvent;
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public abstract interface class io/customer/sdk/device/DeviceTokenProvider {
Expand All @@ -249,7 +264,7 @@ public final class io/customer/sdk/di/CustomerIOComponent : io/customer/sdk/di/D
public final fun getHooksManager ()Lio/customer/sdk/hooks/HooksManager;
public final fun getJsonAdapter ()Lio/customer/sdk/util/JsonAdapter;
public final fun getLogger ()Lio/customer/sdk/util/Logger;
public final fun getMoshi ()Lcom/squareup/moshi/Moshi;
public final fun getModule ()Lkotlinx/serialization/modules/SerializersModule;
public final fun getProfileRepository ()Lio/customer/sdk/repository/ProfileRepository;
public final fun getQueue ()Lio/customer/sdk/queue/Queue;
public final fun getQueueQueryRunner ()Lio/customer/sdk/queue/QueueQueryRunner;
Expand Down
12 changes: 6 additions & 6 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import io.customer.android.Dependencies
plugins {
id 'com.android.library'
id 'kotlin-android'
id "org.jetbrains.kotlin.kapt"
id 'org.jetbrains.kotlin.plugin.serialization' version '1.7.10'
}

ext {
Expand Down Expand Up @@ -59,13 +59,13 @@ dependencies {
implementation Dependencies.coroutinesCore
implementation Dependencies.coroutinesAndroid
implementation Dependencies.retrofit
implementation Dependencies.moshi
implementation Dependencies.retrofitMoshiConverter
implementation Dependencies.okhttpLoggingInterceptor
api Dependencies.androidxCoreKtx
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.1")

kapt(Dependencies.moshiCodeGen)
kaptTest(Dependencies.moshiCodeGen)
kaptAndroidTest(Dependencies.moshiCodeGen)

implementation("com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0") // check for the latest version
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-core:1.5.1'
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1'
}

4 changes: 2 additions & 2 deletions sdk/src/main/java/io/customer/sdk/data/model/EventType.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.customer.sdk.data.model

import com.squareup.moshi.JsonClass
import kotlinx.serialization.Serializable

@JsonClass(generateAdapter = false)
@Serializable
enum class EventType {
event, screen
}

This file was deleted.

Loading

0 comments on commit aad9a11

Please sign in to comment.