X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2FCurrencySelectorFragment.java;h=3bbfe1554219aec3b3dd96b40f5a96feb3207966;hb=04774f5e1c5953df1630962ae4f09d548e8d233f;hp=d25db493f7b05b659bd6cb6c21f0989570737564;hpb=a8764e35e1c5e7e40ab73c51e2ac1a7ac7e03b26;p=mobile-ledger-staging.git diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/CurrencySelectorFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/CurrencySelectorFragment.java index d25db493..3bbfe155 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/CurrencySelectorFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/CurrencySelectorFragment.java @@ -59,9 +59,9 @@ public class CurrencySelectorFragment extends AppCompatDialogFragment public static final String ARG_SHOW_PARAMS = "show-params"; public static final boolean DEFAULT_SHOW_PARAMS = true; private int mColumnCount = DEFAULT_COLUMN_COUNT; - private OnCurrencySelectedListener mListener; private CurrencySelectorModel model; private boolean deferredShowPositionAndPadding; + private OnCurrencySelectedListener onCurrencySelectedListener; /** * Mandatory empty constructor for the fragment manager to instantiate the @@ -106,6 +106,8 @@ public class CurrencySelectorFragment extends AppCompatDialogFragment recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount)); } model = new ViewModelProvider(this).get(CurrencySelectorModel.class); + if (onCurrencySelectedListener != null) + model.setOnCurrencySelectedListener(onCurrencySelectedListener); MobileLedgerProfile profile = Objects.requireNonNull(Data.profile.getValue()); model.currencies.setValue(new CopyOnWriteArrayList<>(profile.getCurrencies())); @@ -200,15 +202,17 @@ public class CurrencySelectorFragment extends AppCompatDialogFragment return csd; } public void setOnCurrencySelectedListener(OnCurrencySelectedListener listener) { - mListener = listener; + onCurrencySelectedListener = listener; + + if (model != null) + model.setOnCurrencySelectedListener(listener); } public void resetOnCurrencySelectedListener() { - mListener = null; + model.resetOnCurrencySelectedListener(); } @Override public void onCurrencySelected(Currency item) { - if (mListener != null) - mListener.onCurrencySelected(item); + model.triggerOnCurrencySelectedListener(item); dismiss(); }