-
Notifications
You must be signed in to change notification settings - Fork 9
/
MainActivity.kt
118 lines (103 loc) · 3.74 KB
/
MainActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package io.customer.example
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import io.customer.base.comunication.Action
import io.customer.base.data.ErrorResult
import io.customer.base.data.Success
import io.customer.sdk.CustomerIO
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.util.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// there are two ways to identify customer
// 1st way
makeSynchronousRequest()
// 2nd way
// makeAsynchronousRequest()
// log events
// makeEventsRequests()
// add custom attributes
makeAddCustomDeviceAttributesRequest()
// register device
makeRegisterDeviceRequest()
}
private fun makeAddCustomDeviceAttributesRequest() {
CustomerIO.instance().deviceAttributes.putAll(mapOf("bingo" to "heyaa"))
}
private fun makeRegisterDeviceRequest() {
CustomerIO.instance().registerDeviceToken("token").enqueue(outputCallback)
}
private val outputCallback = Action.Callback<Unit> { result ->
when (result) {
is ErrorResult -> Log.v("ErrorResult", result.error.getDisplayMessage())
is Success -> Log.v("Success", "Success")
}
}
data class Fol(val a: String, val c: Int)
private fun makeEventsRequests() {
CustomerIO.instance().track(
name = "string event",
attributes = mapOf(
"value" to "string test",
"target" to 1
)
).enqueue(outputCallback)
CustomerIO.instance().track(
name = "int event",
attributes = mapOf("value" to 1388377266772)
).enqueue(outputCallback)
CustomerIO.instance().track(
name = "long event",
attributes = mapOf("value" to 1653L)
).enqueue(outputCallback)
CustomerIO.instance().track(
name = "double event",
attributes = mapOf("value" to 133333.882)
).enqueue(outputCallback)
CustomerIO.instance().track(
name = "array event",
attributes = mapOf("value" to listOf("1", "2"))
).enqueue(outputCallback)
CustomerIO.instance().track(
name = "date event",
attributes = mapOf("value" to Date())
).enqueue(outputCallback)
CustomerIO.instance().track(
name = "timestamp event",
attributes = mapOf("value" to Date().time)
).enqueue(outputCallback)
CustomerIO.instance().track(
name = "custom class event",
attributes = mapOf("value" to Fol(a = "aa", c = 1))
).enqueue(outputCallback)
CustomerIO.instance().screen(
name = "MainActivity"
).enqueue(outputCallback)
}
private fun makeAsynchronousRequest() {
CustomerIO.instance()
.identify(
identifier = "identifier",
attributes = mapOf("email" to "testemail@email.com")
).enqueue(outputCallback)
}
private fun makeSynchronousRequest() {
CoroutineScope(Dispatchers.IO).launch {
when (
val result =
CustomerIO.instance().identify(
identifier = "device-attri",
mapOf("created_at" to 1642659790)
).execute()
) {
is ErrorResult -> Log.v("ErrorResult", result.error.cause.toString())
is Success -> Log.v("Success", "Success")
}
}
}
}