/*
- * Copyright © 2020 Damyan Ivanov.
+ * Copyright © 2021 Damyan Ivanov.
* This file is part of MoLe.
* MoLe is free software: you can distribute it and/or modify it
* under the term of the GNU General Public License as published by
package net.ktnx.mobileledger.ui.activity;
import android.content.Intent;
-import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
+import android.os.Looper;
import androidx.annotation.Nullable;
import net.ktnx.mobileledger.R;
-import net.ktnx.mobileledger.model.Data;
-import net.ktnx.mobileledger.model.MobileLedgerProfile;
+import net.ktnx.mobileledger.db.DB;
import net.ktnx.mobileledger.utils.Logger;
-import net.ktnx.mobileledger.utils.MLDB;
-import net.ktnx.mobileledger.utils.MobileLedgerDatabase;
+
+import java.util.Locale;
public class SplashActivity extends CrashReportingActivity {
private static final long keepActiveForMS = 400;
setContentView(R.layout.splash_activity_layout);
Logger.debug("splash", "onCreate()");
- MobileLedgerDatabase.initComplete.setValue(false);
- MobileLedgerDatabase.initComplete.observe(this, this::onDbInitDoneChanged);
+ DB.initComplete.setValue(false);
+ DB.initComplete.observe(this, this::onDbInitDoneChanged);
}
@Override
protected void onStart() {
startupTime = System.currentTimeMillis();
- AsyncTask<Void, Void, Void> dbInitTask = new DatabaseInitTask();
- dbInitTask.execute();
+ DatabaseInitThread dbInitThread = new DatabaseInitThread();
+ Logger.debug("splash", "starting dbInit task");
+ dbInitThread.start();
}
@Override
protected void onPause() {
if (now > startupTime + keepActiveForMS)
startMainActivity();
else {
- new Handler().postDelayed(this::startMainActivity,
- keepActiveForMS - (now - startupTime));
+ final long delay = keepActiveForMS - (now - startupTime);
+ Logger.debug("splash",
+ String.format(Locale.ROOT, "Scheduling main activity start in %d milliseconds",
+ delay));
+ new Handler(Looper.getMainLooper()).postDelayed(this::startMainActivity, delay);
}
}
private void startMainActivity() {
finish();
}
}
- private static class DatabaseInitTask extends AsyncTask<Void, Void, Void> {
+ private static class DatabaseInitThread extends Thread {
@Override
- protected Void doInBackground(Void... voids) {
- MobileLedgerProfile.loadAllFromDB(null);
+ public void run() {
+ long ignored = DB.get()
+ .getProfileDAO()
+ .getProfileCountSync();
- String profileUUID = MLDB.getOption(MLDB.OPT_PROFILE_UUID, null);
- MobileLedgerProfile startupProfile = Data.getProfile(profileUUID);
- if (startupProfile != null)
- Data.postCurrentProfile(startupProfile);
- return null;
- }
- @Override
- protected void onPostExecute(Void aVoid) {
- Logger.debug("splash", "DatabaseInitTask::onPostExecute()");
- super.onPostExecute(aVoid);
- MobileLedgerDatabase.initComplete.setValue(true);
+ DB.initComplete.postValue(true);
}
}
}