Skip to content

Commit 4dc8cf9

Browse files
committed
Fixed: crash when importing mutual funds accounts
Fixed: deleting an account renders sub-accounts inaccessible. Now sub-accounts are made root accounts instead. Fixed: impossible to scroll new accounts screen
1 parent 6a684a5 commit 4dc8cf9

9 files changed

Lines changed: 122 additions & 90 deletions

File tree

app/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<description>Gnucash Android companion application</description>
2323

2424
<parent>
25-
<version>1.2.1</version>
25+
<version>1.2.2-SNAPSHOT</version>
2626
<groupId>org.gnucash.android</groupId>
2727
<artifactId>gnucash-android-parent</artifactId>
2828
</parent>

app/res/layout/fragment_new_account.xml

Lines changed: 84 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -15,85 +15,89 @@
1515
limitations under the License.
1616
-->
1717

18-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
19-
android:layout_width="match_parent"
20-
android:layout_height="match_parent"
21-
android:orientation="vertical" >
22-
23-
<EditText
24-
android:id="@+id/edit_text_account_name"
25-
android:layout_width="match_parent"
26-
android:layout_height="wrap_content"
27-
android:layout_marginTop="10dp"
28-
android:layout_marginLeft="10dp"
29-
android:layout_marginRight="10dp"
30-
android:layout_marginBottom="20dp"
31-
android:ems="15"
32-
android:inputType="textCapWords"
33-
android:minHeight="?android:attr/listPreferredItemHeight"
34-
android:singleLine="true"
35-
android:ellipsize="start"
36-
android:hint="@string/label_account_name"
37-
style="@style/ListItemText">
38-
<requestFocus />
39-
</EditText>
40-
41-
<TextView
42-
android:text="@string/label_account_currency"
43-
android:layout_height="wrap_content"
44-
android:layout_width="wrap_content"
45-
android:layout_marginBottom="-8dip"
46-
android:layout_marginLeft="10dp"
47-
style="@style/TextAppearance.EditTransaction_LabelSmall" />
48-
49-
<Spinner android:id="@+id/input_currency_spinner"
50-
android:layout_width="match_parent"
51-
android:layout_height="wrap_content"
52-
android:layout_marginLeft="10dp"
53-
android:layout_marginRight="10dp"
54-
android:layout_marginBottom="20dp"
55-
style="@style/ListItem" />
18+
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
19+
android:layout_width="match_parent"
20+
android:layout_height="match_parent">
21+
<LinearLayout
22+
android:layout_width="match_parent"
23+
android:layout_height="match_parent"
24+
android:orientation="vertical" >
5625

57-
<TextView
58-
android:text="@string/label_account_type"
59-
android:layout_height="wrap_content"
60-
android:layout_width="wrap_content"
61-
android:layout_marginBottom="-8dip"
62-
android:layout_marginLeft="10dp"
63-
style="@style/TextAppearance.EditTransaction_LabelSmall" />
26+
<EditText
27+
android:id="@+id/edit_text_account_name"
28+
android:layout_width="match_parent"
29+
android:layout_height="wrap_content"
30+
android:layout_marginTop="10dp"
31+
android:layout_marginLeft="10dp"
32+
android:layout_marginRight="10dp"
33+
android:layout_marginBottom="20dp"
34+
android:ems="15"
35+
android:inputType="textCapWords"
36+
android:minHeight="?android:attr/listPreferredItemHeight"
37+
android:singleLine="true"
38+
android:ellipsize="start"
39+
android:hint="@string/label_account_name"
40+
style="@style/ListItemText">
41+
<requestFocus />
42+
</EditText>
6443

