Skip to content

Commit

Permalink
replace utility method
Browse files Browse the repository at this point in the history
  • Loading branch information
Wenxi Zeng committed May 3, 2024
1 parent d33ef6e commit 0f8a78a
Showing 1 changed file with 1 addition and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,10 @@ package com.segment.analytics.destination.filters.app
import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.segment.analytics.kotlin.core.AliasEvent
import com.segment.analytics.kotlin.core.BaseEvent
import com.segment.analytics.kotlin.core.GroupEvent
import com.segment.analytics.kotlin.core.IdentifyEvent
import com.segment.analytics.kotlin.core.ScreenEvent
import com.segment.analytics.kotlin.core.TrackEvent
import com.segment.analytics.kotlin.core.utilities.LenientJson
import com.segment.analytics.kotlin.core.utilities.getString
import com.segment.analytics.kotlin.core.utilities.toBaseEvent
import com.segment.analytics.plugins.DestinationFilters
import com.segment.analytics.substrata.kotlin.JSObject
import com.segment.analytics.substrata.kotlin.JsonElementConverter
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonObject

class TestActivity : AppCompatActivity() {
Expand Down Expand Up @@ -133,17 +125,4 @@ class TestActivity : AppCompatActivity() {

textView.text = testProgress.toString()
}

private fun JsonObject.toBaseEvent(): BaseEvent? {
val type = getString("type")

return when (type) {
"identify" -> LenientJson.decodeFromJsonElement(IdentifyEvent.serializer(), this)
"track" -> LenientJson.decodeFromJsonElement(TrackEvent.serializer(), this)
"screen" -> LenientJson.decodeFromJsonElement(ScreenEvent.serializer(), this)
"group" -> LenientJson.decodeFromJsonElement(GroupEvent.serializer(), this)
"alias" -> LenientJson.decodeFromJsonElement(AliasEvent.serializer(), this)
else -> null
}
}
}

0 comments on commit 0f8a78a

Please sign in to comment.