use of net.grandcentrix.tray.core.TrayItem in project tray by grandcentrix.
the class TrayProviderHelperTest method testCreatedTime.
public void testCreatedTime() throws Exception {
final long start = System.currentTimeMillis();
mProviderHelper.persist(MODULE_A, KEY_A, STRING_A);
final List<TrayItem> list = mProviderHelper.queryProvider(getUri(MODULE_A, KEY_A));
assertNotNull(list);
assertEquals(1, list.size());
TrayItem itemA = list.get(0);
assertNotNull(itemA.created());
assertEqualsWithin(start, itemA.created().getTime(), 50l);
}
use of net.grandcentrix.tray.core.TrayItem in project tray by grandcentrix.
the class TrayProviderHelperTest method testCreatedTimeDoesNotChange.
public void testCreatedTimeDoesNotChange() throws Exception {
testCreatedTime();
final TrayItem insertedItem = mProviderHelper.getAll().get(0);
final long createdTime = insertedItem.created().getTime();
Thread.sleep(50);
// save again
assertTrue(mProviderHelper.persist(MODULE_A, KEY_A, STRING_B));
final long updatedCreatedTime = mProviderHelper.getAll().get(0).created().getTime();
assertEquals(createdTime, updatedCreatedTime);
}
use of net.grandcentrix.tray.core.TrayItem in project tray by grandcentrix.
the class ImportTrayPreferences method importSharedPreferencesWithLogging.
/**
* logging wrapper for:
* example how to import shared preferences
*/
private void importSharedPreferencesWithLogging() {
final SharedPreferences sharedPreferences = getContext().getSharedPreferences(SampleActivity.SHARED_PREF_NAME, Context.MODE_MULTI_PROCESS);
final HashMap<String, ?> allBefore = new HashMap<>(sharedPreferences.getAll());
Log.v(TAG, allBefore.size() + " items in sharedPreferences: " + allBefore.toString());
// 2 items in sharedPreferences: {userToken=cf26535a-6949-4728-b595-c6d80c094eff, gcmToken=2ca7e9a0-9114-4d55-8d2d-870b8d49fafe}
importSharedPreferences();
final ArrayList<TrayItem> all = new ArrayList<>(getAll());
Log.v(TAG, "imported " + all.size() + " items: " + all.toString());
// imported 2 items: [
// {key: gcm:token, value: 2ca7e9a0-9114-4d55-8d2d-870b8d49fafe, module: imported, created: 14:06:04 05.06.2015, updated: 14:06:04 05.06.2015, migratedKey: gcmToken},
// {key: user:token, value: cf26535a-6949-4728-b595-c6d80c094eff, module: imported, created: 14:06:04 05.06.2015, updated: 14:06:04 05.06.2015, migratedKey: userToken}
// ]
final HashMap<String, ?> allAfter = new HashMap<>(sharedPreferences.getAll());
Log.v(TAG, allAfter.size() + " items in sharedPreferences: " + allAfter.toString());
// 0 items in sharedPreferences: {}
}
use of net.grandcentrix.tray.core.TrayItem in project tray by grandcentrix.
the class ContentProviderStorage method getVersion.
@Override
public int getVersion() throws TrayException {
final Uri internalUri = mTrayUri.builder().setInternal(true).setType(getType()).setModule(getModuleName()).setKey(VERSION).build();
final List<TrayItem> trayItems = mProviderHelper.queryProvider(internalUri);
if (trayItems.size() == 0) {
// fallback, not found
return 0;
}
return Integer.valueOf(trayItems.get(0).value());
}
use of net.grandcentrix.tray.core.TrayItem in project tray by grandcentrix.
the class ContentProviderStorage method get.
@Override
@Nullable
public TrayItem get(@NonNull final String key) {
final Uri uri = mTrayUri.builder().setType(getType()).setModule(getModuleName()).setKey(key).build();
final List<TrayItem> prefs = mProviderHelper.queryProviderSafe(uri);
final int size = prefs.size();
if (size > 1) {
TrayLog.w("found more than one item for key '" + key + "' in module " + getModuleName() + ". " + "This can be caused by using the same name for a device and user specific preference.");
for (int i = 0; i < prefs.size(); i++) {
final TrayItem pref = prefs.get(i);
TrayLog.d("item #" + i + " " + pref);
}
}
return size > 0 ? prefs.get(0) : null;
}
Aggregations