import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
+import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModel;
import net.ktnx.mobileledger.model.LedgerTransactionAccount;
if (index == 0) {
return header;
}
- else if (index <= items.size()) return items.get(index - 1);
- else return trailer;
+
+ if (index <= items.size()) return items.get(index - 1);
+
+ return trailer;
}
// rules:
// 1) at least two account names
isSubmittable.setValue(false);
}
}
- public void removeItem(int pos, NewTransactionItemsAdapter adapter) {
+ public void removeItem(int pos) {
items.remove(pos);
accountCount.setValue(getAccountCount());
- checkTransactionSubmittable(adapter);
+ }
+ public void sendCountNotifications() {
+ accountCount.setValue(getAccountCount());
}
enum ItemType {generalData, transactionRow, bottomFiller}
private LedgerTransactionAccount account;
private MutableLiveData<String> amountHint = new MutableLiveData<>();
private NewTransactionModel model;
- private boolean editable = true;
+ private MutableLiveData<Boolean> editable = new MutableLiveData<>(true);
public Item(NewTransactionModel model) {
this.model = model;
type = ItemType.bottomFiller;
+ editable.setValue(false);
}
public Item(NewTransactionModel model, Date date, String description) {
this.model = model;
this.type = ItemType.generalData;
this.date.setValue(date);
this.description.setValue(description);
+ this.editable.setValue(true);
}
public Item(NewTransactionModel model, LedgerTransactionAccount account) {
this.model = model;
this.type = ItemType.transactionRow;
this.account = account;
+ this.editable.setValue(true);
}
public NewTransactionModel getModel() {
return model;
}
public boolean isEditable() {
ensureType(ItemType.transactionRow);
- return editable;
+ return this.editable.getValue();
}
public void setEditable(boolean editable) {
ensureType(ItemType.transactionRow);
- this.editable = editable;
+ this.editable.setValue(editable);
}
public String getAmountHint() {
ensureType(ItemType.transactionRow);
return String.valueOf(myDay);
}
+ public void observeEditableFlag(NewTransactionActivity activity,
+ Observer<Boolean> observer) {
+ editable.observe(activity, observer);
+ }
+ public void stopObservingEditableFlag(Observer<Boolean> observer) {
+ editable.removeObserver(observer);
+ }
}
}