]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java
new transaction: hide currency/commodity selector by default; add menu item for showing
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / NewTransactionItemHolder.java
1 /*
2  * Copyright © 2019 Damyan Ivanov.
3  * This file is part of MoLe.
4  * MoLe is free software: you can distribute it and/or modify it
5  * under the term of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your opinion), any later version.
8  *
9  * MoLe is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License terms for details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
16  */
17
18 package net.ktnx.mobileledger.ui.activity;
19
20 import android.annotation.SuppressLint;
21 import android.os.Build;
22 import android.text.Editable;
23 import android.text.TextWatcher;
24 import android.text.method.DigitsKeyListener;
25 import android.view.Gravity;
26 import android.view.View;
27 import android.view.ViewGroup;
28 import android.view.inputmethod.EditorInfo;
29 import android.widget.AutoCompleteTextView;
30 import android.widget.EditText;
31 import android.widget.FrameLayout;
32 import android.widget.LinearLayout;
33 import android.widget.TextView;
34
35 import androidx.annotation.NonNull;
36 import androidx.appcompat.app.AppCompatActivity;
37 import androidx.constraintlayout.widget.ConstraintLayout;
38 import androidx.lifecycle.Observer;
39 import androidx.recyclerview.widget.RecyclerView;
40
41 import net.ktnx.mobileledger.R;
42 import net.ktnx.mobileledger.async.DescriptionSelectedCallback;
43 import net.ktnx.mobileledger.model.Currency;
44 import net.ktnx.mobileledger.model.Data;
45 import net.ktnx.mobileledger.model.LedgerTransactionAccount;
46 import net.ktnx.mobileledger.model.MobileLedgerProfile;
47 import net.ktnx.mobileledger.ui.CurrencySelectorFragment;
48 import net.ktnx.mobileledger.ui.DatePickerFragment;
49 import net.ktnx.mobileledger.ui.OnCurrencySelectedListener;
50 import net.ktnx.mobileledger.ui.TextViewClearHelper;
51 import net.ktnx.mobileledger.utils.Colors;
52 import net.ktnx.mobileledger.utils.DimensionUtils;
53 import net.ktnx.mobileledger.utils.Logger;
54 import net.ktnx.mobileledger.utils.MLDB;
55 import net.ktnx.mobileledger.utils.Misc;
56
57 import java.text.DecimalFormatSymbols;
58 import java.util.Calendar;
59 import java.util.Date;
60 import java.util.GregorianCalendar;
61 import java.util.Locale;
62
63 import static net.ktnx.mobileledger.ui.activity.NewTransactionModel.ItemType;
64
65 class NewTransactionItemHolder extends RecyclerView.ViewHolder
66         implements DatePickerFragment.DatePickedListener, DescriptionSelectedCallback,
67         OnCurrencySelectedListener {
68     private final String decimalSeparator;
69     private final String decimalDot;
70     private final TextView tvCurrency;
71     private NewTransactionModel.Item item;
72     private TextView tvDate;
73     private AutoCompleteTextView tvDescription;
74     private AutoCompleteTextView tvAccount;
75     private TextView tvComment;
76     private EditText tvAmount;
77     private LinearLayout lHead;
78     private ViewGroup lAccount;
79     private FrameLayout lPadding;
80     private MobileLedgerProfile mProfile;
81     private Date date;
82     private Observer<Date> dateObserver;
83     private Observer<String> descriptionObserver;
84     private Observer<String> hintObserver;
85     private Observer<Integer> focusedAccountObserver;
86     private Observer<Integer> accountCountObserver;
87     private Observer<Boolean> editableObserver;
88     private Observer<Boolean> commentVisibleObserver;
89     private Observer<String> commentObserver;
90     private Observer<Currency.Position> currencyPositionObserver;
91     private Observer<Boolean> currencyGapObserver;
92     private Observer<Locale> localeObserver;
93     private Observer<Currency> currencyObserver;
94     private Observer<Boolean> showCurrencyObserver;
95     private boolean inUpdate = false;
96     private boolean syncingData = false;
97     private View commentButton;
98     //TODO multiple amounts with different currencies per posting
99     NewTransactionItemHolder(@NonNull View itemView, NewTransactionItemsAdapter adapter) {
100         super(itemView);
101         tvAccount = itemView.findViewById(R.id.account_row_acc_name);
102         tvComment = itemView.findViewById(R.id.comment);
103         new TextViewClearHelper().attachToTextView((EditText) tvComment);
104         commentButton = itemView.findViewById(R.id.comment_button);
105         tvAmount = itemView.findViewById(R.id.account_row_acc_amounts);
106         tvCurrency = itemView.findViewById(R.id.currency);
107         tvDate = itemView.findViewById(R.id.new_transaction_date);
108         tvDescription = itemView.findViewById(R.id.new_transaction_description);
109         lHead = itemView.findViewById(R.id.ntr_data);
110         lAccount = itemView.findViewById(R.id.ntr_account);
111         lPadding = itemView.findViewById(R.id.ntr_padding);
112
113         tvDescription.setNextFocusForwardId(View.NO_ID);
114         tvAccount.setNextFocusForwardId(View.NO_ID);
115         tvAmount.setNextFocusForwardId(View.NO_ID); // magic!
116
117         tvDate.setOnClickListener(v -> pickTransactionDate());
118
119         mProfile = Data.profile.getValue();
120         if (mProfile == null)
121             throw new AssertionError();
122
123         View.OnFocusChangeListener focusMonitor = (v, hasFocus) -> {
124             if (hasFocus) {
125                 boolean wasSyncing = syncingData;
126                 syncingData = true;
127                 try {
128                     final int pos = getAdapterPosition();
129                     adapter.updateFocusedItem(pos);
130                     switch (v.getId()) {
131                         case R.id.account_row_acc_name:
132                             adapter.noteFocusIsOnAccount(pos);
133                             break;
134                         case R.id.account_row_acc_amounts:
135                             adapter.noteFocusIsOnAmount(pos);
136                             break;
137                         case R.id.comment:
138                             adapter.noteFocusIsOnComment(pos);
139                             break;
140                     }
141                 }
142                 finally {
143                     syncingData = wasSyncing;
144                 }
145             }
146         };
147
148         tvDescription.setOnFocusChangeListener(focusMonitor);
149         tvAccount.setOnFocusChangeListener(focusMonitor);
150         tvAmount.setOnFocusChangeListener(focusMonitor);
151
152         itemView.findViewById(R.id.comment_button)
153                 .setOnClickListener(v -> {
154                     final int pos = getAdapterPosition();
155                     adapter.toggleComment(pos);
156                 });
157         MLDB.hookAutocompletionAdapter(tvDescription.getContext(), tvDescription,
158                 MLDB.DESCRIPTION_HISTORY_TABLE, "description", false, adapter, mProfile);
159         MLDB.hookAutocompletionAdapter(tvAccount.getContext(), tvAccount, MLDB.ACCOUNTS_TABLE,
160                 "name", true, this, mProfile);
161
162         // FIXME: react on configuration (locale) changes
163         decimalSeparator = String.valueOf(DecimalFormatSymbols.getInstance()
164                                                               .getMonetaryDecimalSeparator());
165         decimalDot = ".";
166
167         final TextWatcher tw = new TextWatcher() {
168             @Override
169             public void beforeTextChanged(CharSequence s, int start, int count, int after) {
170             }
171
172             @Override
173             public void onTextChanged(CharSequence s, int start, int before, int count) {
174             }
175
176             @Override
177             public void afterTextChanged(Editable s) {
178 //                debug("input", "text changed");
179                 if (inUpdate)
180                     return;
181
182                 Logger.debug("textWatcher", "calling syncData()");
183                 syncData();
184                 Logger.debug("textWatcher",
185                         "syncData() returned, checking if transaction is submittable");
186                 adapter.model.checkTransactionSubmittable(adapter);
187                 Logger.debug("textWatcher", "done");
188             }
189         };
190         final TextWatcher amountWatcher = new TextWatcher() {
191             @Override
192             public void beforeTextChanged(CharSequence s, int start, int count, int after) {
193                 Logger.debug("num",
194                         String.format(Locale.US, "beforeTextChanged: start=%d, count=%d, after=%d",
195                                 start, count, after));
196             }
197             @Override
198             public void onTextChanged(CharSequence s, int start, int before, int count) {
199                 Logger.debug("num",
200                         String.format(Locale.US, "onTextChanged: start=%d, before=%d, count=%d",
201                                 start, before, count));
202             }
203             @Override
204             public void afterTextChanged(Editable s) {
205                 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
206                     // only one decimal separator is allowed
207                     // plus and minus are allowed only at the beginning
208                     String allowed = "0123456789";
209                     String val = s.toString();
210                     if (val.isEmpty() || (tvAmount.getSelectionStart() == 0))
211                         allowed += "-";
212                     if (!val.contains(decimalSeparator) && !val.contains(decimalDot))
213                         allowed += decimalSeparator + decimalDot;
214
215                     tvAmount.setKeyListener(DigitsKeyListener.getInstance(allowed));
216
217                     syncData();
218                     adapter.model.checkTransactionSubmittable(adapter);
219                 }
220             }
221         };
222         tvDescription.addTextChangedListener(tw);
223         tvAccount.addTextChangedListener(tw);
224         tvComment.addTextChangedListener(tw);
225         tvAmount.addTextChangedListener(amountWatcher);
226
227         tvCurrency.setOnClickListener(v -> {
228             CurrencySelectorFragment cpf = new CurrencySelectorFragment();
229             cpf.setOnCurrencySelectedListener(this);
230             final AppCompatActivity activity = (AppCompatActivity) v.getContext();
231             cpf.show(activity.getSupportFragmentManager(), "currency-selector");
232         });
233
234         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
235             tvAmount.setKeyListener(
236                     DigitsKeyListener.getInstance(Data.locale.getValue(), true, true));
237         else
238             tvAmount.setKeyListener(
239                     DigitsKeyListener.getInstance("0123456789+-" + decimalSeparator + decimalDot));
240
241         dateObserver = date -> {
242             if (syncingData)
243                 return;
244             syncingData = true;
245             try {
246                 tvDate.setText(item.getFormattedDate());
247             }
248             finally {
249                 syncingData = false;
250             }
251         };
252         descriptionObserver = description -> {
253             if (syncingData)
254                 return;
255             syncingData = true;
256             try {
257                 tvDescription.setText(description);
258             }
259             finally {
260                 syncingData = false;
261             }
262         };
263         hintObserver = hint -> {
264             if (syncingData)
265                 return;
266             syncingData = true;
267             try {
268                 if (hint == null)
269                     tvAmount.setHint(R.string.zero_amount);
270                 else
271                     tvAmount.setHint(hint);
272             }
273             finally {
274                 syncingData = false;
275             }
276         };
277         editableObserver = this::setEditable;
278         commentVisibleObserver = this::setCommentVisible;
279         commentObserver = this::setComment;
280         focusedAccountObserver = index -> {
281             if ((index != null) && index.equals(getAdapterPosition())) {
282                 switch (item.getType()) {
283                     case generalData:
284                         // bad idea - double pop-up, and not really necessary.
285                         // the user can tap the input to get the calendar
286                         //if (!tvDate.hasFocus()) tvDate.requestFocus();
287                         boolean focused = tvDescription.requestFocus();
288                         tvDescription.dismissDropDown();
289                         if (focused)
290                             Misc.showSoftKeyboard(
291                                     (NewTransactionActivity) tvDescription.getContext());
292                         break;
293                     case transactionRow:
294                         // do nothing if a row element already has the focus
295                         if (!itemView.hasFocus()) {
296                             switch (item.getFocusedElement()) {
297                                 case Amount:
298                                     tvAmount.requestFocus();
299                                     break;
300                                 case Comment:
301                                     tvComment.requestFocus();
302                                     break;
303                                 case Account:
304                                     focused = tvAccount.requestFocus();
305                                     tvAccount.dismissDropDown();
306                                     if (focused)
307                                         Misc.showSoftKeyboard(
308                                                 (NewTransactionActivity) tvAccount.getContext());
309                                     break;
310                             }
311                         }
312
313                         break;
314                 }
315             }
316         };
317         accountCountObserver = count -> {
318             final int adapterPosition = getAdapterPosition();
319             final int layoutPosition = getLayoutPosition();
320             Logger.debug("holder",
321                     String.format(Locale.US, "count=%d; pos=%d, layoutPos=%d [%s]", count,
322                             adapterPosition, layoutPosition, item.getType()
323                                                                  .toString()
324                                                                  .concat(item.getType() ==
325                                                                          ItemType.transactionRow
326                                                                          ? String.format(Locale.US,
327                                                                          "'%s'=%s",
328                                                                          item.getAccount()
329                                                                              .getAccountName(),
330                                                                          item.getAccount()
331                                                                              .isAmountSet()
332                                                                          ? String.format(Locale.US,
333                                                                                  "%.2f",
334                                                                                  item.getAccount()
335                                                                                      .getAmount())
336                                                                          : "unset") : "")));
337             if (adapterPosition == count)
338                 tvAmount.setImeOptions(EditorInfo.IME_ACTION_DONE);
339             else
340                 tvAmount.setImeOptions(EditorInfo.IME_ACTION_NEXT);
341         };
342
343         currencyPositionObserver = position -> {
344             updateCurrencyPositionAndPadding(position, Data.currencyGap.getValue());
345         };
346
347         currencyGapObserver = hasGap -> {
348             updateCurrencyPositionAndPadding(Data.currencySymbolPosition.getValue(), hasGap);
349         };
350
351         localeObserver = locale -> {
352             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
353                 tvAmount.setKeyListener(DigitsKeyListener.getInstance(locale, true, true));
354         };
355
356         currencyObserver = this::setCurrency;
357
358         showCurrencyObserver = showCurrency -> {
359               if (showCurrency) {
360                   tvCurrency.setVisibility(View.VISIBLE);
361               }
362             else {
363                 tvCurrency.setVisibility(View.GONE);
364                 setCurrencyString(null);
365               }
366         };
367     }
368     private void updateCurrencyPositionAndPadding(Currency.Position position, boolean hasGap) {
369         ConstraintLayout.LayoutParams amountLP =
370                 (ConstraintLayout.LayoutParams) tvAmount.getLayoutParams();
371         ConstraintLayout.LayoutParams currencyLP =
372                 (ConstraintLayout.LayoutParams) tvCurrency.getLayoutParams();
373
374         if (position == Currency.Position.before) {
375             currencyLP.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
376             currencyLP.endToEnd = ConstraintLayout.LayoutParams.UNSET;
377
378             amountLP.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
379             amountLP.endToStart = ConstraintLayout.LayoutParams.UNSET;
380             amountLP.startToStart = ConstraintLayout.LayoutParams.UNSET;
381             amountLP.startToEnd = tvCurrency.getId();
382
383             tvCurrency.setGravity(Gravity.END);
384         }
385         else {
386             currencyLP.startToStart = ConstraintLayout.LayoutParams.UNSET;
387             currencyLP.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
388
389             amountLP.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
390             amountLP.startToEnd = ConstraintLayout.LayoutParams.UNSET;
391             amountLP.endToEnd = ConstraintLayout.LayoutParams.UNSET;
392             amountLP.endToStart = tvCurrency.getId();
393
394             tvCurrency.setGravity(Gravity.START);
395         }
396
397         amountLP.resolveLayoutDirection(tvAmount.getLayoutDirection());
398         currencyLP.resolveLayoutDirection(tvCurrency.getLayoutDirection());
399
400         tvAmount.setLayoutParams(amountLP);
401         tvCurrency.setLayoutParams(currencyLP);
402
403         // distance between the amount and the currency symbol
404         int gapSize = DimensionUtils.sp2px(tvCurrency.getContext(), 5);
405
406         if (position == Currency.Position.before) {
407             tvCurrency.setPaddingRelative(0, 0, hasGap ? gapSize : 0, 0);
408         }
409         else {
410             tvCurrency.setPaddingRelative(hasGap ? gapSize : 0, 0, 0, 0);
411         }
412     }
413     private void setCurrencyString(String currency) {
414         if ((currency == null) || currency.isEmpty()) {
415             tvCurrency.setText(R.string.currency_symbol);
416             tvCurrency.setTextColor(0x7f000000 + (0x00ffffff & Colors.defaultTextColor));
417         }
418         else {
419             tvCurrency.setText(currency);
420             tvCurrency.setTextColor(Colors.defaultTextColor);
421         }
422     }
423     private void setCurrency(Currency currency) {
424         setCurrencyString((currency == null) ? null : currency.getName());
425     }
426     private void setEditable(Boolean editable) {
427         tvDate.setEnabled(editable);
428         tvDescription.setEnabled(editable);
429         tvAccount.setEnabled(editable);
430         tvAmount.setEnabled(editable);
431     }
432     private void setCommentVisible(Boolean visible) {
433         if (visible) {
434             // showing; show the comment view and align the comment button to it
435             tvComment.setVisibility(View.VISIBLE);
436             tvComment.requestFocus();
437             ConstraintLayout.LayoutParams lp =
438                     (ConstraintLayout.LayoutParams) commentButton.getLayoutParams();
439             lp.bottomToBottom = R.id.comment;
440
441             commentButton.setLayoutParams(lp);
442         }
443         else {
444             // hiding; hide the comment comment view and align amounts layout under it
445             tvComment.setVisibility(View.GONE);
446             ConstraintLayout.LayoutParams lp =
447                     (ConstraintLayout.LayoutParams) commentButton.getLayoutParams();
448             lp.bottomToBottom = R.id.ntr_account;   // R.id.parent doesn't work here
449
450             commentButton.setLayoutParams(lp);
451         }
452     }
453     private void setComment(String comment) {
454         if ((comment != null) && !comment.isEmpty())
455             commentButton.setBackgroundResource(R.drawable.ic_comment_black_24dp);
456         else
457             commentButton.setBackgroundResource(R.drawable.ic_comment_gray_24dp);
458     }
459     private void beginUpdates() {
460         if (inUpdate)
461             throw new RuntimeException("Already in update mode");
462         inUpdate = true;
463     }
464     private void endUpdates() {
465         if (!inUpdate)
466             throw new RuntimeException("Not in update mode");
467         inUpdate = false;
468     }
469     /**
470      * syncData()
471      * <p>
472      * Stores the data from the UI elements into the model item
473      */
474     private void syncData() {
475         if (item == null)
476             return;
477
478         if (syncingData) {
479             Logger.debug("new-trans", "skipping syncData() loop");
480             return;
481         }
482
483         syncingData = true;
484
485         try {
486             switch (item.getType()) {
487                 case generalData:
488                     item.setDate(String.valueOf(tvDate.getText()));
489                     item.setDescription(String.valueOf(tvDescription.getText()));
490                     break;
491                 case transactionRow:
492                     final LedgerTransactionAccount account = item.getAccount();
493                     account.setAccountName(String.valueOf(tvAccount.getText()));
494
495                     item.setComment(String.valueOf(tvComment.getText()));
496
497                     // TODO: handle multiple amounts
498                     String amount = String.valueOf(tvAmount.getText());
499                     amount = amount.trim();
500
501                     if (amount.isEmpty()) {
502                         account.resetAmount();
503                         account.setCurrency(null);
504                     }
505                     else {
506                         try {
507                             amount = amount.replace(decimalSeparator, decimalDot);
508                             account.setAmount(Float.parseFloat(amount));
509                         }
510                         catch (NumberFormatException e) {
511                             Logger.debug("new-trans", String.format(
512                                     "assuming amount is not set due to number format exception. " +
513                                     "input was '%s'", amount));
514                             account.resetAmount();
515                         }
516                         final String curr = String.valueOf(tvCurrency.getText());
517                         if (curr.equals(tvCurrency.getContext()
518                                                   .getResources()
519                                                   .getString(R.string.currency_symbol)) ||
520                             curr.isEmpty())
521                             account.setCurrency(null);
522                         else
523                             account.setCurrency(curr);
524                     }
525
526                     break;
527                 case bottomFiller:
528                     throw new RuntimeException("Should not happen");
529             }
530         }
531         finally {
532             syncingData = false;
533         }
534     }
535     private void pickTransactionDate() {
536         DatePickerFragment picker = new DatePickerFragment();
537         picker.setFutureDates(mProfile.getFutureDates());
538         picker.setOnDatePickedListener(this);
539         picker.show(((NewTransactionActivity) tvDate.getContext()).getSupportFragmentManager(),
540                 "datePicker");
541     }
542     /**
543      * setData
544      *
545      * @param item updates the UI elements with the data from the model item
546      */
547     @SuppressLint("DefaultLocale")
548     public void setData(NewTransactionModel.Item item) {
549         beginUpdates();
550         try {
551             if (this.item != null && !this.item.equals(item)) {
552                 this.item.stopObservingDate(dateObserver);
553                 this.item.stopObservingDescription(descriptionObserver);
554                 this.item.stopObservingAmountHint(hintObserver);
555                 this.item.stopObservingEditableFlag(editableObserver);
556                 this.item.stopObservingCommentVisible(commentVisibleObserver);
557                 this.item.stopObservingComment(commentObserver);
558                 this.item.getModel()
559                          .stopObservingFocusedItem(focusedAccountObserver);
560                 this.item.getModel()
561                          .stopObservingAccountCount(accountCountObserver);
562                 Data.currencySymbolPosition.removeObserver(currencyPositionObserver);
563                 Data.currencyGap.removeObserver(currencyGapObserver);
564                 Data.locale.removeObserver(localeObserver);
565                 this.item.stopObservingCurrency(currencyObserver);
566                 this.item.getModel().showCurrency.removeObserver(showCurrencyObserver);
567
568                 this.item = null;
569             }
570
571             switch (item.getType()) {
572                 case generalData:
573                     tvDate.setText(item.getFormattedDate());
574                     tvDescription.setText(item.getDescription());
575                     lHead.setVisibility(View.VISIBLE);
576                     lAccount.setVisibility(View.GONE);
577                     lPadding.setVisibility(View.GONE);
578                     setEditable(true);
579                     break;
580                 case transactionRow:
581                     LedgerTransactionAccount acc = item.getAccount();
582                     tvAccount.setText(acc.getAccountName());
583                     tvComment.setText(acc.getComment());
584                     if (acc.isAmountSet()) {
585                         tvAmount.setText(String.format("%1.2f", acc.getAmount()));
586                     }
587                     else {
588                         tvAmount.setText("");
589 //                        tvAmount.setHint(R.string.zero_amount);
590                     }
591                     tvAmount.setHint(item.getAmountHint());
592                     setCurrencyString(acc.getCurrency());
593                     lHead.setVisibility(View.GONE);
594                     lAccount.setVisibility(View.VISIBLE);
595                     lPadding.setVisibility(View.GONE);
596                     setEditable(true);
597                     break;
598                 case bottomFiller:
599                     lHead.setVisibility(View.GONE);
600                     lAccount.setVisibility(View.GONE);
601                     lPadding.setVisibility(View.VISIBLE);
602                     setEditable(false);
603                     break;
604             }
605
606             if (this.item == null) { // was null or has changed
607                 this.item = item;
608                 final NewTransactionActivity activity =
609                         (NewTransactionActivity) tvDescription.getContext();
610                 item.observeDate(activity, dateObserver);
611                 item.observeDescription(activity, descriptionObserver);
612                 item.observeAmountHint(activity, hintObserver);
613                 item.observeEditableFlag(activity, editableObserver);
614                 item.observeCommentVisible(activity, commentVisibleObserver);
615                 item.observeComment(activity, commentObserver);
616                 item.getModel()
617                     .observeFocusedItem(activity, focusedAccountObserver);
618                 item.getModel()
619                     .observeAccountCount(activity, accountCountObserver);
620                 Data.currencySymbolPosition.observe(activity, currencyPositionObserver);
621                 Data.currencyGap.observe(activity, currencyGapObserver);
622                 Data.locale.observe(activity, localeObserver);
623                 item.observeCurrency(activity, currencyObserver);
624                 item.getModel().showCurrency.observe(activity, showCurrencyObserver);
625             }
626         }
627         finally {
628             endUpdates();
629         }
630     }
631     @Override
632     public void onDatePicked(int year, int month, int day) {
633         final Calendar c = GregorianCalendar.getInstance();
634         c.set(year, month, day);
635         item.setDate(c.getTime());
636         boolean focused = tvDescription.requestFocus();
637         if (focused)
638             Misc.showSoftKeyboard((NewTransactionActivity) tvAccount.getContext());
639
640     }
641     @Override
642     public void onCurrencySelected(Currency item) {
643         this.item.setCurrency(item);
644     }
645     @Override
646     public void descriptionSelected(String description) {
647         tvAccount.setText(description);
648         tvAmount.requestFocus(View.FOCUS_FORWARD);
649     }
650 }