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> {
+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
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 == NO_PROFILE_ID) ? dao.lookupNamesByNameSync(
+ String.valueOf(constraint)
+ .toUpperCase()) : dao.lookupNamesInProfileByNameSync(profileId,
+ String.valueOf(constraint)
+ .toUpperCase()));
results.values = matches;
results.count = matches.size();
else {
setNotifyOnChange(false);
clear();
- addAll((List<Account>) results.values);
+ addAll((List<String>) results.values);
notifyDataSetChanged();
}
}