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