package net.ktnx.mobileledger.ui.activity;
import android.annotation.SuppressLint;
+import android.graphics.Typeface;
import android.os.Build;
import android.text.Editable;
import android.text.TextWatcher;
private Observer<Integer> focusedAccountObserver;
private Observer<Integer> accountCountObserver;
private Observer<Boolean> editableObserver;
- private Observer<Boolean> commentVisibleObserver;
- private Observer<String> commentObserver;
private Observer<Currency.Position> currencyPositionObserver;
private Observer<Boolean> currencyGapObserver;
private Observer<Locale> localeObserver;
private Observer<Currency> currencyObserver;
private Observer<Boolean> showCurrencyObserver;
+ private Observer<String> commentObserver;
private boolean inUpdate = false;
private boolean syncingData = false;
private View commentButton;
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);
tvDescription.setNextFocusForwardId(View.NO_ID);
tvAccount.setNextFocusForwardId(View.NO_ID);
tvDate.setOnClickListener(v -> pickTransactionDate());
+ itemView.findViewById(R.id.comment_button)
+ .setOnClickListener(v -> {
+ tvComment.setVisibility(View.VISIBLE);
+ tvComment.requestFocus();
+ });
+
mProfile = Data.profile.getValue();
if (mProfile == null)
throw new AssertionError();
View.OnFocusChangeListener focusMonitor = (v, hasFocus) -> {
+ final int id = v.getId();
if (hasFocus) {
boolean wasSyncing = syncingData;
syncingData = true;
try {
final int pos = getAdapterPosition();
adapter.updateFocusedItem(pos);
- switch (v.getId()) {
+ switch (id) {
case R.id.account_row_acc_name:
adapter.noteFocusIsOnAccount(pos);
break;
syncingData = wasSyncing;
}
}
+
+ 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);
+ }
};
tvDescription.setOnFocusChangeListener(focusMonitor);
tvAccount.setOnFocusChangeListener(focusMonitor);
tvAmount.setOnFocusChangeListener(focusMonitor);
+ tvComment.setOnFocusChangeListener(focusMonitor);
- itemView.findViewById(R.id.comment_button)
- .setOnClickListener(v -> {
- final int pos = getAdapterPosition();
- adapter.toggleComment(pos);
- });
MLDB.hookAutocompletionAdapter(tvDescription.getContext(), tvDescription,
MLDB.DESCRIPTION_HISTORY_TABLE, "description", false, adapter, mProfile);
MLDB.hookAutocompletionAdapter(tvAccount.getContext(), tvAccount, MLDB.ACCOUNTS_TABLE,
}
};
editableObserver = this::setEditable;
- commentVisibleObserver = this::setCommentVisible;
- commentObserver = this::setComment;
focusedAccountObserver = index -> {
if ((index != null) && index.equals(getAdapterPosition())) {
switch (item.getType()) {
item.setCurrency(null);
}
};
+
+ commentObserver = comment -> {
+ final View focusedView = tvComment.findFocus();
+ tvComment.setTypeface(null,
+ (focusedView == tvComment) ? Typeface.NORMAL : Typeface.ITALIC);
+ tvComment.setVisibility(
+ ((focusedView != tvComment) && Misc.isEmptyOrNull(comment)) ? View.INVISIBLE
+ : View.VISIBLE);
+ };
}
private void updateCurrencyPositionAndPadding(Currency.Position position, boolean hasGap) {
ConstraintLayout.LayoutParams amountLP =
commentButton.setLayoutParams(lp);
}
}
- private void setComment(String comment) {
- if ((comment != null) && !comment.isEmpty())
- commentButton.setBackgroundResource(R.drawable.ic_comment_black_24dp);
- else
- commentButton.setBackgroundResource(R.drawable.ic_comment_gray_24dp);
- }
private void beginUpdates() {
if (inUpdate)
throw new RuntimeException("Already in update mode");
this.item.stopObservingDescription(descriptionObserver);
this.item.stopObservingAmountHint(hintObserver);
this.item.stopObservingEditableFlag(editableObserver);
- this.item.stopObservingCommentVisible(commentVisibleObserver);
- this.item.stopObservingComment(commentObserver);
this.item.getModel()
.stopObservingFocusedItem(focusedAccountObserver);
this.item.getModel()
Data.locale.removeObserver(localeObserver);
this.item.stopObservingCurrency(currencyObserver);
this.item.getModel().showCurrency.removeObserver(showCurrencyObserver);
+ this.item.stopObservingComment(commentObserver);
this.item = null;
}
break;
case transactionRow:
item.observeAmountHint(activity, hintObserver);
- item.observeCommentVisible(activity, commentVisibleObserver);
- item.observeComment(activity, commentObserver);
Data.currencySymbolPosition.observe(activity, currencyPositionObserver);
Data.currencyGap.observe(activity, currencyGapObserver);
Data.locale.observe(activity, localeObserver);
item.observeCurrency(activity, currencyObserver);
item.getModel().showCurrency.observe(activity, showCurrencyObserver);
+ item.observeComment(activity, commentObserver);
item.getModel()
.observeAccountCount(activity, accountCountObserver);
break;
public void noteFocusIsOnComment(int position) {
model.noteFocusChanged(position, NewTransactionModel.FocusedElement.Comment);
}
- public void toggleComment(int position) {
- model.toggleComment(position);
- }
private void holdSubmittableChecks() {
checkHoldCounter++;
}
void swapItems(int one, int two) {
Collections.swap(items, one - 1, two - 1);
}
- void toggleComment(int position) {
- final MutableLiveData<Boolean> commentVisible = getItem(position).commentVisible;
- commentVisible.postValue(!commentVisible.getValue());
- }
void moveItemLast(int index) {
/* 0
1 <-- index
private MutableLiveData<Boolean> editable = new MutableLiveData<>(true);
private FocusedElement focusedElement = FocusedElement.Account;
private MutableLiveData<String> comment = new MutableLiveData<>(null);
- private MutableLiveData<Boolean> commentVisible = new MutableLiveData<>(false);
private MutableLiveData<Currency> currency = new MutableLiveData<>(null);
private boolean amountHintIsSet = false;
Item(NewTransactionModel model) {
void stopObservingEditableFlag(Observer<Boolean> observer) {
editable.removeObserver(observer);
}
- void observeCommentVisible(NewTransactionActivity activity, Observer<Boolean> observer) {
- commentVisible.observe(activity, observer);
- }
- void stopObservingCommentVisible(Observer<Boolean> observer) {
- commentVisible.removeObserver(observer);
- }
void observeComment(NewTransactionActivity activity, Observer<String> observer) {
comment.observe(activity, observer);
}
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
- <TextView
- android:id="@+id/comment_button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/ic_comment_gray_24dp"
- app:layout_constraintBottom_toBottomOf="@id/amount_layout"
- app:layout_constraintStart_toStartOf="@+id/ntr_account"
- app:layout_constraintTop_toBottomOf="@+id/account_row_acc_name" />
-
- <EditText
- android:id="@+id/comment"
+ <androidx.constraintlayout.widget.ConstraintLayout
+ android:id="@+id/comment_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
- android:hint="@string/transaction_account_comment_hint"
- android:imeOptions="actionNext"
- android:inputType="text"
- android:visibility="gone"
- app:layout_constraintEnd_toEndOf="@+id/ntr_account"
- app:layout_constraintStart_toEndOf="@id/comment_button"
- app:layout_constraintTop_toBottomOf="@id/account_row_acc_name" />
+ android:alpha="0.50"
+ app:layout_constraintEnd_toStartOf="@id/amount_layout"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@id/account_row_acc_name">
+
+ <TextView
+ android:id="@+id/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/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/comment_button"
+ app:layout_constraintTop_toTopOf="parent" />
+ </androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/amount_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintTop_toBottomOf="@id/comment">
+ app:layout_constraintTop_toBottomOf="@id/account_row_acc_name">
<EditText
- app:layout_constraintTop_toTopOf="parent"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintLeft_toLeftOf="parent"
- app:layout_constraintRight_toLeftOf="@id/currency"
android:id="@+id/account_row_acc_amounts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="80sp"
android:selectAllOnFocus="true"
android:textAlignment="viewEnd"
- app:layout_constraintWidth_min="@dimen/text_margin"/>
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintLeft_toLeftOf="parent"
+ app:layout_constraintRight_toLeftOf="@id/currency"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintWidth_min="@dimen/text_margin" />
<TextView
- app:layout_constraintTop_toTopOf="parent"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintRight_toRightOf="parent"
android:id="@+id/currency"
+ style="@style/TextAppearance.AppCompat.Widget.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
+ android:gravity="center_horizontal"
+ android:minWidth="24dp"
android:text="@string/currency_symbol"
- style="@style/TextAppearance.AppCompat.Widget.Button"
android:textAllCaps="false"
android:visibility="gone"
- android:minWidth="24dp"
- android:gravity="center_horizontal"/>
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintRight_toRightOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>