Skip to content

Commit

Permalink
after restore do not create new account, but show first in DB
Browse files Browse the repository at this point in the history
  • Loading branch information
mtotschnig committed Mar 2, 2012
1 parent 88a8376 commit 2c506e2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
12 changes: 12 additions & 0 deletions src/org/totschnig/myexpenses/ExpensesDbAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,18 @@ public int getAccountCountWithCurrency(String currency) {
return result;
}

public Long getFirstAccountId() {
Cursor mCursor = mDb.rawQuery("select min(_id) from accounts",null);
mCursor.moveToFirst();
Long result;
if (mCursor.isNull(0))
result = null;
else
result = mCursor.getLong(0);
mCursor.close();
return result;
}

/**
* PAYEES
*/
Expand Down
20 changes: 12 additions & 8 deletions src/org/totschnig/myexpenses/MyExpenses.java
Original file line number Diff line number Diff line change
Expand Up @@ -517,14 +517,18 @@ public void newVersionCheck() {
if (pref_version == current_version)
return;
if (pref_version == -1) {
Account account = new Account(
mDbHelper,
getString(R.string.app_name),
0,
getString(R.string.default_account_description),
Currency.getInstance(Locale.getDefault())
);
long account_id = account.save();
//we check if we already have an account
Long account_id = mDbHelper.getFirstAccountId();
if (account_id == null) {
Account account = new Account(
mDbHelper,
getString(R.string.app_name),
0,
getString(R.string.default_account_description),
Currency.getInstance(Locale.getDefault())
);
account_id = account.save();
}
edit.putLong("current_account", account_id).commit();
edit.putInt("currentversion", current_version).commit();
} else if (pref_version != current_version) {
Expand Down

0 comments on commit 2c506e2

Please sign in to comment.