Skip to content

Commit

Permalink
Fixed: crash when creating a sub-account and changing the type to ano…
Browse files Browse the repository at this point in the history
…ther different from the parent

Also added test case

Fixed: crash when dismissing error dialog after export
Fixed: crash when resuming app with passcode set and app killed
  • Loading branch information
codinguser committed Jul 8, 2015
1 parent b1b5d57 commit baa094c
Show file tree
Hide file tree
Showing 24 changed files with 76 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.gnucash.android.db.SplitsDbAdapter;
import org.gnucash.android.db.TransactionsDbAdapter;
import org.gnucash.android.model.Account;
import org.gnucash.android.model.AccountType;
import org.gnucash.android.model.Money;
import org.gnucash.android.receivers.AccountCreator;
import org.gnucash.android.ui.account.AccountsActivity;
Expand All @@ -47,19 +48,24 @@
import java.util.Currency;
import java.util.List;

import static android.support.test.espresso.Espresso.onData;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.clearText;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.longClick;
import static android.support.test.espresso.action.ViewActions.scrollTo;
import static android.support.test.espresso.action.ViewActions.swipeRight;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isChecked;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.isNotChecked;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

@RunWith(AndroidJUnit4.class)
Expand Down Expand Up @@ -213,6 +219,31 @@ public void testChangeParentAccount() {
assertThat(DUMMY_ACCOUNT_UID).isEqualTo(parentUID);
}

/**
* When creating a sub-account (starting from within another account), if we change the account
* type to another type with no accounts of that type, then the parent account list should be hidden.
* The account which is then created is not a sub-account, but rather a top-level account
*/
@Test
public void shouldHideParentAccountViewWhenNoParentsExist(){
onView(withText(DUMMY_ACCOUNT_NAME)).perform(click());
onView(withId(R.id.fragment_transaction_list)).perform(swipeRight());
onView(withText(R.string.label_create_account)).check(matches(isDisplayed())).perform(click());
sleep(1000);
onView(withId(R.id.checkbox_parent_account)).check(matches(allOf(isChecked())));
onView(withId(R.id.input_account_name)).perform(typeText("Trading account"));
onView(withId(R.id.input_account_type_spinner)).perform(click());
onData(allOf(is(instanceOf(String.class)), is(AccountType.TRADING.name()))).perform(click());

onView(withId(R.id.layout_parent_account)).check(matches(not(isDisplayed())));
onView(withId(R.id.menu_save)).perform(click());

//no sub-accounts
assertThat(mAccountsDbAdapter.getSubAccountCount(DUMMY_ACCOUNT_UID)).isEqualTo(0);
assertThat(mAccountsDbAdapter.getSubAccountCount(mAccountsDbAdapter.getOrCreateGnuCashRootAccountUID())).isEqualTo(2);
assertThat(mAccountsDbAdapter.getSimpleAccountList()).extracting("mAccountType").contains(AccountType.TRADING);
}

