Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort the transfer accounts by favorite before sorting them alphabetically #622

Merged
merged 6 commits into from
Dec 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>where</code>
* <p>This method returns the accounts list sorted by the full account name</p>
Expand All @@ -763,6 +764,21 @@ public Cursor fetchAccountsOrderedByFullName(String where, String[] whereArgs) {
AccountEntry.COLUMN_FULL_NAME + " ASC");
}

/**
* Returns a Cursor set of accounts which fulfill <code>where</code>
* <p>This method returns the favorite accounts first, sorted by name, and then the other accounts,
* sorted by name.</p>
* @param where SQL WHERE statement without the 'WHERE' itself
* @param whereArgs where args
* @return Cursor set of accounts which fulfill <code>where</code>
*/
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down