From bd8d730210313d81c2f7ed73f86754332a9976af Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Mon, 8 Apr 2019 21:10:40 +0300 Subject: [PATCH] fix account name auto-completion in new transaction screen started via shortcut --- .../mobileledger/ui/activity/NewTransactionActivity.java | 7 ++++--- app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java | 8 +++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionActivity.java index 310232d2..b2ce8ef2 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionActivity.java @@ -100,7 +100,7 @@ public class NewTransactionActivity extends ProfileThemedActivity }); tvDescription = findViewById(R.id.new_transaction_description); MLDB.hookAutocompletionAdapter(this, tvDescription, MLDB.DESCRIPTION_HISTORY_TABLE, - "description", false, findViewById(R.id.new_transaction_acc_1), this); + "description", false, findViewById(R.id.new_transaction_acc_1), this, mProfile); hookTextChangeListener(tvDescription); progress = findViewById(R.id.save_transaction_progress); @@ -115,7 +115,7 @@ public class NewTransactionActivity extends ProfileThemedActivity TextView tvAmount = (TextView) row.getChildAt(1); hookSwipeListener(row); MLDB.hookAutocompletionAdapter(this, tvAccountName, MLDB.ACCOUNTS_TABLE, "name", true, - tvAmount, null); + tvAmount, null, mProfile); hookTextChangeListener(tvAccountName); hookTextChangeListener(tvAmount); // Log.d("swipe", "hooked to row "+i); @@ -361,7 +361,8 @@ public class NewTransactionActivity extends ProfileThemedActivity if (focus) acc.requestFocus(); hookSwipeListener(row); - MLDB.hookAutocompletionAdapter(this, acc, MLDB.ACCOUNTS_TABLE, "name", true, amt, null); + MLDB.hookAutocompletionAdapter(this, acc, MLDB.ACCOUNTS_TABLE, "name", true, amt, null, + mProfile); hookTextChangeListener(acc); hookTextChangeListener(amt); diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java b/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java index 5075b9ae..c59273b1 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java @@ -36,6 +36,7 @@ import android.widget.SimpleCursorAdapter; import net.ktnx.mobileledger.async.DescriptionSelectedCallback; import net.ktnx.mobileledger.model.Data; +import net.ktnx.mobileledger.model.MobileLedgerProfile; import org.jetbrains.annotations.NonNls; @@ -123,14 +124,15 @@ public final class MLDB { final AutoCompleteTextView view, final String table, final String field, final boolean profileSpecific) { - hookAutocompletionAdapter(context, view, table, field, profileSpecific, null, null); + hookAutocompletionAdapter(context, view, table, field, profileSpecific, null, null, Data.profile.get()); } @TargetApi(Build.VERSION_CODES.N) public static void hookAutocompletionAdapter(final Context context, final AutoCompleteTextView view, final String table, final String field, final boolean profileSpecific, final View nextView, - final DescriptionSelectedCallback callback) { + final DescriptionSelectedCallback callback, + final MobileLedgerProfile profile) { String[] from = {field}; int[] to = {android.R.id.text1}; SimpleCursorAdapter adapter = @@ -155,7 +157,7 @@ public final class MLDB { "FROM %s " + "WHERE profile=? AND %s_upper LIKE '%%'||?||'%%' " + "ORDER BY 2, 1;", field, field, field, field, table, field); - params = new String[]{str, str, str, Data.profile.get().getUuid(), str}; + params = new String[]{str, str, str, profile.getUuid(), str}; } else { sql = String.format("SELECT %s as a, case when %s_upper LIKE ?||'%%' then 1 " + -- 2.39.5