]> git.ktnx.net Git - mobile-ledger.git/commitdiff
fix crash when new trans. is started by a shortcut for removed profile
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 22 Aug 2021 16:53:41 +0000 (19:53 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 22 Aug 2021 16:53:41 +0000 (19:53 +0300)
app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionActivity.java
app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java
app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java
app/src/main/res/values-bg/strings.xml
app/src/main/res/values/strings.xml

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));
index 60fd3cbabd91afc6213c7ee8ddfcde39dea89bcc..9bcac1c81a9b65d2b0d5ada9441493a71efb7120 100644 (file)
@@ -231,10 +231,12 @@ public class NewTransactionFragment extends Fragment {
         outState.putBoolean("keep", true);
         final NewTransactionModel.FocusInfo focusInfo = viewModel.getFocusInfo()
                                                                  .getValue();
-        final int focusedItem = focusInfo.position;
-        if (focusedItem >= 0)
-            outState.putInt("focused-item", focusedItem);
-        outState.putString("focused-element", focusInfo.element.toString());
+        if (focusInfo != null) {
+            final int focusedItem = focusInfo.position;
+            if (focusedItem >= 0)
+                outState.putInt("focused-item", focusedItem);
+            outState.putString("focused-element", focusInfo.element.toString());
+        }
     }
 
     @Override
index 8b96f365fca9ce415d79ff0b1f8a86ba6f478c7e..426cb0417300b51e52116fae6d9dd9463ca0c474 100644 (file)
@@ -74,8 +74,10 @@ public class NewTransactionModel extends ViewModel {
     private final AtomicInteger busyCounter = new AtomicInteger(0);
     private final MutableLiveData<Boolean> busyFlag = new InertMutableLiveData<>(false);
     private final Observer<Profile> profileObserver = profile -> {
-        showCurrency.postValue(profile.getShowCommodityByDefault());
-        showComments.postValue(profile.getShowCommentsByDefault());
+        if (profile != null) {
+            showCurrency.postValue(profile.getShowCommodityByDefault());
+            showComments.postValue(profile.getShowCommentsByDefault());
+        }
     };
     private final MutableLiveData<FocusInfo> focusInfo = new MutableLiveData<>();
     private boolean observingDataProfile;
index 0431916b62402fd8d193f8cc659e9cef18c60c4a..cbc309126f2e017076d482fa2966aff111daa5cb 100644 (file)
     <string name="restore_explanation">Зареждане на настройките на профилите и макетите от резервно копие, създадено по-рано. Съществуващите записи не се променят. Ако искате да върнете някой запис (профил или макет) към състоянитето от резервното копие, първо го изтрийте.</string>
     <string name="config_restored">Успешно възстановяване на настройките</string>
     <string name="no_profile_restore_hint">… а може и да възстановите настройките от резервно копие</string>
+    <string name="profile_not_available">Недостъпен профил</string>
 </resources>
index d7de3af8251aec77d1813f4a112a68a80fd1eb82..d6a756d80d355dcf213a36c2383f2c2f2d1e7982 100644 (file)
     <string name="backups_activity_label">Backup / Restore</string>
     <string name="config_restored">Configuration restored successfully</string>
     <string name="no_profile_restore_hint">… or, you may restore from backup</string>
+    <string name="profile_not_available">Profile not available</string>
 </resources>