From dee1d58effc26bccf90c03d0f71428a436e6eb99 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sun, 22 Aug 2021 19:53:41 +0300 Subject: [PATCH] fix crash when new trans. is started by a shortcut for removed profile --- .../ui/new_transaction/NewTransactionActivity.java | 14 ++++++++++++-- .../ui/new_transaction/NewTransactionFragment.java | 10 ++++++---- .../ui/new_transaction/NewTransactionModel.java | 6 ++++-- app/src/main/res/values-bg/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 5 files changed, 24 insertions(+), 8 deletions(-) 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 9a630f81..0c0cfac0 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 @@ -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)); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java index 60fd3cba..9bcac1c8 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java @@ -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 diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java index 8b96f365..426cb041 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java @@ -74,8 +74,10 @@ public class NewTransactionModel extends ViewModel { private final AtomicInteger busyCounter = new AtomicInteger(0); private final MutableLiveData busyFlag = new InertMutableLiveData<>(false); private final Observer 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 = new MutableLiveData<>(); private boolean observingDataProfile; diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index 0431916b..cbc30912 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -200,4 +200,5 @@ Зареждане на настройките на профилите и макетите от резервно копие, създадено по-рано. Съществуващите записи не се променят. Ако искате да върнете някой запис (профил или макет) към състоянитето от резервното копие, първо го изтрийте. Успешно възстановяване на настройките … а може и да възстановите настройките от резервно копие + Недостъпен профил diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d7de3af8..d6a756d8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -209,4 +209,5 @@ Backup / Restore Configuration restored successfully … or, you may restore from backup + Profile not available -- 2.39.2