Skip to content

Commit 2a90d5b

Browse files
author
Alexandra Batanova
committed
save status of initialize
1 parent 07748d2 commit 2a90d5b

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

mobile-sdk/src/main/java/cloud/mindbox/mobile_sdk/Mindbox.kt

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package cloud.mindbox.mobile_sdk
22

33
import android.content.Context
44
import com.orhanobut.hawk.Hawk
5-
import kotlinx.coroutines.*
5+
import kotlinx.coroutines.CoroutineScope
66
import kotlinx.coroutines.Dispatchers.Default
7+
import kotlinx.coroutines.Job
8+
import kotlinx.coroutines.async
9+
import kotlinx.coroutines.launch
710

811
object Mindbox {
912

@@ -16,7 +19,12 @@ object Mindbox {
1619

1720
Hawk.init(context).build()
1821
mindboxScope.launch {
19-
initializeSdk(context, callback)
22+
if (MindboxPreferences.isFirstInitialize) {
23+
firstInitialize(context, callback)
24+
MindboxPreferences.isFirstInitialize = false
25+
} else {
26+
secondaryInitialize()
27+
}
2028
}
2129
}
2230

@@ -28,14 +36,22 @@ object Mindbox {
2836
return MindboxPreferences.firebaseToken
2937
}
3038

31-
private suspend fun initializeSdk(context: Context, callback: (String?, String?) -> Unit) {
39+
private suspend fun firstInitialize(context: Context, callback: (String?, String?) -> Unit) {
3240
val firebaseToken = mindboxScope.async { IdentifierManager.getFirebaseToken() }
3341
val adid = mindboxScope.async { IdentifierManager.getAdsIdentification(context) }
3442

3543
registerClient(firebaseToken.await(), adid.await(), callback)
3644
}
3745

38-
private fun registerClient(firebaseToken: String?, deviceUuid: String?, callback: (String?, String?) -> Unit) {
46+
private suspend fun secondaryInitialize() {
47+
48+
}
49+
50+
private fun registerClient(
51+
firebaseToken: String?,
52+
deviceUuid: String?,
53+
callback: (String?, String?) -> Unit
54+
) {
3955
callback.invoke(firebaseToken, deviceUuid)
4056
}
4157

mobile-sdk/src/main/java/cloud/mindbox/mobile_sdk/MindboxPreferences.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ import com.orhanobut.hawk.Hawk
44

55
internal object MindboxPreferences {
66

7+
private const val KEY_IS_FIRST_INITIALIZATION = "key_is_first_initialization"
78
private const val KEY_USER_ADID = "key_user_uuid"
89
private const val KEY_INSTALLATION_ID = "key_installation_id"
910
private const val KEY_FIREBASE_TOKEN = "key_firebase_token"
1011

12+
var isFirstInitialize: Boolean
13+
get() = Hawk.get(KEY_IS_FIRST_INITIALIZATION, true)
14+
set(value) {
15+
Hawk.put(KEY_IS_FIRST_INITIALIZATION, value)
16+
}
17+
1118
var userAdid: String?
1219
get() = Hawk.get(KEY_USER_ADID, null)
1320
set(value) {

0 commit comments

Comments
 (0)