diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-07-17 00:03:37 +0200 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-07-17 00:03:37 +0200 |
commit | 38a9242955704232039272fd8b6011d47622495d (patch) | |
tree | 16665564834041b3c1218531d548449e64285f8d /src/eu/siacs/conversations/ui/adapter | |
parent | 670dead69502884d178ab60ec10e8e0e7b7a7915 (diff) |
brought muc invites back. + couple of bug fixes + refactoring
Diffstat (limited to 'src/eu/siacs/conversations/ui/adapter')
-rw-r--r-- | src/eu/siacs/conversations/ui/adapter/KnownHostsAdapter.java | 69 | ||||
-rw-r--r-- | src/eu/siacs/conversations/ui/adapter/ListItemAdapter.java | 39 |
2 files changed, 108 insertions, 0 deletions
diff --git a/src/eu/siacs/conversations/ui/adapter/KnownHostsAdapter.java b/src/eu/siacs/conversations/ui/adapter/KnownHostsAdapter.java new file mode 100644 index 00000000..040e6266 --- /dev/null +++ b/src/eu/siacs/conversations/ui/adapter/KnownHostsAdapter.java @@ -0,0 +1,69 @@ +package eu.siacs.conversations.ui.adapter; + +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 diff --git a/src/eu/siacs/conversations/ui/adapter/ListItemAdapter.java b/src/eu/siacs/conversations/ui/adapter/ListItemAdapter.java new file mode 100644 index 00000000..9ef427fc --- /dev/null +++ b/src/eu/siacs/conversations/ui/adapter/ListItemAdapter.java @@ -0,0 +1,39 @@ +package eu.siacs.conversations.ui.adapter; + +import java.util.List; + +import eu.siacs.conversations.R; +import eu.siacs.conversations.entities.ListItem; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.TextView; + +public class ListItemAdapter extends ArrayAdapter<ListItem> { + + public ListItemAdapter(Context context, List<ListItem> objects) { + super(context, 0, objects); + } + + @Override + public View getView(int position, View view, ViewGroup parent) { + LayoutInflater inflater = (LayoutInflater) getContext() + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + ListItem item = getItem(position); + if (view == null) { + view = (View) inflater.inflate(R.layout.contact, null); + } + TextView name = (TextView) view.findViewById(R.id.contact_display_name); + TextView jid = (TextView) view.findViewById(R.id.contact_jid); + ImageView picture = (ImageView) view.findViewById(R.id.contact_photo); + + jid.setText(item.getJid()); + name.setText(item.getDisplayName()); + picture.setImageBitmap(item.getImage(48, getContext())); + return view; + } + +}
\ No newline at end of file |