com.segment.analytics.TraitsCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
The hassle-free way to add analytics to your Android app.
package com.segment.analytics;
import android.content.Context;
import static com.segment.analytics.Utils.getSharedPreferences;
import static com.segment.analytics.Utils.isNullOrEmpty;
class TraitsCache {
private static final String TRAITS_CACHE_PREFIX = "traits-";
private final StringCache stringCache;
private Traits traits;
TraitsCache(Context context, String tag) {
stringCache = new StringCache(getSharedPreferences(context), TRAITS_CACHE_PREFIX + tag);
if (isNullOrEmpty(stringCache.get())) {
traits = new Traits(context);
} else {
traits = new Traits(stringCache.get());
}
}
Traits get() {
return traits;
}
void save() {
stringCache.set(traits.toString());
}
void delete(Context context) {
stringCache.delete();
traits = new Traits(context);
}
}