]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionActivity.java
fix crash when new trans. is started by a shortcut for removed profile
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / new_transaction / NewTransactionActivity.java
index 9a630f811d2b5f54ae8a22061c2104ba8966df0e..0c0cfac0ec00985b80f8ba556c7a5b78f1eadb0b 100644 (file)
@@ -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));