Skip to content

Commit d5b8735

Browse files
committed
Merge branch 'hotfix/patches'
2 parents 07dc956 + 4e95e9e commit d5b8735

File tree

19 files changed

+385
-296
lines changed

19 files changed

+385
-296
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
Change Log
22
===============================================================================
3+
Version 2.1.6 *(2017-04-15)*
4+
----------------------------
5+
* Fixed #664: Rotating device in transaction view causes crash
6+
* Improved #670: Migrate backup/export files to new location (which does not require permisions from KitKat)
7+
* Improved #669: Update translations
8+
39
Version 2.1.5 *(2017-04-04)*
410
----------------------------
511
* Fixed: Widget button for placeholder accounts tries to create transactions

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ apply plugin: 'android-apt'
66

77
def versionMajor = 2
88
def versionMinor = 1
9-
def versionPatch = 5
10-
def versionBuild = 4
9+
def versionPatch = 6
10+
def versionBuild = 0
1111

1212
def buildTime() {
1313
def df = new SimpleDateFormat("yyyyMMdd HH:mm 'UTC'")

app/src/main/java/org/gnucash/android/app/GnuCashApplication.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.gnucash.android.R;
4242
import org.gnucash.android.db.BookDbHelper;
4343
import org.gnucash.android.db.DatabaseHelper;
44+
import org.gnucash.android.db.MigrationHelper;
4445
import org.gnucash.android.db.adapter.AccountsDbAdapter;
4546
import org.gnucash.android.db.adapter.BooksDbAdapter;
4647
import org.gnucash.android.db.adapter.BudgetAmountsDbAdapter;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@ private void insertBook(SQLiteDatabase db, Book book) {
159159
private void migrateBackupFiles(String activeBookUID){
160160

161161
Log.d(LOG_TAG, "Moving export and backup files to book-specific folders");
162-
File newBasePath = new File(Exporter.BASE_FOLDER_PATH + "/" + activeBookUID);
162+
File newBasePath = new File(Exporter.LEGACY_BASE_FOLDER_PATH + "/" + activeBookUID);
163163
newBasePath.mkdirs();
164164

165-
File src = new File(Exporter.BASE_FOLDER_PATH + "/backups/");
166-
File dst = new File(Exporter.BASE_FOLDER_PATH + "/" + activeBookUID + "/backups/");
165+
File src = new File(Exporter.LEGACY_BASE_FOLDER_PATH + "/backups/");
166+
File dst = new File(Exporter.LEGACY_BASE_FOLDER_PATH + "/" + activeBookUID + "/backups/");
167167
new Thread(new RecursiveMoveFiles(src, dst)).start();
168168

169-
src = new File(Exporter.BASE_FOLDER_PATH + "/exports/");
170-
dst = new File(Exporter.BASE_FOLDER_PATH + "/" + activeBookUID + "/exports/");
169+
src = new File(Exporter.LEGACY_BASE_FOLDER_PATH + "/exports/");
170+
dst = new File(Exporter.LEGACY_BASE_FOLDER_PATH + "/" + activeBookUID + "/exports/");
171171
new Thread(new RecursiveMoveFiles(src, dst)).start();
172172

173173
File nameFile = new File(newBasePath, "Book 1");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class DatabaseSchema {
3939
* Version number of database containing accounts and transactions info.
4040
* With any change to the database schema, this number must increase
4141
*/
42-
public static final int DATABASE_VERSION = 13;
42+
public static final int DATABASE_VERSION = 14;
4343

4444
/**
4545
* Name of the database

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

Lines changed: 84 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import java.io.File;
5757
import java.io.FileInputStream;
5858
import java.io.FileOutputStream;
59+
import java.io.FileWriter;
5960
import java.io.IOException;
6061
import java.io.InputStream;
6162
import java.math.BigDecimal;
@@ -64,6 +65,7 @@
6465
import java.util.ArrayList;
6566
import java.util.HashMap;
6667
import java.util.List;
68+
import java.util.Locale;
6769
import java.util.Map;
6870
import java.util.TimeZone;
6971

@@ -167,12 +169,17 @@ private static String getGnuCashRootAccountUID(SQLiteDatabase db){
167169
* @throws IOException if an error occurred during the file copy
168170
*/
169171
static void moveFile(File src, File dst) throws IOException {
172+
Log.d(LOG_TAG, String.format(Locale.US, "Moving %s from %s to %s",
173+
src.getName(), src.getParent(), dst.getParent()));
170174
FileChannel inChannel = new FileInputStream(src).getChannel();
171175
FileChannel outChannel = new FileOutputStream(dst).getChannel();
172176
try {
173177
long bytesCopied = inChannel.transferTo(0, inChannel.size(), outChannel);
174-
if(bytesCopied >= src.length())
175-
src.delete();
178+
if(bytesCopied >= src.length()) {
179+
boolean result = src.delete();
180+
String msg = result ? "Deleted src file: " : "Could not delete src: ";
181+
Log.d(LOG_TAG, msg + src.getPath());
182+
}
176183
} finally {
177184
if (inChannel != null)
178185
inChannel.close();
@@ -194,7 +201,7 @@ public void run() {
194201
for (File src : oldExportFolder.listFiles()) {
195202
if (src.isDirectory())
196203
continue;
197-
File dst = new File(Exporter.BASE_FOLDER_PATH + "/exports/" + src.getName());
204+
File dst = new File(Exporter.LEGACY_BASE_FOLDER_PATH + "/exports/" + src.getName());
198205
try {
199206
MigrationHelper.moveFile(src, dst);
200207
} catch (IOException e) {
@@ -210,7 +217,7 @@ public void run() {
210217
File oldBackupFolder = new File(oldExportFolder, "backup");
211218
if (oldBackupFolder.exists()){
212219
for (File src : new File(oldExportFolder, "backup").listFiles()) {
213-
File dst = new File(Exporter.BASE_FOLDER_PATH + "/backups/" + src.getName());
220+
File dst = new File(Exporter.LEGACY_BASE_FOLDER_PATH + "/backups/" + src.getName());
214221
try {
215222
MigrationHelper.moveFile(src, dst);
216223
} catch (IOException e) {
@@ -490,8 +497,8 @@ static int upgradeDbToVersion7(SQLiteDatabase db) {
490497
static int upgradeDbToVersion8(SQLiteDatabase db) {
491498
Log.i(DatabaseHelper.LOG_TAG, "Upgrading database to version 8");
492499
int oldVersion = 7;
493-
new File(Exporter.BASE_FOLDER_PATH + "/backups/").mkdirs();
494-
new File(Exporter.BASE_FOLDER_PATH + "/exports/").mkdirs();
500+
new File(Exporter.LEGACY_BASE_FOLDER_PATH + "/backups/").mkdirs();
501+
new File(Exporter.LEGACY_BASE_FOLDER_PATH + "/exports/").mkdirs();
495502
//start moving the files in background thread before we do the database stuff
496503
new Thread(moveExportedFilesToNewDefaultLocation).start();
497504

@@ -1474,4 +1481,75 @@ static int upgradeDbToVersion13(SQLiteDatabase db){
14741481

14751482
return oldVersion;
14761483
}
1484+
1485+
/**
1486+
* Move files from {@code srcDir} to {@code dstDir}
1487+
* Subdirectories will be created in the target as necessary
1488+
* @param srcDir Source directory which should already exist
1489+
* @param dstDir Destination directory which should already exist
1490+
* @see #moveFile(File, File)
1491+
*/
1492+
private static void moveDirectory(File srcDir, File dstDir){
1493+
if (!srcDir.exists() || !srcDir.isDirectory() || !dstDir.isDirectory() || !dstDir.exists()){
1494+
throw new IllegalArgumentException("Source is not a directory, use MigrationHelper.moveFile(...)");
1495+
}
1496+
1497+
for (File src : srcDir.listFiles()){
1498+
if (src.isDirectory()){
1499+
File dst = new File(dstDir, src.getName());
1500+
dst.mkdir();
1501+
moveDirectory(src, dst);
1502+
if (!src.delete())
1503+
Log.i(LOG_TAG, "Failed to delete directory: " + src.getPath());
1504+
continue;
1505+
}
1506+
1507+
try {
1508+
File dst = new File(dstDir, src.getName());
1509+
MigrationHelper.moveFile(src, dst);
1510+
} catch (IOException e) {
1511+
Log.e(LOG_TAG, "Error moving file " + src.getPath());
1512+
Crashlytics.logException(e);
1513+
}
1514+
}
1515+
}
1516+
1517+
/**
1518+
* Upgrade the database to version 14
1519+
* <p>
1520+
* This migration actually does not change anything in the database
1521+
* It moves the backup files to a new backup location which does not require SD CARD write permission
1522+
* </p>
1523+
* @param db SQLite database to be upgraded
1524+
* @return
1525+
*/
1526+
public static int upgradeDbToVersion14(SQLiteDatabase db){
1527+
Log.i(DatabaseHelper.LOG_TAG, "Upgrading database to version 14");
1528+
int oldDbVersion = 13;
1529+
File backupFolder = new File(Exporter.BASE_FOLDER_PATH);
1530+
backupFolder.mkdir();
1531+
1532+
new Thread(new Runnable() {
1533+
@Override
1534+
public void run() {
1535+
File srcDir = new File(Exporter.LEGACY_BASE_FOLDER_PATH);
1536+
File dstDir = new File(Exporter.BASE_FOLDER_PATH);
1537+
moveDirectory(srcDir, dstDir);
1538+
File readmeFile = new File(Exporter.LEGACY_BASE_FOLDER_PATH, "README.txt");
1539+
FileWriter writer = null;
1540+
try {
1541+
writer = new FileWriter(readmeFile);
1542+
writer.write("Backup files have been moved to " + dstDir.getPath() +
1543+
"\nYou can now delete this folder");
1544+
writer.flush();
1545+
} catch (IOException e) {
1546+
e.printStackTrace();
1547+
Log.e(LOG_TAG, "Error creating README file");
1548+
}
1549+
1550+
}
1551+
}).start();
1552+
1553+
return 14;
1554+
}
14771555
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,15 @@ public abstract class Exporter {
6161

6262
/**
6363
* Application folder on external storage
64+
* @deprecated Use {@link #BASE_FOLDER_PATH} instead
6465
*/
65-
public static final String BASE_FOLDER_PATH = Environment.getExternalStorageDirectory() + "/" + BuildConfig.APPLICATION_ID;
66+
@Deprecated
67+
public static final String LEGACY_BASE_FOLDER_PATH = Environment.getExternalStorageDirectory() + "/" + BuildConfig.APPLICATION_ID;
68+
69+
/**
70+
* Application folder on external storage
71+
*/
72+
public static final String BASE_FOLDER_PATH = GnuCashApplication.getAppContext().getExternalFilesDir(null).getAbsolutePath();
6673

6774
/**
6875
* Export options

app/src/main/java/org/gnucash/android/ui/transaction/TransactionsActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
143143
mTabLayout.addTab(mTabLayout.newTab().setText(R.string.section_header_transactions));
144144
}
145145
}
146-
// Hide the favorite icon of the selected account to avoid clutter
147-
((TextView) view).setCompoundDrawablesWithIntrinsicBounds(0,0,0,0);
146+
if (view != null) {
147+
// Hide the favorite icon of the selected account to avoid clutter
148+
((TextView) view).setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
149+
}
148150
//refresh any fragments in the tab with the new account UID
149151
refresh();
150152
}

0 commit comments

Comments
 (0)