Skip to content

Commit

Permalink
Release 1.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
cristidregan committed Jun 19, 2024
1 parent dc727f4 commit 7b6568f
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 30 deletions.
2 changes: 1 addition & 1 deletion OmetriaSDK/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
val versionName = "1.7.0"
val versionName = "1.7.1"

plugins {
id("com.android.library")
Expand Down
142 changes: 116 additions & 26 deletions OmetriaSDK/src/main/java/com/android/ometriasdk/core/LocalCache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.content.SharedPreferences
import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKeys
import com.android.ometriasdk.core.Constants.Logger.CACHE
import com.android.ometriasdk.core.event.OmetriaEvent
import com.android.ometriasdk.core.network.toJson
import com.android.ometriasdk.core.network.toOmetriaEventList
Expand Down Expand Up @@ -52,36 +53,59 @@ internal class LocalCache(private val context: Context) {
}

fun saveIsFirstAppRun(isFirstAppRun: Boolean) {
localCacheEncryptedPreferences.edit().putBoolean(IS_FIRST_APP_RUN_KEY, isFirstAppRun)
.apply()
synchronized(this) {
try {
localCacheEncryptedPreferences.edit()
.putBoolean(IS_FIRST_APP_RUN_KEY, isFirstAppRun)
.apply()
} catch (e: Exception) {
Logger.e(CACHE, e.message ?: "Failed to save isFirstAppRun")
}
}
}

fun isFirstAppRun(): Boolean {
return localCacheEncryptedPreferences.getBoolean(IS_FIRST_APP_RUN_KEY, true)
}

fun saveInstallationId(installationId: String?) {
localCacheEncryptedPreferences.edit().putString(INSTALLATION_ID_KEY, installationId).apply()
synchronized(this) {
try {
localCacheEncryptedPreferences.edit()
.putString(INSTALLATION_ID_KEY, installationId)
.apply()
} catch (e: Exception) {
Logger.e(CACHE, e.message ?: "Failed to save installationId")
}
}
}

fun getInstallationId(): String? {
return localCacheEncryptedPreferences.getString(INSTALLATION_ID_KEY, null)
}

fun saveEvent(ometriaEvent: OmetriaEvent) {
val eventsString =
localCacheEncryptedPreferences.getString(EVENTS_KEY, JSON_ARRAY) ?: JSON_ARRAY
val eventsString = localCacheEncryptedPreferences
.getString(EVENTS_KEY, JSON_ARRAY) ?: JSON_ARRAY

val eventsList = eventsString.toOmetriaEventList()

eventsList.add(ometriaEvent)

localCacheEncryptedPreferences.edit().putString(EVENTS_KEY, eventsList.toJson().toString())
.apply()
synchronized(this) {
try {
localCacheEncryptedPreferences.edit()
.putString(EVENTS_KEY, eventsList.toJson().toString())
.apply()
} catch (e: Exception) {
Logger.e(CACHE, e.message ?: "Failed to save event")
}
}
}

fun getEvents(): List<OmetriaEvent> {
val eventsString = localCacheEncryptedPreferences.getString(EVENTS_KEY, null) ?: JSON_ARRAY
val eventsString = localCacheEncryptedPreferences
.getString(EVENTS_KEY, null) ?: JSON_ARRAY

return eventsString.toOmetriaEventList()
}
Expand All @@ -96,9 +120,15 @@ internal class LocalCache(private val context: Context) {
isBeingFlushed
}

localCacheEncryptedPreferences.edit()
.putString(EVENTS_KEY, cachedEvents.toJson().toString())
.apply()
synchronized(this) {
try {
localCacheEncryptedPreferences.edit()
.putString(EVENTS_KEY, cachedEvents.toJson().toString())
.apply()
} catch (e: Exception) {
Logger.e(CACHE, e.message ?: "Failed to update events")
}
}
}

fun removeEvents(eventsToRemove: List<OmetriaEvent>) {
Expand All @@ -108,70 +138,130 @@ internal class LocalCache(private val context: Context) {
eventsList.remove(eventsList.firstOrNull { it.eventId == event.eventId })
}

localCacheEncryptedPreferences.edit().putString(EVENTS_KEY, eventsList.toJson().toString())
.apply()
synchronized(this) {
try {
localCacheEncryptedPreferences.edit()
.putString(EVENTS_KEY, eventsList.toJson().toString())
.apply()
} catch (e: Exception) {
Logger.e(CACHE, e.message ?: "Failed to remove events")
}
}
}

fun savePushToken(pushToken: String) {
localCacheEncryptedPreferences.edit().putString(PUSH_TOKEN_KEY, pushToken).apply()
synchronized(this) {
try {
localCacheEncryptedPreferences.edit().putString(PUSH_TOKEN_KEY, pushToken).apply()
} catch (e: Exception) {
Logger.e(CACHE, e.message ?: "Failed to save pushToken")
}
}
}

fun getPushToken(): String? {
return localCacheEncryptedPreferences.getString(PUSH_TOKEN_KEY, null)
}