@Test
public void testEditAccount(){
String editedAccountName = "Edited Account";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.gnucash.android.test.ui;

import android.app.Fragment;
import android.content.ContentValues;
import android.content.Intent;
import android.content.SharedPreferences;
Expand All @@ -28,8 +27,6 @@
import android.support.test.runner.AndroidJUnit4;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.Spinner;

import org.gnucash.android.R;
import org.gnucash.android.db.AccountsDbAdapter;
Expand Down Expand Up @@ -58,7 +55,6 @@
import java.util.List;
import java.util.Locale;

import static android.support.test.espresso.Espresso.onData;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.clearText;
import static android.support.test.espresso.action.ViewActions.click;
Expand All @@ -69,15 +65,10 @@
import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
import static android.support.test.espresso.matcher.ViewMatchers.isChecked;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.isNotChecked;
import static android.support.test.espresso.matcher.ViewMatchers.withChild;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withSpinnerText;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.assertj.android.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ public long getID(@NonNull String uid){
* Returns the string unique ID (GUID) of a record in the database
* @param id long database record ID
* @return GUID of the record
* @throws IllegalArgumentException if the record ID does not exist in the database
*/
public String getUID(long id){
Cursor cursor = mDb.query(mTableName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,15 @@ protected void onPostExecute(Boolean importSuccess) {
if (mDelegate != null)
mDelegate.onTaskComplete();

if (progressDialog != null && progressDialog.isShowing())
progressDialog.dismiss();
try {
if (progressDialog != null && progressDialog.isShowing())
progressDialog.dismiss();
} catch (IllegalArgumentException ex){
//TODO: This is a hack to catch "View not attached to window" exceptions
//FIXME by moving the creation and display of the progress dialog to the Fragment
} finally {
progressDialog = null;
}

int message = importSuccess ? R.string.toast_success_importing_accounts : R.string.toast_error_importing_accounts;
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void onCreate(Bundle savedInstanceState) {
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_new_account, container, false);
getSherlockActivity().getSupportActionBar().setTitle(R.string.title_add_account);
getSherlockActivity().getSupportActionBar().setTitle(R.string.label_create_account);
mCurrencySpinner = (Spinner) view.findViewById(R.id.input_currency_spinner);
mNameEditText = (EditText) view.findViewById(R.id.input_account_name);
//mNameEditText.requestFocus();
Expand Down Expand Up @@ -443,14 +443,14 @@ private void setSelectedCurrency(String currencyCode){
* @param parentAccountId Record ID of parent account to be selected
*/
private void setParentAccountSelection(long parentAccountId){
if (parentAccountId > 0 && parentAccountId != mRootAccountId){
mParentCheckBox.setChecked(true);
mParentAccountSpinner.setEnabled(true);
} else
if (parentAccountId <= 0 || parentAccountId == mRootAccountId) {
return;
}

for (int pos = 0; pos < mParentAccountCursorAdapter.getCount(); pos++) {
if (mParentAccountCursorAdapter.getItemId(pos) == parentAccountId){
mParentCheckBox.setChecked(true);
mParentAccountSpinner.setEnabled(true);
mParentAccountSpinner.setSelection(pos, true);
break;
}
Expand Down Expand Up @@ -581,11 +581,15 @@ private void loadParentAccountList(AccountType accountType){
mParentAccountCursor.close();

mParentAccountCursor = mAccountsDbAdapter.fetchAccountsOrderedByFullName(condition, null);
if (mParentAccountCursor.getCount() <= 0){
final View view = getView();
assert view != null;
final View view = getView();
assert view != null;
if (mParentAccountCursor.getCount() <= 0){
mParentCheckBox.setChecked(false); //disable before hiding, else we can still read it when saving
view.findViewById(R.id.layout_parent_account).setVisibility(View.GONE);
view.findViewById(R.id.label_parent_account).setVisibility(View.GONE);
} else {
view.findViewById(R.id.layout_parent_account).setVisibility(View.VISIBLE);
view.findViewById(R.id.label_parent_account).setVisibility(View.VISIBLE);
}

mParentAccountCursorAdapter = new QualifiedAccountNameCursorAdapter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.actionbarsherlock.app.SherlockPreferenceActivity;

import org.gnucash.android.R;
import org.gnucash.android.app.GnuCashApplication;
import org.gnucash.android.ui.UxArgument;
import org.gnucash.android.ui.passcode.PasscodeLockScreenActivity;
import org.gnucash.android.ui.passcode.PasscodePreferenceActivity;
Expand Down Expand Up @@ -108,6 +109,10 @@ public boolean onPreferenceClick(Preference preference) {
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (mEditor == null){
mEditor = PreferenceManager.getDefaultSharedPreferences(GnuCashApplication.getAppContext()).edit();
}

switch (requestCode) {
case PASSCODE_REQUEST_CODE:
if (resultCode == Activity.RESULT_OK && data != null) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_account_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
android:id="@+id/add_preference_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/title_add_account" />
android:text="@string/label_create_account" />
</LinearLayout>
</LinearLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_accounts_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@
android:id="@+id/add_account_button"
style="@style/ButtonStyle"
android:onClick="onNewAccountClick"
android:text="@string/title_add_account" />
android:text="@string/label_create_account" />
</LinearLayout>
</RelativeLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/menu/account_actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/menu_add_account"
android:icon="@drawable/content_new_holo_dark"
android:title="@string/title_add_account"
android:title="@string/label_create_account"
android:showAsAction="always"/>

<item android:id="@+id/menu_recurring_transactions"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/menu/sub_account_actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<item android:id="@+id/menu_add_account"
android:icon="@drawable/content_new_holo_dark"
android:title="@string/title_add_account"
android:title="@string/label_create_account"
android:showAsAction="always"/>

<item android:id="@+id/menu_edit_account"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
limitations under the License.
-->
<resources>
<string name="title_add_account">Neues Konto</string>
<string name="label_create_account">Neues Konto</string>
<string name="title_edit_account">Konto bearbeiten</string>
<string name="info_details">Info</string>
<string name="menu_export">OFX-Datei exportieren</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-el/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-->

<resources>
<string name="title_add_account">Δημιουργία Λογαριασμού</string>
<string name="label_create_account">Δημιουργία Λογαριασμού</string>
<string name="title_edit_account">Επεξεργασία Λογαριασμού</string>
<string name="info_details">Πληροφορίες</string>
<string name="menu_export">Εξαγωγή OFX</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-es-rMX/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-->

<resources>
<string name="title_add_account">Crear cuenta</string>
<string name="label_create_account">Crear cuenta</string>
<string name="title_edit_account">Editar cuenta</string>
<string name="info_details">Detalles</string>
<string name="menu_export">Exportar a OFX</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-->

<resources>
<string name="title_add_account">Crear Cuenta</string>
<string name="label_create_account">Crear Cuenta</string>
<string name="title_edit_account">Editar Cuenta</string>
<string name="info_details">Info</string>
<string name="menu_export">Exportar OFX</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-->

<resources xmlns:tools="http://schemas.android.com/tools" tools:locale="fr">
<string name="title_add_account">Cr&#233;er un compte</string>
<string name="label_create_account">Cr&#233;er un compte</string>
<string name="title_edit_account">Éditer le compte</string>
<string name="info_details">Informations</string>
<string name="menu_export">Exporter en OFX</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-hu/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
-->

<resources>
<string name="title_add_account">Create Account</string>
<string name="label_create_account">Create Account</string>
<string name="title_edit_account">Edit Account</string>
<string name="info_details">Info</string>
<string name="menu_export">Export OFX</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-->

<resources>
<string name="title_add_account">Crea conto</string>
<string name="label_create_account">Crea conto</string>
<string name="title_edit_account">Modifica conto</string>
<string name="info_details">Informazioni</string>
<string name="menu_export">Esporta OFX</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-nb/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-->

<resources>
<string name="title_add_account">Opprett konto</string>
<string name="label_create_account">Opprett konto</string>
<string name="title_edit_account">Rediger konto</string>
<string name="info_details">Informasjon</string>
<string name="menu_export">Eksport OFX</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-->

<resources>
<string name="title_add_account">Nieuw rekening</string>
<string name="label_create_account">Nieuw rekening</string>
<string name="title_edit_account">Rekening bewerken</string>
<string name="info_details">Info</string>
<string name="menu_export">OFX exporteren</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
limitations under the License.
-->
<resources>
<string name="title_add_account">Criar Conta</string>
<string name="label_create_account">Criar Conta</string>
<string name="title_edit_account">Editar Conta</string>
<string name="info_details">Info</string>
<string name="menu_export">Exportar OFX</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-->

<resources>
<string name="title_add_account">Создать счёт</string>
<string name="label_create_account">Создать счёт</string>
<string name="title_edit_account">Редактировать счёт</string>
<string name="info_details">Информация</string>
<string name="menu_export">Экспортировать OFX</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="title_add_account">Створити рахунок</string>
<string name="label_create_account">Створити рахунок</string>
<string name="title_edit_account">Редагувати рахунок</string>
<string name="info_details">Інформація</string>
<string name="menu_export">Експортувати OFX</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-->

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="title_add_account">创建科目</string>
<string name="label_create_account">创建科目</string>
<string name="title_edit_account">修改科目</string>
<string name="info_details">信息</string>
<string name="menu_export">导出OFX</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
-->

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="title_add_account">Create Account</string>
<string name="label_create_account">Create Account</string>
<string name="title_edit_account">Edit Account</string>
<string name="info_details">Info</string>
<string name="menu_export">Export…</string>
Expand Down

0 comments on commit baa094c

Please sign in to comment.