@@ -6,20 +6,22 @@ import com.segment.analytics.kotlin.android.utilities.AndroidKVS
6
6
import com.segment.analytics.kotlin.core.Analytics
7
7
import com.segment.analytics.kotlin.core.Storage
8
8
import com.segment.analytics.kotlin.core.StorageProvider
9
+ import com.segment.analytics.kotlin.core.utilities.EventStream
9
10
import com.segment.analytics.kotlin.core.utilities.FileEventStream
11
+ import com.segment.analytics.kotlin.core.utilities.KVS
10
12
import com.segment.analytics.kotlin.core.utilities.StorageImpl
11
13
import kotlinx.coroutines.CoroutineDispatcher
12
14
import sovran.kotlin.Store
13
15
14
16
@Deprecated(" Use StorageProvider to create storage for Android instead" )
15
17
class AndroidStorage (
16
18
context : Context ,
17
- private val store : Store ,
19
+ store : Store ,
18
20
writeKey : String ,
19
- private val ioDispatcher : CoroutineDispatcher ,
21
+ ioDispatcher : CoroutineDispatcher ,
20
22
directory : String? = null ,
21
23
subject : String? = null
22
- ) : StorageImpl (
24
+ ) : AndroidStorageImpl (
23
25
propertiesFile = AndroidKVS (context.getSharedPreferences("analytics-android-$writeKey", Context .MODE_PRIVATE )),
24
26
eventStream = FileEventStream (context.getDir(directory ? : "segment-disk-queue", Context .MODE_PRIVATE )),
25
27
store = store,
@@ -28,6 +30,38 @@ class AndroidStorage(
28
30
ioDispatcher = ioDispatcher
29
31
)
30
32
33
+ open class AndroidStorageImpl (
34
+ propertiesFile : KVS ,
35
+ eventStream : EventStream ,
36
+ store : Store ,
37
+ writeKey : String ,
38
+ fileIndexKey : String ,
39
+ ioDispatcher : CoroutineDispatcher
40
+ ) : StorageImpl(
41
+ propertiesFile = propertiesFile,
42
+ eventStream = eventStream,
43
+ store = store,
44
+ writeKey = writeKey,
45
+ fileIndexKey = fileIndexKey,
46
+ ioDispatcher = ioDispatcher
47
+ ) {
48
+ override fun read (key : Storage .Constants ): String? {
49
+ return if (key == Storage .Constants .LegacyAppBuild ) {
50
+ // The legacy app build number was stored as an integer so we have to get it
51
+ // as an integer and convert it to a String.
52
+ val noBuild = - 1
53
+ val build = propertiesFile.get(key.rawVal, noBuild)
54
+ if (build != noBuild) {
55
+ build.toString()
56
+ } else {
57
+ null
58
+ }
59
+ } else {
60
+ super .read(key)
61
+ }
62
+ }
63
+ }
64
+
31
65
object AndroidStorageProvider : StorageProvider {
32
66
override fun createStorage (vararg params : Any ): Storage {
33
67
@@ -51,6 +85,6 @@ object AndroidStorageProvider : StorageProvider {
51
85
52
86
val propertiesFile = AndroidKVS (sharedPreferences)
53
87
val eventStream = FileEventStream (eventDirectory)
54
- return StorageImpl (propertiesFile, eventStream, analytics.store, config.writeKey, fileIndexKey, analytics.fileIODispatcher)
88
+ return AndroidStorageImpl (propertiesFile, eventStream, analytics.store, config.writeKey, fileIndexKey, analytics.fileIODispatcher)
55
89
}
56
90
}
0 commit comments