Skip to content

Commit

Permalink
Fix: setup wizard won't complete if manual account creation is selected
Browse files Browse the repository at this point in the history
Fix dialog not shown during initial account import
Fix: setting last import date when only accounts are imported (no transactions)

Fixes codinguser#443
Fixes codinguser#428
Fixes codinguser#438
  • Loading branch information
codinguser committed Dec 1, 2015
1 parent 93cc38d commit 8b8f194
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Version 2.0.4 *(2015-12-xx)*
----------------------------
* Fixed: Transaction export time not always working reliably
* Fixed: Renaming account causes transactions to be deleted

* Fixed: Progress dialog not displayed during initial import
* Fixed: Unable to finish first-run wizard if choosing to create accounts manually

Version 2.0.3 *(2015-11-21)*
----------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,17 +636,23 @@ public long getTimestampOfLatestTransaction(AccountType type, String currencyCod

/**
* Returns the most recent `modified_at` timestamp of non-template transactions in the database
* @return Last moodified time in milliseconds or null if no such transactions exist
* @return Last moodified time in milliseconds or current time if there is none in the database
*/
public Timestamp getTimestampOfLastModification(){
Cursor cursor = mDb.query(TransactionEntry.TABLE_NAME,
new String[]{"MAX(" + TransactionEntry.COLUMN_MODIFIED_AT + ")"},
TransactionEntry.COLUMN_TEMPLATE + " = 0", null, null, null, null);
null, null, null, null, null);

Timestamp timestamp = null;
if (cursor.moveToNext()){
if (cursor.moveToFirst()){
String timeString = cursor.getString(0);
timestamp = Timestamp.valueOf(timeString);
if (timeString == null) //in case there were no transactions in the XML file (account structure only)
timestamp = new Timestamp(System.currentTimeMillis());
else {
timestamp = Timestamp.valueOf(timeString);
}
}
cursor.close();
return timestamp;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public static void parse(InputStream gncXmlInputStream) throws ParserConfigurati
xr.parse(new InputSource(bos));
long endTime = System.nanoTime();


Timestamp timeStamp = TransactionsDbAdapter.getInstance().getTimestampOfLastModification();
PreferenceManager.getDefaultSharedPreferences(GnuCashApplication.getAppContext())
.edit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,11 @@ public static void startXmlFileChooser(Activity activity) {
* <p>This method is usually called in response to {@link AccountsActivity#startXmlFileChooser(Activity)}</p>
* @param context Activity context
* @param data Intent data containing the XML uri
* @param onFinishTask Task to be executed when import is complete
*/
public static void importXmlFileFromIntent(Activity context, Intent data) {
public static void importXmlFileFromIntent(Activity context, Intent data, TaskDelegate onFinishTask) {
GncXmlExporter.createBackup();
new ImportAsyncTask(context).execute(data.getData());
new ImportAsyncTask(context, onFinishTask).execute(data.getData());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {

switch (requestCode) {
case AccountsActivity.REQUEST_PICK_ACCOUNTS_FILE:
AccountsActivity.importXmlFileFromIntent(this, data);
AccountsActivity.importXmlFileFromIntent(this, data, null);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case AccountsActivity.REQUEST_PICK_ACCOUNTS_FILE:
if (resultCode == Activity.RESULT_OK && data != null) {
AccountsActivity.importXmlFileFromIntent(this, data);
AccountsActivity.importXmlFileFromIntent(this, data, null);
}
break;
case GeneralPreferenceFragment.PASSCODE_REQUEST_CODE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.gnucash.android.app.GnuCashApplication;
import org.gnucash.android.importer.ImportAsyncTask;
import org.gnucash.android.ui.account.AccountsActivity;
import org.gnucash.android.ui.util.TaskDelegate;

import java.io.FileNotFoundException;
import java.io.InputStream;
Expand Down Expand Up @@ -212,6 +213,8 @@ private void createAccountsAndFinish() {
finish();
} else if (mAccountOptions.equals(getString(R.string.wizard_option_import_my_accounts))){
AccountsActivity.startXmlFileChooser(this);
} else {
finish();
}
}

Expand Down Expand Up @@ -252,9 +255,13 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode){
case AccountsActivity.REQUEST_PICK_ACCOUNTS_FILE:
if (resultCode == Activity.RESULT_OK && data != null) {
AccountsActivity.importXmlFileFromIntent(this, data);
AccountsActivity.importXmlFileFromIntent(this, data, new TaskDelegate() {
@Override
public void onTaskComplete() {
finish();
}
});
}
finish();
break;
}
}
Expand Down

0 comments on commit 8b8f194

Please sign in to comment.