From: Damyan Ivanov Date: Mon, 30 Aug 2021 19:46:08 +0000 (+0300) Subject: fix a crash when returning to new transaction with no focused input X-Git-Tag: v0.20.1~6 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=e0a6b020086a2b03626cfaf3a50123a6fae4c4e4;p=mobile-ledger.git fix a crash when returning to new transaction with no focused input for example, after an unsuccessful save --- 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 b11945d2..ec9fb39c 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 @@ -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()); } } 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 426cb041..81f1ed07 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 @@ -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; }