]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java
completely abandon fiddling with KeyListener's
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / NewTransactionItemHolder.java
index 81487af661a1f4b7dcc9c9539f1991755c32eba8..05b7258f50566af7e9ec212a7f45c418f394dd23 100644 (file)
 
 package net.ktnx.mobileledger.ui.activity;
 
+import android.annotation.SuppressLint;
+import android.graphics.Typeface;
 import android.text.Editable;
 import android.text.TextWatcher;
+import android.view.Gravity;
 import android.view.View;
+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.R;
 import net.ktnx.mobileledger.async.DescriptionSelectedCallback;
+import net.ktnx.mobileledger.model.Currency;
 import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.LedgerTransactionAccount;
 import net.ktnx.mobileledger.model.MobileLedgerProfile;
+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.DimensionUtils;
 import net.ktnx.mobileledger.utils.Logger;
 import net.ktnx.mobileledger.utils.MLDB;
 import net.ktnx.mobileledger.utils.Misc;
 
+import java.text.DecimalFormatSymbols;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.Locale;
 
+import static net.ktnx.mobileledger.ui.activity.NewTransactionModel.ItemType;
+
 class NewTransactionItemHolder extends RecyclerView.ViewHolder
         implements DatePickerFragment.DatePickedListener, DescriptionSelectedCallback {
+    private final String decimalDot;
+    private final TextView tvCurrency;
+    private final Observer<Boolean> showCommentsObserver;
+    private final TextView tvTransactionComment;
+    private String decimalSeparator;
     private NewTransactionModel.Item item;
     private TextView tvDate;
     private AutoCompleteTextView tvDescription;
     private AutoCompleteTextView tvAccount;
-    private TextView tvAmount;
-    private ConstraintLayout lHead;
-    private LinearLayout lAccount;
+    private TextView tvComment;
+    private EditText tvAmount;
+    private ViewGroup lHead;
+    private ViewGroup lAccount;
     private FrameLayout lPadding;
     private MobileLedgerProfile mProfile;
     private Date date;
     private Observer<Date> dateObserver;
     private Observer<String> descriptionObserver;
+    private Observer<String> transactionCommentObserver;
     private Observer<String> hintObserver;
     private Observer<Integer> focusedAccountObserver;
     private Observer<Integer> accountCountObserver;
+    private Observer<Boolean> editableObserver;
+    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 Observer<Boolean> 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);
-        tvAccount = itemView.findViewById(R.id.account_row_acc_name);
+        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 = 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);
+        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);
         tvAmount.setNextFocusForwardId(View.NO_ID); // magic!
 
-        tvDate.setOnFocusChangeListener((v, hasFocus) -> {
-            if (hasFocus) pickTransactionDate();
-        });
         tvDate.setOnClickListener(v -> pickTransactionDate());
 
+        commentButton.setOnClickListener(v -> {
+            tvComment.setVisibility(View.VISIBLE);
+            tvComment.requestFocus();
+        });
+
+        transactionCommentLayout.findViewById(R.id.comment_button)
+                                .setOnClickListener(v -> {
+                                    tvTransactionComment.setVisibility(View.VISIBLE);
+                                    tvTransactionComment.requestFocus();
+                                });
+
         mProfile = Data.profile.getValue();
