diff options
Diffstat (limited to 'src/eu/siacs/conversations')
6 files changed, 128 insertions, 11 deletions
diff --git a/src/eu/siacs/conversations/entities/Contact.java b/src/eu/siacs/conversations/entities/Contact.java index 59e0fa12..248d41b7 100644 --- a/src/eu/siacs/conversations/entities/Contact.java +++ b/src/eu/siacs/conversations/entities/Contact.java @@ -320,4 +320,13 @@ public class Contact implements ListItem { public int compareTo(ListItem another) { return this.getDisplayName().compareToIgnoreCase(another.getDisplayName()); } + + public String getServer() { + String[] split = getJid().split("@"); + if (split.length >= 2) { + return split[1]; + } else { + return null; + } + } } diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 9993dd67..6c652f8d 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -2,6 +2,7 @@ package eu.siacs.conversations.services; import java.security.SecureRandom; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; @@ -430,6 +431,7 @@ public class XmppConnectionService extends Service { contact.resetOption(Contact.Options.DIRTY_DELETE); } else { contact.setOption(Contact.Options.IN_ROSTER); + contact.resetOption(Contact.Options.DIRTY_PUSH); contact.parseSubscriptionFromElement(item); } } @@ -1262,6 +1264,7 @@ public class XmppConnectionService extends Service { public void pushContactToServer(Contact contact) { contact.resetOption(Contact.Options.DIRTY_DELETE); + contact.setOption(Contact.Options.DIRTY_PUSH); Account account = contact.getAccount(); if (account.getStatus() == Account.STATUS_ONLINE) { IqPacket iq = new IqPacket(IqPacket.TYPE_SET); @@ -1274,9 +1277,6 @@ public class XmppConnectionService extends Service { Log.d("xmppService", "contact had pending subscription"); sendPresenceUpdatesTo(contact); } - contact.resetOption(Contact.Options.DIRTY_PUSH); - } else { - contact.setOption(Contact.Options.DIRTY_PUSH); } } @@ -1290,7 +1290,6 @@ public class XmppConnectionService extends Service { item.setAttribute("jid", contact.getJid()); item.setAttribute("subscription", "remove"); account.getXmppConnection().sendIqPacket(iq, null); - contact.resetOption(Contact.Options.DIRTY_DELETE); } } @@ -1496,4 +1495,22 @@ public class XmppConnectionService extends Service { }).start(); } + + public List<String> getKnownHosts() { + List<String> hosts = new ArrayList<String>(); + for(Account account : getAccounts()) { + if (!hosts.contains(account.getServer())) { + hosts.add(account.getServer()); + } + for(Contact contact : account.getRoster().getContacts()) { + if (contact.showInRoster()) { + String server = contact.getServer(); + if (server!=null && !hosts.contains(server)) { + hosts.add(server); + } + } + } + } + return hosts; + } } diff --git a/src/eu/siacs/conversations/ui/EditAccount.java b/src/eu/siacs/conversations/ui/EditAccount.java index e1bcaeb5..9a0b8d84 100644 --- a/src/eu/siacs/conversations/ui/EditAccount.java +++ b/src/eu/siacs/conversations/ui/EditAccount.java @@ -1,14 +1,19 @@ package eu.siacs.conversations.ui; +import java.util.List; + import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.utils.KnownHostsAdapter; import eu.siacs.conversations.utils.Validator; import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; +import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; +import android.widget.AutoCompleteTextView; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; @@ -19,6 +24,8 @@ import android.widget.TextView; public class EditAccount extends DialogFragment { protected Account account; + + protected AutoCompleteTextView mAccountJid; public void setAccount(Account account) { this.account = account; @@ -30,16 +37,28 @@ public class EditAccount extends DialogFragment { protected EditAccountListener listener = null; + private KnownHostsAdapter mKnownHostsAdapter; + public void setEditAccountListener(EditAccountListener listener) { this.listener = listener; } + + public void setKnownHosts(List<String> hosts, Context context) { + this.mKnownHostsAdapter = new KnownHostsAdapter(context, android.R.layout.simple_list_item_1, hosts); + if (this.mAccountJid != null) { + this.mAccountJid.setAdapter(this.mKnownHostsAdapter); + } + } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.edit_account_dialog, null); - final EditText jidText = (EditText) view.findViewById(R.id.account_jid); + mAccountJid = (AutoCompleteTextView) view.findViewById(R.id.account_jid); + if (this.mKnownHostsAdapter!=null) { + mAccountJid.setAdapter(this.mKnownHostsAdapter); + } final TextView confirmPwDesc = (TextView) view .findViewById(R.id.account_confirm_password_desc); @@ -51,7 +70,7 @@ public class EditAccount extends DialogFragment { .findViewById(R.id.edit_account_register_new); if (account != null) { - jidText.setText(account.getJid()); + mAccountJid.setText(account.getJid()); password.setText(account.getPassword()); if (account.isOptionSet(Account.OPTION_REGISTER)) { registerAccount.setChecked(true); diff --git a/src/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/eu/siacs/conversations/ui/ManageAccountActivity.java index c52916a2..f72e3d93 100644 --- a/src/eu/siacs/conversations/ui/ManageAccountActivity.java +++ b/src/eu/siacs/conversations/ui/ManageAccountActivity.java @@ -433,6 +433,7 @@ public class ManageAccountActivity extends XmppActivity { } }); dialog.show(getFragmentManager(), "edit_account"); + dialog.setKnownHosts(xmppConnectionService.getKnownHosts(),this); } @@ -449,6 +450,7 @@ public class ManageAccountActivity extends XmppActivity { } }); dialog.show(getFragmentManager(), "add_account"); + dialog.setKnownHosts(xmppConnectionService.getKnownHosts(),this); } diff --git a/src/eu/siacs/conversations/ui/StartConversation.java b/src/eu/siacs/conversations/ui/StartConversation.java index 880b4a9b..3986929f 100644 --- a/src/eu/siacs/conversations/ui/StartConversation.java +++ b/src/eu/siacs/conversations/ui/StartConversation.java @@ -12,8 +12,6 @@ import android.app.Fragment; import android.app.FragmentTransaction; import android.app.ListFragment; import android.content.Context; -import android.content.DialogInterface; -import android.database.DataSetObserver; import android.graphics.Color; import android.os.Bundle; import android.support.v13.app.FragmentPagerAdapter; @@ -29,11 +27,10 @@ import android.widget.AdapterView; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; -import android.widget.EditText; +import android.widget.AutoCompleteTextView; import android.widget.ImageView; import android.widget.ListView; import android.widget.SearchView; -import android.widget.SpinnerAdapter; import android.widget.SearchView.OnQueryTextListener; import android.widget.Spinner; import android.widget.TextView; @@ -42,6 +39,7 @@ import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.ListItem; +import eu.siacs.conversations.utils.KnownHostsAdapter; import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.Validator; @@ -61,6 +59,7 @@ public class StartConversation extends XmppActivity { private ArrayAdapter<ListItem> mConferenceAdapter; private List<String> mActivatedAccounts = new ArrayList<String>(); + private List<String> mKnownHosts; private TabListener mTabListener = new TabListener() { @@ -176,7 +175,8 @@ public class StartConversation extends XmppActivity { builder.setTitle(R.string.create_contact); View dialogView = getLayoutInflater().inflate(R.layout.create_contact_dialog, null); final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account); - final EditText jid = (EditText) dialogView.findViewById(R.id.jid); + final AutoCompleteTextView jid = (AutoCompleteTextView) dialogView.findViewById(R.id.jid); + jid.setAdapter(new KnownHostsAdapter(this, android.R.layout.simple_list_item_1, mKnownHosts)); populateAccountSpinner(spinner); builder.setView(dialogView); builder.setNegativeButton(R.string.cancel, null); @@ -259,6 +259,7 @@ public class StartConversation extends XmppActivity { this.mActivatedAccounts.add(account.getJid()); } } + this.mKnownHosts = xmppConnectionService.getKnownHosts(); } protected void filterContacts(String needle) { diff --git a/src/eu/siacs/conversations/utils/KnownHostsAdapter.java b/src/eu/siacs/conversations/utils/KnownHostsAdapter.java new file mode 100644 index 00000000..a0a223dd --- /dev/null +++ b/src/eu/siacs/conversations/utils/KnownHostsAdapter.java @@ -0,0 +1,69 @@ +package eu.siacs.conversations.utils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import android.content.Context; +import android.widget.ArrayAdapter; +import android.widget.Filter; + +public class KnownHostsAdapter extends ArrayAdapter<String> { + private ArrayList<String> domains; + private Filter domainFilter = new Filter() { + + @Override + protected FilterResults performFiltering(CharSequence constraint) { + if (constraint != null) { + ArrayList<String> suggestions = new ArrayList<String>(); + final String[] split = constraint.toString().split("@"); + if (split.length == 1) { + for (String domain : domains) { + suggestions.add(split[0].toLowerCase(Locale.getDefault()) + "@" + domain); + } + } else if (split.length == 2) { + for (String domain : domains) { + if (domain.contains(split[1])) { + suggestions.add(split[0].toLowerCase(Locale.getDefault()) + "@" + domain); + } + } + } else { + return new FilterResults(); + } + FilterResults filterResults = new FilterResults(); + filterResults.values = suggestions; + filterResults.count = suggestions.size(); + return filterResults; + } else { + return new FilterResults(); + } + } + + @Override + protected void publishResults(CharSequence constraint, + FilterResults results) { + ArrayList<String> filteredList = ((ArrayList<String>) results.values); + if (results != null && results.count > 0) { + clear(); + for (String c : filteredList) { + add(c); + } + notifyDataSetChanged(); + } + } + }; + + public KnownHostsAdapter(Context context, int viewResourceId, + List<String> mKnownHosts) { + super(context, viewResourceId, mKnownHosts); + domains = new ArrayList<String>(mKnownHosts.size()); + for (String domain : mKnownHosts) { + domains.add(new String(domain)); + } + } + + @Override + public Filter getFilter() { + return domainFilter; + } +}
\ No newline at end of file |