import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
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 androidx.appcompat.app.AppCompatActivity;
+import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.RecyclerView;
import net.ktnx.mobileledger.model.Data;
import net.ktnx.mobileledger.model.LedgerTransactionAccount;
import net.ktnx.mobileledger.model.MobileLedgerProfile;
-import net.ktnx.mobileledger.ui.AutoCompleteTextViewWithClear;
+import net.ktnx.mobileledger.ui.CurrencySelectorFragment;
import net.ktnx.mobileledger.ui.DatePickerFragment;
+import net.ktnx.mobileledger.ui.TextViewClearHelper;
+import net.ktnx.mobileledger.utils.Colors;
import net.ktnx.mobileledger.utils.Logger;
import net.ktnx.mobileledger.utils.MLDB;
import net.ktnx.mobileledger.utils.Misc;
private Observer<Integer> focusedAccountObserver;
private Observer<Integer> accountCountObserver;
private Observer<Boolean> editableObserver;
+ private Observer<Boolean> commentVisibleObserver;
+ private Observer<String> commentObserver;
private boolean inUpdate = false;
private boolean syncingData = false;
+ private View commentButton;
NewTransactionItemHolder(@NonNull View itemView, NewTransactionItemsAdapter adapter) {
super(itemView);
tvAccount = itemView.findViewById(R.id.account_row_acc_name);
tvComment = itemView.findViewById(R.id.comment);
+ new TextViewClearHelper().attachToTextView((EditText) tvComment);
+ commentButton = itemView.findViewById(R.id.comment_button);
tvAmount = itemView.findViewById(R.id.account_row_acc_amounts);
tvDate = itemView.findViewById(R.id.new_transaction_date);
tvDescription = itemView.findViewById(R.id.new_transaction_description);
tvAccount.setOnFocusChangeListener(focusMonitor);
tvAmount.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()) {
tvAccount.setEnabled(editable);
tvAmount.setEnabled(editable);
}
+ private void setCommentVisible(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 comment view and align amounts layout under it
+ tvComment.setVisibility(View.GONE);
+ ConstraintLayout.LayoutParams lp =
+ (ConstraintLayout.LayoutParams) commentButton.getLayoutParams();
+ lp.bottomToBottom = R.id.ntr_account; // R.id.parent doesn't work here
+
+ 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");
final LedgerTransactionAccount account = item.getAccount();
account.setAccountName(String.valueOf(tvAccount.getText()));
- account.setComment(String.valueOf(tvComment.getText()));
+ item.setComment(String.valueOf(tvComment.getText()));
// TODO: handle multiple amounts
String amount = String.valueOf(tvAmount.getText());
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()
item.observeDescription(activity, descriptionObserver);
item.observeAmountHint(activity, hintObserver);
item.observeEditableFlag(activity, editableObserver);
+ item.observeCommentVisible(activity, commentVisibleObserver);
+ item.observeComment(activity, commentObserver);
item.getModel()
.observeFocusedItem(activity, focusedAccountObserver);
item.getModel()
public void swapItems(int one, int two) {
Collections.swap(items, one-1, two-1);
}
+ public void toggleComment(int position) {
+ final MutableLiveData<Boolean> commentVisible = getItem(position).commentVisible;
+ commentVisible.postValue(!commentVisible.getValue());
+ }
enum ItemType {generalData, transactionRow, bottomFiller}
//==========================================================================================
private NewTransactionModel model;
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);
public Item(NewTransactionModel model) {
this.model = model;
type = ItemType.bottomFiller;
public void stopObservingEditableFlag(Observer<Boolean> observer) {
editable.removeObserver(observer);
}
+ public void observeCommentVisible(NewTransactionActivity activity,
+ Observer<Boolean> observer) {
+ commentVisible.observe(activity, observer);
+ }
+ public void stopObservingCommentVisible(Observer<Boolean> observer) {
+ commentVisible.removeObserver(observer);
+ }
+ public void observeComment(NewTransactionActivity activity,
+ Observer<String> observer) {
+ comment.observe(activity, observer);
+ }
+ public void stopObservingComment(Observer<String> observer) {
+ comment.removeObserver(observer);
+ }
+ public void setComment(String comment) {
+ getAccount().setComment(comment);
+ this.comment.postValue(comment);
+ }
}
}
--- /dev/null
+<!--
+ ~ Copyright Google Inc.
+ ~
+ ~ Licensed under the Apache License, version 2.0 ("the License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the license at:
+ ~
+ ~ https://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distribution under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ ~
+ ~ Modified/adapted by Damyan Ivanov for MoLe
+ -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:autoMirrored="true"
+ android:tint="#CCCCCC"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M21.99,4c0,-1.1 -0.89,-2 -1.99,-2L4,2c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h14l4,4 -0.01,-18zM18,14L6,14v-2h12v2zM18,11L6,11L6,9h12v2zM18,8L6,8L6,6h12v2z" />
+</vector>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/ntr_account"
android:layout_width="match_parent"
- android:layout_height="wrap_content">
+ android:layout_height="wrap_content"
+ android:animateLayoutChanges="true">
<net.ktnx.mobileledger.ui.AutoCompleteTextViewWithClear
android:id="@+id/account_row_acc_name"
android:id="@+id/comment_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:alpha="0.5"
- android:drawableStart="@drawable/ic_comment_black_24dp"
- app:layout_constraintBottom_toBottomOf="@+id/comment"
+ android:background="@drawable/ic_comment_gray_24dp"
+ app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/ntr_account"
app:layout_constraintTop_toBottomOf="@+id/account_row_acc_name" />
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" />