]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/db/AccountAutocompleteAdapter.java
show current account balance when choosing account in new transactions
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / db / AccountAutocompleteAdapter.java
index 6f18225d7bd7e054be463aae98c7d90823b333c0..6a92b6170214a9026fba0e57e40c640b4d218c60 100644 (file)
@@ -24,20 +24,27 @@ 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;
 
+import static net.ktnx.mobileledger.db.Profile.NO_PROFILE_ID;
+
 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 = NO_PROFILE_ID;
     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 +73,13 @@ public class AccountAutocompleteAdapter extends ArrayAdapter<String> {
                 return results;
             }
 
+            Logger.debug("acc", String.format("Looking for account '%s'", constraint));
             final List<String> matches = AccountDAO.unbox(
-                    (profileUUID == null) ? dao.lookupByNameSync(String.valueOf(constraint))
-                                          : dao.lookupInProfileByNameSync(profileUUID,
-                                                  String.valueOf(constraint)));
+                    (profileId == NO_PROFILE_ID) ? dao.lookupNamesByNameSync(
+                            String.valueOf(constraint)
+                                  .toUpperCase()) : dao.lookupNamesInProfileByNameSync(profileId,
+                            String.valueOf(constraint)
+                                  .toUpperCase()));
             results.values = matches;
             results.count = matches.size();