X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fnew_transaction%2FNewTransactionActivity.java;h=50b8c63ea508513dac4aafc5161d2f1920c77b4a;hb=5eadaa3fd9348a396f541ee96a8608dd200e8a7f;hp=51f872f6fef08c612c0c1d24d1b2436b1b9105fe;hpb=311cb018cc9cd6be1f189e2fc674a517ff4d47fc;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 51f872f6..50b8c63e 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 @@ -39,8 +39,8 @@ 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.TransactionDAO; @@ -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) { @@ -198,7 +208,7 @@ public class NewTransactionActivity extends ProfileThemedActivity getResources().getDisplayMetrics())); } @Override - public void done(String error, Object arg) { + public void onTransactionSaveDone(String error, Object arg) { Bundle b = new Bundle(); if (error != null) { b.putString("error", error); @@ -362,17 +372,13 @@ public class NewTransactionActivity extends ProfileThemedActivity 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); });