-        if (mProfile == null) throw new AssertionError();
+        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 (id) {
+                        case R.id.account_row_acc_name:
+                            adapter.noteFocusIsOnAccount(pos);
+                            break;
+                        case R.id.account_row_acc_amounts:
+                            adapter.noteFocusIsOnAmount(pos);
+                            break;
+                        case R.id.comment:
+                            adapter.noteFocusIsOnComment(pos);
+                            break;
+                        case R.id.transaction_comment:
+                            adapter.noteFocusIsOnTransactionComment(pos);
+                            break;
+                        case R.id.new_transaction_description:
+                            adapter.noteFocusIsOnDescription(pos);
+                            break;
+                    }
+                }
+                finally {
+                    syncingData = wasSyncing;
+                }
+            }
+
+            if (id == R.id.comment) {
+                commentFocusChanged(commentLayout, tvComment, hasFocus);
+            }
+            else if (id == R.id.transaction_comment) {
+                commentFocusChanged(transactionCommentLayout, tvTransactionComment, hasFocus);
+            }
+        };
+
+        tvDescription.setOnFocusChangeListener(focusMonitor);
+        tvAccount.setOnFocusChangeListener(focusMonitor);
+        tvAmount.setOnFocusChangeListener(focusMonitor);
+        tvComment.setOnFocusChangeListener(focusMonitor);
+        tvTransactionComment.setOnFocusChangeListener(focusMonitor);
 
         MLDB.hookAutocompletionAdapter(tvDescription.getContext(), tvDescription,
                 MLDB.DESCRIPTION_HISTORY_TABLE, "description", false, adapter, mProfile);
         MLDB.hookAutocompletionAdapter(tvAccount.getContext(), tvAccount, MLDB.ACCOUNTS_TABLE,
                 "name", true, this, mProfile);
 
+        decimalSeparator = String.valueOf(DecimalFormatSymbols.getInstance()
+                                                              .getMonetaryDecimalSeparator());
+        localeObserver = locale -> {
+            decimalSeparator = String.valueOf(DecimalFormatSymbols.getInstance(locale)
+                                                                  .getMonetaryDecimalSeparator());
+        };
+
+        decimalDot = ".";
+
         final TextWatcher tw = new TextWatcher() {
             @Override
             public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@@ -104,22 +205,50 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
             @Override
             public void afterTextChanged(Editable s) {
 //                debug("input", "text changed");
-                if (inUpdate) return;
+                if (inUpdate)
+                    return;
 
                 Logger.debug("textWatcher", "calling syncData()");
                 syncData();
                 Logger.debug("textWatcher",
                         "syncData() returned, checking if transaction is submittable");
-                adapter.model.checkTransactionSubmittable(adapter);
+                adapter.checkTransactionSubmittable();
                 Logger.debug("textWatcher", "done");
             }
         };
+        final TextWatcher amountWatcher = new TextWatcher() {
+            @Override
+            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+                Logger.debug("num",
+                        String.format(Locale.US, "beforeTextChanged: start=%d, count=%d, after=%d",
+                                start, count, after));
+            }
+            @Override
+            public void onTextChanged(CharSequence s, int start, int before, int count) {}
+            @Override
+            public void afterTextChanged(Editable s) {
+
+                if (syncData())
+                    adapter.checkTransactionSubmittable();
+            }
+        };
         tvDescription.addTextChangedListener(tw);
+        tvTransactionComment.addTextChangedListener(tw);
         tvAccount.addTextChangedListener(tw);
-        tvAmount.addTextChangedListener(tw);
+        tvComment.addTextChangedListener(tw);
+        tvAmount.addTextChangedListener(amountWatcher);
+
+        tvCurrency.setOnClickListener(v -> {
+            CurrencySelectorFragment cpf = new CurrencySelectorFragment();
+            cpf.showPositionAndPadding();
+            cpf.setOnCurrencySelectedListener(c -> item.setCurrency(c));
+            final AppCompatActivity activity = (AppCompatActivity) v.getContext();
+            cpf.show(activity.getSupportFragmentManager(), "currency-selector");
+        });
 
         dateObserver = date -> {
-            if (syncingData) return;
+            if (syncingData)
+                return;
             syncingData = true;
             try {
                 tvDate.setText(item.getFormattedDate());
@@ -129,7 +258,8 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
             }
         };
         descriptionObserver = description -> {
-            if (syncingData) return;
+            if (syncingData)
+                return;
             syncingData = true;
             try {
                 tvDescription.setText(description);
@@ -138,62 +268,274 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
                 syncingData = false;
             }
         };
