Skip to content

Commit

Permalink
Merge branch 'hotfix/patches' of github.com:codinguser/gnucash-androi…
Browse files Browse the repository at this point in the history
…d into hotfix/patches
  • Loading branch information
codinguser committed Nov 13, 2014
2 parents 0c91287 + 8af589b commit 1cdf8b0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
8 changes: 2 additions & 6 deletions app/src/org/gnucash/android/db/TransactionsDbAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -546,14 +546,10 @@ public Cursor fetchRecord(long rowId) {
* @return Cursor to the data set containing all matching transactions
*/
public Cursor fetchTransactionsStartingWith(String prefix){
StringBuffer stringBuffer = new StringBuffer(TransactionEntry.COLUMN_DESCRIPTION)
.append(" LIKE '").append(prefix).append("%'");
String selection = stringBuffer.toString();

return mDb.query(TransactionEntry.TABLE_NAME,
new String[]{TransactionEntry._ID, TransactionEntry.COLUMN_DESCRIPTION},
selection,
null, null, null,
TransactionEntry.COLUMN_DESCRIPTION + " LIKE ?",
new String[]{prefix+"%"}, null, null,
TransactionEntry.COLUMN_DESCRIPTION + " ASC");
}

Expand Down
19 changes: 11 additions & 8 deletions app/src/org/gnucash/android/ui/account/AccountFormFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Account> accountsToUpdate = new ArrayList<Account>();
boolean nameChanged = false;
if (mAccount == null){
String name = getEnteredName();
if (name == null || name.length() == 0){
Expand All @@ -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());
Expand Down Expand Up @@ -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();
Expand All @@ -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 ('" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public CharSequence convertToString(Cursor cursor) {
adapter.setFilterQueryProvider(new FilterQueryProvider() {
@Override
public Cursor runQuery(CharSequence name) {
return mTransactionsDbAdapter.fetchTransactionsStartingWith(name.toString());
return mTransactionsDbAdapter.fetchTransactionsStartingWith(name==null?"":name.toString());
}
});

Expand Down Expand Up @@ -343,15 +343,17 @@ private void initializeViewsWithTransaction(){

//if there are more than two splits (which is the default for one entry), then
//disable editing of the transfer account. User should open editor
if (mTransaction.getSplits().size() > 2) {
setAmountEditViewVisible(View.GONE);
} else {
if (mSplitsList.size() == 2 && mSplitsList.get(0).isPairOf(mSplitsList.get(1))) {
for (Split split : mTransaction.getSplits()) {
//two splits, one belongs to this account and the other to another account
if (mUseDoubleEntry && !split.getAccountUID().equals(mAccountUID)) {
setSelectedTransferAccount(mAccountsDbAdapter.getAccountID(split.getAccountUID()));
}
}
} else {
if (mUseDoubleEntry) {
setAmountEditViewVisible(View.GONE);
}
}
mSplitsList = new ArrayList<Split>(mTransaction.getSplits()); //we need a copy so we can modify with impunity
mAmountEditText.setEnabled(mSplitsList.size() <= 2);
Expand Down

0 comments on commit 1cdf8b0

Please sign in to comment.