Skip to content
Snippets Groups Projects
Commit 9bdd7ee2 authored by Jawnnypoo's avatar Jawnnypoo
Browse files

Use hashset for getting autocomplete accounts so that we do not get duplicates.

parent a317c0fe
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -12,6 +12,9 @@ import android.widget.ArrayAdapter;
import com.commit451.gitlab.R;
 
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
 
/**
* Automagically fills in email accounts
Loading
Loading
@@ -36,19 +39,21 @@ public class EmailAutoCompleteTextView extends AppCompatAutoCompleteTextView {
 
private void init() {
if (isInEditMode()) { return; }
ArrayList<String> accounts = getEmailAccounts();
Collection<String> accounts = getEmailAccounts();
if (accounts != null && !accounts.isEmpty()) {
ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), R.layout.support_simple_spinner_dropdown_item, accounts);
ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(),
R.layout.support_simple_spinner_dropdown_item,
new ArrayList<>(accounts));
setAdapter(adapter);
}
}
 
/**
* Get all the accounts that appear to be email accounts
* Get all the accounts that appear to be email accounts. HashSet so that we do not get duplicates
* @return list of email accounts
*/
private ArrayList<String> getEmailAccounts() {
ArrayList<String> emailAccounts = new ArrayList<>();
private Set<String> getEmailAccounts() {
HashSet<String> emailAccounts = new HashSet<>();
AccountManager manager = (AccountManager) getContext().getSystemService(Context.ACCOUNT_SERVICE);
final Account[] accounts = manager.getAccounts();
for (Account account : accounts) {
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment