Skip to content

Commit

Permalink
Fixed: crash when importing mutual funds accounts
Browse files Browse the repository at this point in the history
Fixed: deleting an account renders sub-accounts inaccessible.
Now sub-accounts are made root accounts instead.
Fixed: impossible to scroll new accounts screen
  • Loading branch information
codinguser committed Jun 23, 2013
1 parent 6a684a5 commit 4dc8cf9
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 90 deletions.
2 changes: 1 addition & 1 deletion app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<description>Gnucash Android companion application</description>

<parent>
<version>1.2.1</version>
<version>1.2.2-SNAPSHOT</version>
<groupId>org.gnucash.android</groupId>
<artifactId>gnucash-android-parent</artifactId>
</parent>
Expand Down
164 changes: 84 additions & 80 deletions app/res/layout/fragment_new_account.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,85 +15,89 @@
limitations under the License.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<EditText
android:id="@+id/edit_text_account_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="20dp"
android:ems="15"
android:inputType="textCapWords"
android:minHeight="?android:attr/listPreferredItemHeight"
android:singleLine="true"
android:ellipsize="start"
android:hint="@string/label_account_name"
style="@style/ListItemText">
<requestFocus />
</EditText>

<TextView
android:text="@string/label_account_currency"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginBottom="-8dip"
android:layout_marginLeft="10dp"
style="@style/TextAppearance.EditTransaction_LabelSmall" />

<Spinner android:id="@+id/input_currency_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="20dp"
style="@style/ListItem" />
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
android:text="@string/label_account_type"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginBottom="-8dip"
android:layout_marginLeft="10dp"
style="@style/TextAppearance.EditTransaction_LabelSmall" />
<EditText
android:id="@+id/edit_text_account_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="20dp"
android:ems="15"
android:inputType="textCapWords"
android:minHeight="?android:attr/listPreferredItemHeight"
android:singleLine="true"
android:ellipsize="start"
android:hint="@string/label_account_name"
style="@style/ListItemText">
<requestFocus />
</EditText>

<Spinner android:id="@+id/input_account_type_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="20dp"
style="@style/ListItem" />

<TextView android:id="@+id/label_parent_account"
android:text="@string/label_parent_account"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginBottom="-8dip"
style="@style/TextAppearance.EditTransaction_LabelSmall" />

<LinearLayout android:id="@+id/layout_parent_account"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/ListItem"
android:orientation="horizontal" >

<CheckBox android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false" />
<Spinner
android:id="@+id/input_parent_account"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:minHeight="?android:attr/listPreferredItemHeight" />
</LinearLayout>
</LinearLayout>
<TextView
android:text="@string/label_account_currency"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginBottom="-8dip"
android:layout_marginLeft="10dp"
style="@style/TextAppearance.EditTransaction_LabelSmall" />

<Spinner android:id="@+id/input_currency_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="20dp"
style="@style/ListItem" />

<TextView
android:text="@string/label_account_type"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginBottom="-8dip"
android:layout_marginLeft="10dp"
style="@style/TextAppearance.EditTransaction_LabelSmall" />

<Spinner android:id="@+id/input_account_type_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="20dp"
style="@style/ListItem" />

<TextView android:id="@+id/label_parent_account"
android:text="@string/label_parent_account"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginBottom="-8dip"
style="@style/TextAppearance.EditTransaction_LabelSmall" />

<LinearLayout android:id="@+id/layout_parent_account"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/ListItem"
android:orientation="horizontal" >

<CheckBox android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false" />
<Spinner
android:id="@+id/input_parent_account"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:minHeight="?android:attr/listPreferredItemHeight" />
</LinearLayout>
</LinearLayout>
</ScrollView>
2 changes: 1 addition & 1 deletion app/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,6 @@
<item>EQUITY</item>
<item>CURRENCY</item>
<item>STOCK</item>
<item>MUTUAL_FUND</item>
<item>MUTUAL</item>
</string-array>
</resources>
4 changes: 2 additions & 2 deletions app/src/org/gnucash/android/data/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class Account {
* they are currently not used except for exporting
*/
public enum AccountType {CASH, BANK, CREDIT, ASSET, LIABILITY, INCOME, EXPENSE,
PAYABLE, RECEIVABLE, EQUITY, CURRENCY, STOCK, MUTUAL_FUND, ROOT};
PAYABLE, RECEIVABLE, EQUITY, CURRENCY, STOCK, MUTUAL, ROOT};

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

