use of io.realm.RealmConfiguration in project app by TourLive.
the class ImportFragment method setDataToDemo.
private void setDataToDemo() throws IOException {
RealmConfiguration config = new RealmConfiguration.Builder().name(DEMOREALM).deleteRealmIfMigrationNeeded().modules(new RealmModul()).build();
RadioTourApplication.setInstance(config);
}
use of io.realm.RealmConfiguration in project Neuronizer by djuelg.
the class AndroidApplication method onCreate.
@Override
public void onCreate() {
super.onCreate();
// initiate Realm
Realm.init(this);
RealmConfiguration realmConfiguration = createConfiguration(DEFAULT_REALM_NAME);
Realm.setDefaultConfiguration(realmConfiguration);
}
use of io.realm.RealmConfiguration in project ForPDA by RadiationX.
the class App method onCreate.
@Override
public void onCreate() {
super.onCreate();
instance = this;
long time = System.currentTimeMillis();
ACRA.init(this);
ACRA.getErrorReporter().putCustomData("USER_NICK", getPreferences().getString("auth.user.nick", "null"));
RxJavaPlugins.setErrorHandler(throwable -> {
Log.d("SUKA", "RxJavaPlugins errorHandler " + throwable);
throwable.printStackTrace();
});
setTheme(isDarkTheme() ? R.style.DarkAppTheme : R.style.LightAppTheme);
try {
String inputHistory = getPreferences().getString("app.versions.history", "");
String[] history = TextUtils.split(inputHistory, ";");
int lastVNum = 0;
boolean disorder = false;
for (String version : history) {
int vNum = Integer.parseInt(version);
if (vNum < lastVNum) {
disorder = true;
}
lastVNum = vNum;
}
Object vCode = BuildConfig.VERSION_CODE;
String sVCode = "" + vCode;
int nVCode = Integer.parseInt(sVCode);
if (lastVNum < nVCode) {
List<String> list = new ArrayList<>(Arrays.asList(history));
list.add(Integer.toString(nVCode));
getPreferences().edit().putString("app.versions.history", TextUtils.join(";", list)).apply();
}
if (disorder) {
throw new Exception("Нарушение порядка версий!");
}
} catch (Exception ex) {
ex.printStackTrace();
ACRA.getErrorReporter().putCustomData("VERSIONS_HISTORY", getPreferences().getString("app.versions.history", ""));
ACRA.getErrorReporter().handleException(ex);
}
ACRA.getErrorReporter().putCustomData("VERSIONS_HISTORY", getPreferences().getString("app.versions.history", ""));
density = getResources().getDisplayMetrics().density;
initImageLoader(this);
px2 = getContext().getResources().getDimensionPixelSize(R.dimen.dp2);
px4 = getContext().getResources().getDimensionPixelSize(R.dimen.dp4);
px6 = getContext().getResources().getDimensionPixelSize(R.dimen.dp6);
px8 = getContext().getResources().getDimensionPixelSize(R.dimen.dp8);
px12 = getContext().getResources().getDimensionPixelSize(R.dimen.dp12);
px14 = getContext().getResources().getDimensionPixelSize(R.dimen.dp14);
px16 = getContext().getResources().getDimensionPixelSize(R.dimen.dp16);
px20 = getContext().getResources().getDimensionPixelSize(R.dimen.dp20);
px24 = getContext().getResources().getDimensionPixelSize(R.dimen.dp24);
px32 = getContext().getResources().getDimensionPixelSize(R.dimen.dp32);
px36 = getContext().getResources().getDimensionPixelSize(R.dimen.dp36);
px40 = getContext().getResources().getDimensionPixelSize(R.dimen.dp40);
px48 = getContext().getResources().getDimensionPixelSize(R.dimen.dp48);
px56 = getContext().getResources().getDimensionPixelSize(R.dimen.dp56);
px64 = getContext().getResources().getDimensionPixelSize(R.dimen.dp64);
for (Field f : R.string.class.getFields()) {
try {
if (f.getName().contains("res_s_")) {
templateStringCache.put(f.getName(), getString(f.getInt(f)));
}
} catch (Exception ignore) {
}
}
keyboardHeight = getPreferences().getInt("keyboard_height", getContext().getResources().getDimensionPixelSize(R.dimen.default_keyboard_height));
savedKeyboardHeight = keyboardHeight;
Realm.init(this);
RealmConfiguration configuration = new RealmConfiguration.Builder().name("forpda.realm").schemaVersion(4).migration(new DbMigration()).build();
Realm.setDefaultConfiguration(configuration);
Client.get(getContext());
getPreferences().registerOnSharedPreferenceChangeListener(preferenceChangeListener);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
BroadcastReceiver receiver = new BroadcastReceiver() {
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onReceive(Context context, Intent intent) {
Log.d(App.class.getSimpleName(), "DOZE ON RECEIVE " + intent);
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (pm == null)
return;
if (pm.isDeviceIdleMode()) {
// the device is now in doze mode
Log.d(App.class.getSimpleName(), "DOZE MODE ENABLYA");
} else {
// the device just woke up from doze mode
Log.d(App.class.getSimpleName(), "DOZE MODE DISABLYA");
NotificationsService.startAndCheck();
}
}
};
registerReceiver(receiver, new IntentFilter(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED));
}
IntentFilter wakeUpFilter = new IntentFilter();
wakeUpFilter.addAction(Intent.ACTION_BOOT_COMPLETED);
wakeUpFilter.addAction(Intent.ACTION_SCREEN_ON);
registerReceiver(new WakeUpReceiver(), wakeUpFilter);
// На каких-то диких калькуляторах может быть ANR, поэтому в фоновый поток
Observable.fromCallable(() -> {
JobConfig.addLogger((priority, tag, message, t) -> {
Log.e("JobLogger", "Job: pr=" + priority + "; t=" + tag + "; m=" + message + "; th=" + t);
});
JobConfig.setLogcatEnabled(false);
JobManager.create(this).addJobCreator(new NotificationsJobCreator());
JobManager.instance().cancelAllForTag(NotificationsJob.TAG);
new JobRequest.Builder(NotificationsJob.TAG).setPeriodic(TimeUnit.MINUTES.toMillis(16L)).setRequiresCharging(false).setRequiresDeviceIdle(false).setRequiredNetworkType(JobRequest.NetworkType.ANY).build().schedule();
return true;
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe();
QmsHelper.init();
Log.e("APP", "TIME APP FINAL " + (System.currentTimeMillis() - time));
}
use of io.realm.RealmConfiguration in project realm-java by realm.
the class SyncSession method notifySessionError.
// This callback will happen on the thread running the Sync Client.
void notifySessionError(String nativeErrorCategory, int nativeErrorCode, String errorMessage, String clientResetPathInfo) {
if (errorHandler == null) {
return;
}
ErrorCode errCode = ErrorCode.fromNativeError(nativeErrorCategory, nativeErrorCode);
if (errCode == ErrorCode.CLIENT_RESET) {
// errorMessage contains the path to the backed up file
if (clientResetPathInfo == null) {
throw new IllegalStateException("Missing Client Reset info.");
}
RealmConfiguration backupRealmConfiguration = configuration.forErrorRecovery(clientResetPathInfo);
if (clientResetHandler instanceof ManuallyRecoverUnsyncedChangesStrategy) {
((ManuallyRecoverUnsyncedChangesStrategy) clientResetHandler).onClientReset(this, new ClientResetRequiredError(appNativePointer, errCode, errorMessage, configuration, backupRealmConfiguration));
} else if (clientResetHandler instanceof DiscardUnsyncedChangesStrategy) {
((DiscardUnsyncedChangesStrategy) clientResetHandler).onError(this, new ClientResetRequiredError(appNativePointer, errCode, errorMessage, configuration, backupRealmConfiguration));
}
} else {
AppException wrappedError;
if (errCode == ErrorCode.UNKNOWN) {
wrappedError = new AppException(nativeErrorCategory, nativeErrorCode, errorMessage);
} else {
wrappedError = new AppException(errCode, errorMessage);
}
errorHandler.onError(this, wrappedError);
}
}
use of io.realm.RealmConfiguration in project xabber-android by redsolution.
the class MessageDatabaseManager method createRealmConfiguration.
private RealmConfiguration createRealmConfiguration() {
return new RealmConfiguration.Builder().name(REALM_MESSAGE_DATABASE_NAME).schemaVersion(REALM_MESSAGE_DATABASE_VERSION).modules(new MessageRealmDatabaseModule()).migration(new RealmMigration() {
@Override
public void migrate(DynamicRealm realm1, long oldVersion, long newVersion) {
RealmSchema schema = realm1.getSchema();
if (oldVersion == 1) {
schema.create(SyncInfo.class.getSimpleName()).addField(SyncInfo.FIELD_ACCOUNT, String.class, FieldAttribute.INDEXED).addField(SyncInfo.FIELD_USER, String.class, FieldAttribute.INDEXED).addField(SyncInfo.FIELD_FIRST_MAM_MESSAGE_MAM_ID, String.class).addField(SyncInfo.FIELD_FIRST_MAM_MESSAGE_STANZA_ID, String.class).addField(SyncInfo.FIELD_LAST_MESSAGE_MAM_ID, String.class).addField(SyncInfo.FIELD_REMOTE_HISTORY_COMPLETELY_LOADED, boolean.class);
oldVersion++;
}
if (oldVersion == 2) {
schema.create(MessageItem.class.getSimpleName()).addField(MessageItem.Fields.UNIQUE_ID, String.class, FieldAttribute.PRIMARY_KEY).addField(MessageItem.Fields.ACCOUNT, String.class, FieldAttribute.INDEXED).addField(MessageItem.Fields.USER, String.class, FieldAttribute.INDEXED).addField(MessageItem.Fields.RESOURCE, String.class).addField(MessageItem.Fields.ACTION, String.class).addField(MessageItem.Fields.TEXT, String.class).addField(MessageItem.Fields.TIMESTAMP, Long.class, FieldAttribute.INDEXED).addField(MessageItem.Fields.DELAY_TIMESTAMP, Long.class).addField(MessageItem.Fields.STANZA_ID, String.class).addField(MessageItem.Fields.INCOMING, boolean.class).addField(MessageItem.Fields.UNENCRYPTED, boolean.class).addField(MessageItem.Fields.SENT, boolean.class).addField(MessageItem.Fields.READ, boolean.class).addField(MessageItem.Fields.DELIVERED, boolean.class).addField(MessageItem.Fields.OFFLINE, boolean.class).addField(MessageItem.Fields.ERROR, boolean.class).addField(MessageItem.Fields.IS_RECEIVED_FROM_MAM, boolean.class).addField(MessageItem.Fields.FILE_PATH, String.class).addField(MessageItem.Fields.FILE_SIZE, Long.class);
oldVersion++;
}
if (oldVersion == 3) {
schema.get(MessageItem.class.getSimpleName()).addIndex(MessageItem.Fields.SENT);
oldVersion++;
}
if (oldVersion == 4) {
schema.get(MessageItem.class.getSimpleName()).addField(MessageItem.Fields.FORWARDED, boolean.class);
oldVersion++;
}
if (oldVersion == 5) {
schema.get(MessageItem.class.getSimpleName()).addField(MessageItem.Fields.ACKNOWLEDGED, boolean.class);
oldVersion++;
}
if (oldVersion == 6) {
schema.create("LogMessage").addField("level", int.class).addField("tag", Date.class).addField("message", String.class).addField("datetime", String.class);
oldVersion++;
}
if (oldVersion == 7) {
schema.remove("LogMessage");
oldVersion++;
}
if (oldVersion == 8) {
schema.get(MessageItem.class.getSimpleName()).addField(MessageItem.Fields.FILE_URL, String.class);
oldVersion++;
}
if (oldVersion == 9) {
schema.remove("BlockedContactsForAccount");
schema.remove("BlockedContact");
oldVersion++;
}
if (oldVersion == 10) {
schema.get(MessageItem.class.getSimpleName()).addField(MessageItem.Fields.IS_IN_PROGRESS, boolean.class);
oldVersion++;
}
if (oldVersion == 11) {
schema.get(MessageItem.class.getSimpleName()).addField(MessageItem.Fields.IS_IMAGE, boolean.class);
oldVersion++;
}
if (oldVersion == 12) {
schema.get(MessageItem.class.getSimpleName()).addField(MessageItem.Fields.IMAGE_WIDTH, Integer.class).addField(MessageItem.Fields.IMAGE_HEIGHT, Integer.class);
oldVersion++;
}
if (oldVersion == 13) {
schema.get(MessageItem.class.getSimpleName()).removeField(MessageItem.Fields.UNENCRYPTED).addField(MessageItem.Fields.ENCRYPTED, boolean.class);
oldVersion++;
}
if (oldVersion == 14) {
schema.get(MessageItem.class.getSimpleName()).addField(MessageItem.Fields.ERROR_DESCR, String.class);
oldVersion++;
}
if (oldVersion == 15) {
schema.create(Attachment.class.getSimpleName()).addField("uniqueId", String.class, FieldAttribute.PRIMARY_KEY, FieldAttribute.REQUIRED).addField("title", String.class).addField("filePath", String.class).addField("fileUrl", String.class).addField("fileSize", Long.class).addField("isImage", boolean.class).addField("imageWidth", Integer.class).addField("imageHeight", Integer.class).addField("duration", Long.class).addField("mimeType", String.class);
schema.get(MessageItem.class.getSimpleName()).addRealmListField(MessageItem.Fields.ATTACHMENTS, schema.get(Attachment.class.getSimpleName()));
oldVersion++;
}
if (oldVersion == 16) {
schema.create(ForwardId.class.getSimpleName()).addField("id", String.class, FieldAttribute.PRIMARY_KEY, FieldAttribute.REQUIRED).addField("forwardMessageId", String.class);
schema.get(MessageItem.class.getSimpleName()).addField(MessageItem.Fields.ORIGINAL_STANZA, String.class).addField(MessageItem.Fields.ORIGINAL_FROM, String.class).addField(MessageItem.Fields.PARENT_MESSAGE_ID, String.class).addField(MessageItem.Fields.FROM_MUC, boolean.class).addRealmListField(MessageItem.Fields.FORWARDED_IDS, schema.get(ForwardId.class.getSimpleName()));
oldVersion++;
}
if (oldVersion == 17) {
schema.get(MessageItem.class.getSimpleName()).addField(MessageItem.Fields.DISPLAYED, boolean.class);
oldVersion++;
}
if (oldVersion == 18) {
schema.get(MessageItem.class.getSimpleName()).transform(new RealmObjectSchema.Function() {
@Override
public void apply(DynamicRealmObject obj) {
obj.setBoolean(MessageItem.Fields.READ, true);
}
});
oldVersion++;
}
if (oldVersion == 19) {
schema.get(MessageItem.class.getSimpleName()).addField(MessageItem.Fields.PREVIOUS_ID, String.class).addField(MessageItem.Fields.ARCHIVED_ID, String.class).transform(new RealmObjectSchema.Function() {
@Override
public void apply(DynamicRealmObject obj) {
obj.setString(MessageItem.Fields.PREVIOUS_ID, "legacy");
}
});
oldVersion++;
}
if (oldVersion == 20) {
schema.create(ContactGroup.class.getSimpleName()).addField(ContactGroup.Fields.GROUP_NAME, String.class, FieldAttribute.PRIMARY_KEY, FieldAttribute.REQUIRED);
schema.create(ContactRealm.class.getSimpleName()).addField(ContactRealm.Fields.ID, String.class, FieldAttribute.PRIMARY_KEY, FieldAttribute.REQUIRED).addField(ContactRealm.Fields.ACCOUNT, String.class).addField(ContactRealm.Fields.USER, String.class).addField(ContactRealm.Fields.NAME, String.class).addField(ContactRealm.Fields.ACCOUNT_RESOURCE, String.class).addRealmObjectField(ContactRealm.Fields.LAST_MESSAGE, schema.get(MessageItem.class.getSimpleName())).addRealmListField(ContactRealm.Fields.GROUPS, schema.get(ContactGroup.class.getSimpleName()));
oldVersion++;
}
if (oldVersion == 21) {
schema.get(MessageItem.class.getSimpleName()).addField(MessageItem.Fields.MARKUP_TEXT, String.class);
oldVersion++;
}
if (oldVersion == 22) {
schema.get(MessageItem.class.getSimpleName()).addField(MessageItem.Fields.GROUPCHAT_USER_ID, String.class);
oldVersion++;
}
}
}).build();
}
Aggregations