From 6b0e9c35923d66d658f81168bc0da50046a8e1bd Mon Sep 17 00:00:00 2001 From: Brieuc Viel Date: Mon, 18 Apr 2016 16:31:24 +0200 Subject: [PATCH] [Presence] chat fragment updated from master --- src/org/linphone/ChatFragment.java | 72 +++++++++++++++++------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/src/org/linphone/ChatFragment.java b/src/org/linphone/ChatFragment.java index 99aeb4791..c6faa037b 100644 --- a/src/org/linphone/ChatFragment.java +++ b/src/org/linphone/ChatFragment.java @@ -22,11 +22,8 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; -import java.util.Map; import org.linphone.compatibility.Compatibility; import org.linphone.core.LinphoneAddress; @@ -38,7 +35,6 @@ import org.linphone.core.LinphoneContent; import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCoreFactory; import org.linphone.core.LinphoneCoreListenerBase; -import org.linphone.core.LinphoneFriend; import org.linphone.mediastream.Log; import org.linphone.ui.BubbleChat; @@ -81,7 +77,6 @@ import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.EditText; -import android.widget.Filterable; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; @@ -392,7 +387,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC registerForContextMenu(v); RelativeLayout rlayout = new RelativeLayout(context); - CheckBox deleteChatBubble = (CheckBox) v.findViewById(R.id.delete); + /* CheckBox deleteChatBubble = (CheckBox) v.findViewById(R.id.delete_message); if(isEditMode) { deleteChatBubble.setVisibility(View.VISIBLE); @@ -402,7 +397,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC layoutParams.setMargins(100, 10, 10, 10); v.setLayoutParams(layoutParams); } else { - LinearLayout message_layout = (LinearLayout) v.findViewById(R.id.message_layout); + LinearLayout message_layout = (LinearLayout) v.findViewById(R.id.message_content); message_layout.setGravity(Gravity.RIGHT); } @@ -449,6 +444,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC } rlayout.addView(v); } + */ return rlayout; } } @@ -1006,48 +1002,64 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC } } - - - private void searchContacts(String search) { if (search == null || search.length() == 0) { resultContactsSearch.setAdapter(new SearchContactsListAdapter(null)); return; } - List result = new ArrayList(); - /* if(search != null) { + List result = new ArrayList(); + if(search != null) { for (ContactAddress c : searchAdapter.contacts) { String address = c.address; if(address.startsWith("sip:")) address = address.substring(4); - if (c.contact.getFullName().toLowerCase().startsWith(search.toLowerCase()) || address.toLowerCase().startsWith(search.toLowerCase())) { + if (c.contact.getFullName().toLowerCase(Locale.getDefault()).startsWith(search.toLowerCase(Locale.getDefault())) + || address.toLowerCase(Locale.getDefault()).startsWith(search.toLowerCase(Locale.getDefault()))) { result.add(c); } } } - */ + resultContactsSearch.setAdapter(new SearchContactsListAdapter(result)); searchAdapter.notifyDataSetChanged(); } - - class SearchContactsListAdapter extends BaseAdapter { + private List contacts; private LayoutInflater mInflater; - private List contacts; - Map map = new LinkedHashMap(); - SearchContactsListAdapter(List contactsList) { - contacts = contactsList; + SearchContactsListAdapter(List contactsList) { + mInflater = inflater; + if(contactsList == null){ + contacts = getContactsList(); + } else { + contacts = contactsList; + } + } + public List getContactsList() { + List list = new ArrayList(); + if(ContactsManager.getInstance().hasContacts()) { + for (LinphoneContact con : ContactsManager.getInstance().getContacts()) { + for (LinphoneNumberOrAddress noa : con.getNumbersOrAddresses()) { + list.add(new ContactAddress(con, noa.getValue())); + } + } + } + return list; } public int getCount() { return contacts.size(); } - public LinphoneContact getItem(int position) { - return contacts.get(position); + public ContactAddress getItem(int position) { + if (contacts == null || position >= contacts.size()) { + contacts = getContactsList(); + return contacts.get(position); + } else { + return contacts.get(position); + } } public long getItemId(int position) { @@ -1056,10 +1068,10 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC public View getView(int position, View convertView, ViewGroup parent) { View view = null; - LinphoneContact c; + ContactAddress contact; do { - c = getItem(position); - } while (c == null); + contact = getItem(position); + } while (contact == null); if (convertView != null) { view = convertView; @@ -1067,19 +1079,19 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC view = mInflater.inflate(R.layout.search_contact_cell, parent, false); } - final String a = contact.getFullName(); - //final LinphoneContact c = contact; + final String a = contact.address; + final LinphoneContact c = contact.contact; TextView name = (TextView) view.findViewById(R.id.contact_name); name.setText(c.getFullName()); - final String laddress = c.getNumbersOrAddresses().get(0).toString(); + TextView address = (TextView) view.findViewById(R.id.contact_address); + address.setText(a); view.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { - //exitNewConversationMode(c, a, null); - exitNewConversationMode(laddress); + exitNewConversationMode(a); } });