|
|
|
@ -58,8 +58,18 @@ class TransactionDataFragment : EditableDataFragment(), StaticRowRepresentableDa |
|
|
|
|
|
|
|
|
|
|
|
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? { |
|
|
|
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? { |
|
|
|
return when (row) { |
|
|
|
return when (row) { |
|
|
|
TransactionRow.BANKROLL -> row.editingDescriptors(mapOf("defaultValue" to this.transaction.bankroll, "data" to getRealm().sorted<Bankroll>() )) |
|
|
|
TransactionRow.BANKROLL -> row.editingDescriptors( |
|
|
|
TransactionRow.TYPE -> row.editingDescriptors(mapOf("defaultValue" to this.transaction.type, "data" to getRealm().sorted<TransactionType>() )) |
|
|
|
mapOf( |
|
|
|
|
|
|
|
"defaultValue" to this.transaction.bankroll, |
|
|
|
|
|
|
|
"data" to getRealm().sorted<Bankroll>() |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
TransactionRow.TYPE -> row.editingDescriptors( |
|
|
|
|
|
|
|
mapOf( |
|
|
|
|
|
|
|
"defaultValue" to this.transaction.type, |
|
|
|
|
|
|
|
"data" to getRealm().sorted<TransactionType>() |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) |
|
|
|
TransactionRow.AMOUNT -> row.editingDescriptors(mapOf("defaultValue" to (if (this.transaction.amount != 0.0) this.transaction.amount.round() else ""))) |
|
|
|
TransactionRow.AMOUNT -> row.editingDescriptors(mapOf("defaultValue" to (if (this.transaction.amount != 0.0) this.transaction.amount.round() else ""))) |
|
|
|
TransactionRow.COMMENT -> row.editingDescriptors(mapOf("defaultValue" to this.transaction.comment)) |
|
|
|
TransactionRow.COMMENT -> row.editingDescriptors(mapOf("defaultValue" to this.transaction.comment)) |
|
|
|
else -> super.editDescriptors(row) |
|
|
|
else -> super.editDescriptors(row) |
|
|
|
@ -68,7 +78,14 @@ class TransactionDataFragment : EditableDataFragment(), StaticRowRepresentableDa |
|
|
|
|
|
|
|
|
|
|
|
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
|
|
|
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
|
|
|
when (row) { |
|
|
|
when (row) { |
|
|
|
TransactionRow.DATE -> DateTimePickerManager.create(requireContext(), row, this, this.transaction.date, onlyDate = true, isClearable = false) |
|
|
|
TransactionRow.DATE -> DateTimePickerManager.create( |
|
|
|
|
|
|
|
requireContext(), |
|
|
|
|
|
|
|
row, |
|
|
|
|
|
|
|
this, |
|
|
|
|
|
|
|
this.transaction.date, |
|
|
|
|
|
|
|
onlyDate = true, |
|
|
|
|
|
|
|
isClearable = false |
|
|
|
|
|
|
|
) |
|
|
|
else -> super.onRowSelected(position, row, fromAction) |
|
|
|
else -> super.onRowSelected(position, row, fromAction) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -80,7 +97,7 @@ class TransactionDataFragment : EditableDataFragment(), StaticRowRepresentableDa |
|
|
|
if (primaryKey == null) { // automatically change the row for new data |
|
|
|
if (primaryKey == null) { // automatically change the row for new data |
|
|
|
GlobalScope.launch(Dispatchers.Main) { |
|
|
|
GlobalScope.launch(Dispatchers.Main) { |
|
|
|
delay(200) |
|
|
|
delay(200) |
|
|
|
when(row) { |
|
|
|
when (row) { |
|
|
|
TransactionRow.BANKROLL -> onRowSelected(0, TransactionRow.TYPE) |
|
|
|
TransactionRow.BANKROLL -> onRowSelected(0, TransactionRow.TYPE) |
|
|
|
TransactionRow.TYPE -> onRowSelected(0, TransactionRow.AMOUNT) |
|
|
|
TransactionRow.TYPE -> onRowSelected(0, TransactionRow.AMOUNT) |
|
|
|
// TransactionRow.AMOUNT -> onRowSelected(0, TransactionRow.DATE) |
|
|
|
// TransactionRow.AMOUNT -> onRowSelected(0, TransactionRow.DATE) |
|
|
|
@ -88,7 +105,14 @@ class TransactionDataFragment : EditableDataFragment(), StaticRowRepresentableDa |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun willSaveData() { |
|
|
|
|
|
|
|
super.willSaveData() |
|
|
|
|
|
|
|
val additive = this.transaction.type?.additive ?: true |
|
|
|
|
|
|
|
if (!additive) { |
|
|
|
|
|
|
|
this.transaction.amount *= -1 |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |