Skip to content

Commit

Permalink
Fix crash when deleting scheduled exports
Browse files Browse the repository at this point in the history
  • Loading branch information
codinguser committed Dec 1, 2015
1 parent 3624798 commit a90da4d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ public abstract class DatabaseAdapter<Model extends BaseModel> {

protected SQLiteStatement mReplaceStatement;

public enum UpdateMethod {
insert, update, replace
};

/**
* Opens the database adapter with an existing database
* @param db SQLiteDatabase object
Expand Down Expand Up @@ -427,7 +423,7 @@ public String getUID(long id){
if (cursor.moveToFirst()) {
uid = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseSchema.CommonColumns.COLUMN_UID));
} else {
throw new IllegalArgumentException("Account record ID " + id + " does not exist in the db");
throw new IllegalArgumentException(mTableName + " Record ID " + id + " does not exist in the db");
}
} finally {
cursor.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,24 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
case R.id.context_menu_delete:
for (long id : getListView().getCheckedItemIds()) {
Log.i(TAG, "Cancelling scheduled transaction(s)");
String trnUID = mTransactionsDbAdapter.getUID(id);
ScheduledActionDbAdapter scheduledActionDbAdapter = GnuCashApplication.getScheduledEventDbAdapter();
List<ScheduledAction> actions = scheduledActionDbAdapter.getScheduledActionsWithUID(trnUID);

if (mTransactionsDbAdapter.deleteRecord(id)){
Toast.makeText(getActivity(), R.string.toast_recurring_transaction_deleted, Toast.LENGTH_SHORT).show();
for (ScheduledAction action : actions) {
scheduledActionDbAdapter.deleteRecord(action.getUID());

if (mActionType == ScheduledAction.ActionType.TRANSACTION) {
Log.i(TAG, "Cancelling scheduled transaction(s)");
String trnUID = mTransactionsDbAdapter.getUID(id);
ScheduledActionDbAdapter scheduledActionDbAdapter = GnuCashApplication.getScheduledEventDbAdapter();
List<ScheduledAction> actions = scheduledActionDbAdapter.getScheduledActionsWithUID(trnUID);

if (mTransactionsDbAdapter.deleteRecord(id)) {
Toast.makeText(getActivity(),
R.string.toast_recurring_transaction_deleted,
Toast.LENGTH_SHORT).show();
for (ScheduledAction action : actions) {
scheduledActionDbAdapter.deleteRecord(action.getUID());
}
}
} else if (mActionType == ScheduledAction.ActionType.BACKUP){
Log.i(TAG, "Removing scheduled exports");
ScheduledActionDbAdapter.getInstance().deleteRecord(id);
}
}
mode.finish();
Expand Down

0 comments on commit a90da4d

Please sign in to comment.