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

#869 Account pick list sorted everywhere by Favorites first #870

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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 @@ -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 <code>where</code>
* <p>This method returns the accounts list sorted by the full account 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 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 <code>where</code>
// * <p>This method returns the accounts list sorted by the full account 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 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 <code>where</code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<View> mSplitItemViewList;
private String mAccountUID;
private Commodity mCommodity;
private AccountsDbAdapter mAccountsDbAdapter;
private Cursor mCursor;
private SimpleCursorAdapter mAccountCursorAdapter;
private List<View> mSplitItemViewList;
private String mAccountUID;
private Commodity mCommodity;

private BigDecimal mBaseAmount = BigDecimal.ZERO;

Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
<string name="title_progress_exporting_transactions">Exportation des transactions</string>
<string name="label_no_recurring_transactions">Pas de transactions planifiées à afficher.</string>
<string name="toast_recurring_transaction_deleted">Transaction récurrente supprimée avec succès</string>
<string name="label_placeholder_account">Compte de référence</string>
<string name="label_placeholder_account">Compte virtuel</string>
<string name="label_default_transfer_account">Compte de transfert par défaut</string>
<plurals name="label_sub_accounts">
<item quantity="one">%d sous-compte</item>
Expand Down