From: Damyan Ivanov Date: Sun, 22 Aug 2021 16:53:41 +0000 (+0300) Subject: fix crash when new trans. is started by a shortcut for removed profile X-Git-Tag: v0.20.0~3 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=dee1d58effc26bccf90c03d0f71428a436e6eb99;p=mobile-ledger.git fix crash when new trans. is started by a shortcut for removed profile --- 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