Skip to content

Commit 1cdf8b0

Browse files
committed
Merge branch 'hotfix/patches' of github.com:codinguser/gnucash-android into hotfix/patches
2 parents 0c91287 + 8af589b commit 1cdf8b0

3 files changed

Lines changed: 19 additions & 18 deletions

File tree

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -546,14 +546,10 @@ public Cursor fetchRecord(long rowId) {
546546
* @return Cursor to the data set containing all matching transactions
547547
*/
548548
public Cursor fetchTransactionsStartingWith(String prefix){
549-
StringBuffer stringBuffer = new StringBuffer(TransactionEntry.COLUMN_DESCRIPTION)
550-
.append(" LIKE '").append(prefix).append("%'");
551-
String selection = stringBuffer.toString();
552-
553549
return mDb.query(TransactionEntry.TABLE_NAME,
554550
new String[]{TransactionEntry._ID, TransactionEntry.COLUMN_DESCRIPTION},
555-
selection,
556-
null, null, null,
551+
TransactionEntry.COLUMN_DESCRIPTION + " LIKE ?",
552+
new String[]{prefix+"%"}, null, null,
557553
TransactionEntry.COLUMN_DESCRIPTION + " ASC");
558554
}
559555

app/src/org/gnucash/android/ui/account/AccountFormFragment.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -554,10 +554,10 @@ private void loadParentAccountList(AccountType accountType){
554554

555555
if (mAccount != null){ //if editing an account
556556
mDescendantAccountUIDs = mAccountsDbAdapter.getDescendantAccountUIDs(mAccount.getUID(), null, null);
557-
mDescendantAccountUIDs.add(mAccountUID); //cannot set self as parent
558557
// limit cyclic account hierarchies.
559558
condition += " AND (" + DatabaseSchema.AccountEntry.COLUMN_PARENT_ACCOUNT_UID + " IS NULL "
560-
+ " OR " + DatabaseSchema.AccountEntry.COLUMN_UID + " NOT IN ( '" + TextUtils.join("','", mDescendantAccountUIDs) + "' ) )";
559+
+ " OR " + DatabaseSchema.AccountEntry.COLUMN_UID + " NOT IN ( '"
560+
+ TextUtils.join("','", mDescendantAccountUIDs) + "','" + mAccountUID + "' ) )";
561561
}
562562

563563
//if we are reloading the list, close the previous cursor first
@@ -684,6 +684,7 @@ public void onDestroy() {
684684
private void saveAccount() {
685685
// accounts to update, in case we're updating full names of a sub account tree
686686
ArrayList<Account> accountsToUpdate = new ArrayList<Account>();
687+
boolean nameChanged = false;
687688
if (mAccount == null){
688689
String name = getEnteredName();
689690
if (name == null || name.length() == 0){
@@ -694,8 +695,10 @@ private void saveAccount() {
694695
}
695696
mAccount = new Account(getEnteredName());
696697
}
697-
else
698-
mAccount.setName(getEnteredName());
698+
else {
699+
nameChanged = !mAccount.getName().equals(getEnteredName());
700+
mAccount.setName(getEnteredName());
701+
}
699702

700703
String curCode = mCurrencyCodes.get(mCurrencySpinner
701704
.getSelectedItemPosition());
@@ -730,8 +733,8 @@ private void saveAccount() {
730733

731734
long parentAccountId = mAccountsDbAdapter.getID(mParentAccountUID);
732735
// update full names
733-
if (mDescendantAccountUIDs == null || newParentAccountId != parentAccountId) {
734-
// new Account or parent account changed
736+
if (nameChanged || mDescendantAccountUIDs == null || newParentAccountId != parentAccountId) {
737+
// current account name changed or new Account or parent account changed
735738
String newAccountFullName;
736739
if (newParentAccountId == mRootAccountId){
737740
newAccountFullName = mAccount.getName();
@@ -742,8 +745,8 @@ private void saveAccount() {
742745
}
743746
mAccount.setFullName(newAccountFullName);
744747
if (mDescendantAccountUIDs != null) {
745-
// modifying existing account
746-
if (parentAccountId != newParentAccountId && mDescendantAccountUIDs.size() > 0) {
748+
// modifying existing account, e.t. name changed and/or parent changed
749+
if ((nameChanged || parentAccountId != newParentAccountId) && mDescendantAccountUIDs.size() > 0) {
747750
// parent change, update all full names of descent accounts
748751
accountsToUpdate.addAll(mAccountsDbAdapter.getSimpleAccountList(
749752
DatabaseSchema.AccountEntry.COLUMN_UID + " IN ('" +

app/src/org/gnucash/android/ui/transaction/TransactionFormFragment.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public CharSequence convertToString(Cursor cursor) {
284284
adapter.setFilterQueryProvider(new FilterQueryProvider() {
285285
@Override
286286
public Cursor runQuery(CharSequence name) {
287-
return mTransactionsDbAdapter.fetchTransactionsStartingWith(name.toString());
287+
return mTransactionsDbAdapter.fetchTransactionsStartingWith(name==null?"":name.toString());
288288
}
289289
});
290290

@@ -343,15 +343,17 @@ private void initializeViewsWithTransaction(){
343343

344344
//if there are more than two splits (which is the default for one entry), then
345345
//disable editing of the transfer account. User should open editor
346-
if (mTransaction.getSplits().size() > 2) {
347-
setAmountEditViewVisible(View.GONE);
348-
} else {
346+
if (mSplitsList.size() == 2 && mSplitsList.get(0).isPairOf(mSplitsList.get(1))) {
349347
for (Split split : mTransaction.getSplits()) {
350348
//two splits, one belongs to this account and the other to another account
351349
if (mUseDoubleEntry && !split.getAccountUID().equals(mAccountUID)) {
352350
setSelectedTransferAccount(mAccountsDbAdapter.getAccountID(split.getAccountUID()));
353351
}
354352
}
353+
} else {
354+
if (mUseDoubleEntry) {
355+
setAmountEditViewVisible(View.GONE);
356+
}
355357
}
356358
mSplitsList = new ArrayList<Split>(mTransaction.getSplits()); //we need a copy so we can modify with impunity
357359
mAmountEditText.setEnabled(mSplitsList.size() <= 2);

0 commit comments

Comments
 (0)