Skip to content

Commit

Permalink
Handle exceptional condition of category with empty space
Browse files Browse the repository at this point in the history
  • Loading branch information
mtotschnig committed Sep 18, 2024
1 parent ddd270e commit bcec255
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1083,37 +1083,44 @@ abstract class BaseMyExpenses : LaunchActivity(), OnDialogResultListener, Contri
subMenu = Menu(
buildList {
if (transaction.catId != null && !transaction.isSplit) {
add(MenuEntry(
label = UiText.StringValue(
transaction.categoryPath!!
),
command = "FILTER_FOR_CATEGORY"
) {
addFilterCriterion(
CategoryCriterion(
transaction.categoryPath,
transaction.catId
)
)
}
)
}
if (transaction.payeeId != null) {
add(
MenuEntry(
if (transaction.categoryPath != null) {
add(MenuEntry(
label = UiText.StringValue(
transaction.payee!!
transaction.categoryPath
),
command = "FILTER_FOR_PAYEE"
command = "FILTER_FOR_CATEGORY"
) {
addFilterCriterion(
PayeeCriterion(
transaction.payee,
transaction.payeeId
CategoryCriterion(
transaction.categoryPath,
transaction.catId
)
)
}
)
})
} else {
CrashHandler.report(IllegalStateException("Category path is null"))
}
}
if (transaction.payeeId != null) {
if (transaction.payee != null) {
add(
MenuEntry(
label = UiText.StringValue(
transaction.payee
),
command = "FILTER_FOR_PAYEE"
) {
addFilterCriterion(
PayeeCriterion(
transaction.payee,
transaction.payeeId
)
)
}
)
} else {
CrashHandler.report(IllegalStateException("Payee is null"))
}
}
if (transaction.methodId != null) {
val label =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public Template(Cursor c) {
defaultAction = Action.valueOf(c.getString(c.getColumnIndexOrThrow(KEY_DEFAULT_ACTION)));
} catch (IllegalArgumentException ignored) {}
setDebtId(getLongOrNull(c, KEY_DEBT_ID));
String originalCurrency = getStringOrNull(c, KEY_ORIGINAL_CURRENCY);
String originalCurrency = getStringOrNull(c, KEY_ORIGINAL_CURRENCY, false);
if (originalCurrency != null) {
setOriginalAmount(
new Money(currencyContext.get(originalCurrency),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ KEY_METHOD_LABEL, KEY_STATUS, TRANSFER_AMOUNT(VIEW_ALL), KEY_TEMPLATEID, KEY_UUI
t.setCrStatus(CrStatus.UNRECONCILED);
}
t.setMethodId(getLongOrNull(c, KEY_METHODID));
t.setMethodLabel(getStringOrNull(c, KEY_METHOD_LABEL));
t.setMethodLabel(getStringOrNull(c, KEY_METHOD_LABEL, false));
t.setCatId(catId);
t.setPayee(getString(c, KEY_PAYEE_NAME));
t.setPayeeId(getLongOrNull(c, KEY_PAYEEID));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ abstract class BaseTransactionDatabase(
append(" LEFT JOIN $TABLE_METHODS ON $KEY_METHODID = $TABLE_METHODS.$KEY_ROWID")
if (tableName != TABLE_CHANGES) {
append(" LEFT JOIN $TABLE_ACCOUNTS ON $KEY_ACCOUNTID = $TABLE_ACCOUNTS.$KEY_ROWID")
append(" LEFT JOIN Tree ON $KEY_CATID = TREE.$KEY_ROWID")
append(" LEFT JOIN Tree ON $KEY_CATID = Tree.$KEY_ROWID")
}
if (tableName == TABLE_TRANSACTIONS) {
append(" LEFT JOIN $TABLE_PLAN_INSTANCE_STATUS ON $tableName.$KEY_ROWID = $TABLE_PLAN_INSTANCE_STATUS.$KEY_TRANSACTIONID")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ fun Cursor.getString(column: String) = requireString(getColumnIndexOrThrow(colum
fun Cursor.getInt(column: String) = getInt(getColumnIndexOrThrow(column))
fun Cursor.getLong(column: String) = getLong(getColumnIndexOrThrow(column))
fun Cursor.getDouble(column: String) = getDouble(getColumnIndexOrThrow(column))
fun Cursor.getStringOrNull(column: String) =
getStringOrNull(getColumnIndexOrThrow(column))?.takeIf { it.isNotEmpty() }
fun Cursor.getStringOrNull(column: String, allowEmpty: Boolean = false) =
getStringOrNull(getColumnIndexOrThrow(column))?.takeIf { allowEmpty || it.isNotEmpty() }

fun Cursor.getIntOrNull(column: String) = getIntOrNull(getColumnIndexOrThrow(column))
fun Cursor.getLongOrNull(column: String) = getLongOrNull(getColumnIndexOrThrow(column))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ data class Transaction(
catId = getLongOrNull(KEY_CATID),
payee = getString(KEY_PAYEE_NAME),
methodLabel = getStringOrNull(KEY_METHOD_LABEL),
categoryPath = getStringOrNull(KEY_PATH),
categoryPath = getStringOrNull(KEY_PATH, allowEmpty = true),
transferAccount = getStringOrNull(KEY_TRANSFER_ACCOUNT_LABEL),
transferPeer = transferPeer,
transferAmount = transferAccountId?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ data class Transaction2(
payee = cursor.getStringOrNull(KEY_PAYEE_NAME),
methodLabel = cursor.getStringOrNull(KEY_METHOD_LABEL),
methodIcon = cursor.getStringIfExists(KEY_METHOD_ICON),
categoryPath = cursor.getStringOrNull(KEY_PATH),
categoryPath = cursor.getStringOrNull(KEY_PATH, allowEmpty = true),
transferPeer = transferPeer,
transferAccount = cursor.getLongOrNull(KEY_TRANSFER_ACCOUNT),
transferAccountLabel = cursor.getStringOrNull(KEY_TRANSFER_ACCOUNT_LABEL),
Expand Down

0 comments on commit bcec255

Please sign in to comment.