X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fnew_transaction%2FNewTransactionActivity.java;h=d4355a9b012df33398474e2658eaba5dd660058c;hb=860e0419d619210bb59bcae1b64d8c5db90eef70;hp=2daf048369d16138eb0a1fc71d4765e6bdaff939;hpb=86591ee6e207027990a641973a60627746ed16ad;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionActivity.java index 2daf0483..d4355a9b 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionActivity.java @@ -20,7 +20,6 @@ package net.ktnx.mobileledger.ui.new_transaction; import android.content.Context; import android.content.Intent; import android.database.AbstractCursor; -import android.os.AsyncTask; import android.os.Bundle; import android.os.ParcelFormatException; import android.util.TypedValue; @@ -39,10 +38,11 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder; import net.ktnx.mobileledger.BuildConfig; import net.ktnx.mobileledger.R; -import net.ktnx.mobileledger.async.AsyncCrasher; import net.ktnx.mobileledger.async.DescriptionSelectedCallback; +import net.ktnx.mobileledger.async.GeneralBackgroundTasks; import net.ktnx.mobileledger.async.SendTransactionTask; import net.ktnx.mobileledger.async.TaskCallback; +import net.ktnx.mobileledger.dao.BaseDAO; import net.ktnx.mobileledger.dao.TransactionDAO; import net.ktnx.mobileledger.databinding.ActivityNewTransactionBinding; import net.ktnx.mobileledger.db.DB; @@ -54,6 +54,7 @@ import net.ktnx.mobileledger.model.MatchedTemplate; import net.ktnx.mobileledger.ui.FabManager; import net.ktnx.mobileledger.ui.QR; import net.ktnx.mobileledger.ui.activity.ProfileThemedActivity; +import net.ktnx.mobileledger.ui.activity.SplashActivity; import net.ktnx.mobileledger.ui.templates.TemplatesActivity; import net.ktnx.mobileledger.utils.Logger; import net.ktnx.mobileledger.utils.Misc; @@ -83,8 +84,17 @@ public class NewTransactionActivity extends ProfileThemedActivity b = ActivityNewTransactionBinding.inflate(getLayoutInflater(), null, false); setContentView(b.getRoot()); setSupportActionBar(b.toolbar); - Data.observeProfile(this, - mobileLedgerProfile -> b.toolbar.setSubtitle(mobileLedgerProfile.getName())); + Data.observeProfile(this, profile -> { + if (profile == null) { + Logger.debug("new-t-act", "no active profile. Redirecting to SplashActivity"); + Intent intent = new Intent(this, SplashActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME | Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + finish(); + } + else + b.toolbar.setSubtitle(profile.getName()); + }); NavHostFragment navHostFragment = (NavHostFragment) Objects.requireNonNull( getSupportFragmentManager().findFragmentById(R.id.new_transaction_nav)); @@ -163,7 +173,7 @@ public class NewTransactionActivity extends ProfileThemedActivity } public boolean onSimulateCrashMenuItemClicked(MenuItem item) { debug("crash", "Will crash intentionally"); - new AsyncCrasher().execute(); + GeneralBackgroundTasks.run(() -> { throw new RuntimeException("Simulated crash");}); return true; } public boolean onCreateOptionsMenu(Menu menu) { @@ -207,7 +217,7 @@ public class NewTransactionActivity extends ProfileThemedActivity else { navController.navigate(R.id.action_newTransactionSavingFragment_Success, b); - AsyncTask.execute(() -> commitToDb((LedgerTransaction) arg)); + BaseDAO.runAsync(() -> commitToDb((LedgerTransaction) arg)); } } public void commitToDb(LedgerTransaction tr) { @@ -356,23 +366,19 @@ public class NewTransactionActivity extends ProfileThemedActivity if (!model.accountListIsEmpty()) return; - AsyncTask.execute(() -> { + BaseDAO.runAsync(() -> { String accFilter = mProfile.getPreferredAccountsFilter(); TransactionDAO trDao = DB.get() .getTransactionDAO(); - TransactionWithAccounts tr; + TransactionWithAccounts tr = null; - if (Misc.emptyIsNull(accFilter) != null) { + if (Misc.emptyIsNull(accFilter) != null) tr = trDao.getFirstByDescriptionHavingAccountSync(description, accFilter); - if (tr != null) { - model.loadTransactionIntoModel(tr); - return; - } - } + if (tr == null) + tr = trDao.getFirstByDescriptionSync(description); - tr = trDao.getFirstByDescriptionSync(description); if (tr != null) model.loadTransactionIntoModel(tr); });