X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FNewTransactionItemHolder.java;h=3e6cab36328f7079e569f4efaad78de619de16aa;hb=ee3c0ffdb714b35759198466f955e2333fdd8c8b;hp=d92a4c69d542aaef4496ac002d4de7b6a80aed9e;hpb=7b3937e47b0b270651ad3083e467bfaaf62e9dc8;p=mobile-ledger.git 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 d92a4c69..3e6cab36 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 @@ -81,6 +81,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder private Date date; private Observer dateObserver; private Observer descriptionObserver; + private Observer transactionCommentObserver; private Observer hintObserver; private Observer focusedAccountObserver; private Observer accountCountObserver; @@ -97,17 +98,17 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder //TODO multiple amounts with different currencies per posting NewTransactionItemHolder(@NonNull View itemView, NewTransactionItemsAdapter adapter) { super(itemView); - tvAccount = itemView.findViewById(R.id.account_row_acc_name); - tvComment = itemView.findViewById(R.id.comment); + lAccount = itemView.findViewById(R.id.ntr_account); + tvAccount = lAccount.findViewById(R.id.account_row_acc_name); + tvComment = lAccount.findViewById(R.id.comment); tvTransactionComment = itemView.findViewById(R.id.transaction_comment); new TextViewClearHelper().attachToTextView((EditText) tvComment); - commentButton = itemView.findViewById(R.id.comment_button); + commentButton = lAccount.findViewById(R.id.comment_button); tvAmount = itemView.findViewById(R.id.account_row_acc_amounts); tvCurrency = itemView.findViewById(R.id.currency); tvDate = itemView.findViewById(R.id.new_transaction_date); tvDescription = itemView.findViewById(R.id.new_transaction_description); lHead = itemView.findViewById(R.id.ntr_data); - lAccount = itemView.findViewById(R.id.ntr_account); lPadding = itemView.findViewById(R.id.ntr_padding); final View commentLayout = itemView.findViewById(R.id.comment_layout); final View transactionCommentLayout = @@ -124,7 +125,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder tvComment.requestFocus(); }); - itemView.findViewById(R.id.transaction_comment_button) + transactionCommentLayout.findViewById(R.id.comment_button) .setOnClickListener(v -> { tvTransactionComment.setVisibility(View.VISIBLE); tvTransactionComment.requestFocus(); @@ -152,6 +153,12 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder case R.id.comment: adapter.noteFocusIsOnComment(pos); break; + case R.id.transaction_comment: + adapter.noteFocusIsOnTransactionComment(pos); + break; + case R.id.new_transaction_description: + adapter.noteFocusIsOnDescription(pos); + break; } } finally { @@ -162,7 +169,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder if (id == R.id.comment) { commentFocusChanged(commentLayout, tvComment, hasFocus); } - else if ( id == R.id.transaction_comment) { + else if (id == R.id.transaction_comment) { commentFocusChanged(transactionCommentLayout, tvTransactionComment, hasFocus); } }; @@ -171,6 +178,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder tvAccount.setOnFocusChangeListener(focusMonitor); tvAmount.setOnFocusChangeListener(focusMonitor); tvComment.setOnFocusChangeListener(focusMonitor); + tvTransactionComment.setOnFocusChangeListener(focusMonitor); MLDB.hookAutocompletionAdapter(tvDescription.getContext(), tvDescription, MLDB.DESCRIPTION_HISTORY_TABLE, "description", false, adapter, mProfile); @@ -235,6 +243,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder } }; tvDescription.addTextChangedListener(tw); + tvTransactionComment.addTextChangedListener(tw); tvAccount.addTextChangedListener(tw); tvComment.addTextChangedListener(tw); tvAmount.addTextChangedListener(amountWatcher); @@ -276,6 +285,15 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder syncingData = false; } }; + transactionCommentObserver = transactionComment -> { + final View focusedView = tvTransactionComment.findFocus(); + tvTransactionComment.setTypeface(null, + (focusedView == tvTransactionComment) ? Typeface.NORMAL : Typeface.ITALIC); + tvTransactionComment.setVisibility(((focusedView != tvTransactionComment) && + Misc.isEmptyOrNull(transactionComment)) + ? View.INVISIBLE : View.VISIBLE); + + }; hintObserver = hint -> { if (syncingData) return; @@ -292,41 +310,47 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder }; editableObserver = this::setEditable; focusedAccountObserver = index -> { - if ((index != null) && index.equals(getAdapterPosition())) { - switch (item.getType()) { - case generalData: - // bad idea - double pop-up, and not really necessary. - // the user can tap the input to get the calendar - //if (!tvDate.hasFocus()) tvDate.requestFocus(); - boolean focused = tvDescription.requestFocus(); - tvDescription.dismissDropDown(); - if (focused) - Misc.showSoftKeyboard( - (NewTransactionActivity) tvDescription.getContext()); - break; - case transactionRow: - // do nothing if a row element already has the focus - if (!itemView.hasFocus()) { - switch (item.getFocusedElement()) { - case Amount: - tvAmount.requestFocus(); - break; - case Comment: - tvComment.setVisibility(View.VISIBLE); - tvComment.requestFocus(); - break; - case Account: - focused = tvAccount.requestFocus(); - tvAccount.dismissDropDown(); - if (focused) - Misc.showSoftKeyboard( - (NewTransactionActivity) tvAccount.getContext()); - break; - } - } + if ((index == null) || !index.equals(getAdapterPosition()) || itemView.hasFocus()) + return; - break; - } + switch (item.getType()) { + case generalData: + // bad idea - double pop-up, and not really necessary. + // the user can tap the input to get the calendar + //if (!tvDate.hasFocus()) tvDate.requestFocus(); + switch (item.getFocusedElement()) { + case TransactionComment: + tvTransactionComment.setVisibility(View.VISIBLE); + tvTransactionComment.requestFocus(); + break; + case Description: + boolean focused = tvDescription.requestFocus(); + tvDescription.dismissDropDown(); + if (focused) + Misc.showSoftKeyboard( + (NewTransactionActivity) tvDescription.getContext()); + break; + } + break; + case transactionRow: + switch (item.getFocusedElement()) { + case Amount: + tvAmount.requestFocus(); + break; + case Comment: + tvComment.setVisibility(View.VISIBLE); + tvComment.requestFocus(); + break; + case Account: + boolean focused = tvAccount.requestFocus(); + tvAccount.dismissDropDown(); + if (focused) + Misc.showSoftKeyboard( + (NewTransactionActivity) tvAccount.getContext()); + break; + } + + break; } }; accountCountObserver = count -> { @@ -398,23 +422,22 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder 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(); + + commentLayout.setVisibility(View.VISIBLE); } 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; + commentLayout.setVisibility(View.GONE); } tvAccount.setLayoutParams(accountParams); @@ -424,15 +447,22 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder }; } 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) + int textColor; + if (hasFocus) { + textColor = Colors.defaultTextColor; + textView.setTypeface(null, Typeface.NORMAL); textView.setHint(R.string.transaction_account_comment_hint); - else + } + else { + textColor = Colors.defaultTextColorDisabled; + textView.setTypeface(null, Typeface.ITALIC); textView.setHint(""); + if (Misc.isEmptyOrNull(textView.getText())) { + textView.setVisibility(View.INVISIBLE); + } + } + textView.setTextColor(textColor); - if (!hasFocus && Misc.isEmptyOrNull(textView.getText())) - textView.setVisibility(View.INVISIBLE); } private void updateCurrencyPositionAndPadding(Currency.Position position, boolean hasGap) { ConstraintLayout.LayoutParams amountLP = @@ -531,6 +561,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder case generalData: item.setDate(String.valueOf(tvDate.getText())); item.setDescription(String.valueOf(tvDescription.getText())); + item.setTransactionComment(String.valueOf(tvTransactionComment.getText())); break; case transactionRow: final LedgerTransactionAccount account = item.getAccount(); @@ -596,6 +627,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder if (this.item != null && !this.item.equals(item)) { this.item.stopObservingDate(dateObserver); this.item.stopObservingDescription(descriptionObserver); + this.item.stopObservingTransactionComment(transactionCommentObserver); this.item.stopObservingAmountHint(hintObserver); this.item.stopObservingEditableFlag(editableObserver); this.item.getModel() @@ -617,6 +649,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder case generalData: tvDate.setText(item.getFormattedDate()); tvDescription.setText(item.getDescription()); + tvTransactionComment.setText(item.getTransactionComment()); lHead.setVisibility(View.VISIBLE); lAccount.setVisibility(View.GONE); lPadding.setVisibility(View.GONE); @@ -663,6 +696,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder case generalData: item.observeDate(activity, dateObserver); item.observeDescription(activity, descriptionObserver); + item.observeTransactionComment(activity, transactionCommentObserver); break; case transactionRow: item.observeAmountHint(activity, hintObserver);