/*
- * 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 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;
public class SplashActivity extends CrashReportingActivity {
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() {
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);
+ MobileLedgerDatabase.initComplete.postValue(true);
}
}
}