|
1 | 1 | package com.onesignal.core.internal.preferences
|
2 | 2 |
|
| 3 | +/** |
| 4 | + * Provides access to the low level preferences. There are one or more preference |
| 5 | + * stores, identified by [PreferenceStores], each store contains a key for each |
| 6 | + * preference. Each key has a known data type, it's value can be fetched/stored as |
| 7 | + * needed. Stored preferences will persist across the lifetime of the app installation. |
| 8 | + */ |
3 | 9 | internal interface IPreferencesService {
|
| 10 | + /** |
| 11 | + * Retrieve a [String] value identified by the [store] and [key] provided. |
| 12 | + * |
| 13 | + * @param store The name of the preference store. |
| 14 | + * @param key The key to retrieve. |
| 15 | + * @param defValue The optional default value to return, if the [key] was not previously saved. |
| 16 | + * |
| 17 | + * @return the value in the preference store, or [defValue] if not previously saved. |
| 18 | + */ |
4 | 19 | fun getString(store: String, key: String, defValue: String? = null): String?
|
| 20 | + |
| 21 | + /** |
| 22 | + * Retrieve a [Boolean] value identified by the [store] and [key] provided. |
| 23 | + * |
| 24 | + * @param store The name of the preference store. |
| 25 | + * @param key The key to retrieve. |
| 26 | + * @param defValue The optional default value to return, if the [key] was not previously saved. |
| 27 | + * |
| 28 | + * @return the value in the preference store, or [defValue] if not previously saved. |
| 29 | + */ |
5 | 30 | fun getBool(store: String, key: String, defValue: Boolean? = null): Boolean?
|
| 31 | + |
| 32 | + /** |
| 33 | + * Retrieve a [Int] value identified by the [store] and [key] provided. |
| 34 | + * |
| 35 | + * @param store The name of the preference store. |
| 36 | + * @param key The key to retrieve. |
| 37 | + * @param defValue The optional default value to return, if the [key] was not previously saved. |
| 38 | + * |
| 39 | + * @return the value in the preference store, or [defValue] if not previously saved. |
| 40 | + */ |
6 | 41 | fun getInt(store: String, key: String, defValue: Int? = null): Int?
|
| 42 | + |
| 43 | + /** |
| 44 | + * Retrieve a [Long] value identified by the [store] and [key] provided. |
| 45 | + * |
| 46 | + * @param store The name of the preference store. |
| 47 | + * @param key The key to retrieve. |
| 48 | + * @param defValue The optional default value to return, if the [key] was not previously saved. |
| 49 | + * |
| 50 | + * @return the value in the preference store, or [defValue] if not previously saved. |
| 51 | + */ |
7 | 52 | fun getLong(store: String, key: String, defValue: Long? = null): Long?
|
| 53 | + |
| 54 | + /** |
| 55 | + * Retrieve a [Set] of [String] value identified by the [store] and [key] provided. |
| 56 | + * |
| 57 | + * @param store The name of the preference store. |
| 58 | + * @param key The key to retrieve. |
| 59 | + * @param defValue The optional default value to return, if the [key] was not previously saved. |
| 60 | + * |
| 61 | + * @return the value in the preference store, or [defValue] if not previously saved. |
| 62 | + */ |
8 | 63 | fun getStringSet(store: String, key: String, defValue: Set<String>? = null): Set<String>?
|
9 | 64 |
|
| 65 | + /** |
| 66 | + * Save a [String] value identified by the [store] and [key] provided. |
| 67 | + * |
| 68 | + * @param store The name of the preference store. |
| 69 | + * @param key The key to retrieve. |
| 70 | + * @param value The value to save. |
| 71 | + */ |
10 | 72 | fun saveString(store: String, key: String, value: String?)
|
| 73 | + |
| 74 | + /** |
| 75 | + * Save a [Boolean] value identified by the [store] and [key] provided. |
| 76 | + * |
| 77 | + * @param store The name of the preference store. |
| 78 | + * @param key The key to retrieve. |
| 79 | + * @param value The value to save. |
| 80 | + */ |
11 | 81 | fun saveBool(store: String, key: String, value: Boolean?)
|
| 82 | + |
| 83 | + /** |
| 84 | + * Save a [Int] value identified by the [store] and [key] provided. |
| 85 | + * |
| 86 | + * @param store The name of the preference store. |
| 87 | + * @param key The key to retrieve. |
| 88 | + * @param value The value to save. |
| 89 | + */ |
12 | 90 | fun saveInt(store: String, key: String, value: Int?)
|
| 91 | + |
| 92 | + /** |
| 93 | + * Save a [Long] value identified by the [store] and [key] provided. |
| 94 | + * |
| 95 | + * @param store The name of the preference store. |
| 96 | + * @param key The key to retrieve. |
| 97 | + * @param value The value to save. |
| 98 | + */ |
13 | 99 | fun saveLong(store: String, key: String, value: Long?)
|
| 100 | + |
| 101 | + /** |
| 102 | + * Save a [Set] of [String] value identified by the [store] and [key] provided. |
| 103 | + * |
| 104 | + * @param store The name of the preference store. |
| 105 | + * @param key The key to retrieve. |
| 106 | + * @param value The value to save. |
| 107 | + */ |
14 | 108 | fun saveStringSet(store: String, key: String, value: Set<String>?)
|
15 | 109 | }
|
16 | 110 |
|
17 | 111 | internal object PreferenceStores {
|
| 112 | + /** |
| 113 | + * The default OneSignal store, keys defined in [PreferenceOneSignalKeys]. |
| 114 | + */ |
18 | 115 | const val ONESIGNAL = "OneSignal"
|
| 116 | + |
| 117 | + /** |
| 118 | + * The player purchase store, keys defined in [PreferencePlayerPurchasesKeys]. |
| 119 | + */ |
19 | 120 | const val PLAYER_PURCHASES = "GTPlayerPurchases"
|
20 |
| - const val TRIGGERS = "OneSignalTriggers" |
21 | 121 | }
|
22 | 122 |
|
23 | 123 | internal object PreferencePlayerPurchasesKeys {
|
24 | 124 | // Player Purchase Keys
|
| 125 | + /** |
| 126 | + * (String) The purchase tokens that have been tracked. |
| 127 | + */ |
25 | 128 | const val PREFS_PURCHASE_TOKENS = "purchaseTokens"
|
| 129 | + |
| 130 | + /** |
| 131 | + * (Boolean) Whether new purchases should be treated as existing. |
| 132 | + */ |
26 | 133 | const val PREFS_EXISTING_PURCHASES = "ExistingPurchases"
|
27 | 134 | }
|
28 | 135 |
|
29 |
| -internal object PreferenceTriggerKeys |
30 |
| - |
31 | 136 | internal object PreferenceOneSignalKeys {
|
32 |
| - // TODO: Remove this once the tasks below have been finished... |
33 |
| - // 1. Fix all of the SharedPreference Keys so they are organized by usage with comments |
34 |
| - // ex. |
35 |
| - // // In-App Messaging |
36 |
| - // public static final String PREFS_OS_CACHED_IAMS = "PREFS_OS_CACHED_IAMS"; |
37 |
| - // public static final String PREFS_OS_DISMISSED_IAMS = "PREFS_OS_DISPLAYED_IAMS"; |
38 |
| - // public static final String PREFS_OS_IMPRESSIONED_IAMS = "PREFS_OS_IMPRESSIONED_IAMS"; |
39 |
| - // public static final String PREFS_OS_CLICKED_CLICK_IDS_IAMS = "PREFS_OS_CLICKED_CLICK_IDS_IAMS"; |
40 |
| - // 2. Match keys with value names |
41 |
| - // ex. |
42 |
| - // public static final String PREFS_OS_LAST_LOCATION_TIME = "OS_LAST_LOCATION_TIME"; |
43 |
| - // 3. Follow syntax and make new names relevant (specific and as short as possible) |
44 |
| - // ex. |
45 |
| - // Start with prefix "PREFS_OS_" + "LAST_LOCATION_TIME" |
46 |
| - // Unorganized Keys |
| 137 | + // Location |
| 138 | + /** |
| 139 | + * (Long) The last time the device location was captured, in Unix time milliseconds. |
| 140 | + */ |
47 | 141 | const val PREFS_OS_LAST_LOCATION_TIME = "OS_LAST_LOCATION_TIME"
|
48 |
| - const val PREFS_GT_SOUND_ENABLED = "GT_SOUND_ENABLED" |
49 |
| - const val PREFS_OS_LAST_SESSION_TIME = "OS_LAST_SESSION_TIME" |
50 |
| - const val PREFS_GT_VIBRATE_ENABLED = "GT_VIBRATE_ENABLED" |
51 |
| - const val PREFS_OS_FILTER_OTHER_GCM_RECEIVERS = "OS_FILTER_OTHER_GCM_RECEIVERS" |
52 |
| - const val PREFS_GT_APP_ID = "GT_APP_ID" |
53 |
| - const val PREFS_GT_PLAYER_ID = "GT_PLAYER_ID" |
54 |
| - const val PREFS_GT_UNSENT_ACTIVE_TIME = "GT_UNSENT_ACTIVE_TIME" |
55 |
| - const val PREFS_OS_UNSENT_ATTRIBUTED_ACTIVE_TIME = "OS_UNSENT_ATTRIBUTED_ACTIVE_TIME" |
56 |
| - const val PREFS_ONESIGNAL_USERSTATE_DEPENDVALYES_ = "ONESIGNAL_USERSTATE_DEPENDVALYES_" |
57 |
| - const val PREFS_ONESIGNAL_USERSTATE_SYNCVALYES_ = "ONESIGNAL_USERSTATE_SYNCVALYES_" |
58 |
| - const val PREFS_ONESIGNAL_ACCEPTED_NOTIFICATION_LAST = "ONESIGNAL_ACCEPTED_NOTIFICATION_LAST" |
59 |
| - const val PREFS_ONESIGNAL_SUBSCRIPTION_LAST = "ONESIGNAL_SUBSCRIPTION_LAST" |
60 |
| - const val PREFS_ONESIGNAL_PLAYER_ID_LAST = "ONESIGNAL_PLAYER_ID_LAST" |
61 |
| - const val PREFS_ONESIGNAL_PUSH_TOKEN_LAST = "ONESIGNAL_PUSH_TOKEN_LAST" |
62 |
| - const val PREFS_ONESIGNAL_PERMISSION_ACCEPTED_LAST = "ONESIGNAL_PERMISSION_ACCEPTED_LAST" |
63 |
| - const val PREFS_GT_DO_NOT_SHOW_MISSING_GPS = "GT_DO_NOT_SHOW_MISSING_GPS" |
64 |
| - const val PREFS_ONESIGNAL_SUBSCRIPTION = "ONESIGNAL_SUBSCRIPTION" |
65 |
| - const val PREFS_ONESIGNAL_SYNCED_SUBSCRIPTION = "ONESIGNAL_SYNCED_SUBSCRIPTION" |
66 |
| - const val PREFS_GT_REGISTRATION_ID = "GT_REGISTRATION_ID" |
67 |
| - const val PREFS_ONESIGNAL_USER_PROVIDED_CONSENT = "ONESIGNAL_USER_PROVIDED_CONSENT" |
68 |
| - const val PREFS_OS_ETAG_PREFIX = "PREFS_OS_ETAG_PREFIX_" |
69 |
| - const val PREFS_OS_HTTP_CACHE_PREFIX = "PREFS_OS_HTTP_CACHE_PREFIX_" |
70 |
| - |
71 |
| - // Remote params |
72 |
| - const val PREFS_GT_FIREBASE_TRACKING_ENABLED = "GT_FIREBASE_TRACKING_ENABLED" |
73 |
| - const val PREFS_OS_RESTORE_TTL_FILTER = "OS_RESTORE_TTL_FILTER" |
74 |
| - const val PREFS_OS_CLEAR_GROUP_SUMMARY_CLICK = "OS_CLEAR_GROUP_SUMMARY_CLICK" |
75 |
| - const val PREFS_OS_UNSUBSCRIBE_WHEN_NOTIFICATIONS_DISABLED = "PREFS_OS_UNSUBSCRIBE_WHEN_NOTIFICATIONS_DISABLED" |
76 |
| - const val PREFS_OS_DISABLE_GMS_MISSING_PROMPT = "PREFS_OS_DISABLE_GMS_MISSING_PROMPT" |
77 |
| - const val PREFS_OS_REQUIRES_USER_PRIVACY_CONSENT = "PREFS_OS_REQUIRES_USER_PRIVACY_CONSENT" |
78 |
| - const val PREFS_OS_LOCATION_SHARED = "PREFS_OS_LOCATION_SHARED" |
79 | 142 |
|
80 |
| - // Remote params - Receive Receipts (aka Confirmed Deliveries) |
81 |
| - const val PREFS_OS_RECEIVE_RECEIPTS_ENABLED = "PREFS_OS_RECEIVE_RECEIPTS_ENABLED" |
| 143 | + // HTTP |
| 144 | + /** |
| 145 | + * (String) A prefix key for retrieving the ETAG for a given HTTP GET cache key. The cache |
| 146 | + * key should be appended to this prefix. |
| 147 | + */ |
| 148 | + const val PREFS_OS_ETAG_PREFIX = "PREFS_OS_ETAG_PREFIX_" |
82 | 149 |
|
83 |
| - // On Focus Influence |
84 |
| - const val PREFS_OS_ATTRIBUTED_INFLUENCES = "PREFS_OS_ATTRIBUTED_INFLUENCES" |
| 150 | + /** |
| 151 | + * (String) A prefix key for retrieving the response for a given HTTP GET cache key. The cache |
| 152 | + * key should be appended to this prefix. |
| 153 | + */ |
| 154 | + const val PREFS_OS_HTTP_CACHE_PREFIX = "PREFS_OS_HTTP_CACHE_PREFIX_" |
85 | 155 |
|
86 | 156 | // Outcomes
|
| 157 | + /** |
| 158 | + * (String Set) The set of unattributed outcome events that have occurred to ensure uniqueness when requested. |
| 159 | + */ |
87 | 160 | const val PREFS_OS_UNATTRIBUTED_UNIQUE_OUTCOME_EVENTS_SENT = "PREFS_OS_UNATTRIBUTED_UNIQUE_OUTCOME_EVENTS_SENT"
|
88 | 161 |
|
89 |
| - // Email |
90 |
| - const val PREFS_OS_EMAIL_ID = "OS_EMAIL_ID" |
91 |
| - const val PREFS_ONESIGNAL_EMAIL_ID_LAST = "PREFS_ONESIGNAL_EMAIL_ID_LAST" |
92 |
| - const val PREFS_ONESIGNAL_EMAIL_ADDRESS_LAST = "PREFS_ONESIGNAL_EMAIL_ADDRESS_LAST" |
93 |
| - |
94 |
| - // SMS |
95 |
| - const val PREFS_OS_SMS_ID = "PREFS_OS_SMS_ID" |
96 |
| - const val PREFS_OS_SMS_ID_LAST = "PREFS_OS_SMS_ID_LAST" |
97 |
| - const val PREFS_OS_SMS_NUMBER_LAST = "PREFS_OS_SMS_NUMBER_LAST" |
98 |
| - |
99 | 162 | // In-App Messaging
|
| 163 | + /** |
| 164 | + * (String) The serialized IAMs TODO: This isn't currently used, determine if actually needed for cold start IAM fetch delay |
| 165 | + */ |
100 | 166 | const val PREFS_OS_CACHED_IAMS = "PREFS_OS_CACHED_IAMS"
|
| 167 | + |
| 168 | + /** |
| 169 | + * (String Set) The set of IAM IDs that have been dismissed on this device. |
| 170 | + */ |
101 | 171 | const val PREFS_OS_DISMISSED_IAMS = "PREFS_OS_DISPLAYED_IAMS"
|
| 172 | + |
| 173 | + /** |
| 174 | + * (String Set) The set of IAM IDs that have impressed (displayed) on the device. |
| 175 | + */ |
102 | 176 | const val PREFS_OS_IMPRESSIONED_IAMS = "PREFS_OS_IMPRESSIONED_IAMS"
|
| 177 | + |
| 178 | + /** |
| 179 | + * (String Set) The set of click IDs that the device has clicked on. |
| 180 | + */ |
103 | 181 | const val PREFS_OS_CLICKED_CLICK_IDS_IAMS = "PREFS_OS_CLICKED_CLICK_IDS_IAMS"
|
| 182 | + |
| 183 | + /** |
| 184 | + * (String Set) The set of page IDs that have impressed (displayed) on the device. |
| 185 | + */ |
104 | 186 | const val PREFS_OS_PAGE_IMPRESSIONED_IAMS = "PREFS_OS_PAGE_IMPRESSIONED_IAMS"
|
| 187 | + |
| 188 | + /** |
| 189 | + * (Long) The last time an IAM was dismissed, in unix time milliseconds. |
| 190 | + */ |
105 | 191 | const val PREFS_OS_LAST_TIME_IAM_DISMISSED = "PREFS_OS_LAST_TIME_IAM_DISMISSED"
|
106 | 192 |
|
107 | 193 | // Models
|
| 194 | + /** |
| 195 | + * (String) A prefix key for retrieving a specific model store contents. The name of the model |
| 196 | + * store should be appended to this prefix. |
| 197 | + */ |
108 | 198 | const val MODEL_STORE_PREFIX = "MODEL_STORE_"
|
109 | 199 | }
|
0 commit comments