From 5f7220594ff0d97ca0e8e5643ea1d5fad5d1f636 Mon Sep 17 00:00:00 2001 From: JeanGarf Date: Sun, 19 Jan 2020 22:57:58 +0100 Subject: [PATCH 1/3] #869 - Remove fetchAccountsOrderedByFullName() method in order to use fetchAccountsOrderedByFavoriteAndFullName() everywhere --- .../android/db/adapter/AccountsDbAdapter.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/gnucash/android/db/adapter/AccountsDbAdapter.java b/app/src/main/java/org/gnucash/android/db/adapter/AccountsDbAdapter.java index e19138306..f5d43e25d 100644 --- a/app/src/main/java/org/gnucash/android/db/adapter/AccountsDbAdapter.java +++ b/app/src/main/java/org/gnucash/android/db/adapter/AccountsDbAdapter.java @@ -731,20 +731,21 @@ public Cursor fetchAccounts(@Nullable String where, @Nullable String[] whereArgs null, where, whereArgs, null, null, orderBy); } - - /** - * Returns a Cursor set of accounts which fulfill where - *

This method returns the accounts list sorted by the full account name

- * @param where SQL WHERE statement without the 'WHERE' itself - * @param whereArgs where args - * @return Cursor set of accounts which fulfill where - */ - public Cursor fetchAccountsOrderedByFullName(String where, String[] whereArgs) { - Log.v(LOG_TAG, "Fetching all accounts from db where " + where); - return mDb.query(AccountEntry.TABLE_NAME, - null, where, whereArgs, null, null, - AccountEntry.COLUMN_FULL_NAME + " ASC"); - } + + // #869 +// /** +// * Returns a Cursor set of accounts which fulfill where +// *

This method returns the accounts list sorted by the full account name

