X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FNewTransactionItemHolder.java;h=62f0de49677df85c70b58890907bb084994713b7;hb=667ce42731c95a98926657fea359b56209f9348e;hp=f283aee53e124f609bd4084b46ada0920743f5fd;hpb=ff27cd8c41424676ec046c58448d23cd4313d1dc;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 f283aee5..62f0de49 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 @@ -20,6 +20,7 @@ package net.ktnx.mobileledger.ui.activity; import android.annotation.SuppressLint; import android.graphics.Typeface; import android.text.Editable; +import android.text.TextUtils; import android.text.TextWatcher; import android.view.Gravity; import android.view.View; @@ -65,36 +66,35 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder private final TextView tvCurrency; private final Observer showCommentsObserver; private final TextView tvTransactionComment; + private final TextView tvDate; + private final AutoCompleteTextView tvDescription; + private final TextView tvDummy; + private final AutoCompleteTextView tvAccount; + private final TextView tvComment; + private final EditText tvAmount; + private final ViewGroup lHead; + private final ViewGroup lAccount; + private final FrameLayout lPadding; + private final MobileLedgerProfile mProfile; + private final Observer dateObserver; + private final Observer descriptionObserver; + private final Observer transactionCommentObserver; + private final Observer hintObserver; + private final Observer focusedAccountObserver; + private final Observer accountCountObserver; + private final Observer editableObserver; + private final Observer currencyPositionObserver; + private final Observer currencyGapObserver; + private final Observer localeObserver; + private final Observer currencyObserver; + private final Observer showCurrencyObserver; + private final Observer commentObserver; + private final Observer amountValidityObserver; private String decimalSeparator; private NewTransactionModel.Item item; - private TextView tvDate; - private AutoCompleteTextView tvDescription; - private TextView tvDummy; - private AutoCompleteTextView tvAccount; - private TextView tvComment; - private EditText tvAmount; - private ViewGroup lHead; - private ViewGroup lAccount; - private FrameLayout lPadding; - private MobileLedgerProfile mProfile; private Date date; - private Observer dateObserver; - private Observer descriptionObserver; - private Observer transactionCommentObserver; - private Observer hintObserver; - private Observer focusedAccountObserver; - private Observer accountCountObserver; - private Observer editableObserver; - private Observer currencyPositionObserver; - private Observer currencyGapObserver; - private Observer localeObserver; - private Observer currencyObserver; - private Observer showCurrencyObserver; - private Observer commentObserver; - private Observer amountValidityObserver; private boolean inUpdate = false; private boolean syncingData = false; - private View commentButton; //TODO multiple amounts with different currencies per posting NewTransactionItemHolder(@NonNull View itemView, NewTransactionItemsAdapter adapter) { super(itemView); @@ -103,7 +103,6 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder tvComment = lAccount.findViewById(R.id.comment); tvTransactionComment = itemView.findViewById(R.id.transaction_comment); new TextViewClearHelper().attachToTextView((EditText) tvComment); - 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); @@ -121,10 +120,11 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder tvDate.setOnClickListener(v -> pickTransactionDate()); - commentButton.setOnClickListener(v -> { - tvComment.setVisibility(View.VISIBLE); - tvComment.requestFocus(); - }); + lAccount.findViewById(R.id.comment_button) + .setOnClickListener(v -> { + tvComment.setVisibility(View.VISIBLE); + tvComment.requestFocus(); + }); transactionCommentLayout.findViewById(R.id.comment_button) .setOnClickListener(v -> { @@ -132,9 +132,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder tvTransactionComment.requestFocus(); }); - mProfile = Data.profile.getValue(); - if (mProfile == null) - throw new AssertionError(); + mProfile = Data.getProfile(); View.OnFocusChangeListener focusMonitor = (v, hasFocus) -> { final int id = v.getId(); @@ -188,10 +186,9 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder decimalSeparator = String.valueOf(DecimalFormatSymbols.getInstance() .getMonetaryDecimalSeparator()); - localeObserver = locale -> { - decimalSeparator = String.valueOf(DecimalFormatSymbols.getInstance(locale) - .getMonetaryDecimalSeparator()); - }; + localeObserver = locale -> decimalSeparator = String.valueOf( + DecimalFormatSymbols.getInstance(locale) + .getMonetaryDecimalSeparator()); decimalDot = "."; @@ -274,9 +271,9 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder 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); + tvTransactionComment.setVisibility( + ((focusedView != tvTransactionComment) && TextUtils.isEmpty(transactionComment)) + ? View.INVISIBLE : View.VISIBLE); }; hintObserver = hint -> { @@ -393,8 +390,8 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder tvComment.setTypeface(null, (focusedView == tvComment) ? Typeface.NORMAL : Typeface.ITALIC); tvComment.setVisibility( - ((focusedView != tvComment) && Misc.isEmptyOrNull(comment)) ? View.INVISIBLE - : View.VISIBLE); + ((focusedView != tvComment) && TextUtils.isEmpty(comment)) ? View.INVISIBLE + : View.VISIBLE); }; showCommentsObserver = show -> { @@ -448,7 +445,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder textColor = (alpha << 24) | (0x00ffffff & textColor); textView.setTypeface(null, Typeface.ITALIC); textView.setHint(""); - if (Misc.isEmptyOrNull(textView.getText())) { + if (TextUtils.isEmpty(textView.getText())) { textView.setVisibility(View.INVISIBLE); } } @@ -687,7 +684,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder final NewTransactionActivity activity = (NewTransactionActivity) tvDescription.getContext(); - if (!item.isOfType(ItemType.bottomFiller)) { + if (!item.isBottomFiller()) { item.observeEditableFlag(activity, editableObserver); item.getModel() .observeFocusedItem(activity, focusedAccountObserver); @@ -721,7 +718,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder } @Override public void onDatePicked(int year, int month, int day) { - item.setDate(new SimpleDate(year, month+1, day)); + item.setDate(new SimpleDate(year, month + 1, day)); boolean focused = tvDescription.requestFocus(); if (focused) Misc.showSoftKeyboard((NewTransactionActivity) tvAccount.getContext());