Skip to content

Commit

Permalink
refactor(dataSourcesImpl): Made all runtime constants as top-level pr…
Browse files Browse the repository at this point in the history
…operty
  • Loading branch information
looee1q committed Dec 20, 2024
1 parent a75c569 commit c0a92e5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import com.personalization.sdk.data.models.NotificationSourceDto
import com.personalization.sdk.data.repositories.preferences.PreferencesDataSource
import javax.inject.Inject

private const val DEFAULT_TYPE: String = ""
private const val DEFAULT_ID: String = ""
private const val DEFAULT_TIME: Long = 0L

private const val SOURCE_TYPE_KEY: String = "source_type"
private const val SOURCE_ID_KEY: String = "source_id"
private const val SOURCE_TIME_KEY: String = "source_time"

class NotificationDataSourceImpl @Inject constructor(
private val preferencesDataSource: PreferencesDataSource
) : NotificationDataSource {
Expand All @@ -24,14 +32,4 @@ class NotificationDataSourceImpl @Inject constructor(

private fun getTime(): Long = preferencesDataSource.getValue(SOURCE_TIME_KEY, DEFAULT_TIME)
override fun saveTime(value: Long) = preferencesDataSource.saveValue(SOURCE_TIME_KEY, value)

companion object {
private const val DEFAULT_TYPE: String = ""
private const val DEFAULT_ID: String = ""
private const val DEFAULT_TIME: Long = 0L

private const val SOURCE_TYPE_KEY: String = "source_type"
private const val SOURCE_ID_KEY: String = "source_id"
private const val SOURCE_TIME_KEY: String = "source_time"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import android.content.Context
import android.content.SharedPreferences
import javax.inject.Inject
import javax.inject.Singleton
import kotlin.math.roundToInt

private const val DEFAULT_TOKEN = ""
private const val DEFAULT_LAST_PUSH_TOKEN_DATE = 0L
private val DEFAULT_SEGMENT = arrayOf("A", "B").random()

private const val TOKEN_KEY = "token"
private const val LAST_PUSH_TOKEN_DATE_KEY = "last_push_token_date"
private const val SEGMENT_KEY = ".segment"

@Singleton
class PreferencesDataSourceImpl @Inject constructor() : PreferencesDataSource {
Expand Down Expand Up @@ -73,14 +80,4 @@ class PreferencesDataSourceImpl @Inject constructor() : PreferencesDataSource {
override fun removeValue(field: String) {
sharedPreferences?.edit()?.remove(field)?.apply()
}

companion object {
private const val DEFAULT_TOKEN = ""
private const val DEFAULT_LAST_PUSH_TOKEN_DATE = 0L
private val DEFAULT_SEGMENT = arrayOf("A", "B")[Math.random().roundToInt()]

private const val TOKEN_KEY = "token"
private const val LAST_PUSH_TOKEN_DATE_KEY = "last_push_token_date"
private const val SEGMENT_KEY = ".segment"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import org.json.JSONObject

private const val DEFAULT_DID = ""
private const val DEFAULT_SID = ""
private const val DEFAULT_SID_LAST_ACT_TIME = 0L

private const val DID_KEY = "did"
private const val SID_KEY = "sid"
private const val SID_LAST_ACT_KEY = "sid_last_act"

class UserSettingsDataSourceImpl @AssistedInject constructor(
private val preferencesDataSource: PreferencesDataSource,
@Assisted("shopId") private val shopId: String,
Expand Down Expand Up @@ -56,15 +64,4 @@ class UserSettingsDataSourceImpl @AssistedInject constructor(
override fun setIsInitialized(value: Boolean) {
isInitialized = value
}

companion object {

private const val DEFAULT_DID = ""
private const val DEFAULT_SID = ""
private const val DEFAULT_SID_LAST_ACT_TIME = 0L

private const val DID_KEY = "did"
private const val SID_KEY = "sid"
private const val SID_LAST_ACT_KEY = "sid_last_act"
}
}

0 comments on commit c0a92e5

Please sign in to comment.