Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions library/src/main/java/io/constructor/core/ConstructorIo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,25 @@ object ConstructorIo {
*/
fun getSessionId() = preferenceHelper.getSessionId()

/**
* Sets the sessionId
*/
fun setSessionId(sessionId: Int) {
preferenceHelper.setSessionId(sessionId);
}

/**
* Returns the current client identifier (a random GUID assigned to the app running on the device)
*/
fun getClientId() = preferenceHelper.id

/**
* Sets the clientId
*/
fun setClientId(clientId: String) {
preferenceHelper.id = clientId;
}

internal fun testInit(context: Context?, constructorIoConfig: ConstructorIoConfig, dataManager: DataManager, preferenceHelper: PreferencesHelper, configMemoryHolder: ConfigMemoryHolder) {
if (context == null) {
throw IllegalStateException("Context is null, please init library using ConstructorIo.with(context)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ constructor(@ConstructorSdk val preferences: SharedPreferences) {
return preferences.getInt(SESSION_ID, 1)
}

fun setSessionId(sessionId: Int) {
preferences.edit().putInt(SESSION_ID, sessionId).apply()
}

internal fun resetSession(sessionIncrementAction: ((String) -> Unit)?): Int {
val sessionId = 1
preferences.edit().putInt(SESSION_ID, sessionId).apply()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class PreferencesHelperTest {
assertEquals(1, preferencesHelper.getSessionId())
}

@Test
fun saveAndRetrieveSessionId() {
preferencesHelper.setSessionId(123);
assertEquals(123, preferencesHelper.getSessionId())
}

@Test
fun getSessionIdAfter30Minutes() {
preferencesHelper.resetSession(null)
Expand Down