-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add identity module and file storage (#8)
* feat: add identity module and file storage
- Loading branch information
1 parent
4a4ff66
commit 8b7bada
Showing
27 changed files
with
736 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,31 @@ | ||
package com.amplitude.core | ||
|
||
import com.amplitude.core.platform.ObservePlugin | ||
|
||
class State { | ||
var userId: String? = null | ||
set(value: String?) { | ||
userId = value | ||
plugins.forEach { plugin -> | ||
plugin.onUserIdChanged(value) | ||
} | ||
} | ||
|
||
var deviceId: String? = null | ||
set(value: String?) { | ||
deviceId = value | ||
plugins.forEach { plugin -> | ||
plugin.onDeviceIdChanged(value) | ||
} | ||
} | ||
|
||
val plugins: MutableList<ObservePlugin> = mutableListOf() | ||
|
||
fun add(plugin: ObservePlugin) = synchronized(plugins) { | ||
plugins.add(plugin) | ||
} | ||
|
||
} | ||
fun remove(plugin: ObservePlugin) = synchronized(plugins) { | ||
plugins.removeAll { it === plugin } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
core/src/main/java/com/amplitude/core/utilities/AnalyticsIdentityListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.amplitude.core.utilities | ||
|
||
import com.amplitude.core.State | ||
import com.amplitude.id.Identity | ||
import com.amplitude.id.IdentityListener | ||
import com.amplitude.id.IdentityUpdateType | ||
|
||
class AnalyticsIdentityListener(private val state: State) : IdentityListener { | ||
|
||
override fun onUserIdChange(userId: String?) { | ||
state.userId = userId | ||
} | ||
|
||
override fun onDeviceIdChange(deviceId: String?) { | ||
state.deviceId = deviceId | ||
} | ||
|
||
override fun onIdentityChanged(identity: Identity, updateType: IdentityUpdateType) { | ||
if (updateType == IdentityUpdateType.Initialized) { | ||
state.userId = identity.userId | ||
state.deviceId = identity.deviceId | ||
// TODO("update device id based on configuration") | ||
} | ||
} | ||
} |
Oops, something went wrong.