]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java
@NotNull annotation
[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.TextViewClearHelper;
50 import net.ktnx.mobileledger.utils.Colors;
51 import net.ktnx.mobileledger.utils.DimensionUtils;
52 import net.ktnx.mobileledger.utils.Logger;
53 import net.ktnx.mobileledger.utils.MLDB;
54 import net.ktnx.mobileledger.utils.Misc;
55
56 import org.jetbrains.annotations.NotNull;
57
58 import java.text.DecimalFormatSymbols;
59 import java.util.Calendar;
60 import java.util.Date;
61 import java.util.GregorianCalendar;
62 import java.util.Locale;
63
64 import static net.ktnx.mobileledger.ui.activity.NewTransactionModel.ItemType;
65
66 class NewTransactionItemHolder extends RecyclerView.ViewHolder
67         implements DatePickerFragment.DatePickedListener, DescriptionSelectedCallback {
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     private NewTransactionItemsAdapter adapter;
99     //TODO multiple amounts with different currencies per posting
100     NewTransactionItemHolder(@NonNull View itemView, NewTransactionItemsAdapter adapter) {
101         super(itemView);
102         this.adapter = adapter;
103         tvAccount = itemView.findViewById(R.id.account_row_acc_name);
104         tvComment = itemView.findViewById(R.id.comment);
105         new TextViewClearHelper().attachToTextView((EditText) tvComment);
106         commentButton = itemView.findViewById(R.id.comment_button);
107         tvAmount = itemView.findViewById(R.id.account_row_acc_amounts);
108         tvCurrency = itemView.findViewById(R.id.currency);
109         tvDate = itemView.findViewById(R.id.new_transaction_date);
110         tvDescription = itemView.findViewById(R.id.new_transaction_description);
111         lHead = itemView.findViewById(R.id.ntr_data);
112         lAccount = itemView.findViewById(R.id.ntr_account);
113         lPadding = itemView.findViewById(R.id.ntr_padding);
114
115         tvDescription.setNextFocusForwardId(View.NO_ID);
116         tvAccount.setNextFocusForwardId(View.NO_ID);
117         tvAmount.setNextFocusForwardId(View.NO_ID); // magic!
118
119         tvDate.setOnClickListener(v -> pickTransactionDate());
120
121         mProfile = Data.profile.getValue();
122         if (mProfile == null)
123             throw new AssertionError();
124
125         View.OnFocusChangeListener focusMonitor = (v, hasFocus) -> {
126             if (hasFocus) {
127                 boolean wasSyncing = syncingData;
128                 syncingData = true;
129                 try {
130                     final int pos = getAdapterPosition();
131                     adapter.updateFocusedItem(pos);
132                     switch (v.getId()) {
133                         case R.id.account_row_acc_name:
134                             adapter.noteFocusIsOnAccount(pos);
135                             break;
136                         case R.id.account_row_acc_amounts:
137                             adapter.noteFocusIsOnAmount(pos);
138                             break;
139                         case R.id.comment:
140                             adapter.noteFocusIsOnComment(pos);
141                             break;
142                     }
143                 }
144                 finally {
145                     syncingData = wasSyncing;
146                 }
147             }
148         };
149
150         tvDescription.setOnFocusChangeListener(focusMonitor);
151         tvAccount.setOnFocusChangeListener(focusMonitor);
152         tvAmount.setOnFocusChangeListener(focusMonitor);
153
154         itemView.findViewById(R.id.comment_button)
155                 .setOnClickListener(v -> {
156                     final int pos = getAdapterPosition();
157                     adapter.toggleComment(pos);
158                 });
159         MLDB.hookAutocompletionAdapter(tvDescription.getContext(), tvDescription,
160                 MLDB.DESCRIPTION_HISTORY_TABLE, "description", false, adapter, mProfile);
161         MLDB.hookAutocompletionAdapter(tvAccount.getContext(), tvAccount, MLDB.ACCOUNTS_TABLE,
162                 "name", true, this, mProfile);
163
164         // FIXME: react on configuration (locale) changes
165         decimalSeparator = String.valueOf(DecimalFormatSymbols.getInstance()
166                                                               .getMonetaryDecimalSeparator());
167         decimalDot = ".";
168
169         final TextWatcher tw = new TextWatcher() {
170             @Override
171             public void beforeTextChanged(CharSequence s, int start, int count, int after) {
172             }
173
174             @Override
175             public void onTextChanged(CharSequence s, int start, int before, int count) {
176             }
177
178             @Override
179             public void afterTextChanged(Editable s) {
180 //                debug("input", "text changed");
181                 if (inUpdate)
182                     return;
183
184                 Logger.debug("textWatcher", "calling syncData()");
185                 syncData();
186                 Logger.debug("textWatcher",
187                         "syncData() returned, checking if transaction is submittable");
188                 adapter.checkTransactionSubmittable();
189                 Logger.debug("textWatcher", "done");
190             }
191         };
192         final TextWatcher amountWatcher = new TextWatcher() {
193             @Override
194             public void beforeTextChanged(CharSequence s, int start, int count, int after) {
195                 Logger.debug("num",
196                         String.format(Locale.US, "beforeTextChanged: start=%d, count=%d, after=%d",
197                                 start, count, after));
198             }
199             @Override
200             public void onTextChanged(CharSequence s, int start, int before, int count) {}
201             @Override
202             public void afterTextChanged(Editable s) {
203                 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
204                     // only one decimal separator is allowed
205                     // plus and minus are allowed only at the beginning
206                     String allowed = "0123456789";
207                     String val = s.toString();
208                     Logger.debug("input", val);
209                     if (val.isEmpty() || (tvAmount.getSelectionStart() == 0))
210                         allowed += "-";
211                     if (!val.contains(decimalSeparator) && !val.contains(decimalDot))
212                         allowed += decimalSeparator + decimalDot;
213
214                     tvAmount.setKeyListener(DigitsKeyListener.getInstance(allowed));
215                 }
216
217                 if (syncData())
218                     adapter.checkTransactionSubmittable();
219             }
220         };
221         tvDescription.addTextChangedListener(tw);
222         tvAccount.addTextChangedListener(tw);
223         tvComment.addTextChangedListener(tw);
224         tvAmount.addTextChangedListener(amountWatcher);
225
226         tvCurrency.setOnClickListener(v -> {
227             CurrencySelectorFragment cpf = new CurrencySelectorFragment();
228             cpf.showPositionAndPadding();
229             cpf.setOnCurrencySelectedListener(c -> item.setCurrency(c));
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         localeObserver = locale -> {
344             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
345                 tvAmount.setKeyListener(DigitsKeyListener.getInstance(locale, true, true));
346         };
347
348         currencyObserver = currency -> {
349             setCurrency(currency);
350             adapter.checkTransactionSubmittable();
351         };
352
353         currencyGapObserver = hasGap -> {
354             updateCurrencyPositionAndPadding(Data.currencySymbolPosition.getValue(), hasGap);
355         };
356
357         currencyPositionObserver = position -> {
358             updateCurrencyPositionAndPadding(position, Data.currencyGap.getValue());
359         };
360
361         showCurrencyObserver = showCurrency -> {
362             if (showCurrency) {
363                 tvCurrency.setVisibility(View.VISIBLE);
364             }
365             else {
366                 tvCurrency.setVisibility(View.GONE);
367                 item.setCurrency(null);
368             }
369         };
370     }
371     private void updateCurrencyPositionAndPadding(Currency.Position position, boolean hasGap) {
372         ConstraintLayout.LayoutParams amountLP =
373                 (ConstraintLayout.LayoutParams) tvAmount.getLayoutParams();
374         ConstraintLayout.LayoutParams currencyLP =
375                 (ConstraintLayout.LayoutParams) tvCurrency.getLayoutParams();
376
377         if (position == Currency.Position.before) {
378             currencyLP.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
379             currencyLP.endToEnd = ConstraintLayout.LayoutParams.UNSET;
380
381             amountLP.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
382             amountLP.endToStart = ConstraintLayout.LayoutParams.UNSET;
383             amountLP.startToStart = ConstraintLayout.LayoutParams.UNSET;
384             amountLP.startToEnd = tvCurrency.getId();
385
386             tvCurrency.setGravity(Gravity.END);
387         }
388         else {
389             currencyLP.startToStart = ConstraintLayout.LayoutParams.UNSET;
390             currencyLP.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
391
392             amountLP.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
393             amountLP.startToEnd = ConstraintLayout.LayoutParams.UNSET;
394             amountLP.endToEnd = ConstraintLayout.LayoutParams.UNSET;
395             amountLP.endToStart = tvCurrency.getId();
396
397             tvCurrency.setGravity(Gravity.START);
398         }
399
400         amountLP.resolveLayoutDirection(tvAmount.getLayoutDirection());
401         currencyLP.resolveLayoutDirection(tvCurrency.getLayoutDirection());
402
403         tvAmount.setLayoutParams(amountLP);
404         tvCurrency.setLayoutParams(currencyLP);
405
406         // distance between the amount and the currency symbol
407         int gapSize = DimensionUtils.sp2px(tvCurrency.getContext(), 5);
408
409         if (position == Currency.Position.before) {
410             tvCurrency.setPaddingRelative(0, 0, hasGap ? gapSize : 0, 0);
411         }
412         else {
413             tvCurrency.setPaddingRelative(hasGap ? gapSize : 0, 0, 0, 0);
414         }
415     }
416     private void setCurrencyString(String currency) {
417         if ((currency == null) || currency.isEmpty()) {
418             tvCurrency.setText(R.string.currency_symbol);
419             tvCurrency.setTextColor(0x7f000000 + (0x00ffffff & Colors.defaultTextColor));
420         }
421         else {
422             tvCurrency.setText(currency);
423             tvCurrency.setTextColor(Colors.defaultTextColor);
424         }
425     }
426     private void setCurrency(Currency currency) {
427         setCurrencyString((currency == null) ? null : currency.getName());
428     }
429     private void setEditable(Boolean editable) {
430         tvDate.setEnabled(editable);
431         tvDescription.setEnabled(editable);
432         tvAccount.setEnabled(editable);
433         tvAmount.setEnabled(editable);
434     }
435     private void setCommentVisible(@NotNull Boolean visible) {
436         if (visible) {
437             // showing; show the comment view and align the comment button to it
438             tvComment.setVisibility(View.VISIBLE);
439             tvComment.requestFocus();
440             ConstraintLayout.LayoutParams lp =
441                     (ConstraintLayout.LayoutParams) commentButton.getLayoutParams();
442             lp.bottomToBottom = R.id.comment;
443
444             commentButton.setLayoutParams(lp);
445         }
446         else {
447             // hiding; hide the comment comment view and align amounts layout under it
448             tvComment.setVisibility(View.GONE);
449             ConstraintLayout.LayoutParams lp =
450                     (ConstraintLayout.LayoutParams) commentButton.getLayoutParams();
451             lp.bottomToBottom = R.id.ntr_account;   // R.id.parent doesn't work here
452
453             commentButton.setLayoutParams(lp);
454         }
455     }
456     private void setComment(String comment) {
457         if ((comment != null) && !comment.isEmpty())
458             commentButton.setBackgroundResource(R.drawable.ic_comment_black_24dp);
459         else
460             commentButton.setBackgroundResource(R.drawable.ic_comment_gray_24dp);
461     }
462     private void beginUpdates() {
463         if (inUpdate)
464             throw new RuntimeException("Already in update mode");
465         inUpdate = true;
466     }
467     private void endUpdates() {
468         if (!inUpdate)
469             throw new RuntimeException("Not in update mode");
470         inUpdate = false;
471     }
472     /**
473      * syncData()
474      * <p>
475      * Stores the data from the UI elements into the model item
476      * Returns true if there were changes made that suggest transaction has to be
477      * checked for being submittable
478      */
479     private boolean syncData() {
480         if (item == null)
481             return false;
482
483         if (syncingData) {
484             Logger.debug("new-trans", "skipping syncData() loop");
485             return false;
486         }
487
488         syncingData = true;
489
490         try {
491             switch (item.getType()) {
492                 case generalData:
493                     item.setDate(String.valueOf(tvDate.getText()));
494                     item.setDescription(String.valueOf(tvDescription.getText()));
495                     break;
496                 case transactionRow:
497                     final LedgerTransactionAccount account = item.getAccount();
498                     account.setAccountName(String.valueOf(tvAccount.getText()));
499
500                     item.setComment(String.valueOf(tvComment.getText()));
501
502                     String amount = String.valueOf(tvAmount.getText());
503                     amount = amount.trim();
504
505                     if (amount.isEmpty()) {
506                         account.resetAmount();
507 //                        account.setCurrency(null);
508                     }
509                     else {
510                         try {
511                             amount = amount.replace(decimalSeparator, decimalDot);
512                             account.setAmount(Float.parseFloat(amount));
513                         }
514                         catch (NumberFormatException e) {
515                             Logger.debug("new-trans", String.format(
516                                     "assuming amount is not set due to number format exception. " +
517                                     "input was '%s'", amount));
518                             account.resetAmount();
519                         }
520                         final String curr = String.valueOf(tvCurrency.getText());
521                         if (curr.equals(tvCurrency.getContext()
522                                                   .getResources()
523                                                   .getString(R.string.currency_symbol)) ||
524                             curr.isEmpty())
525                             account.setCurrency(null);
526                         else
527                             account.setCurrency(curr);
528                     }
529
530                     break;
531                 case bottomFiller:
532                     throw new RuntimeException("Should not happen");
533             }
534
535             return true;
536         }
537         finally {
538             syncingData = false;
539         }
540     }
541     private void pickTransactionDate() {
542         DatePickerFragment picker = new DatePickerFragment();
543         picker.setFutureDates(mProfile.getFutureDates());
544         picker.setOnDatePickedListener(this);
545         picker.show(((NewTransactionActivity) tvDate.getContext()).getSupportFragmentManager(),
546                 "datePicker");
547     }
548     /**
549      * setData
550      *
551      * @param item updates the UI elements with the data from the model item
552      */
553     @SuppressLint("DefaultLocale")
554     public void setData(NewTransactionModel.Item item) {
555         beginUpdates();
556         try {
557             if (this.item != null && !this.item.equals(item)) {
558                 this.item.stopObservingDate(dateObserver);
559                 this.item.stopObservingDescription(descriptionObserver);
560                 this.item.stopObservingAmountHint(hintObserver);
561                 this.item.stopObservingEditableFlag(editableObserver);
562                 this.item.stopObservingCommentVisible(commentVisibleObserver);
563                 this.item.stopObservingComment(commentObserver);
564                 this.item.getModel()
565                          .stopObservingFocusedItem(focusedAccountObserver);
566                 this.item.getModel()
567                          .stopObservingAccountCount(accountCountObserver);
568                 Data.currencySymbolPosition.removeObserver(currencyPositionObserver);
569                 Data.currencyGap.removeObserver(currencyGapObserver);
570                 Data.locale.removeObserver(localeObserver);
571                 this.item.stopObservingCurrency(currencyObserver);
572                 this.item.getModel().showCurrency.removeObserver(showCurrencyObserver);
573
574                 this.item = null;
575             }
576
577             switch (item.getType()) {
578                 case generalData:
579                     tvDate.setText(item.getFormattedDate());
580                     tvDescription.setText(item.getDescription());
581                     lHead.setVisibility(View.VISIBLE);
582                     lAccount.setVisibility(View.GONE);
583                     lPadding.setVisibility(View.GONE);
584                     setEditable(true);
585                     break;
586                 case transactionRow:
587                     LedgerTransactionAccount acc = item.getAccount();
588                     tvAccount.setText(acc.getAccountName());
589                     tvComment.setText(acc.getComment());
590                     if (acc.isAmountSet()) {
591                         tvAmount.setText(String.format("%1.2f", acc.getAmount()));
592                     }
593                     else {
594                         tvAmount.setText("");
595 //                        tvAmount.setHint(R.string.zero_amount);
596                     }
597                     tvAmount.setHint(item.getAmountHint());
598                     setCurrencyString(acc.getCurrency());
599                     lHead.setVisibility(View.GONE);
600                     lAccount.setVisibility(View.VISIBLE);
601                     lPadding.setVisibility(View.GONE);
602                     setEditable(true);
603                     break;
604                 case bottomFiller:
605                     lHead.setVisibility(View.GONE);
606                     lAccount.setVisibility(View.GONE);
607                     lPadding.setVisibility(View.VISIBLE);
608                     setEditable(false);
609                     break;
610             }
611             if (this.item == null) { // was null or has changed
612                 this.item = item;
613                 final NewTransactionActivity activity =
614                         (NewTransactionActivity) tvDescription.getContext();
615
616                 if (!item.isOfType(ItemType.bottomFiller)) {
617                     item.observeEditableFlag(activity, editableObserver);
618                     item.getModel()
619                         .observeFocusedItem(activity, focusedAccountObserver);
620                 }
621                 switch (item.getType()) {
622                     case generalData:
623                         item.observeDate(activity, dateObserver);
624                         item.observeDescription(activity, descriptionObserver);
625                         break;
626                     case transactionRow:
627                         item.observeAmountHint(activity, hintObserver);
628                         item.observeCommentVisible(activity, commentVisibleObserver);
629                         item.observeComment(activity, commentObserver);
630                         Data.currencySymbolPosition.observe(activity, currencyPositionObserver);
631                         Data.currencyGap.observe(activity, currencyGapObserver);
632                         Data.locale.observe(activity, localeObserver);
633                         item.observeCurrency(activity, currencyObserver);
634                         item.getModel().showCurrency.observe(activity, showCurrencyObserver);
635                         item.getModel()
636                             .observeAccountCount(activity, accountCountObserver);
637                         break;
638                 }
639             }
640         }
641         finally {
642             endUpdates();
643         }
644     }
645     @Override
646     public void onDatePicked(int year, int month, int day) {
647         final Calendar c = GregorianCalendar.getInstance();
648         c.set(year, month, day);
649         item.setDate(c.getTime());
650         boolean focused = tvDescription.requestFocus();
651         if (focused)
652             Misc.showSoftKeyboard((NewTransactionActivity) tvAccount.getContext());
653
654     }
655     @Override
656     public void descriptionSelected(String description) {
657         tvAccount.setText(description);
658         tvAmount.requestFocus(View.FOCUS_FORWARD);
659     }
660 }