Skip to content

Commit

Permalink
Update version and CHANGELOG for v2.4.1-beta2 release
Browse files Browse the repository at this point in the history
Fix crash during export of transations after upgrade to v2.4.1-beta1
   The commodities table was replaced, however, there are references to
   the commodities in the transactions

Remove GnuCash Android Google+ Community Page link (Google+ is dead)
  • Loading branch information
codinguser committed Nov 21, 2019
1 parent 4fac627 commit a9fcb9f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 21 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Change Log
===============================================================================
Version 2.4.0 *(2018-06-15)*
Version 2.4.1 *(2019-11-30)*
----------------------------
* Fixes #809: Crash when exporting CSV
* Fixes #811: Add button in schedule action disappears after rotation
* Fixes #790: Missing transaction description margin
* Fixes crash if during database upgrade triggered by scheduled action
* Improve performance of CSV export
* Improved: Add book name to accounts listing view
* Improved: Update translations
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ apply plugin: 'io.fabric'
def versionMajor = 2
def versionMinor = 4
def versionPatch = 1
def versionBuild = 1
def versionBuild = 2

static def buildTime() {
def df = new SimpleDateFormat("yyyyMMdd HH:mm 'UTC'")
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/java/org/gnucash/android/db/DatabaseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import android.widget.Toast;

import com.crashlytics.android.Crashlytics;

import org.gnucash.android.app.GnuCashApplication;
import org.gnucash.android.model.Commodity;
import org.xml.sax.SAXException;

Expand Down Expand Up @@ -264,7 +262,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
Log.i(LOG_TAG, "Upgrading database from version "
+ oldVersion + " to " + newVersion);

Toast.makeText(GnuCashApplication.getAppContext(), "Upgrading GnuCash database", Toast.LENGTH_SHORT).show();
//TODO: Find way to show a progress dialog for long running db upgrades
/*
* NOTE: In order to modify the database, create a new static method in the MigrationHelper class
* called upgradeDbToVersion<#>, e.g. int upgradeDbToVersion10(SQLiteDatabase) in order to upgrade to version 10.
Expand Down Expand Up @@ -354,7 +352,7 @@ private void createDatabaseTables(SQLiteDatabase db) {
db.execSQL(createBudgetAmountUidIndex);

try {
MigrationHelper.importCommodities(db);
MigrationHelper.importCommodities(db, true);
} catch (SAXException | ParserConfigurationException | IOException e) {
Log.e(LOG_TAG, "Error loading currencies into the database");
e.printStackTrace();
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/org/gnucash/android/db/MigrationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public void run() {
/**
* Imports commodities into the database from XML resource file
*/
static void importCommodities(SQLiteDatabase db) throws SAXException, ParserConfigurationException, IOException {
static void importCommodities(SQLiteDatabase db, boolean deleteExisting) throws SAXException, ParserConfigurationException, IOException {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
Expand All @@ -246,7 +246,7 @@ static void importCommodities(SQLiteDatabase db) throws SAXException, ParserConf

/** Create handler to handle XML Tags ( extends DefaultHandler ) */

CommoditiesXmlHandler handler = new CommoditiesXmlHandler(db);
CommoditiesXmlHandler handler = new CommoditiesXmlHandler(db, deleteExisting);

xr.setContentHandler(handler);
xr.parse(new InputSource(bos));
Expand Down Expand Up @@ -883,7 +883,7 @@ static int upgradeDbToVersion9(SQLiteDatabase db){
+ "' ON " + CommodityEntry.TABLE_NAME + "(" + CommodityEntry.COLUMN_UID + ")");

try {
importCommodities(db);
importCommodities(db, true);
} catch (SAXException | ParserConfigurationException | IOException e) {
Log.e(LOG_TAG, "Error loading currencies into the database", e);
Crashlytics.logException(e);
Expand Down Expand Up @@ -1633,7 +1633,7 @@ static int upgradeDbToVersion15(SQLiteDatabase db) {
* Upgrades the database to version 16.
* <p>This migration makes the following changes to the database:
* <ul>
* <li>Re-populate the commodities table (see #731)</li>
* <li>Update the commodities table (see #731)</li>
* </ul>
* </p>
* @param db SQLite database to be upgraded
Expand All @@ -1644,7 +1644,7 @@ static int upgradeDbToVersion16(SQLiteDatabase db) {
int dbVersion = 15;

try {
importCommodities(db);
importCommodities(db, false);
dbVersion = 16;
} catch (SAXException | ParserConfigurationException | IOException e) {
Log.e(LOG_TAG, "Error loading currencies into the database", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
*/
package org.gnucash.android.importer;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import org.gnucash.android.app.GnuCashApplication;
import org.gnucash.android.db.DatabaseSchema;
import org.gnucash.android.db.adapter.CommoditiesDbAdapter;
import org.gnucash.android.db.adapter.DatabaseAdapter;
import org.gnucash.android.model.Commodity;
Expand All @@ -44,17 +46,23 @@ public class CommoditiesXmlHandler extends DefaultHandler {
* List of commodities parsed from the XML file.
* They will be all added to db at once at the end of the document
*/
private List<Commodity> mCommodities;
private List<Commodity> mCommodities = new ArrayList<>();

private boolean deleteExisting;

private CommoditiesDbAdapter mCommoditiesDbAdapter;

public CommoditiesXmlHandler(SQLiteDatabase db){
public CommoditiesXmlHandler(SQLiteDatabase db, boolean deleteExisting){
initAdapter(db);
this.deleteExisting = deleteExisting;
}

private void initAdapter(SQLiteDatabase db) {
if (db == null){
mCommoditiesDbAdapter = GnuCashApplication.getCommoditiesDbAdapter();
} else {
mCommoditiesDbAdapter = new CommoditiesDbAdapter(db);
}
mCommodities = new ArrayList<>();
}

@Override
Expand Down Expand Up @@ -82,7 +90,25 @@ public void startElement(String uri, String localName, String qName, Attributes

@Override
public void endDocument() throws SAXException {
mCommoditiesDbAdapter.deleteAllRecords();
mCommoditiesDbAdapter.bulkAddRecords(mCommodities, DatabaseAdapter.UpdateMethod.insert);
if (this.deleteExisting){
mCommoditiesDbAdapter.deleteAllRecords();
mCommoditiesDbAdapter.bulkAddRecords(mCommodities, DatabaseAdapter.UpdateMethod.insert);
} else {
List<String> existingCurrencyCodes = new ArrayList<>();

try(Cursor cursor = mCommoditiesDbAdapter.fetchAllRecords()) {
while (cursor.moveToNext()) {
String code = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseSchema.CommodityEntry.COLUMN_MNEMONIC));
existingCurrencyCodes.add(code);
}
}
for (Commodity commodity : mCommodities) {
if (existingCurrencyCodes.contains(commodity.getCurrencyCode())){
mCommoditiesDbAdapter.addRecord(commodity, DatabaseAdapter.UpdateMethod.update);
} else {
mCommoditiesDbAdapter.addRecord(commodity, DatabaseAdapter.UpdateMethod.insert);
}
}
}
}
}
5 changes: 0 additions & 5 deletions app/src/main/res/xml/fragment_about_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<Preference android:key="@string/key_about_gnucash" android:summary="@string/app_version_name"
android:title="@string/title_about_gnucash"/>
<Preference android:title="@string/title_google_plus_community"
android:summary="@string/summary_google_plus" >
<intent android:action="android.intent.action.VIEW"
android:data="https://plus.google.com/communities/104728406764752407046"/>
</Preference>
<Preference android:title="@string/title_translate_gnucash"
android:summary="@string/summary_translate_gnucash">
<intent android:action="android.intent.action.VIEW"
Expand Down

0 comments on commit a9fcb9f

Please sign in to comment.