]> git.ktnx.net Git - mobile-ledger.git/commitdiff
fix a crash when returning to new transaction with no focused input
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 30 Aug 2021 19:46:08 +0000 (22:46 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 30 Aug 2021 19:46:08 +0000 (22:46 +0300)
for example, after an unsuccessful save

app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java
app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java

index b11945d2e44a37fad9319461d413d479d4ba1de8..ec9fb39c7331fcb3fe6ed845258c9a0539cfb693 100644 (file)
@@ -191,7 +191,9 @@ public class NewTransactionFragment extends Fragment {
         if (savedInstanceState != null) {
             keep |= savedInstanceState.getBoolean("keep", true);
             focused = savedInstanceState.getInt("focused-item", 0);
-            element = FocusedElement.valueOf(savedInstanceState.getString("focused-element"));
+            final String focusedElementString = savedInstanceState.getString("focused-element");
+            if (focusedElementString != null)
+                element = FocusedElement.valueOf(focusedElementString);
         }
 
         if (!keep) {
@@ -234,7 +236,8 @@ public class NewTransactionFragment extends Fragment {
             final int focusedItem = focusInfo.position;
             if (focusedItem >= 0)
                 outState.putInt("focused-item", focusedItem);
-            outState.putString("focused-element", focusInfo.element.toString());
+            if (focusInfo.element != null)
+                outState.putString("focused-element", focusInfo.element.toString());
         }
     }
 
index 426cb0417300b51e52116fae6d9dd9463ca0c474..81f1ed07ae7d4d20753cc0304918be903cdec1a5 100644 (file)
@@ -370,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));
@@ -896,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;
         }