65-
<Spinner android:id="@+id/input_account_type_spinner"
66-
android:layout_width="match_parent"
67-
android:layout_height="wrap_content"
68-
android:layout_marginLeft="10dp"
69-
android:layout_marginRight="10dp"
70-
android:layout_marginBottom="20dp"
71-
style="@style/ListItem" />
72-
73-
<TextView android:id="@+id/label_parent_account"
74-
android:text="@string/label_parent_account"
75-
android:layout_height="wrap_content"
76-
android:layout_width="wrap_content"
77-
android:layout_marginLeft="10dp"
78-
android:layout_marginBottom="-8dip"
79-
style="@style/TextAppearance.EditTransaction_LabelSmall" />
80-
81-
<LinearLayout android:id="@+id/layout_parent_account"
82-
android:layout_width="match_parent"
83-
android:layout_height="wrap_content"
84-
style="@style/ListItem"
85-
android:orientation="horizontal" >
86-
87-
<CheckBox android:id="@+id/checkbox"
88-
android:layout_width="wrap_content"
89-
android:layout_height="wrap_content"
90-
android:focusable="false" />
91-
<Spinner
92-
android:id="@+id/input_parent_account"
93-
android:layout_width="match_parent"
94-
android:layout_height="wrap_content"
95-
android:layout_marginLeft="10dp"
96-
android:layout_marginRight="10dp"
97-
android:minHeight="?android:attr/listPreferredItemHeight" />
98-
</LinearLayout>
99-
</LinearLayout>
44+
<TextView
45+
android:text="@string/label_account_currency"
46+
android:layout_height="wrap_content"
47+
android:layout_width="wrap_content"
48+
android:layout_marginBottom="-8dip"
49+
android:layout_marginLeft="10dp"
50+
style="@style/TextAppearance.EditTransaction_LabelSmall" />
51+
52+
<Spinner android:id="@+id/input_currency_spinner"
53+
android:layout_width="match_parent"
54+
android:layout_height="wrap_content"
55+
android:layout_marginLeft="10dp"
56+
android:layout_marginRight="10dp"
57+
android:layout_marginBottom="20dp"
58+
style="@style/ListItem" />
59+
60+
<TextView
61+
android:text="@string/label_account_type"
62+
android:layout_height="wrap_content"
63+
android:layout_width="wrap_content"
64+
android:layout_marginBottom="-8dip"
65+
android:layout_marginLeft="10dp"
66+
style="@style/TextAppearance.EditTransaction_LabelSmall" />
67+
68+
<Spinner android:id="@+id/input_account_type_spinner"
69+
android:layout_width="match_parent"
70+
android:layout_height="wrap_content"
71+
android:layout_marginLeft="10dp"
72+
android:layout_marginRight="10dp"
73+
android:layout_marginBottom="20dp"
74+
style="@style/ListItem" />
75+
76+
<TextView android:id="@+id/label_parent_account"
77+
android:text="@string/label_parent_account"
78+
android:layout_height="wrap_content"
79+
android:layout_width="wrap_content"
80+
android:layout_marginLeft="10dp"
81+
android:layout_marginBottom="-8dip"
82+
style="@style/TextAppearance.EditTransaction_LabelSmall" />
83+
84+
<LinearLayout android:id="@+id/layout_parent_account"
85+
android:layout_width="match_parent"
86+
android:layout_height="wrap_content"
87+
style="@style/ListItem"
88+
android:orientation="horizontal" >
89+
90+
<CheckBox android:id="@+id/checkbox"
91+
android:layout_width="wrap_content"
92+
android:layout_height="wrap_content"
93+
android:focusable="false" />
94+
<Spinner
95+
android:id="@+id/input_parent_account"
96+
android:layout_width="match_parent"
97+
android:layout_height="wrap_content"
98+
android:layout_marginLeft="10dp"
99+
android:layout_marginRight="10dp"
100+
android:minHeight="?android:attr/listPreferredItemHeight" />
101+
</LinearLayout>
102+
</LinearLayout>
103+
</ScrollView>

app/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,6 @@
567567
<item>EQUITY</item>
568568
<item>CURRENCY</item>
569569
<item>STOCK</item>
570-
<item>MUTUAL_FUND</item>
570+
<item>MUTUAL</item>
571571
</string-array>
572572
</resources>

app/src/org/gnucash/android/data/Account.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class Account {
5252
* they are currently not used except for exporting
5353
*/
5454
public enum AccountType {CASH, BANK, CREDIT, ASSET, LIABILITY, INCOME, EXPENSE,
55-
PAYABLE, RECEIVABLE, EQUITY, CURRENCY, STOCK, MUTUAL_FUND, ROOT};
55+
PAYABLE, RECEIVABLE, EQUITY, CURRENCY, STOCK, MUTUAL, ROOT};
5656