+        transactionCommentObserver = transactionComment -> {
+            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);
+
+        };
         hintObserver = hint -> {
-            if (syncingData) return;
+            if (syncingData)
+                return;
             syncingData = true;
             try {
-                tvAmount.setHint(hint);
+                if (hint == null)
+                    tvAmount.setHint(R.string.zero_amount);
+                else
+                    tvAmount.setHint(hint);
             }
             finally {
                 syncingData = false;
             }
         };
+        editableObserver = this::setEditable;
         focusedAccountObserver = index -> {
-            if ((index != null) && index.equals(getAdapterPosition())) {
-                switch (item.getType()) {
-                    case generalData:
-                        // bad idea - double pop-up, and not really necessary.
-                        // the user can tap the input to get the calendar
-                        //if (!tvDate.hasFocus()) tvDate.requestFocus();
-                        boolean focused = tvDescription.requestFocus();
-                        tvDescription.dismissDropDown();
-                        if (focused) Misc.showSoftKeyboard(
-                                (NewTransactionActivity) tvDescription.getContext());
-                        break;
-                    case transactionRow:
-                        focused = tvAccount.requestFocus();
-                        tvAccount.dismissDropDown();
-                        if (focused)
-                            Misc.showSoftKeyboard((NewTransactionActivity) tvAccount.getContext());
+            if ((index == null) || !index.equals(getAdapterPosition()) || itemView.hasFocus())
+                return;
 
-                        break;
-                }
+            switch (item.getType()) {
+                case generalData:
+                    // bad idea - double pop-up, and not really necessary.
+                    // the user can tap the input to get the calendar
+                    //if (!tvDate.hasFocus()) tvDate.requestFocus();
+                    switch (item.getFocusedElement()) {
+                        case TransactionComment:
+                            tvTransactionComment.setVisibility(View.VISIBLE);
+                            tvTransactionComment.requestFocus();
+                            break;
+                        case Description:
+                            boolean focused = tvDescription.requestFocus();
+                            tvDescription.dismissDropDown();
+                            if (focused)
+                                Misc.showSoftKeyboard(
+                                        (NewTransactionActivity) tvDescription.getContext());
+                            break;
+                    }
+                    break;
+                case transactionRow:
+                    switch (item.getFocusedElement()) {
+                        case Amount:
+                            tvAmount.requestFocus();
+                            break;
+                        case Comment:
+                            tvComment.setVisibility(View.VISIBLE);
+                            tvComment.requestFocus();
+                            break;
+                        case Account:
+                            boolean focused = tvAccount.requestFocus();
+                            tvAccount.dismissDropDown();
+                            if (focused)
+                                Misc.showSoftKeyboard(
+                                        (NewTransactionActivity) tvAccount.getContext());
+                            break;
+                    }
+
+                    break;
             }
         };
         accountCountObserver = count -> {
-            if (getAdapterPosition() == count) tvAmount.setImeOptions(EditorInfo.IME_ACTION_DONE);
-            else tvAmount.setImeOptions(EditorInfo.IME_ACTION_NEXT);
+            final int adapterPosition = getAdapterPosition();
+            final int layoutPosition = getLayoutPosition();
+            Logger.debug("holder",
+                    String.format(Locale.US, "count=%d; pos=%d, layoutPos=%d [%s]", count,
+                            adapterPosition, layoutPosition, item.getType()
+                                                                 .toString()
+                                                                 .concat(item.getType() ==
+                                                                         ItemType.transactionRow
+                                                                         ? String.format(Locale.US,
+                                                                         "'%s'=%s",
+                                                                         item.getAccount()
+                                                                             .getAccountName(),
+                                                                         item.getAccount()
+                                                                             .isAmountSet()
+                                                                         ? String.format(Locale.US,
+                                                                                 "%.2f",
+                                                                                 item.getAccount()
+                                                                                     .getAmount())
+                                                                         : "unset") : "")));
+            if (adapterPosition == count)
+                tvAmount.setImeOptions(EditorInfo.IME_ACTION_DONE);
+            else
+                tvAmount.setImeOptions(EditorInfo.IME_ACTION_NEXT);
+        };
+
+        currencyObserver = currency -> {
+            setCurrency(currency);
+            adapter.checkTransactionSubmittable();
         };
+
+        currencyGapObserver =
+                hasGap -> updateCurrencyPositionAndPadding(Data.currencySymbolPosition.getValue(),
+                        hasGap);
+
+        currencyPositionObserver =
+                position -> updateCurrencyPositionAndPadding(position, Data.currencyGap.getValue());
+
+        showCurrencyObserver = showCurrency -> {
+            if (showCurrency) {
+                tvCurrency.setVisibility(View.VISIBLE);
+            }
+            else {
+                tvCurrency.setVisibility(View.GONE);
+                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);
+        };
+
+        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);
+        };
+
+        amountValidityObserver = valid -> {
+            tvAmount.setCompoundDrawablesRelativeWithIntrinsicBounds(
+                    valid ? 0 : R.drawable.ic_error_outline_black_24dp, 0, 0, 0);
+            tvAmount.setMinEms(valid ? 4 : 5);
+        };
+    }
+    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 =
+                (ConstraintLayout.LayoutParams) tvAmount.getLayoutParams();
+        ConstraintLayout.LayoutParams currencyLP =
+                (ConstraintLayout.LayoutParams) tvCurrency.getLayoutParams();
+
+        if (position == Currency.Position.before) {
+            currencyLP.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
+            currencyLP.endToEnd = ConstraintLayout.LayoutParams.UNSET;
+
+            amountLP.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
+            amountLP.endToStart = ConstraintLayout.LayoutParams.UNSET;
+            amountLP.startToStart = ConstraintLayout.LayoutParams.UNSET;
+            amountLP.startToEnd = tvCurrency.getId();
+
+            tvCurrency.setGravity(Gravity.END);
+        }
+        else {
+            currencyLP.startToStart = ConstraintLayout.LayoutParams.UNSET;
+            currencyLP.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
+
+            amountLP.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
+            amountLP.startToEnd = ConstraintLayout.LayoutParams.UNSET;
+            amountLP.endToEnd = ConstraintLayout.LayoutParams.UNSET;
+            amountLP.endToStart = tvCurrency.getId();
+
+            tvCurrency.setGravity(Gravity.START);
+        }
+
+        amountLP.resolveLayoutDirection(tvAmount.getLayoutDirection());
+        currencyLP.resolveLayoutDirection(tvCurrency.getLayoutDirection());
+
+        tvAmount.setLayoutParams(amountLP);
+        tvCurrency.setLayoutParams(currencyLP);
+
+        // distance between the amount and the currency symbol
+        int gapSize = DimensionUtils.sp2px(tvCurrency.getContext(), 5);
+
+        if (position == Currency.Position.before) {
+            tvCurrency.setPaddingRelative(0, 0, hasGap ? gapSize : 0, 0);
+        }
+        else {
+            tvCurrency.setPaddingRelative(hasGap ? gapSize : 0, 0, 0, 0);
+        }
+    }
+    private void setCurrencyString(String currency) {
+        if ((currency == null) || currency.isEmpty()) {
+            tvCurrency.setText(R.string.currency_symbol);
+            tvCurrency.setTextColor(0x7f000000 + (0x00ffffff & Colors.defaultTextColor));
+        }
+        else {
+            tvCurrency.setText(currency);
+            tvCurrency.setTextColor(Colors.defaultTextColor);
+        }
+    }
+    private void setCurrency(Currency currency) {
+        setCurrencyString((currency == null) ? null : currency.getName());
+    }
+    private void setEditable(Boolean editable) {
+        tvDate.setEnabled(editable);
+        tvDescription.setEnabled(editable);
+        tvAccount.setEnabled(editable);
+        tvAmount.setEnabled(editable);
     }
     private void beginUpdates() {
-        if (inUpdate) throw new RuntimeException("Already in update mode");
+        if (inUpdate)
+            throw new RuntimeException("Already in update mode");
         inUpdate = true;
     }
     private void endUpdates() {
-        if (!inUpdate) throw new RuntimeException("Not in update mode");
+        if (!inUpdate)
+            throw new RuntimeException("Not in update mode");
         inUpdate = false;
     }
     /**
      * syncData()
      * <p>
      * Stores the data from the UI elements into the model item
+     * Returns true if there were changes made that suggest transaction has to be
+     * checked for being submittable
      */
