fixed #38
This commit is contained in:
parent
e97b524455
commit
a523127a80
|
@ -3,7 +3,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
android:padding="8dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/your_account"
|
||||
|
@ -26,7 +26,7 @@
|
|||
android:textColor="@color/primarytext"
|
||||
android:text="@string/account_settings_jabber_id" />
|
||||
|
||||
<EditText
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/jid"
|
||||
android:paddingTop="8dp"
|
||||
android:layout_width="fill_parent"
|
||||
|
|
|
@ -13,17 +13,15 @@
|
|||
|
||||
|
||||
|
||||
<EditText
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/account_jid"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:inputType="textEmailAddress"
|
||||
android:hint="@string/account_settings_example_jabber_id">
|
||||
android:hint="@string/account_settings_example_jabber_id" />
|
||||
|
||||
|
||||
</EditText>
|
||||
|
||||
|
||||
<TextView
|
||||
android:paddingTop="8dp"
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -1496,4 +1497,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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -20,6 +25,8 @@ 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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue