fixed #38
This commit is contained in:
parent
e97b524455
commit
a523127a80
|
@ -3,7 +3,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="16dp">
|
android:padding="8dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/your_account"
|
android:id="@+id/your_account"
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
android:textColor="@color/primarytext"
|
android:textColor="@color/primarytext"
|
||||||
android:text="@string/account_settings_jabber_id" />
|
android:text="@string/account_settings_jabber_id" />
|
||||||
|
|
||||||
<EditText
|
<AutoCompleteTextView
|
||||||
android:id="@+id/jid"
|
android:id="@+id/jid"
|
||||||
android:paddingTop="8dp"
|
android:paddingTop="8dp"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
|
|
|
@ -13,16 +13,14 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<EditText
|
<AutoCompleteTextView
|
||||||
android:id="@+id/account_jid"
|
android:id="@+id/account_jid"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:ems="10"
|
android:ems="10"
|
||||||
android:inputType="textEmailAddress"
|
android:inputType="textEmailAddress"
|
||||||
android:hint="@string/account_settings_example_jabber_id">
|
android:hint="@string/account_settings_example_jabber_id" />
|
||||||
|
|
||||||
|
|
||||||
</EditText>
|
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
|
|
@ -320,4 +320,13 @@ public class Contact implements ListItem {
|
||||||
public int compareTo(ListItem another) {
|
public int compareTo(ListItem another) {
|
||||||
return this.getDisplayName().compareToIgnoreCase(another.getDisplayName());
|
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.security.SecureRandom;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -1496,4 +1497,22 @@ public class XmppConnectionService extends Service {
|
||||||
}).start();
|
}).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;
|
package eu.siacs.conversations.ui;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
|
import eu.siacs.conversations.utils.KnownHostsAdapter;
|
||||||
import eu.siacs.conversations.utils.Validator;
|
import eu.siacs.conversations.utils.Validator;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.DialogFragment;
|
import android.app.DialogFragment;
|
||||||
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.AutoCompleteTextView;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
|
@ -19,6 +24,8 @@ import android.widget.TextView;
|
||||||
public class EditAccount extends DialogFragment {
|
public class EditAccount extends DialogFragment {
|
||||||
|
|
||||||
protected Account account;
|
protected Account account;
|
||||||
|
|
||||||
|
protected AutoCompleteTextView mAccountJid;
|
||||||
|
|
||||||
public void setAccount(Account account) {
|
public void setAccount(Account account) {
|
||||||
this.account = account;
|
this.account = account;
|
||||||
|
@ -30,16 +37,28 @@ public class EditAccount extends DialogFragment {
|
||||||
|
|
||||||
protected EditAccountListener listener = null;
|
protected EditAccountListener listener = null;
|
||||||
|
|
||||||
|
private KnownHostsAdapter mKnownHostsAdapter;
|
||||||
|
|
||||||
public void setEditAccountListener(EditAccountListener listener) {
|
public void setEditAccountListener(EditAccountListener listener) {
|
||||||
this.listener = 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
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||||
View view = inflater.inflate(R.layout.edit_account_dialog, null);
|
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
|
final TextView confirmPwDesc = (TextView) view
|
||||||
.findViewById(R.id.account_confirm_password_desc);
|
.findViewById(R.id.account_confirm_password_desc);
|
||||||
|
|
||||||
|
@ -51,7 +70,7 @@ public class EditAccount extends DialogFragment {
|
||||||
.findViewById(R.id.edit_account_register_new);
|
.findViewById(R.id.edit_account_register_new);
|
||||||
|
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
jidText.setText(account.getJid());
|
mAccountJid.setText(account.getJid());
|
||||||
password.setText(account.getPassword());
|
password.setText(account.getPassword());
|
||||||
if (account.isOptionSet(Account.OPTION_REGISTER)) {
|
if (account.isOptionSet(Account.OPTION_REGISTER)) {
|
||||||
registerAccount.setChecked(true);
|
registerAccount.setChecked(true);
|
||||||
|
|
|
@ -433,6 +433,7 @@ public class ManageAccountActivity extends XmppActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
dialog.show(getFragmentManager(), "edit_account");
|
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.show(getFragmentManager(), "add_account");
|
||||||
|
dialog.setKnownHosts(xmppConnectionService.getKnownHosts(),this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,6 @@ import android.app.Fragment;
|
||||||
import android.app.FragmentTransaction;
|
import android.app.FragmentTransaction;
|
||||||
import android.app.ListFragment;
|
import android.app.ListFragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.database.DataSetObserver;
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v13.app.FragmentPagerAdapter;
|
import android.support.v13.app.FragmentPagerAdapter;
|
||||||
|
@ -29,11 +27,10 @@ import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.EditText;
|
import android.widget.AutoCompleteTextView;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.SearchView;
|
import android.widget.SearchView;
|
||||||
import android.widget.SpinnerAdapter;
|
|
||||||
import android.widget.SearchView.OnQueryTextListener;
|
import android.widget.SearchView.OnQueryTextListener;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
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.Contact;
|
||||||
import eu.siacs.conversations.entities.Conversation;
|
import eu.siacs.conversations.entities.Conversation;
|
||||||
import eu.siacs.conversations.entities.ListItem;
|
import eu.siacs.conversations.entities.ListItem;
|
||||||
|
import eu.siacs.conversations.utils.KnownHostsAdapter;
|
||||||
import eu.siacs.conversations.utils.UIHelper;
|
import eu.siacs.conversations.utils.UIHelper;
|
||||||
import eu.siacs.conversations.utils.Validator;
|
import eu.siacs.conversations.utils.Validator;
|
||||||
|
|
||||||
|
@ -61,6 +59,7 @@ public class StartConversation extends XmppActivity {
|
||||||
private ArrayAdapter<ListItem> mConferenceAdapter;
|
private ArrayAdapter<ListItem> mConferenceAdapter;
|
||||||
|
|
||||||
private List<String> mActivatedAccounts = new ArrayList<String>();
|
private List<String> mActivatedAccounts = new ArrayList<String>();
|
||||||
|
private List<String> mKnownHosts;
|
||||||
|
|
||||||
private TabListener mTabListener = new TabListener() {
|
private TabListener mTabListener = new TabListener() {
|
||||||
|
|
||||||
|
@ -176,7 +175,8 @@ public class StartConversation extends XmppActivity {
|
||||||
builder.setTitle(R.string.create_contact);
|
builder.setTitle(R.string.create_contact);
|
||||||
View dialogView = getLayoutInflater().inflate(R.layout.create_contact_dialog, null);
|
View dialogView = getLayoutInflater().inflate(R.layout.create_contact_dialog, null);
|
||||||
final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account);
|
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);
|
populateAccountSpinner(spinner);
|
||||||
builder.setView(dialogView);
|
builder.setView(dialogView);
|
||||||
builder.setNegativeButton(R.string.cancel, null);
|
builder.setNegativeButton(R.string.cancel, null);
|
||||||
|
@ -259,6 +259,7 @@ public class StartConversation extends XmppActivity {
|
||||||
this.mActivatedAccounts.add(account.getJid());
|
this.mActivatedAccounts.add(account.getJid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.mKnownHosts = xmppConnectionService.getKnownHosts();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void filterContacts(String needle) {
|
protected void filterContacts(String needle) {
|
||||||
|
|
69
src/eu/siacs/conversations/utils/KnownHostsAdapter.java
Normal file
69
src/eu/siacs/conversations/utils/KnownHostsAdapter.java
Normal file
|
@ -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 a new issue