case MUTUAL_FUND:
case MUTUAL:
case STOCK:
case EQUITY:
case CURRENCY:
Expand Down
32 changes: 29 additions & 3 deletions app/src/org/gnucash/android/db/AccountsDbAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public long addAccount(Account account){
}
return rowId;
}

/**
* Deletes an account with database id <code>rowId</code>
* All the transactions in the account will also be deleted
Expand All @@ -112,7 +112,26 @@ public boolean destructiveDeleteAccount(long rowId){
result &= deleteRecord(DatabaseHelper.ACCOUNTS_TABLE_NAME, rowId);
return result;
}


/**
* Reassigns all accounts with parent UID <code>oldParentUID</code> to <code>newParentUID</code>
* @param oldParentUID Old parent account Unique ID
* @param newParentUID Unique ID of new parent account
* @return Number of records which are modified
*/
public int reassignParent(String oldParentUID, String newParentUID){
ContentValues contentValues = new ContentValues();
if (newParentUID == null)
contentValues.putNull(DatabaseHelper.KEY_PARENT_ACCOUNT_UID);
else
contentValues.put(DatabaseHelper.KEY_PARENT_ACCOUNT_UID, newParentUID);

return mDb.update(DatabaseHelper.ACCOUNTS_TABLE_NAME,
contentValues,
DatabaseHelper.KEY_PARENT_ACCOUNT_UID + "= '" + oldParentUID + "' ",
null);
}

/**
* Deletes an account while preserving the linked transactions
* Reassigns all transactions belonging to the account with id <code>rowId</code> to
Expand Down Expand Up @@ -329,9 +348,16 @@ public Cursor fetchRecord(long rowId) {
return fetchRecord(DatabaseHelper.ACCOUNTS_TABLE_NAME, rowId);
}

/**
* Deletes an account and its transactions from the database.
* This is equivalent to calling {@link #destructiveDeleteAccount(long)}
* @param rowId ID of record to be deleted
* @return <code>true</code> if successful, <code>false</code> otherwise
*/
@Override
public boolean deleteRecord(long rowId) {
return deleteRecord(DatabaseHelper.ACCOUNTS_TABLE_NAME, rowId);
return destructiveDeleteAccount(rowId);
//return deleteRecord(DatabaseHelper.ACCOUNTS_TABLE_NAME, rowId);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,10 @@ public void tryDeleteAccount(long rowId) {
* @param rowId Record ID of the account to be deleted
*/
protected void deleteAccount(long rowId) {
String accountUID = mAccountsDbAdapter.getAccountUID(rowId);
boolean deleted = mAccountsDbAdapter.destructiveDeleteAccount(rowId);
if (deleted) {
mAccountsDbAdapter.reassignParent(accountUID, null);
Toast.makeText(getActivity(), R.string.toast_account_deleted, Toast.LENGTH_SHORT).show();
WidgetConfigurationActivity.updateAllWidgets(getActivity().getApplicationContext());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ public static void parse(Context context, InputStream accountsInputStream){
xr.parse(new InputSource(bos));

} catch (Exception e) {
Toast.makeText(context, R.string.toast_error_importing_accounts, Toast.LENGTH_LONG).show();
e.printStackTrace();
Toast.makeText(context, R.string.toast_error_importing_accounts, Toast.LENGTH_LONG).show();
}
}
}
2 changes: 1 addition & 1 deletion integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<version>1.2.1</version>
<version>1.2.2-SNAPSHOT</version>
<groupId>org.gnucash.android</groupId>
<artifactId>gnucash-android-parent</artifactId>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<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">
<modelVersion>4.0.0</modelVersion>
<version>1.2.1</version>
<version>1.2.2-SNAPSHOT</version>
<groupId>org.gnucash.android</groupId>
<artifactId>gnucash-android-parent</artifactId>
<name>GnuCash Android parent</name>
Expand Down

0 comments on commit 4dc8cf9

Please sign in to comment.