From 0f121edb68f2f04e957bc9433e7531140a0bbe16 Mon Sep 17 00:00:00 2001 From: Yongxin Wang Date: Sun, 9 Nov 2014 11:03:45 +0800 Subject: [PATCH] Update full name when account name changed --- .../ui/account/AccountFormFragment.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/org/gnucash/android/ui/account/AccountFormFragment.java b/app/src/org/gnucash/android/ui/account/AccountFormFragment.java index 91d5136ad..eb7f58716 100644 --- a/app/src/org/gnucash/android/ui/account/AccountFormFragment.java +++ b/app/src/org/gnucash/android/ui/account/AccountFormFragment.java @@ -554,10 +554,10 @@ private void loadParentAccountList(AccountType accountType){ if (mAccount != null){ //if editing an account mDescendantAccountUIDs = mAccountsDbAdapter.getDescendantAccountUIDs(mAccount.getUID(), null, null); - mDescendantAccountUIDs.add(mAccountUID); //cannot set self as parent // limit cyclic account hierarchies. condition += " AND (" + DatabaseSchema.AccountEntry.COLUMN_PARENT_ACCOUNT_UID + " IS NULL " - + " OR " + DatabaseSchema.AccountEntry.COLUMN_UID + " NOT IN ( '" + TextUtils.join("','", mDescendantAccountUIDs) + "' ) )"; + + " OR " + DatabaseSchema.AccountEntry.COLUMN_UID + " NOT IN ( '" + + TextUtils.join("','", mDescendantAccountUIDs) + "','" + mAccountUID + "' ) )"; } //if we are reloading the list, close the previous cursor first @@ -684,6 +684,7 @@ public void onDestroy() { private void saveAccount() { // accounts to update, in case we're updating full names of a sub account tree ArrayList accountsToUpdate = new ArrayList(); + boolean nameChanged = false; if (mAccount == null){ String name = getEnteredName(); if (name == null || name.length() == 0){ @@ -694,8 +695,10 @@ private void saveAccount() { } mAccount = new Account(getEnteredName()); } - else - mAccount.setName(getEnteredName()); + else { + nameChanged = !mAccount.getName().equals(getEnteredName()); + mAccount.setName(getEnteredName()); + } String curCode = mCurrencyCodes.get(mCurrencySpinner .getSelectedItemPosition()); @@ -730,8 +733,8 @@ private void saveAccount() { long parentAccountId = mAccountsDbAdapter.getID(mParentAccountUID); // update full names - if (mDescendantAccountUIDs == null || newParentAccountId != parentAccountId) { - // new Account or parent account changed + if (nameChanged || mDescendantAccountUIDs == null || newParentAccountId != parentAccountId) { + // current account name changed or new Account or parent account changed String newAccountFullName; if (newParentAccountId == mRootAccountId){ newAccountFullName = mAccount.getName(); @@ -742,8 +745,8 @@ private void saveAccount() { } mAccount.setFullName(newAccountFullName); if (mDescendantAccountUIDs != null) { - // modifying existing account - if (parentAccountId != newParentAccountId && mDescendantAccountUIDs.size() > 0) { + // modifying existing account, e.t. name changed and/or parent changed + if ((nameChanged || parentAccountId != newParentAccountId) && mDescendantAccountUIDs.size() > 0) { // parent change, update all full names of descent accounts accountsToUpdate.addAll(mAccountsDbAdapter.getSimpleAccountList( DatabaseSchema.AccountEntry.COLUMN_UID + " IN ('" +