5757
/**
5858
* Accounts types which are used by the OFX standard
@@ -340,7 +340,7 @@ public static OfxAccountType convertToOfxAccountType(AccountType accountType){
340340
case ASSET:
341341
return OfxAccountType.SAVINGS;
342342

343-
case MUTUAL_FUND:
343+
case MUTUAL:
344344
case STOCK:
345345
case EQUITY:
346346
case CURRENCY:

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public long addAccount(Account account){
9090
}
9191
return rowId;
9292
}
93-
93+
9494
/**
9595
* Deletes an account with database id <code>rowId</code>
9696
* All the transactions in the account will also be deleted
@@ -112,7 +112,26 @@ public boolean destructiveDeleteAccount(long rowId){
112112
result &= deleteRecord(DatabaseHelper.ACCOUNTS_TABLE_NAME, rowId);
113113
return result;
114114
}
115-
115+
116+
/**
117+
* Reassigns all accounts with parent UID <code>oldParentUID</code> to <code>newParentUID</code>
118+
* @param oldParentUID Old parent account Unique ID
119+
* @param newParentUID Unique ID of new parent account
120+
* @return Number of records which are modified
121+
*/
122+
public int reassignParent(String oldParentUID, String newParentUID){
123+
ContentValues contentValues = new ContentValues();
124+
if (newParentUID == null)
125+
contentValues.putNull(DatabaseHelper.KEY_PARENT_ACCOUNT_UID);
126+
else
127+
contentValues.put(DatabaseHelper.KEY_PARENT_ACCOUNT_UID, newParentUID);
128+
129+
return mDb.update(DatabaseHelper.ACCOUNTS_TABLE_NAME,
130+
contentValues,
131+
DatabaseHelper.KEY_PARENT_ACCOUNT_UID + "= '" + oldParentUID + "' ",
132+
null);
133+
}
134+
116135
/**
117136
* Deletes an account while preserving the linked transactions
118137
* Reassigns all transactions belonging to the account with id <code>rowId</code> to
@@ -329,9 +348,16 @@ public Cursor fetchRecord(long rowId) {
329348
return fetchRecord(DatabaseHelper.ACCOUNTS_TABLE_NAME, rowId);
330349
}
331350

351+
/**
352+
* Deletes an account and its transactions from the database.
353+
* This is equivalent to calling {@link #destructiveDeleteAccount(long)}
354+
* @param rowId ID of record to be deleted
355+
* @return <code>true</code> if successful, <code>false</code> otherwise
356+
*/
332357
@Override
333358
public boolean deleteRecord(long rowId) {
334-
return deleteRecord(DatabaseHelper.ACCOUNTS_TABLE_NAME, rowId);
359+
return destructiveDeleteAccount(rowId);
360+
//return deleteRecord(DatabaseHelper.ACCOUNTS_TABLE_NAME, rowId);
335361
}
336362

337363
/**

app/src/org/gnucash/android/ui/accounts/AccountsListFragment.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,10 @@ public void tryDeleteAccount(long rowId) {
276276
* @param rowId Record ID of the account to be deleted
277277
*/
278278
protected void deleteAccount(long rowId) {
279+
String accountUID = mAccountsDbAdapter.getAccountUID(rowId);
279280
boolean deleted = mAccountsDbAdapter.destructiveDeleteAccount(rowId);
280281
if (deleted) {
282+
mAccountsDbAdapter.reassignParent(accountUID, null);
281283
Toast.makeText(getActivity(), R.string.toast_account_deleted, Toast.LENGTH_SHORT).show();
282284
WidgetConfigurationActivity.updateAllWidgets(getActivity().getApplicationContext());
283285
}

app/src/org/gnucash/android/util/GnucashAccountXmlHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ public static void parse(Context context, InputStream accountsInputStream){
136136
xr.parse(new InputSource(bos));
137137

138138
} catch (Exception e) {
139-
Toast.makeText(context, R.string.toast_error_importing_accounts, Toast.LENGTH_LONG).show();
140139
e.printStackTrace();
140+
Toast.makeText(context, R.string.toast_error_importing_accounts, Toast.LENGTH_LONG).show();
141141
}
142142
}
143143
}

integration-tests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
1818
<modelVersion>4.0.0</modelVersion>
1919
<parent>
20-
<version>1.2.1</version>
20+
<version>1.2.2-SNAPSHOT</version>
2121
<groupId>org.gnucash.android</groupId>
2222
<artifactId>gnucash-android-parent</artifactId>
2323
</parent>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
1919
<modelVersion>4.0.0</modelVersion>
20-
<version>1.2.1</version>
20+
<version>1.2.2-SNAPSHOT</version>
2121
<groupId>org.gnucash.android</groupId>
2222
<artifactId>gnucash-android-parent</artifactId>
2323
<name>GnuCash Android parent</name>

0 commit comments

Comments
 (0)