]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java
fix a crash when returning to new transaction with no focused input
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / new_transaction / NewTransactionModel.java
index 8b96f365fca9ce415d79ff0b1f8a86ba6f478c7e..81f1ed07ae7d4d20753cc0304918be903cdec1a5 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;
@@ -368,7 +370,7 @@ public class NewTransactionModel extends ViewModel {
             noteFocusChanged(fi.position - 1, fi.element);
         setItems(newList);
     }
-    void noteFocusChanged(int position, FocusedElement element) {
+    void noteFocusChanged(int position, @Nullable FocusedElement element) {
         FocusInfo present = focusInfo.getValue();
         if (present == null || present.position != position || present.element != element)
             focusInfo.setValue(new FocusInfo(position, element));
@@ -894,7 +896,7 @@ public class NewTransactionModel extends ViewModel {
     public static class FocusInfo {
         int position;
         FocusedElement element;
-        public FocusInfo(int position, FocusedElement element) {
+        public FocusInfo(int position, @Nullable FocusedElement element) {
             this.position = position;
             this.element = element;
         }