-
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.
improve: save user details in sample app cache
- Loading branch information
1 parent
ba3946f
commit f0a7339
Showing
5 changed files
with
51 additions
and
65 deletions.
There are no files selected for viewing
44 changes: 36 additions & 8 deletions
44
test/src/main/java/com/rakuten/test/AppUserInfoProvider.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 |
---|---|---|
@@ -1,16 +1,44 @@ | ||
package com.rakuten.test | ||
|
||
import android.content.Context | ||
import com.rakuten.tech.mobile.inappmessaging.runtime.UserInfoProvider | ||
import com.rakuten.tech.mobile.sdkutils.PreferencesUtil | ||
|
||
class AppUserInfoProvider : UserInfoProvider { | ||
|
||
var userId = "" | ||
var accessToken = "" | ||
var idTracking = "" | ||
class AppUserInfoProvider(private val context: Context) : UserInfoProvider { | ||
|
||
override fun provideAccessToken() = accessToken | ||
override fun provideAccessToken(): String { | ||
if (!isIdTracking()) { | ||
return PreferencesUtil.getString(context, SHARED_FILE, TOKEN_OR_ID_TRACKING, "").orEmpty() | ||
} | ||
return "" | ||
} | ||
|
||
override fun provideUserId(): String { | ||
return PreferencesUtil.getString(context, SHARED_FILE, USER_ID, "").orEmpty() | ||
} | ||
|
||
override fun provideIdTrackingIdentifier(): String { | ||
if (isIdTracking()) { | ||
return PreferencesUtil.getString(context, SHARED_FILE, TOKEN_OR_ID_TRACKING, "").orEmpty() | ||
} | ||
return "" | ||
} | ||
|
||
fun isIdTracking(): Boolean { | ||
return PreferencesUtil.getBoolean(context, SHARED_FILE, IS_ID_TRACKING, true) | ||
} | ||
|
||
override fun provideUserId() = userId | ||
fun saveUser(userId: String, tokenOrIdTracking: String, isIdTracking: Boolean) { | ||
PreferencesUtil.clear(context, SHARED_FILE) | ||
PreferencesUtil.putString(context, SHARED_FILE, USER_ID, userId) | ||
PreferencesUtil.putString(context, SHARED_FILE, TOKEN_OR_ID_TRACKING, tokenOrIdTracking) | ||
PreferencesUtil.putBoolean(context, SHARED_FILE, IS_ID_TRACKING, isIdTracking) | ||
} | ||
|
||
override fun provideIdTrackingIdentifier() = idTracking | ||
companion object { | ||
private const val USER_ID: String = "user-id" | ||
private const val SHARED_FILE: String = "user-shared-file" | ||
private const val TOKEN_OR_ID_TRACKING: String = "token-or-id-tracking" | ||
private const val IS_ID_TRACKING: String = "is-id-tracking" | ||
} | ||
} |
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