X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FSplashActivity.java;h=b868366b9d94bdf1529a428cd0d5fe2147c1de90;hb=804f1fa43c2feb45a80cc281f39cd981953785db;hp=4988d1c5a6d6dd80f8cde0dd9b38a94809a7f201;hpb=7c9147eff10c80c18757db1d2e41f529585551e6;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/SplashActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/SplashActivity.java index 4988d1c5..b868366b 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/SplashActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/SplashActivity.java @@ -1,5 +1,5 @@ /* - * 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 @@ -18,21 +18,20 @@ 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; +import java.util.Locale; + public class SplashActivity extends CrashReportingActivity { - private static final long keepActiveForMS = 500; + private static final long keepActiveForMS = 400; private long startupTime; private boolean running = true; @Override @@ -53,8 +52,9 @@ public class SplashActivity extends CrashReportingActivity { startupTime = System.currentTimeMillis(); - AsyncTask dbInitTask = new DatabaseInitTask(); - dbInitTask.execute(); + DatabaseInitThread dbInitThread = new DatabaseInitThread(); + Logger.debug("splash", "starting dbInit task"); + dbInitThread.start(); } @Override protected void onPause() { @@ -79,8 +79,11 @@ public class SplashActivity extends CrashReportingActivity { 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().postDelayed(this::startMainActivity, delay); } } private void startMainActivity() { @@ -97,22 +100,14 @@ public class SplashActivity extends CrashReportingActivity { finish(); } } - private static class DatabaseInitTask extends AsyncTask { + 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.setCurrentProfile(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); } } }