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

Last Used Payee: enable two tiers: account level or global level #2082

Merged
merged 1 commit into from
Jan 17, 2025
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
40 changes: 30 additions & 10 deletions app/src/main/java/com/money/manager/ex/core/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public Context getContext() {
* Method, which returns the last payee used
* @return last payee used
*/
public Payee getLastPayeeUsed() {
public Payee getLastPayeeUsed(long accountId) {
// MmxOpenHelper helper = MmxOpenHelper.getInstance(getContext());
Payee payee = null;

Expand All @@ -146,17 +146,37 @@ public Payee getLastPayeeUsed() {
"ORDER BY C.TransDate DESC, C.TransId DESC " +
"LIMIT 1";

Cursor cursor = openHelper.get().getReadableDatabase().query(sql);

// check if cursor can be open
if (cursor != null && cursor.moveToFirst()) {
payee = new Payee();
payee.loadFromCursor(cursor);
// SQL query with accountId filtering
String sqlWithAccountId =
"SELECT C.TransID, C.TransDate, C.PAYEEID, P.PAYEENAME, P.CATEGID " +
"FROM CHECKINGACCOUNT_V1 C " +
"INNER JOIN PAYEE_V1 P ON C.PAYEEID = P.PAYEEID " +
"WHERE C.TransCode <> 'Transfer' " +
"AND (C.DELETEDTIME IS NULL OR C.DELETEDTIME = '') " +
"AND (C.accountid = ? OR C.toaccountid = ?) " +
"ORDER BY C.TransDate DESC, C.TransId DESC " +
"LIMIT 1";

// Attempt query with accountId
try (Cursor cursor = openHelper.get().getReadableDatabase().query(
sqlWithAccountId,
new String[]{String.valueOf(accountId), String.valueOf(accountId)})) {
if (cursor != null && cursor.moveToFirst()) {
payee = new Payee();
payee.loadFromCursor(cursor);
}
}

cursor.close();
if (payee == null) {
try (Cursor cursor = openHelper.get().getReadableDatabase().query(sql)) {
// check if cursor can be open
if (cursor != null && cursor.moveToFirst()) {
payee = new Payee();
payee.loadFromCursor(cursor);
}
}
}
//close database
//helper.close();


return payee;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ private boolean handleIntent(Bundle savedInstanceState) {
executor.execute(() -> {
try {
Core core = new Core(getApplicationContext());
Payee payee = core.getLastPayeeUsed();
Payee payee = core.getLastPayeeUsed(mCommon.transactionEntity.getAccountId());
if (payee != null && mCommon.transactionEntity.getPayeeId() == Constants.NOT_SET) {
// get id payee and category
mCommon.transactionEntity.setPayeeId(payee.getId());
Expand Down Expand Up @@ -597,7 +597,7 @@ private boolean handleIntent(Bundle savedInstanceState) {
if("L".equals(PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
.getString(getString(PreferenceConstants.PREF_DEFAULT_PAYEE), "N"))) {
Core core = new Core(this);
Payee payee = core.getLastPayeeUsed();
Payee payee = core.getLastPayeeUsed(mCommon.transactionEntity.getAccountId());

if (payee != null) {
mCommon.transactionEntity.setPayeeId(payee.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ public EditTransactionCommonFunctions(MmxBaseFragmentActivity parentActivity,
public ArrayList<Attachment> mAttachments;

public ArrayList<Taglink> mTaglinks;
public String mTagLinksString;

// Controls
public EditTransactionViewHolder viewHolder;
Expand All @@ -147,7 +146,7 @@ public EditTransactionCommonFunctions(MmxBaseFragmentActivity parentActivity,
private final ArrayList<String> mAccountNameList = new ArrayList<>();
private final ArrayList<Long> mAccountIdList = new ArrayList<>();
private TransactionTypes previousTransactionType = TransactionTypes.Withdrawal;
private String[] mStatusItems, mStatusValues; // arrays to manage trans.code and status
private String[] mStatusValues; // arrays to manage trans.code and status
private String mUserDateFormat;

public boolean deleteMarkedSplits(IRepository repository) {
Expand Down Expand Up @@ -717,12 +716,12 @@ public void initSplitCategories() {
}

public void initStatusSelector() {
mStatusItems = activity.getResources().getStringArray(R.array.status_items);
String[] statusItems = activity.getResources().getStringArray(R.array.status_items);
mStatusValues = activity.getResources().getStringArray(R.array.status_values);

// create adapter for spinnerStatus
ArrayAdapter<String> adapterStatus = new ArrayAdapter<>(getActivity(),
android.R.layout.simple_spinner_item, mStatusItems);
android.R.layout.simple_spinner_item, statusItems);
adapterStatus.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
viewHolder.spinStatus.setAdapter(adapterStatus);

Expand Down
Loading