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 651f1a73d..0a33d1d9f 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 @@ -749,6 +749,7 @@ 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

@@ -763,6 +764,21 @@ public Cursor fetchAccountsOrderedByFullName(String where, String[] whereArgs) { AccountEntry.COLUMN_FULL_NAME + " ASC"); } + /** + * Returns a Cursor set of accounts which fulfill where + *

This method returns the favorite accounts first, sorted by name, and then the other accounts, + * sorted by name.

+ * @param where SQL WHERE statement without the 'WHERE' itself + * @param whereArgs where args + * @return Cursor set of accounts which fulfill where + */ + public Cursor fetchAccountsOrderedByFavoriteAndFullName(String where, String[] whereArgs) { + Log.v(LOG_TAG, "Fetching all accounts from db where " + where + " order by Favorite then Name"); + return mDb.query(AccountEntry.TABLE_NAME, + null, where, whereArgs, null, null, + AccountEntry.COLUMN_FAVORITE + " DESC, " + AccountEntry.COLUMN_FULL_NAME + " ASC"); + } + /** * Returns the balance of an account while taking sub-accounts into consideration * @return Account Balance of an account including sub-accounts diff --git a/app/src/main/java/org/gnucash/android/ui/budget/BudgetAmountEditorFragment.java b/app/src/main/java/org/gnucash/android/ui/budget/BudgetAmountEditorFragment.java index a625cb57b..a87c40d32 100644 --- a/app/src/main/java/org/gnucash/android/ui/budget/BudgetAmountEditorFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/budget/BudgetAmountEditorFragment.java @@ -204,7 +204,7 @@ private void setupAccountSpinnerAdapter(){ if (mAccountCursor != null) { mAccountCursor.close(); } - mAccountCursor = mAccountsDbAdapter.fetchAccountsOrderedByFullName(conditions, null); + mAccountCursor = mAccountsDbAdapter.fetchAccountsOrderedByFavoriteAndFullName(conditions, null); mAccountCursorAdapter = new QualifiedAccountNameCursorAdapter(getActivity(), mAccountCursor); } diff --git a/app/src/main/java/org/gnucash/android/ui/budget/BudgetFormFragment.java b/app/src/main/java/org/gnucash/android/ui/budget/BudgetFormFragment.java index b35125bac..553a400c9 100644 --- a/app/src/main/java/org/gnucash/android/ui/budget/BudgetFormFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/budget/BudgetFormFragment.java @@ -122,7 +122,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { mBudgetAmounts = new ArrayList<>(); String conditions = "(" + DatabaseSchema.AccountEntry.COLUMN_HIDDEN + " = 0 )"; mAccountsDbAdapter = AccountsDbAdapter.getInstance(); - Cursor accountCursor = mAccountsDbAdapter.fetchAccountsOrderedByFullName(conditions, null); + Cursor accountCursor = mAccountsDbAdapter.fetchAccountsOrderedByFavoriteAndFullName(conditions, null); mAccountsCursorAdapter = new QualifiedAccountNameCursorAdapter(getActivity(), accountCursor); } diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java index 9689b5b80..e2e2c7ba5 100644 --- a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java @@ -323,6 +323,10 @@ public void onActivityCreated(Bundle savedInstanceState) { @Override public void onItemSelected(AdapterView adapterView, View view, int position, long id) { + // Remove the favorite star from the view to avoid visual clutter. + TextView qualifiedAccountName = (TextView) view; + qualifiedAccountName.setCompoundDrawablesWithIntrinsicBounds(0,0,0,0); + if (mSplitsList.size() == 2) { //when handling simple transfer to one account for (Split split : mSplitsList) { if (!split.getAccountUID().equals(mAccountUID)) { @@ -579,7 +583,7 @@ private void updateTransferAccountsList(){ if (mCursor != null) { mCursor.close(); } - mCursor = mAccountsDbAdapter.fetchAccountsOrderedByFullName(conditions, new String[]{mAccountUID, AccountType.ROOT.name()}); + mCursor = mAccountsDbAdapter.fetchAccountsOrderedByFavoriteAndFullName(conditions, new String[]{mAccountUID, AccountType.ROOT.name()}); mAccountCursorAdapter = new QualifiedAccountNameCursorAdapter(getActivity(), mCursor); mTransferAccountSpinner.setAdapter(mAccountCursorAdapter); diff --git a/app/src/main/java/org/gnucash/android/util/QualifiedAccountNameCursorAdapter.java b/app/src/main/java/org/gnucash/android/util/QualifiedAccountNameCursorAdapter.java index a2b310932..dcf17c13d 100644 --- a/app/src/main/java/org/gnucash/android/util/QualifiedAccountNameCursorAdapter.java +++ b/app/src/main/java/org/gnucash/android/util/QualifiedAccountNameCursorAdapter.java @@ -68,6 +68,13 @@ public void bindView(View view, Context context, Cursor cursor) { super.bindView(view, context, cursor); TextView textView = (TextView) view.findViewById(android.R.id.text1); textView.setEllipsize(TextUtils.TruncateAt.MIDDLE); + + Integer isFavorite = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.AccountEntry.COLUMN_FAVORITE)); + if(isFavorite == 0) { + textView.setCompoundDrawablesWithIntrinsicBounds(0,0,0,0); + } else { + textView.setCompoundDrawablesWithIntrinsicBounds(0,0,R.drawable.ic_star_black_24dp,0); + } } /**