fun clearEvents() {
localCacheEncryptedPreferences.edit().remove(EVENTS_KEY).apply()
synchronized(this) {
try {
localCacheEncryptedPreferences.edit().remove(EVENTS_KEY).apply()
} catch (e: Exception) {
Logger.e(CACHE, e.message ?: "Failed to clear events")
}
}
}

fun saveCustomerId(customerId: String?) {
localCacheEncryptedPreferences.edit().putString(CUSTOMER_ID_KEY, customerId).apply()
synchronized(this) {
try {
localCacheEncryptedPreferences.edit().putString(CUSTOMER_ID_KEY, customerId).apply()
} catch (e: Exception) {
Logger.e(CACHE, e.message ?: "Failed to save customerId")
}
}
}

fun getCustomerId(): String? {
return localCacheEncryptedPreferences.getString(CUSTOMER_ID_KEY, null)
}

fun saveEmail(email: String?) {
localCacheEncryptedPreferences.edit().putString(EMAIL_KEY, email).apply()
synchronized(this) {
try {
localCacheEncryptedPreferences.edit().putString(EMAIL_KEY, email).apply()
} catch (e: Exception) {
Logger.e(CACHE, e.message ?: "Failed to save email")
}
}
}

fun getEmail(): String? {
return localCacheEncryptedPreferences.getString(EMAIL_KEY, null)
}

fun clearProfileIdentifiedData() {
localCacheEncryptedPreferences.edit().remove(CUSTOMER_ID_KEY).apply()
localCacheEncryptedPreferences.edit().remove(EMAIL_KEY).apply()
synchronized(this) {
try {
localCacheEncryptedPreferences.edit().remove(CUSTOMER_ID_KEY).apply()
localCacheEncryptedPreferences.edit().remove(EMAIL_KEY).apply()
} catch (e: Exception) {
Logger.e(CACHE, e.message ?: "Failed to clear profile identified data")
}
}
}

fun saveAreNotificationsEnabled(areNotificationsEnabled: Boolean) {
localCacheEncryptedPreferences.edit()
.putBoolean(ARE_NOTIFICATIONS_ENABLED_KEY, areNotificationsEnabled).apply()
synchronized(this) {
try {
localCacheEncryptedPreferences.edit()
.putBoolean(ARE_NOTIFICATIONS_ENABLED_KEY, areNotificationsEnabled)
.apply()
} catch (e: Exception) {
Logger.e(CACHE, e.message ?: "Failed to save areNotificationsEnabled")
}
}
}

fun areNotificationsEnabled(): Boolean {
return localCacheEncryptedPreferences.getBoolean(ARE_NOTIFICATIONS_ENABLED_KEY, true)
}

fun saveIsFirstPermissionsUpdateEvent(isFirstPermissionsUpdateEvent: Boolean) {
localCacheEncryptedPreferences.edit()
.putBoolean(IS_FIRST_PERMISSION_UPDATE_EVENT_KEY, isFirstPermissionsUpdateEvent).apply()
synchronized(this) {
try {
localCacheEncryptedPreferences.edit()
.putBoolean(IS_FIRST_PERMISSION_UPDATE_EVENT_KEY, isFirstPermissionsUpdateEvent)
.apply()
} catch (e: Exception) {
Logger.e(CACHE, e.message ?: "Failed to save isFirstPermissionsUpdateEvent")
}
}
}

fun isFirstPermissionsUpdateEvent(): Boolean {
return localCacheEncryptedPreferences.getBoolean(IS_FIRST_PERMISSION_UPDATE_EVENT_KEY, true)
return localCacheEncryptedPreferences.getBoolean(
IS_FIRST_PERMISSION_UPDATE_EVENT_KEY,
true
)
}

fun getSdkVersionRN(): String? {
return localCacheEncryptedPreferences.getString(SDK_VERSION_RN_KEY, null)
}

fun saveApiToken(apiToken: String) {
localCacheEncryptedPreferences.edit().putString(API_TOKEN_KEY, apiToken).apply()
synchronized(this) {
try {
localCacheEncryptedPreferences.edit().putString(API_TOKEN_KEY, apiToken).apply()
} catch (e: Exception) {
Logger.e(CACHE, e.message ?: "Failed to save apiToken")
}
}
}

fun getApiToken(): String? {
return localCacheEncryptedPreferences.getString(API_TOKEN_KEY, null)
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ To install the library inside **Android Studio**, declare it as dependency in yo

```gradle
dependencies {
implementation 'com.ometria:android-sdk:1.7.0'
implementation 'com.ometria:android-sdk:1.7.1'
}
```

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
applicationId = "com.android.sample"
minSdk = 23
targetSdk = 33
versionCode = 11
versionName = "1.2.0"
versionCode = 12
versionName = "1.3.0"
}
signingConfigs {
getByName("debug") {
Expand Down

0 comments on commit 7b6568f

Please sign in to comment.