Skip to content

Commit

Permalink
Fixed: Invalid QIF generated
Browse files Browse the repository at this point in the history
Fixed: no multicurrency QIF generated

Added Crashlytics logging statements
Fixed: crash when refreshing account transactions
Updated version numbers for beta3 release
  • Loading branch information
codinguser committed May 7, 2015
1 parent a59632e commit 866c94f
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 63 deletions.
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: 'crashlytics'
def versionMajor = 1
def versionMinor = 6
def versionPatch = 0
def versionBuild = 2
def versionBuild = 3

def buildTime() {
def df = new SimpleDateFormat("yyyyMMdd_HHmm'UTC'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public void onCreate(){
try {
mDb = mDbHelper.getWritableDatabase();
} catch (SQLException e) {
Crashlytics.logException(e);
Log.e(getClass().getName(), "Error getting database: " + e.getMessage());
mDb = mDbHelper.getReadableDatabase();
}
Expand Down Expand Up @@ -165,6 +166,7 @@ public static String getDefaultCurrency(){
try { //there are some strange locales out there
currencyCode = Currency.getInstance(locale).getCurrencyCode();
} catch (Throwable e) {
Crashlytics.logException(e);
Log.e(context.getString(R.string.app_name), "" + e.getMessage());
} finally {
currencyCode = prefs.getString(context.getString(R.string.key_default_currency), currencyCode);
Expand Down
31 changes: 0 additions & 31 deletions app/src/main/java/org/gnucash/android/db/AccountsDbAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -866,37 +866,6 @@ public List<String> getDescendantAccountUIDs(String accountUID, String where, St
return accountsList;
}

/**
* Returns a list of IDs for the sub-accounts for account <code>accountId</code>
* @param accountId Account ID whose sub-accounts are to be retrieved
* @return List of IDs for the sub-accounts for account <code>accountId</code>
*/
public List<Long> getSubAccountIds(long accountId){
List<Long> subAccounts = new ArrayList<Long>();
String accountUID;
try {
accountUID = getUID(accountId);
} catch (IllegalArgumentException e) {
return subAccounts;
}

Cursor cursor = mDb.query(AccountEntry.TABLE_NAME,
new String[]{AccountEntry._ID},
AccountEntry.COLUMN_PARENT_ACCOUNT_UID + " = ?",
new String[]{accountUID},
null, null, null);

try {
while (cursor.moveToNext()) {
subAccounts.add(cursor.getLong(cursor.getColumnIndexOrThrow(AccountEntry._ID)));
}
} finally {
cursor.close();
}

return subAccounts;
}

/**
* Returns a cursor to the dataset containing sub-accounts of the account with record ID <code>accoundId</code>
* @param accountUID GUID of the parent account
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ public int deleteAllRecords(){
* Returns the string unique ID (GUID) of a record in the database
* @param uid GUID of the record
* @return Long record ID
* @throws IllegalArgumentException if the GUID does not exist in the database
*/
public long getID(@NonNull String uid){
Cursor cursor = mDb.query(mTableName,
Expand Down
86 changes: 57 additions & 29 deletions app/src/main/java/org/gnucash/android/export/ExportAsyncTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,37 +252,40 @@ public void onResult(DriveApi.DriveContentsResult result) {
return;
}
final DriveContents driveContents = result.getDriveContents();
// write content to DriveContents
OutputStream outputStream = driveContents.getOutputStream();
File exportedFile = new File(mExportParams.getTargetFilepath());

try {
FileInputStream fileInputStream = new FileInputStream(exportedFile);
byte[] buffer = new byte[1024];
int count = 0;

while ((count = fileInputStream.read(buffer)) >= 0) {
outputStream.write(buffer, 0, count);
// write content to DriveContents
OutputStream outputStream = driveContents.getOutputStream();
List<String> exportedFilePaths = getExportedFiles();
for (String exportedFilePath : exportedFilePaths) {
File exportedFile = new File(exportedFilePath);
FileInputStream fileInputStream = new FileInputStream(exportedFile);
byte[] buffer = new byte[1024];
int count = 0;

while ((count = fileInputStream.read(buffer)) >= 0) {
outputStream.write(buffer, 0, count);
}
fileInputStream.close();
outputStream.flush();
exportedFile.delete();

MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle(exportedFile.getName())
.setMimeType(getExportMimeType())
.build();

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
String folderId = sharedPreferences.getString(mContext.getString(R.string.key_google_drive_app_folder_id), "");
DriveFolder folder = Drive.DriveApi.getFolder(googleApiClient, DriveId.decodeFromString(folderId));
// create a file on root folder
folder.createFile(googleApiClient, changeSet, driveContents)
.setResultCallback(fileCallback);
}
fileInputStream.close();
outputStream.flush();
exportedFile.delete();

} catch (IOException e) {
Crashlytics.logException(e);
Log.e(TAG, e.getMessage());
}

MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle(exportedFile.getName())
.setMimeType(getExportMimeType())
.build();

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
String folderId = sharedPreferences.getString(mContext.getString(R.string.key_google_drive_app_folder_id), "");
DriveFolder folder = Drive.DriveApi.getFolder(googleApiClient, DriveId.decodeFromString(folderId));
// create a file on root folder
folder.createFile(googleApiClient, changeSet, driveContents)
.setResultCallback(fileCallback);
}
});
}
Expand Down Expand Up @@ -311,10 +314,13 @@ private void copyExportToDropbox() {
DbxFile dbExportFile = null;
try {
DbxFileSystem dbxFileSystem = DbxFileSystem.forAccount(mDbxAcctMgr.getLinkedAccount());
File exportedFile = new File(mExportParams.getTargetFilepath());
dbExportFile = dbxFileSystem.create(new DbxPath(exportedFile.getName()));
dbExportFile.writeFromExistingFile(exportedFile, false);
exportedFile.delete();
List<String> exportedFilePaths = getExportedFiles();
for (String exportedFilePath : exportedFilePaths) {
File exportedFile = new File(exportedFilePath);
dbExportFile = dbxFileSystem.create(new DbxPath(exportedFile.getName()));
dbExportFile.writeFromExistingFile(exportedFile, false);
exportedFile.delete();
}
} catch (DbxException.Unauthorized unauthorized) {
Crashlytics.logException(unauthorized);
Log.e(TAG, unauthorized.getMessage());
Expand All @@ -329,6 +335,28 @@ private void copyExportToDropbox() {
}
}

/**
* Returns the list of files generated by one export session.
* <p>Typically it is one file. But QIF export generate multiple files per currency.</p>
* @return List of paths to exported files
* @throws IOException if the exported files could not be created
*/
private List<String> getExportedFiles() throws IOException {
List<String> exportedFilePaths;
if (mExportParams.getExportFormat() == ExportFormat.QIF) {
String path = mExportParams.getTargetFilepath();
exportedFilePaths = splitQIF(new File(path), new File(path));
} else {
exportedFilePaths = new ArrayList<>();
exportedFilePaths.add(mExportParams.getTargetFilepath());
}
return exportedFilePaths;
}

/**
* Copies the exported file from the internal storage where it is generated to external storage
* which is accessible to the user
*/
private void copyExportToSDCard() {
Log.i(TAG, "Moving exported file to external storage");
File src = new File(mExportParams.getTargetFilepath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,8 @@ public void importAccounts() {
try {
startActivityForResult(chooser, AccountsActivity.REQUEST_PICK_ACCOUNTS_FILE);
} catch (ActivityNotFoundException ex){
Crashlytics.log("No file manager for selecting files available");
Crashlytics.logException(ex);
Toast.makeText(this, R.string.toast_install_file_manager, Toast.LENGTH_LONG).show();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public class TransactionsActivity extends PassLockActivity implements

private ViewPager mPager;

private SparseArray<Refreshable> mFragmentPageReferenceMap = new SparseArray<Refreshable>();
private SparseArray<Refreshable> mFragmentPageReferenceMap = new SparseArray<>();

private OnNavigationListener mTransactionListNavigationListener = new OnNavigationListener() {

Expand Down Expand Up @@ -329,7 +329,13 @@ protected void onResume() {
private void setTitleIndicatorColor() {
//Basically, if we are in a top level account, use the default title color.
//but propagate a parent account's title color to children who don't have own color
String colorCode = mAccountsDbAdapter.getAccountColorCode(mAccountsDbAdapter.getID(mAccountUID));
long accountId = -1;
try {
accountId = mAccountsDbAdapter.getID(mAccountUID);
} catch (IllegalArgumentException e){
Log.e(TAG, e.getMessage());
}
String colorCode = mAccountsDbAdapter.getAccountColorCode(accountId);
int iColor = -1;
if (colorCode != null){
iColor = Color.parseColor(colorCode);
Expand Down

0 comments on commit 866c94f

Please sign in to comment.