From: Damyan Ivanov Date: Sun, 10 May 2020 18:47:31 +0000 (+0000) Subject: transaction-level comments in new transaction UI, optional X-Git-Tag: v0.13.0~18 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=7b3937e47b0b270651ad3083e467bfaaf62e9dc8;p=mobile-ledger.git transaction-level comments in new transaction UI, optional --- diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java index 1074bcb9..39f53a97 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java @@ -75,20 +75,30 @@ public class NewTransactionFragment extends Fragment { @Override public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); + final FragmentActivity activity = getActivity(); + inflater.inflate(R.menu.new_transaction_fragment, menu); menu.findItem(R.id.action_reset_new_transaction_activity) .setOnMenuItemClickListener(item -> { listAdapter.reset(); return true; }); + final MenuItem toggleCurrencyItem = menu.findItem(R.id.toggle_currency); toggleCurrencyItem.setOnMenuItemClickListener(item -> { viewModel.toggleCurrencyVisible(); return true; }); - final FragmentActivity activity = getActivity(); if (activity != null) viewModel.showCurrency.observe(activity, toggleCurrencyItem::setChecked); + + final MenuItem toggleCommentsItem = menu.findItem(R.id.toggle_comments); + toggleCommentsItem.setOnMenuItemClickListener(item -> { + viewModel.toggleShowComments(); + return true; + }); + if (activity != null) + viewModel.showComments.observe(activity, toggleCommentsItem::setChecked); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, 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 63de5370..d92a4c69 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 @@ -53,8 +53,6 @@ import net.ktnx.mobileledger.utils.Logger; import net.ktnx.mobileledger.utils.MLDB; import net.ktnx.mobileledger.utils.Misc; -import org.jetbrains.annotations.NotNull; - import java.text.DecimalFormatSymbols; import java.util.Calendar; import java.util.Date; @@ -68,6 +66,8 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder private final String decimalSeparator; private final String decimalDot; private final TextView tvCurrency; + private final Observer showCommentsObserver; + private final TextView tvTransactionComment; private NewTransactionModel.Item item; private TextView tvDate; private AutoCompleteTextView tvDescription; @@ -99,6 +99,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder super(itemView); tvAccount = itemView.findViewById(R.id.account_row_acc_name); tvComment = itemView.findViewById(R.id.comment); + tvTransactionComment = itemView.findViewById(R.id.transaction_comment); new TextViewClearHelper().attachToTextView((EditText) tvComment); commentButton = itemView.findViewById(R.id.comment_button); tvAmount = itemView.findViewById(R.id.account_row_acc_amounts); @@ -108,7 +109,9 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder lHead = itemView.findViewById(R.id.ntr_data); lAccount = itemView.findViewById(R.id.ntr_account); lPadding = itemView.findViewById(R.id.ntr_padding); - View commentLayout = itemView.findViewById(R.id.comment_layout); + final View commentLayout = itemView.findViewById(R.id.comment_layout); + final View transactionCommentLayout = + itemView.findViewById(R.id.transaction_comment_layout); tvDescription.setNextFocusForwardId(View.NO_ID); tvAccount.setNextFocusForwardId(View.NO_ID); @@ -116,10 +119,15 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder tvDate.setOnClickListener(v -> pickTransactionDate()); - itemView.findViewById(R.id.comment_button) + commentButton.setOnClickListener(v -> { + tvComment.setVisibility(View.VISIBLE); + tvComment.requestFocus(); + }); + + itemView.findViewById(R.id.transaction_comment_button) .setOnClickListener(v -> { - tvComment.setVisibility(View.VISIBLE); - tvComment.requestFocus(); + tvTransactionComment.setVisibility(View.VISIBLE); + tvTransactionComment.requestFocus(); }); mProfile = Data.profile.getValue(); @@ -152,15 +160,10 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder } if (id == R.id.comment) { - commentLayout.setAlpha(hasFocus ? 1f : 0.5f); - tvComment.setTypeface(null, hasFocus ? Typeface.NORMAL : Typeface.ITALIC); - if (hasFocus) - tvComment.setHint(R.string.transaction_account_comment_hint); - else - tvComment.setHint(""); - - if (!hasFocus && Misc.isEmptyOrNull(tvComment.getText())) - tvComment.setVisibility(View.INVISIBLE); + commentFocusChanged(commentLayout, tvComment, hasFocus); + } + else if ( id == R.id.transaction_comment) { + commentFocusChanged(transactionCommentLayout, tvTransactionComment, hasFocus); } }; @@ -387,6 +390,49 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder ((focusedView != tvComment) && Misc.isEmptyOrNull(comment)) ? View.INVISIBLE : View.VISIBLE); }; + + showCommentsObserver = show -> { + final View amountLayout = itemView.findViewById(R.id.amount_layout); + ConstraintLayout.LayoutParams amountLayoutParams = + (ConstraintLayout.LayoutParams) amountLayout.getLayoutParams(); + ConstraintLayout.LayoutParams accountParams = + (ConstraintLayout.LayoutParams) tvAccount.getLayoutParams(); + if (show) { + commentLayout.setVisibility(View.VISIBLE); + + accountParams.endToStart = ConstraintLayout.LayoutParams.UNSET; + accountParams.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID; + + amountLayoutParams.topToTop = ConstraintLayout.LayoutParams.UNSET; + amountLayoutParams.topToBottom = tvAccount.getId(); + } + else { + commentLayout.setVisibility(View.GONE); + + accountParams.endToStart = amountLayout.getId(); + accountParams.endToEnd = ConstraintLayout.LayoutParams.UNSET; + + amountLayoutParams.topToBottom = ConstraintLayout.LayoutParams.UNSET; + amountLayoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID; + + } + + tvAccount.setLayoutParams(accountParams); + amountLayout.setLayoutParams(amountLayoutParams); + + transactionCommentLayout.setVisibility(show ? View.VISIBLE : View.GONE); + }; + } + private void commentFocusChanged(View layout, TextView textView, boolean hasFocus) { + layout.setAlpha(hasFocus ? 1f : 0.5f); + textView.setTypeface(null, hasFocus ? Typeface.NORMAL : Typeface.ITALIC); + if (hasFocus) + textView.setHint(R.string.transaction_account_comment_hint); + else + textView.setHint(""); + + if (!hasFocus && Misc.isEmptyOrNull(textView.getText())) + textView.setVisibility(View.INVISIBLE); } private void updateCurrencyPositionAndPadding(Currency.Position position, boolean hasGap) { ConstraintLayout.LayoutParams amountLP = @@ -452,27 +498,6 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder tvAccount.setEnabled(editable); tvAmount.setEnabled(editable); } - private void setCommentVisible(@NotNull Boolean visible) { - if (visible) { - // showing; show the comment view and align the comment button to it - tvComment.setVisibility(View.VISIBLE); - tvComment.requestFocus(); - ConstraintLayout.LayoutParams lp = - (ConstraintLayout.LayoutParams) commentButton.getLayoutParams(); - lp.bottomToBottom = R.id.comment; - - commentButton.setLayoutParams(lp); - } - else { - // hiding; hide the comment view and align the comment bottom to the amount - tvComment.setVisibility(View.GONE); - ConstraintLayout.LayoutParams lp = - (ConstraintLayout.LayoutParams) commentButton.getLayoutParams(); - lp.bottomToBottom = R.id.amount_layout; // R.id.parent doesn't work here - - commentButton.setLayoutParams(lp); - } - } private void beginUpdates() { if (inUpdate) throw new RuntimeException("Already in update mode"); @@ -583,6 +608,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder this.item.stopObservingCurrency(currencyObserver); this.item.getModel().showCurrency.removeObserver(showCurrencyObserver); this.item.stopObservingComment(commentObserver); + this.item.getModel().showComments.removeObserver(showCommentsObserver); this.item = null; } @@ -630,6 +656,8 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder item.observeEditableFlag(activity, editableObserver); item.getModel() .observeFocusedItem(activity, focusedAccountObserver); + item.getModel() + .observeShowComments(activity, showCommentsObserver); } switch (item.getType()) { case generalData: diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java index 062495c1..d7663bcd 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java @@ -59,6 +59,10 @@ public class NewTransactionModel extends ViewModel { profile -> showCurrency.postValue(profile.getShowCommodityByDefault()); private final AtomicInteger busyCounter = new AtomicInteger(0); private final MutableLiveData busyFlag = new MutableLiveData<>(false); + final MutableLiveData showComments = new MutableLiveData<>(false); + void observeShowComments(LifecycleOwner owner, Observer observer) { + showComments.observe(owner, observer); + } void observeBusyFlag(@NonNull LifecycleOwner owner, Observer observer) { busyFlag.observe(owner, observer); } @@ -207,6 +211,9 @@ public class NewTransactionModel extends ViewModel { public boolean getBusyFlag() { return busyFlag.getValue(); } + public void toggleShowComments() { + showComments.setValue(!showComments.getValue()); + } enum ItemType {generalData, transactionRow, bottomFiller} enum FocusedElement {Account, Comment, Amount} diff --git a/app/src/main/res/layout/new_transaction_row.xml b/app/src/main/res/layout/new_transaction_row.xml index 5a057934..44d902e0 100644 --- a/app/src/main/res/layout/new_transaction_row.xml +++ b/app/src/main/res/layout/new_transaction_row.xml @@ -73,6 +73,36 @@ app:layout_constraintStart_toEndOf="@id/new_transaction_date" app:layout_constraintTop_toTopOf="parent" /> + + + + + + + + Показване по подразбиране на полето за валута Валута по подразбиране Липсват трансакции с предпочитаната сметка - + Коментари diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 187a8f64..a2358696 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -159,4 +159,5 @@ Default commodity No transactions with preferred account found icon + Comments