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;
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;
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;
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));
try {
SendTransactionTask saver =
- new SendTransactionTask(this, mProfile, model.getSimulateSaveFlag());
- saver.execute(tr);
+ new SendTransactionTask(this, mProfile, tr, model.getSimulateSaveFlag());
+ saver.start();
}
catch (Exception e) {
debug("new-transaction", "Unknown error: " + e);
}
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) {
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);
else {
navController.navigate(R.id.action_newTransactionSavingFragment_Success, b);
- AsyncTask.execute(() -> commitToDb((LedgerTransaction) arg));
+ BaseDAO.runAsync(() -> commitToDb((LedgerTransaction) arg));
}
}
public void commitToDb(LedgerTransaction tr) {
.create()
.show();
}
- public void descriptionSelected(String description) {
+ public void onDescriptionSelected(String description) {
debug("description selected", description);
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);
});