From: Damyan Ivanov Date: Sun, 5 May 2019 18:44:03 +0000 (+0300) Subject: fix hooking profile-specific auto-completion adapter X-Git-Tag: v0.10.0~5 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=aff298c5d65b279b40884cf8273bd4eeb054adaa;p=mobile-ledger.git fix hooking profile-specific auto-completion adapter at this point the main profile may not have been loaded yet so don't give it to the hooking routine, which would instead retrieve the profile when the auto-completion is triggered, at which point Data.profile must be populated the other user of these routines, the new transaction activity is also bound to a profile (either the main one in Data.profile, or another -- if invoced via app shortcut) so it may pass the profile as a parameter --- diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java index 7ebf4e91..6340b3e2 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java @@ -116,7 +116,7 @@ public class TransactionListFragment extends MobileLedgerListFragment { vAccountFilter = mActivity.findViewById(R.id.transaction_list_account_name_filter); accNameFilter = mActivity.findViewById(R.id.transaction_filter_account_name); - MLDB.hookAutocompletionAdapter(mActivity, accNameFilter, "accounts", "name", true); + MLDB.hookAutocompletionAdapter(mActivity, accNameFilter, "accounts", "name"); accNameFilter.setOnItemClickListener((parent, view, position, id) -> { // debug("tmp", "direct onItemClick"); MatrixCursor mc = (MatrixCursor) parent.getItemAtPosition(position); 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 e769be4e..5741a2e6 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java @@ -136,10 +136,8 @@ public final class MLDB { @TargetApi(Build.VERSION_CODES.N) public static void hookAutocompletionAdapter(final Context context, final AutoCompleteTextView view, - final String table, final String field, - final boolean profileSpecific) { - hookAutocompletionAdapter(context, view, table, field, profileSpecific, null, null, - Data.profile.getValue()); + final String table, final String field) { + hookAutocompletionAdapter(context, view, table, field, true, null, null, null); } @TargetApi(Build.VERSION_CODES.N) public static void hookAutocompletionAdapter(final Context context, @@ -166,13 +164,15 @@ public final class MLDB { String sql; String[] params; if (profileSpecific) { + MobileLedgerProfile p = (profile == null) ? Data.profile.getValue() : profile; + if (p == null) throw new AssertionError(); sql = String.format("SELECT %s as a, case when %s_upper LIKE ?||'%%' then 1 " + "WHEN %s_upper LIKE '%%:'||?||'%%' then 2 " + "WHEN %s_upper LIKE '%% '||?||'%%' then 3 else 9 end " + "FROM %s " + "WHERE profile=? AND %s_upper LIKE '%%'||?||'%%' " + "ORDER BY 2, 1;", field, field, field, field, table, field); - params = new String[]{str, str, str, profile.getUuid(), str}; + params = new String[]{str, str, str, p.getUuid(), str}; } else { sql = String.format("SELECT %s as a, case when %s_upper LIKE ?||'%%' then 1 " +