import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.FrameLayout;
-import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
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;
private final String decimalSeparator;
private final String decimalDot;
private final TextView tvCurrency;
+ private final Observer<Boolean> showCommentsObserver;
+ private final TextView tvTransactionComment;
private NewTransactionModel.Item item;
private TextView tvDate;
private AutoCompleteTextView tvDescription;
private AutoCompleteTextView tvAccount;
private TextView tvComment;
private EditText tvAmount;
- private LinearLayout lHead;
+ private ViewGroup lHead;
private ViewGroup lAccount;
private FrameLayout lPadding;
private MobileLedgerProfile mProfile;
//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);
- 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);
tvDate.setOnClickListener(v -> pickTransactionDate());
- itemView.findViewById(R.id.comment_button)
+ commentButton.setOnClickListener(v -> {
+ tvComment.setVisibility(View.VISIBLE);
+ tvComment.requestFocus();
+ });
+
+ transactionCommentLayout.findViewById(R.id.comment_button)
.setOnClickListener(v -> {
- tvComment.setVisibility(View.VISIBLE);
- tvComment.requestFocus();
+ tvTransactionComment.setVisibility(View.VISIBLE);
+ tvTransactionComment.requestFocus();
});
mProfile = Data.profile.getValue();
}
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);
}
};
tvAmount.requestFocus();
break;
case Comment:
+ tvComment.setVisibility(View.VISIBLE);
tvComment.requestFocus();
break;
case Account:
((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) {
+ 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 {
+ 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);
+ amountLayout.setLayoutParams(amountLayoutParams);
+
+ transactionCommentLayout.setVisibility(show ? View.VISIBLE : View.GONE);
+ };
+ }
+ private void commentFocusChanged(View layout, TextView textView, boolean hasFocus) {
+ int textColor;
+ if (hasFocus) {
+ textColor = Colors.defaultTextColor;
+ textView.setTypeface(null, Typeface.NORMAL);
+ textView.setHint(R.string.transaction_account_comment_hint);
+ }
+ else {
+ textColor = Colors.defaultTextColorDisabled;
+ textView.setTypeface(null, Typeface.ITALIC);
+ textView.setHint("");
+ if (Misc.isEmptyOrNull(textView.getText())) {
+ textView.setVisibility(View.INVISIBLE);
+ }
+ }
+ textView.setTextColor(textColor);
+
}
private void updateCurrencyPositionAndPadding(Currency.Position position, boolean hasGap) {
ConstraintLayout.LayoutParams amountLP =
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");
this.item.stopObservingCurrency(currencyObserver);
this.item.getModel().showCurrency.removeObserver(showCurrencyObserver);
this.item.stopObservingComment(commentObserver);
+ this.item.getModel().showComments.removeObserver(showCommentsObserver);
this.item = null;
}
item.observeEditableFlag(activity, editableObserver);
item.getModel()
.observeFocusedItem(activity, focusedAccountObserver);
+ item.getModel()
+ .observeShowComments(activity, showCommentsObserver);
}
switch (item.getType()) {
case generalData: