use of forpdateam.ru.forpda.common.realm.DbMigration 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));
}
Aggregations