Skip to content

Commit 6c320cf

Browse files
committed
Merge branch 'hotfix/patches'
2 parents eece627 + e589a26 commit 6c320cf

File tree

49 files changed

+495
-373
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+495
-373
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
Change Log
22
===============================================================================
3+
Version 2.0.4 *(2015-12-02)*
4+
----------------------------
5+
* Fixed: Transaction export time not always working reliably
6+
* Fixed: Renaming account causes transactions to be deleted
7+
* Fixed: Progress dialog not displayed during initial import
8+
* Fixed: Unable to finish first-run wizard if choosing to create accounts manually
9+
* Fixed: Removed inapplicable options in scheduled actions context menu
10+
311
Version 2.0.3 *(2015-11-21)*
412
----------------------------
513
* Fixed: Unable to enter decimal amounts in split editor

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apply plugin: 'io.fabric'
55

66
def versionMajor = 2
77
def versionMinor = 0
8-
def versionPatch = 3
8+
def versionPatch = 4
99
def versionBuild = 0
1010

1111
def buildTime() {

app/src/main/java/org/gnucash/android/db/AccountsDbAdapter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,9 +794,13 @@ private Money computeBalance(String accountUID, long startTimestamp, long endTim
794794
* @param endTimestamp the end timestamp of the time range
795795
* @return Money balance of account list
796796
*/
797-
public Money getAccountsBalance(List<String> accountUIDList, long startTimestamp, long endTimestamp) {
797+
public Money getAccountsBalance(@NonNull List<String> accountUIDList, long startTimestamp, long endTimestamp) {
798798
String currencyCode = GnuCashApplication.getDefaultCurrencyCode();
799799
Money balance = Money.createZeroInstance(currencyCode);
800+
801+
if (accountUIDList.isEmpty())
802+
return balance;
803+
800804
boolean hasDebitNormalBalance = getAccountType(accountUIDList.get(0)).hasDebitNormalBalance();
801805

802806
SplitsDbAdapter splitsDbAdapter = SplitsDbAdapter.getInstance();

app/src/main/java/org/gnucash/android/db/DatabaseAdapter.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ public String getUID(long id){
423423
if (cursor.moveToFirst()) {
424424
uid = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseSchema.CommonColumns.COLUMN_UID));
425425
} else {
426-
throw new IllegalArgumentException("Account record ID " + id + " does not exist in the db");
426+
throw new IllegalArgumentException(mTableName + " Record ID " + id + " does not exist in the db");
427427
}
428428
} finally {
429429
cursor.close();
@@ -620,6 +620,20 @@ public void setTransactionSuccessful() {
620620
mDb.setTransactionSuccessful();
621621
}
622622

623+
/// Foreign key constraits should be enabled in general.
624+
/// But if it affects speed (check constraints takes time)
625+
/// and the constrained can be assured by the program,
626+
/// or if some SQL exec will cause deletion of records
627+
/// (like use replace in accounts update will delete all transactions)
628+
/// that need not be deleted, then it can be disabled temporarily
629+
public void enableForeignKey(boolean enable) {
630+
if (enable){
631+
mDb.execSQL("PRAGMA foreign_keys=ON");
632+
} else {
633+
mDb.execSQL("PRAGMA foreign_keys=OFF");
634+
}
635+
}
636+
623637
/**
624638
* Expose mDb.endTransaction()
625639
*/

app/src/main/java/org/gnucash/android/db/TransactionsDbAdapter.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.gnucash.android.model.Split;
3838
import org.gnucash.android.model.Transaction;
3939

40+
import java.sql.Timestamp;
4041
import java.util.ArrayList;
4142
import java.util.List;
4243

@@ -633,6 +634,26 @@ public long getTimestampOfLatestTransaction(AccountType type, String currencyCod
633634
return getTimestamp("MAX", type, currencyCode);
634635
}
635636

637+
/**
638+
* Returns the most recent `modified_at` timestamp of non-template transactions in the database
639+
* @return Last moodified time in milliseconds or current time if there is none in the database
640+
*/
641+
public Timestamp getTimestampOfLastModification(){
642+
Cursor cursor = mDb.query(TransactionEntry.TABLE_NAME,
643+
new String[]{"MAX(" + TransactionEntry.COLUMN_MODIFIED_AT + ")"},
644+
null, null, null, null, null);
645+
646+
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
647+
if (cursor.moveToFirst()){
648+
String timeString = cursor.getString(0);
649+
if (timeString != null){ //in case there were no transactions in the XML file (account structure only)
650+
timestamp = Timestamp.valueOf(timeString);
651+
}
652+
}
653+
cursor.close();
654+
return timestamp;
655+
}
656+
636657
/**
637658
* Returns the earliest or latest timestamp of transactions for a specific account type and currency
638659
* @param mod Mode (either MAX or MIN)

app/src/main/java/org/gnucash/android/export/Exporter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ public String getExportMimeType(){
201201
public static class ExporterException extends RuntimeException{
202202

203203
public ExporterException(ExportParams params){
204-
super("Failed to generate " + params.getExportFormat().toString());
204+
super("Failed to generate export with parameters: " + params.toString());
205205
}
206206

207207
public ExporterException(@NonNull ExportParams params, @NonNull String msg) {
208-
super("Failed to generate " + params.getExportFormat().toString() + "-" + msg);
208+
super("Failed to generate export with parameters: " + params.toString() + " - " + msg);
209209
}
210210

211211
public ExporterException(ExportParams params, Throwable throwable){

app/src/main/java/org/gnucash/android/importer/GncXmlImporter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.util.Log;
2222

2323
import org.gnucash.android.app.GnuCashApplication;
24+
import org.gnucash.android.db.TransactionsDbAdapter;
2425
import org.gnucash.android.export.Exporter;
2526
import org.xml.sax.InputSource;
2627
import org.xml.sax.SAXException;
@@ -93,8 +94,11 @@ public static void parse(InputStream gncXmlInputStream) throws ParserConfigurati
9394
xr.parse(new InputSource(bos));
9495
long endTime = System.nanoTime();
9596

96-
String timeStamp = new Timestamp(System.currentTimeMillis()).toString();
97-
PreferenceManager.getDefaultSharedPreferences(GnuCashApplication.getAppContext()).edit().putString(Exporter.PREF_LAST_EXPORT_TIME, timeStamp).apply();
97+
Timestamp timeStamp = TransactionsDbAdapter.getInstance().getTimestampOfLastModification();
98+
PreferenceManager.getDefaultSharedPreferences(GnuCashApplication.getAppContext())
99+
.edit()
100+
.putString(Exporter.PREF_LAST_EXPORT_TIME, timeStamp.toString())
101+
.apply();
98102

99103
Log.d(GncXmlImporter.class.getSimpleName(), String.format("%d ns spent on importing the file", endTime-startTime));
100104
}

app/src/main/java/org/gnucash/android/ui/account/AccountFormFragment.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,9 @@ private void saveAccount() {
846846
if (mAccountsDbAdapter == null)
847847
mAccountsDbAdapter = AccountsDbAdapter.getInstance();
848848
// bulk update, will not update transactions
849+
mAccountsDbAdapter.enableForeignKey(false);
849850
mAccountsDbAdapter.bulkAddRecords(accountsToUpdate);
851+
mAccountsDbAdapter.enableForeignKey(true);
850852

851853
finishFragment();
852854
}

app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,10 +525,11 @@ public static void startXmlFileChooser(Activity activity) {
525525
* <p>This method is usually called in response to {@link AccountsActivity#startXmlFileChooser(Activity)}</p>
526526
* @param context Activity context
527527
* @param data Intent data containing the XML uri
528+
* @param onFinishTask Task to be executed when import is complete
528529
*/
529-
public static void importXmlFileFromIntent(Activity context, Intent data) {
530+
public static void importXmlFileFromIntent(Activity context, Intent data, TaskDelegate onFinishTask) {
530531
GncXmlExporter.createBackup();
531-
new ImportAsyncTask(context).execute(data.getData());
532+
new ImportAsyncTask(context, onFinishTask).execute(data.getData());
532533
}
533534

534535
/**

app/src/main/java/org/gnucash/android/ui/common/BaseDrawerActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
193193

194194
switch (requestCode) {
195195
case AccountsActivity.REQUEST_PICK_ACCOUNTS_FILE:
196-
AccountsActivity.importXmlFileFromIntent(this, data);
196+
AccountsActivity.importXmlFileFromIntent(this, data, null);
197197
break;
198198
}
199199
}

0 commit comments

Comments
 (0)