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;
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);
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();
+ });
+
+ 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();
}
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);
}
};
((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 =
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:
app:layout_constraintStart_toEndOf="@id/new_transaction_date"
app:layout_constraintTop_toTopOf="parent" />
+ <androidx.constraintlayout.widget.ConstraintLayout
+ android:id="@+id/transaction_comment_layout"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:alpha="0.50"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@id/new_transaction_description">
+
+ <TextView
+ android:id="@+id/transaction_comment_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/ic_comment_gray_24dp"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
+
+ <net.ktnx.mobileledger.ui.EditTextWithClear
+ android:id="@+id/transaction_comment"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:imeOptions="actionNext"
+ android:inputType="text"
+ android:visibility="invisible"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toEndOf="@id/transaction_comment_button"
+ app:layout_constraintTop_toTopOf="parent" />
+ </androidx.constraintlayout.widget.ConstraintLayout>
+
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout