import androidx.lifecycle.ViewModel;
import net.ktnx.mobileledger.BuildConfig;
+import net.ktnx.mobileledger.model.Currency;
import net.ktnx.mobileledger.model.LedgerTransactionAccount;
import net.ktnx.mobileledger.utils.Logger;
import net.ktnx.mobileledger.utils.Misc;
getItem(position).setFocusedElement(element);
}
public void swapItems(int one, int two) {
- Collections.swap(items, one-1, two-1);
+ Collections.swap(items, one - 1, two - 1);
}
public void toggleComment(int position) {
final MutableLiveData<Boolean> commentVisible = getItem(position).commentVisible;
commentVisible.postValue(!commentVisible.getValue());
}
+ public void moveItemLast(int index) {
+ /* 0
+ 1 <-- index
+ 2
+ 3 <-- desired position
+ */
+ int itemCount = items.size();
+
+ if (index < itemCount - 1) {
+ Item acc = items.remove(index);
+ items.add(itemCount - 1, acc);
+ }
+ }
enum ItemType {generalData, transactionRow, bottomFiller}
//==========================================================================================
private FocusedElement focusedElement = FocusedElement.Account;
private MutableLiveData<String> comment = new MutableLiveData<>(null);
private MutableLiveData<Boolean> commentVisible = new MutableLiveData<>(false);
+ private MutableLiveData<Currency> currency = new MutableLiveData<>(null);
public Item(NewTransactionModel model) {
this.model = model;
type = ItemType.bottomFiller;
public void stopObservingCommentVisible(Observer<Boolean> observer) {
commentVisible.removeObserver(observer);
}
- public void observeComment(NewTransactionActivity activity,
- Observer<String> observer) {
+ public void observeComment(NewTransactionActivity activity, Observer<String> observer) {
comment.observe(activity, observer);
}
public void stopObservingComment(Observer<String> observer) {
getAccount().setComment(comment);
this.comment.postValue(comment);
}
+ public Currency getCurrency() {
+ return this.currency.getValue();
+ }
+ public void setCurrency(Currency currency) {
+ getAccount().setCurrency((currency != null && !currency.getName()
+ .isEmpty()) ? currency.getName()
+ : null);
+ this.currency.setValue(currency);
+ }
+ public void observeCurrency(NewTransactionActivity activity, Observer<Currency> observer) {
+ currency.observe(activity, observer);
+ }
+ public void stopObservingCurrency(Observer<Currency> observer) {
+ currency.removeObserver(observer);
+ }
}
}