-    private void syncData() {
-        if (item == null) return;
+    private boolean syncData() {
+        if (item == null)
+            return false;
 
         if (syncingData) {
             Logger.debug("new-trans", "skipping syncData() loop");
-            return;
+            return false;
         }
 
         syncingData = true;
@@ -203,24 +545,50 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
                 case generalData:
                     item.setDate(String.valueOf(tvDate.getText()));
                     item.setDescription(String.valueOf(tvDescription.getText()));
+                    item.setTransactionComment(String.valueOf(tvTransactionComment.getText()));
                     break;
                 case transactionRow:
-                    item.getAccount()
-                        .setAccountName(String.valueOf(tvAccount.getText()));
+                    final LedgerTransactionAccount account = item.getAccount();
+                    account.setAccountName(String.valueOf(tvAccount.getText()));
+
+                    item.setComment(String.valueOf(tvComment.getText()));
 
-                    // TODO: handle multiple amounts
                     String amount = String.valueOf(tvAmount.getText());
                     amount = amount.trim();
 
-                    if (!amount.isEmpty()) item.getAccount()
-                                               .setAmount(Float.parseFloat(amount));
-                    else item.getAccount()
-                             .resetAmount();
+                    if (amount.isEmpty()) {
+                        account.resetAmount();
+                        item.validateAmount();
+                    }
+                    else {
+                        try {
+                            amount = amount.replace(decimalSeparator, decimalDot);
+                            account.setAmount(Float.parseFloat(amount));
+                            item.validateAmount();
+                        }
+                        catch (NumberFormatException e) {
+                            Logger.debug("new-trans", String.format(
+                                    "assuming amount is not set due to number format exception. " +
+                                    "input was '%s'", amount));
+                            account.invalidateAmount();
+                            item.invalidateAmount();
+                        }
+                        final String curr = String.valueOf(tvCurrency.getText());
+                        if (curr.equals(tvCurrency.getContext()
+                                                  .getResources()
+                                                  .getString(R.string.currency_symbol)) ||
+                            curr.isEmpty())
+                            account.setCurrency(null);
+                        else
+                            account.setCurrency(curr);
+                    }
 
                     break;
                 case bottomFiller:
                     throw new RuntimeException("Should not happen");
             }
+
+            return true;
         }
         finally {
             syncingData = false;
@@ -228,6 +596,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
     }
     private void pickTransactionDate() {
         DatePickerFragment picker = new DatePickerFragment();
+        picker.setFutureDates(mProfile.getFutureDates());
         picker.setOnDatePickedListener(this);
         picker.show(((NewTransactionActivity) tvDate.getContext()).getSupportFragmentManager(),
                 "datePicker");
@@ -237,17 +606,28 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
      *
      * @param item updates the UI elements with the data from the model item
      */
+    @SuppressLint("DefaultLocale")
     public void setData(NewTransactionModel.Item item) {
         beginUpdates();
         try {
             if (this.item != null && !this.item.equals(item)) {
                 this.item.stopObservingDate(dateObserver);
                 this.item.stopObservingDescription(descriptionObserver);
+                this.item.stopObservingTransactionComment(transactionCommentObserver);
                 this.item.stopObservingAmountHint(hintObserver);
+                this.item.stopObservingEditableFlag(editableObserver);
                 this.item.getModel()
                          .stopObservingFocusedItem(focusedAccountObserver);
                 this.item.getModel()
                          .stopObservingAccountCount(accountCountObserver);
+                Data.currencySymbolPosition.removeObserver(currencyPositionObserver);
+                Data.currencyGap.removeObserver(currencyGapObserver);
+                Data.locale.removeObserver(localeObserver);
+                this.item.stopObservingCurrency(currencyObserver);
+                this.item.getModel().showCurrency.removeObserver(showCurrencyObserver);
+                this.item.stopObservingComment(commentObserver);
+                this.item.getModel().showComments.removeObserver(showCommentsObserver);
+                this.item.stopObservingAmountValidity(amountValidityObserver);
 
                 this.item = null;
             }
@@ -256,38 +636,68 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
                 case generalData:
                     tvDate.setText(item.getFormattedDate());
                     tvDescription.setText(item.getDescription());
+                    tvTransactionComment.setText(item.getTransactionComment());
                     lHead.setVisibility(View.VISIBLE);
                     lAccount.setVisibility(View.GONE);
                     lPadding.setVisibility(View.GONE);
+                    setEditable(true);
                     break;
                 case transactionRow:
                     LedgerTransactionAccount acc = item.getAccount();
                     tvAccount.setText(acc.getAccountName());
-                    tvAmount.setText(
-                            acc.isAmountSet() ? String.format(Locale.US, "%1.2f", acc.getAmount())
-                                              : "");
+                    tvComment.setText(acc.getComment());
+                    if (acc.isAmountSet()) {
+                        tvAmount.setText(String.format("%1.2f", acc.getAmount()));
+                    }
+                    else {
+                        tvAmount.setText("");
+//                        tvAmount.setHint(R.string.zero_amount);
+                    }
+                    tvAmount.setHint(item.getAmountHint());
+                    setCurrencyString(acc.getCurrency());
                     lHead.setVisibility(View.GONE);
                     lAccount.setVisibility(View.VISIBLE);
                     lPadding.setVisibility(View.GONE);
+                    setEditable(true);
                     break;
                 case bottomFiller:
                     lHead.setVisibility(View.GONE);
                     lAccount.setVisibility(View.GONE);
                     lPadding.setVisibility(View.VISIBLE);
+                    setEditable(false);
                     break;
             }
-
             if (this.item == null) { // was null or has changed
                 this.item = item;
                 final NewTransactionActivity activity =
                         (NewTransactionActivity) tvDescription.getContext();
-                item.observeDate(activity, dateObserver);
-                item.observeDescription(activity, descriptionObserver);
-                item.observeAmountHint(activity, hintObserver);
-                item.getModel()
-                    .observeFocusedItem(activity, focusedAccountObserver);
-                item.getModel()
-                    .observeAccountCount(activity, accountCountObserver);
+
+                if (!item.isOfType(ItemType.bottomFiller)) {
+                    item.observeEditableFlag(activity, editableObserver);
+                    item.getModel()
+                        .observeFocusedItem(activity, focusedAccountObserver);
+                    item.getModel()
+                        .observeShowComments(activity, showCommentsObserver);
+                }
+                switch (item.getType()) {
+                    case generalData:
+                        item.observeDate(activity, dateObserver);
+                        item.observeDescription(activity, descriptionObserver);
+                        item.observeTransactionComment(activity, transactionCommentObserver);
+                        break;
+                    case transactionRow:
+                        item.observeAmountHint(activity, hintObserver);
+                        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);
+                        item.observeAmountValidity(activity, amountValidityObserver);
+                        break;
+                }
             }
         }
         finally {
@@ -300,7 +710,8 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
         c.set(year, month, day);
         item.setDate(c.getTime());
         boolean focused = tvDescription.requestFocus();
-        if (focused) Misc.showSoftKeyboard((NewTransactionActivity) tvAccount.getContext());
+        if (focused)
+            Misc.showSoftKeyboard((NewTransactionActivity) tvAccount.getContext());
 
     }
     @Override