+// * @param where SQL WHERE statement without the 'WHERE' itself +// * @param whereArgs where args +// * @return Cursor set of accounts which fulfill where +// */ +// public Cursor fetchAccountsOrderedByFullName(String where, String[] whereArgs) { +// Log.v(LOG_TAG, "Fetching all accounts from db where " + where); +// return mDb.query(AccountEntry.TABLE_NAME, +// null, where, whereArgs, null, null, +// AccountEntry.COLUMN_FULL_NAME + " ASC"); +// } /** * Returns a Cursor set of accounts which fulfill where From b03d505264dda391dc1e3852a5bf92f1e3bd18d8 Mon Sep 17 00:00:00 2001 From: JeanGarf Date: Sun, 19 Jan 2020 23:02:05 +0100 Subject: [PATCH 2/3] =?UTF-8?q?Translations=20:=20Fr=20Compte=20de=20r?= =?UTF-8?q?=C3=A9f=C3=A9rence=20=3D>=20Compte=20virtuel=20(like=20in=20des?= =?UTF-8?q?ktop=20gnucash)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/values-fr/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 9ab498501..cd7da5e71 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -145,7 +145,7 @@ Exportation des transactions Pas de transactions planifiées à afficher. Transaction récurrente supprimée avec succès - Compte de référence + Compte virtuel Compte de transfert par défaut %d sous-compte From f442bd59eaed01bbd60afe0cf49a870581d7a14e Mon Sep 17 00:00:00 2001 From: JeanGarf Date: Sun, 19 Jan 2020 23:03:00 +0100 Subject: [PATCH 3/3] Fixes #869 - Replace use of fetchAccountsOrderedByFullName() by fetchAccountsOrderedByFavoriteAndFullName() --- .../ui/account/AccountFormFragment.java | 6 ++-- .../account/DeleteAccountDialogFragment.java | 13 ++++--- .../ui/transaction/SplitEditorFragment.java | 36 ++++++++++++------- .../dialog/BulkMoveDialogFragment.java | 5 +-- 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/org/gnucash/android/ui/account/AccountFormFragment.java b/app/src/main/java/org/gnucash/android/ui/account/AccountFormFragment.java index 35d5f3e7b..45b785945 100644 --- a/app/src/main/java/org/gnucash/android/ui/account/AccountFormFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/account/AccountFormFragment.java @@ -575,8 +575,8 @@ private void loadDefaultTransferAccountList(){ + " AND " + DatabaseSchema.AccountEntry.COLUMN_HIDDEN + "=0" + " AND " + DatabaseSchema.AccountEntry.COLUMN_TYPE + " != ?"; - Cursor defaultTransferAccountCursor = mAccountsDbAdapter.fetchAccountsOrderedByFullName(condition, - new String[]{AccountType.ROOT.name()}); + Cursor defaultTransferAccountCursor = mAccountsDbAdapter.fetchAccountsOrderedByFavoriteAndFullName(condition, + new String[]{AccountType.ROOT.name()}); if (mDefaultTransferAccountSpinner.getCount() <= 0) { setDefaultTransferAccountInputsVisible(false); @@ -611,7 +611,7 @@ private void loadParentAccountList(AccountType accountType){ if (mParentAccountCursor != null) mParentAccountCursor.close(); - mParentAccountCursor = mAccountsDbAdapter.fetchAccountsOrderedByFullName(condition, null); + mParentAccountCursor = mAccountsDbAdapter.fetchAccountsOrderedByFavoriteAndFullName(condition, null); final View view = getView(); assert view != null; if (mParentAccountCursor.getCount() <= 0){ diff --git a/app/src/main/java/org/gnucash/android/ui/account/DeleteAccountDialogFragment.java b/app/src/main/java/org/gnucash/android/ui/account/DeleteAccountDialogFragment.java index 4d5f6c551..cf38aa4cf 100644 --- a/app/src/main/java/org/gnucash/android/ui/account/DeleteAccountDialogFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/account/DeleteAccountDialogFragment.java @@ -148,8 +148,10 @@ public void onActivityCreated(Bundle savedInstanceState) { + DatabaseSchema.AccountEntry.COLUMN_PLACEHOLDER + " = 0 AND " + DatabaseSchema.AccountEntry.COLUMN_UID + " NOT IN ('" + TextUtils.join("','", descendantAccountUIDs) + "')" + ")"; - Cursor cursor = accountsDbAdapter.fetchAccountsOrderedByFullName(transactionDeleteConditions, - new String[]{mOriginAccountUID, currencyCode, accountType.name()}); + Cursor cursor = accountsDbAdapter.fetchAccountsOrderedByFavoriteAndFullName(transactionDeleteConditions, + new String[]{mOriginAccountUID, + currencyCode, + accountType.name()}); SimpleCursorAdapter mCursorAdapter = new QualifiedAccountNameCursorAdapter(getActivity(), cursor); mTransactionsDestinationAccountSpinner.setAdapter(mCursorAdapter); @@ -160,8 +162,11 @@ public void onActivityCreated(Bundle savedInstanceState) { + DatabaseSchema.AccountEntry.COLUMN_TYPE + " = ? AND " + DatabaseSchema.AccountEntry.COLUMN_UID + " NOT IN ('" + TextUtils.join("','", descendantAccountUIDs) + "')" + ")"; - cursor = accountsDbAdapter.fetchAccountsOrderedByFullName(accountMoveConditions, - new String[]{mOriginAccountUID, currencyCode, accountType.name()}); + cursor = accountsDbAdapter.fetchAccountsOrderedByFavoriteAndFullName(accountMoveConditions, + new String[]{mOriginAccountUID, + currencyCode, + accountType.name()}); + mCursorAdapter = new QualifiedAccountNameCursorAdapter(getActivity(), cursor); mAccountsDestinationAccountSpinner.setAdapter(mCursorAdapter); diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/SplitEditorFragment.java b/app/src/main/java/org/gnucash/android/ui/transaction/SplitEditorFragment.java index 1494b16c7..9e456d905 100644 --- a/app/src/main/java/org/gnucash/android/ui/transaction/SplitEditorFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/transaction/SplitEditorFragment.java @@ -83,12 +83,12 @@ public class SplitEditorFragment extends Fragment { @BindView(R.id.calculator_keyboard) KeyboardView mKeyboardView; @BindView(R.id.imbalance_textview) TextView mImbalanceTextView; - private AccountsDbAdapter mAccountsDbAdapter; - private Cursor mCursor; - private SimpleCursorAdapter mCursorAdapter; - private List mSplitItemViewList; - private String mAccountUID; - private Commodity mCommodity; + private AccountsDbAdapter mAccountsDbAdapter; + private Cursor mCursor; + private SimpleCursorAdapter mAccountCursorAdapter; + private List mSplitItemViewList; + private String mAccountUID; + private Commodity mCommodity; private BigDecimal mBaseAmount = BigDecimal.ZERO; @@ -216,11 +216,13 @@ private void initArgs() { mAccountUID = ((FormActivity) getActivity()).getCurrentAccountUID(); mBaseAmount = new BigDecimal(args.getString(UxArgument.AMOUNT_STRING)); + // Get account list that are not hidden nor placeholder, and sort them with Favorites first String conditions = "(" + DatabaseSchema.AccountEntry.COLUMN_HIDDEN + " = 0 AND " + DatabaseSchema.AccountEntry.COLUMN_PLACEHOLDER + " = 0" + ")"; - mCursor = mAccountsDbAdapter.fetchAccountsOrderedByFullName(conditions, null); + mCursor = mAccountsDbAdapter.fetchAccountsOrderedByFavoriteAndFullName(conditions, null); + mCommodity = CommoditiesDbAdapter.getInstance().getCommodity(mAccountsDbAdapter.getCurrencyCode(mAccountUID)); } @@ -328,20 +330,30 @@ public BigDecimal getAmountValue(){ * @param accountId Database ID of the transfer account */ private void setSelectedTransferAccount(long accountId, final Spinner accountsSpinner){ - for (int pos = 0; pos < mCursorAdapter.getCount(); pos++) { - if (mCursorAdapter.getItemId(pos) == accountId){ + for (int pos = 0; pos < mAccountCursorAdapter.getCount(); pos++) { + if (mAccountCursorAdapter.getItemId(pos) == accountId){ accountsSpinner.setSelection(pos); break; } } } + /** * Updates the list of possible transfer accounts. * Only accounts with the same currency can be transferred to */ - private void updateTransferAccountsList(Spinner transferAccountSpinner){ - mCursorAdapter = new QualifiedAccountNameCursorAdapter(getActivity(), mCursor); - transferAccountSpinner.setAdapter(mCursorAdapter); + private void updateTransferAccountsList(Spinner transferAccountSpinnerView) { + + // + // Fetch Accounts from DB sorted with Favorites at first + // + + // Adapter in order to make Cursor adapted to be put in a View + mAccountCursorAdapter = new QualifiedAccountNameCursorAdapter(getActivity(), + mCursor); + + // Put the Adapter in the View + transferAccountSpinnerView.setAdapter(mAccountCursorAdapter); } /** diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/dialog/BulkMoveDialogFragment.java b/app/src/main/java/org/gnucash/android/ui/transaction/dialog/BulkMoveDialogFragment.java index b18c9e496..2bb71a8f4 100644 --- a/app/src/main/java/org/gnucash/android/ui/transaction/dialog/BulkMoveDialogFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/transaction/dialog/BulkMoveDialogFragment.java @@ -125,8 +125,9 @@ public void onActivityCreated(Bundle savedInstanceState) { + DatabaseSchema.AccountEntry.COLUMN_HIDDEN + " = 0 AND " + DatabaseSchema.AccountEntry.COLUMN_PLACEHOLDER + " = 0" + ")"; - Cursor cursor = accountsDbAdapter.fetchAccountsOrderedByFullName(conditions, - new String[]{mOriginAccountUID, accountsDbAdapter.getCurrencyCode(mOriginAccountUID)}); + Cursor cursor = accountsDbAdapter.fetchAccountsOrderedByFavoriteAndFullName(conditions, + new String[]{mOriginAccountUID, + accountsDbAdapter.getCurrencyCode(mOriginAccountUID)}); SimpleCursorAdapter mCursorAdapter = new QualifiedAccountNameCursorAdapter(getActivity(), cursor); mDestinationAccountSpinner.setAdapter(mCursorAdapter);