X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Futils%2FMLDB.java;h=ab792ae47d1e7b7c54cb97cc77f5031e40a12713;hp=e769be4e8de61ae08491e5e69d42ee7c60a7495f;hb=1b36e6425230f00d2b6fee293629fd64e59db74b;hpb=90383a155ec16a9f13b1e6ac94a118033e09b3aa 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..ab792ae4 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java @@ -25,7 +25,6 @@ import android.database.sqlite.SQLiteDatabase; import android.os.AsyncTask; import android.os.Build; import android.provider.FontsContract; -import android.view.View; import android.widget.AutoCompleteTextView; import android.widget.FilterQueryProvider; import android.widget.SimpleCursorAdapter; @@ -136,16 +135,14 @@ 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); } @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 boolean profileSpecific, final DescriptionSelectedCallback callback, final MobileLedgerProfile profile) { String[] from = {field}; @@ -166,13 +163,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 " + @@ -204,14 +203,9 @@ public final class MLDB { view.setAdapter(adapter); - if (nextView != null) { - view.setOnItemClickListener((parent, itemView, position, id) -> { - nextView.requestFocus(View.FOCUS_FORWARD); - if (callback != null) { - callback.descriptionSelected(String.valueOf(view.getText())); - } - }); - } + if (callback != null) view.setOnItemClickListener((parent, itemView, position, id) -> { + callback.descriptionSelected(String.valueOf(view.getText())); + }); } }