From: Damyan Ivanov Date: Fri, 17 Apr 2020 19:11:21 +0000 (+0300) Subject: make the position/padding currency parameters optional X-Git-Tag: v0.12.0~52 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=d2409f5625f84f811a323dbd1e0358dd7993e4da;p=mobile-ledger.git make the position/padding currency parameters optional --- 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 57c602b4..d25db493 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/CurrencySelectorFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/CurrencySelectorFragment.java @@ -55,10 +55,13 @@ public class CurrencySelectorFragment extends AppCompatDialogFragment implements OnCurrencySelectedListener, OnCurrencyLongClickListener { public static final int DEFAULT_COLUMN_COUNT = 2; - private static final String ARG_COLUMN_COUNT = "column-count"; + public static final String ARG_COLUMN_COUNT = "column-count"; + 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; /** * Mandatory empty constructor for the fragment manager to instantiate the @@ -68,12 +71,13 @@ public class CurrencySelectorFragment extends AppCompatDialogFragment } @SuppressWarnings("unused") public static CurrencySelectorFragment newInstance() { - return newInstance(DEFAULT_COLUMN_COUNT); + return newInstance(DEFAULT_COLUMN_COUNT, DEFAULT_SHOW_PARAMS); } - public static CurrencySelectorFragment newInstance(int columnCount) { + public static CurrencySelectorFragment newInstance(int columnCount, boolean showParams) { CurrencySelectorFragment fragment = new CurrencySelectorFragment(); Bundle args = new Bundle(); args.putInt(ARG_COLUMN_COUNT, columnCount); + args.putBoolean(ARG_SHOW_PARAMS, showParams); fragment.setArguments(args); return fragment; } @@ -182,6 +186,17 @@ public class CurrencySelectorFragment extends AppCompatDialogFragment Data.currencyGap.setValue(checked); }); + model.observePositionAndPaddingVisible(this, visible -> { + csd.findViewById(R.id.params_panel) + .setVisibility(visible ? View.VISIBLE : View.GONE); + }); + + if ((savedInstanceState != null) ? savedInstanceState.getBoolean(ARG_SHOW_PARAMS, + DEFAULT_SHOW_PARAMS) : DEFAULT_SHOW_PARAMS) + model.showPositionAndPadding(); + else + model.hidePositionAndPadding(); + return csd; } public void setOnCurrencySelectedListener(OnCurrencySelectedListener listener) { @@ -206,4 +221,10 @@ public class CurrencySelectorFragment extends AppCompatDialogFragment list.remove(item); model.currencies.setValue(list); } + public void showPositionAndPadding() { + deferredShowPositionAndPadding = true; + } + public void hidePositionAndPadding() { + deferredShowPositionAndPadding = false; + } } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/CurrencySelectorModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/CurrencySelectorModel.java index 10fea517..a2bc9ca4 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/CurrencySelectorModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/CurrencySelectorModel.java @@ -17,7 +17,9 @@ package net.ktnx.mobileledger.ui; +import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.MutableLiveData; +import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModel; import net.ktnx.mobileledger.model.Currency; @@ -26,7 +28,17 @@ import java.util.List; public class CurrencySelectorModel extends ViewModel { public final MutableLiveData> currencies; + private final MutableLiveData positionAndPaddingVisible = new MutableLiveData<>(true); public CurrencySelectorModel() { this.currencies = new MutableLiveData<>(); } + public void showPositionAndPadding() { + positionAndPaddingVisible.postValue(true); + } + public void hidePositionAndPadding() { + positionAndPaddingVisible.postValue(false); + } + public void observePositionAndPaddingVisible(LifecycleOwner activity, Observer observer) { + positionAndPaddingVisible.observe(activity, observer); + } } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java index a72de5d0..89c88731 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java @@ -226,6 +226,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder tvCurrency.setOnClickListener(v -> { CurrencySelectorFragment cpf = new CurrencySelectorFragment(); cpf.setOnCurrencySelectedListener(this); + cpf.showPositionAndPadding(); final AppCompatActivity activity = (AppCompatActivity) v.getContext(); cpf.show(activity.getSupportFragmentManager(), "currency-selector"); });