fix account name auto-completion in new transaction screen started via shortcut
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 8 Apr 2019 18:10:40 +0000 (21:10 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 8 Apr 2019 18:11:26 +0000 (21:11 +0300)
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionActivity.java
app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java

index 310232d..b2ce8ef 100644 (file)
@@ -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);
 
index 5075b9a..c59273b 100644 (file)
@@ -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 " +