]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/db/AccountAutocompleteAdapter.java
Room-based profile management
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / db / AccountAutocompleteAdapter.java
index 9eabeb914ee75b31f4b035f0b68d0f9f7243ed38..9b6d41ba9505ccc413e0c9f4982289333ef34fd9 100644 (file)
@@ -24,20 +24,25 @@ import android.widget.Filter;
 import androidx.annotation.NonNull;
 
 import net.ktnx.mobileledger.dao.AccountDAO;
+import net.ktnx.mobileledger.utils.Logger;
 
 import java.util.ArrayList;
 import java.util.List;
 
-public class AccountAutocompleteAdapter extends ArrayAdapter<Account> {
+public class AccountAutocompleteAdapter extends ArrayAdapter<String> {
     private final AccountFilter filter = new AccountFilter();
     private final AccountDAO dao = DB.get()
                                      .getAccountDAO();
-    private String profileUUID;
+    private long profileId;
     public AccountAutocompleteAdapter(Context context) {
         super(context, android.R.layout.simple_dropdown_item_1line, new ArrayList<>());
     }
-    public void setProfileUUID(String profileUUID) {
-        this.profileUUID = profileUUID;
+    public AccountAutocompleteAdapter(Context context, @NonNull Profile profile) {
+        this(context);
+        profileId = profile.getId();
+    }
+    public void setProfileId(long profileId) {
+        this.profileId = profileId;
     }
     @NonNull
     @Override
@@ -66,10 +71,12 @@ public class AccountAutocompleteAdapter extends ArrayAdapter<Account> {
                 return results;
             }
 
-            final List<Account> matches =
-                    (profileUUID == null) ? dao.lookupByNameSync(String.valueOf(constraint))
-                                          : dao.lookupInProfileByNameSync(profileUUID,
-                                                  String.valueOf(constraint));
+            Logger.debug("acc", String.format("Looking for account '%s'", constraint));
+            final List<String> matches = AccountDAO.unbox((profileId == 0) ? dao.lookupByNameSync(
+                    String.valueOf(constraint)
+                          .toUpperCase()) : dao.lookupInProfileByNameSync(profileId,
+                    String.valueOf(constraint)
+                          .toUpperCase()));
             results.values = matches;
             results.count = matches.size();
 
@@ -84,7 +91,7 @@ public class AccountAutocompleteAdapter extends ArrayAdapter<Account> {
             else {
                 setNotifyOnChange(false);
                 clear();
-                addAll((List<Account>) results.values);
+                addAll((List<String>) results.values);
                 notifyDataSetChanged();
             }
         }