Creation of chat worked
This commit is contained in:
parent
1fc73e18fe
commit
f8bf1b24c5
7 changed files with 254 additions and 34 deletions
30
res/layout/contact_selected.xml
Normal file
30
res/layout/contact_selected.xml
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginRight="5dp"
|
||||
>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/contactChatDelete"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginRight="3dp"
|
||||
android:gravity="center"
|
||||
android:src="@drawable/chat_group_delete"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sipUri"
|
||||
style="@style/font6"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginRight="5dp"
|
||||
android:layout_toEndOf="@+id/contactChatDelete"
|
||||
android:layout_toRightOf="@+id/contactChatDelete"
|
||||
android:gravity="center"
|
||||
android:lines="1"
|
||||
android:scrollHorizontally="true"/>
|
||||
|
||||
</RelativeLayout>
|
|
@ -112,10 +112,32 @@
|
|||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_below="@+id/layoutSearchField"
|
||||
<HorizontalScrollView
|
||||
android:id="@+id/layoutContactsSelected"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="50dp"
|
||||
android:layout_below="@+id/layoutSearchField"
|
||||
android:layout_marginTop="5dp"
|
||||
android:background="@drawable/resizable_textfield"
|
||||
android:lines="1"
|
||||
android:visibility="gone">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/contactsSelected"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:lines="1"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp"
|
||||
android:scrollIndicators="bottom"/>
|
||||
</HorizontalScrollView>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_below="@+id/layoutContactsSelected"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/relativeLayout">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/contactsList"
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
android:layout_alignParentRight="true"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_gravity="right"
|
||||
android:visibility="invisible"
|
||||
android:paddingRight="20dp"
|
||||
android:src="@drawable/check_unselected"/>
|
||||
android:src="@drawable/check_selected"/>
|
||||
</RelativeLayout>
|
||||
|
|
|
@ -28,11 +28,16 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.EditText;
|
||||
import android.widget.HorizontalScrollView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Erwan Croze.
|
||||
*/
|
||||
|
@ -40,7 +45,10 @@ import android.widget.TextView;
|
|||
public class ChatCreationFragment extends Fragment implements View.OnClickListener, AdapterView.OnItemClickListener, ContactsUpdatedListener {
|
||||
private LayoutInflater mInflater;
|
||||
private ListView contactsList;
|
||||
private LinearLayout contactsSelectedLayout;
|
||||
private HorizontalScrollView contactsSelectLayout;
|
||||
private TextView noSipContact, noContact;
|
||||
private List<ContactAddress> contactsSelected;
|
||||
private ImageView allContacts, linphoneContacts;
|
||||
private boolean onlyDisplayLinphoneContacts;
|
||||
private View allContactsSelected, linphoneContactsSelected;
|
||||
|
@ -48,18 +56,20 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
|
|||
private EditText searchField;
|
||||
private ProgressBar contactsFetchInProgress;
|
||||
private SearchContactsListAdapter searchAdapter;
|
||||
private ImageView back;
|
||||
private ImageView back, next;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
mInflater = inflater;
|
||||
View view = inflater.inflate(R.layout.create_chat, container, false);
|
||||
contactsSelected = new ArrayList<ContactAddress>();
|
||||
|
||||
noSipContact = (TextView) view.findViewById(R.id.noSipContact);
|
||||
noContact = (TextView) view.findViewById(R.id.noContact);
|
||||
|
||||
contactsList = (ListView) view.findViewById(R.id.contactsList);
|
||||
contactsList.setOnItemClickListener(this);
|
||||
contactsSelectedLayout = (LinearLayout) view.findViewById(R.id.contactsSelected);
|
||||
contactsSelectLayout = (HorizontalScrollView) view.findViewById(R.id.layoutContactsSelected);
|
||||
|
||||
allContacts = (ImageView) view.findViewById(R.id.all_contacts);
|
||||
allContacts.setOnClickListener(this);
|
||||
|
@ -76,6 +86,9 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
|
|||
back = (ImageView) view.findViewById(R.id.back);
|
||||
back.setOnClickListener(this);
|
||||
|
||||
next = (ImageView) view.findViewById(R.id.next);
|
||||
next.setOnClickListener(this);
|
||||
|
||||
clearSearchField = (ImageView) view.findViewById(R.id.clearSearchField);
|
||||
clearSearchField.setOnClickListener(this);
|
||||
|
||||
|
@ -84,6 +97,8 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
|
|||
|
||||
searchAdapter = new SearchContactsListAdapter(null, mInflater, contactsFetchInProgress);
|
||||
contactsList.setAdapter(searchAdapter);
|
||||
contactsList.setOnItemClickListener(this);
|
||||
|
||||
|
||||
searchField = (EditText) view.findViewById(R.id.searchField);
|
||||
searchField.addTextChangedListener(new TextWatcher() {
|
||||
|
@ -107,7 +122,48 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
|
|||
return view;
|
||||
}
|
||||
|
||||
public ChatCreationFragment() {
|
||||
private void updateList() {
|
||||
searchAdapter.searchContacts(searchField.getText().toString(), contactsList);
|
||||
searchAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void updateListSelected() {
|
||||
if (contactsSelected.size() > 0) {
|
||||
contactsSelectLayout.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
contactsSelectLayout.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateContactsClick(ContactAddress ca) {
|
||||
if(ca.isSelect()) {
|
||||
ContactSelectView csv = new ContactSelectView(LinphoneActivity.instance());
|
||||
csv.setListener(this);
|
||||
csv.setContactName(ca);
|
||||
contactsSelected.add(ca);
|
||||
View viewContact = LayoutInflater.from(LinphoneActivity.instance()).inflate(R.layout.contact_selected, null);
|
||||
((TextView)viewContact.findViewById(R.id.sipUri)).setText(ca.getContact().getFullName());
|
||||
viewContact.findViewById(R.id.contactChatDelete).setOnClickListener(this);
|
||||
ca.setView(viewContact);
|
||||
contactsSelectedLayout.addView(viewContact);
|
||||
} else {
|
||||
contactsSelected.remove(ca);
|
||||
contactsSelectedLayout.removeAllViews();
|
||||
for (ContactAddress contactAddress : contactsSelected) {
|
||||
contactsSelectedLayout.addView(contactAddress.getView());
|
||||
}
|
||||
}
|
||||
searchAdapter.setContactsSelectedList(contactsSelected);
|
||||
contactsSelectedLayout.invalidate();
|
||||
}
|
||||
|
||||
private void removeContactFromView(View v) {
|
||||
for (ContactAddress ca : contactsSelected) {
|
||||
if (ca.getView() == v) {
|
||||
ca.setSelect(false);
|
||||
updateContactsClick(ca);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -119,16 +175,14 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
|
|||
allContacts.setEnabled(false);
|
||||
linphoneContacts.setEnabled(true);
|
||||
linphoneContactsSelected.setVisibility(View.INVISIBLE);
|
||||
searchAdapter.setContactsList(null);
|
||||
searchAdapter.searchContacts(searchField.getText().toString(), contactsList);
|
||||
updateList();
|
||||
} else if (id == R.id.linphone_contacts) {
|
||||
searchAdapter.setOnlySipContact(true);
|
||||
linphoneContactsSelected.setVisibility(View.VISIBLE);
|
||||
linphoneContacts.setEnabled(false);
|
||||
allContacts.setEnabled(onlyDisplayLinphoneContacts = true);
|
||||
allContactsSelected.setVisibility(View.INVISIBLE);
|
||||
searchAdapter.setContactsList(null);
|
||||
searchAdapter.searchContacts(searchField.getText().toString(), contactsList);
|
||||
updateList();
|
||||
} else if (id == R.id.back) {
|
||||
getFragmentManager().popBackStackImmediate();
|
||||
} else if (id == R.id.next) {
|
||||
|
@ -136,16 +190,24 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
|
|||
} else if (id == R.id.clearSearchField) {
|
||||
searchField.setText("");
|
||||
searchAdapter.searchContacts("", contactsList);
|
||||
} else if (id == R.id.deleteContact) {
|
||||
//TODO
|
||||
removeContactFromView(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
||||
|
||||
// Get contact
|
||||
ContactAddress ca = searchAdapter.getContacts().get(i);
|
||||
ca.setSelect(!ca.isSelect());
|
||||
updateContactsClick(ca);
|
||||
updateList();
|
||||
updateListSelected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContactsUpdated() {
|
||||
|
||||
searchAdapter.searchContacts(searchField.getText().toString(), contactsList);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,16 +19,35 @@ along with this program; if not, write to the Free Software
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
import android.view.View;
|
||||
|
||||
public class ContactAddress {
|
||||
LinphoneContact contact;
|
||||
String address;
|
||||
boolean isLinphoneContact;
|
||||
boolean isSelect = false;
|
||||
private LinphoneContact contact;
|
||||
private String address;
|
||||
private boolean isLinphoneContact;
|
||||
private boolean isSelect = false;
|
||||
private View view;
|
||||
|
||||
public boolean isSelect() {
|
||||
return isSelect;
|
||||
}
|
||||
|
||||
public void setView(View v) {
|
||||
view = v;
|
||||
}
|
||||
|
||||
public View getView() {
|
||||
return view;
|
||||
}
|
||||
|
||||
public LinphoneContact getContact() {
|
||||
return contact;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setSelect(boolean select) {
|
||||
isSelect = select;
|
||||
}
|
||||
|
@ -42,4 +61,13 @@ public class ContactAddress {
|
|||
this.address = a;
|
||||
this.isLinphoneContact = isLC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other){
|
||||
if (other == null) return false;
|
||||
if (other == this) return true;
|
||||
if (!(other instanceof ContactAddress))return false;
|
||||
if (((ContactAddress)other).getAddress() == this.getAddress()) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
60
src/android/org/linphone/ContactSelectView.java
Normal file
60
src/android/org/linphone/ContactSelectView.java
Normal file
|
@ -0,0 +1,60 @@
|
|||
package org.linphone;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
/*
|
||||
ContactSelectView.java
|
||||
Copyright (C) 2017 Belledonne Communications, Grenoble, France
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Created by Erwan Croze.
|
||||
*/
|
||||
|
||||
public class ContactSelectView extends View {
|
||||
private TextView contactName;
|
||||
private ImageView deleteContact;
|
||||
|
||||
ContactSelectView(Context context) {
|
||||
super(context);
|
||||
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE );
|
||||
|
||||
View view = inflater.inflate(R.layout.contact_selected, null);
|
||||
|
||||
contactName = view.findViewById(R.id.sipUri);
|
||||
deleteContact = view.findViewById(R.id.contactChatDelete);
|
||||
|
||||
}
|
||||
|
||||
public void setContactName(ContactAddress ca) {
|
||||
if (ca.getContact() != null) {
|
||||
contactName.setText(ca.getContact().getFirstName());
|
||||
} else {
|
||||
LinphoneManager.getLc().createFriendWithAddress(ca.getAddress()).getName();
|
||||
contactName.setText(ca.getAddress());
|
||||
}
|
||||
}
|
||||
|
||||
public void setListener(OnClickListener listener) {
|
||||
deleteContact.setOnClickListener(listener);
|
||||
}
|
||||
}
|
|
@ -19,7 +19,6 @@ along with this program; if not, write to the Free Software
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
import android.media.Image;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -38,6 +37,7 @@ import java.util.Locale;
|
|||
*/
|
||||
|
||||
public class SearchContactsListAdapter extends BaseAdapter {
|
||||
|
||||
private class ViewHolder {
|
||||
public TextView name;
|
||||
public TextView address;
|
||||
|
@ -52,14 +52,16 @@ public class SearchContactsListAdapter extends BaseAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
public List<ContactAddress> getContacts() {
|
||||
return contacts;
|
||||
}
|
||||
|
||||
private List<ContactAddress> contacts;
|
||||
private List<ContactAddress> contactsSelected;
|
||||
private LayoutInflater mInflater;
|
||||
private ProgressBar progressBar;
|
||||
private boolean mOnlySipContact = false;
|
||||
private View.OnClickListener listener;
|
||||
|
||||
public List<ContactAddress> getContacts() {
|
||||
return contacts;
|
||||
}
|
||||
|
||||
public void setOnlySipContact(boolean enable) {
|
||||
mOnlySipContact = enable;
|
||||
|
@ -69,11 +71,10 @@ public class SearchContactsListAdapter extends BaseAdapter {
|
|||
this.listener = listener;
|
||||
}
|
||||
|
||||
private View.OnClickListener listener;
|
||||
|
||||
SearchContactsListAdapter(List<ContactAddress> contactsList, LayoutInflater inflater, ProgressBar pB) {
|
||||
mInflater = inflater;
|
||||
progressBar = pB;
|
||||
setContactsSelectedList(null);
|
||||
setContactsList(contactsList);
|
||||
}
|
||||
|
||||
|
@ -87,6 +88,14 @@ public class SearchContactsListAdapter extends BaseAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
public void setContactsSelectedList(List<ContactAddress> contactsList) {
|
||||
if (contactsList == null) {
|
||||
contactsSelected = new ArrayList<ContactAddress>();
|
||||
} else {
|
||||
contactsSelected = contactsList;
|
||||
}
|
||||
}
|
||||
|
||||
public List<ContactAddress> getContactsList() {
|
||||
List<ContactAddress> list = new ArrayList<ContactAddress>();
|
||||
if(ContactsManager.getInstance().hasContacts()) {
|
||||
|
@ -99,10 +108,17 @@ public class SearchContactsListAdapter extends BaseAdapter {
|
|||
value = value.substring(4);
|
||||
value = LinphoneUtils.getFullAddressFromUsername(value);
|
||||
}
|
||||
list.add(new ContactAddress(con, value, con.isInLinphoneFriendList()));
|
||||
ContactAddress ca = new ContactAddress(con, value, con.isInLinphoneFriendList());
|
||||
list.add(ca);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (ContactAddress caS : contactsSelected) {
|
||||
for (ContactAddress ca : list) {
|
||||
if (ca.equals(caS)) ca.setSelect(true);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
@ -125,7 +141,7 @@ public class SearchContactsListAdapter extends BaseAdapter {
|
|||
|
||||
public void searchContacts(String search, ListView resultContactsSearch) {
|
||||
if (search == null || search.length() == 0) {
|
||||
setContactsList(null);
|
||||
contacts = getContactsList();
|
||||
resultContactsSearch.setAdapter(this);
|
||||
return;
|
||||
}
|
||||
|
@ -133,9 +149,10 @@ public class SearchContactsListAdapter extends BaseAdapter {
|
|||
List<ContactAddress> result = new ArrayList<ContactAddress>();
|
||||
if(search != null) {
|
||||
for (ContactAddress c : getContacts()) {
|
||||
String address = c.address;
|
||||
String address = c.getAddress();
|
||||
if (address.startsWith("sip:")) address = address.substring(4);
|
||||
if (c.contact.getFullName() != null && c.contact.getFullName().toLowerCase(Locale.getDefault()).startsWith(search.toLowerCase(Locale.getDefault()))
|
||||
if (c.getContact().getFullName() != null
|
||||
&& c.getContact().getFullName().toLowerCase(Locale.getDefault()).startsWith(search.toLowerCase(Locale.getDefault()))
|
||||
|| address.toLowerCase(Locale.getDefault()).startsWith(search.toLowerCase(Locale.getDefault()))) {
|
||||
result.add(c);
|
||||
}
|
||||
|
@ -166,8 +183,8 @@ public class SearchContactsListAdapter extends BaseAdapter {
|
|||
view.setTag(holder);
|
||||
}
|
||||
|
||||
final String a = contact.address;
|
||||
LinphoneContact c = contact.contact;
|
||||
final String a = contact.getAddress();
|
||||
LinphoneContact c = contact.getContact();
|
||||
|
||||
holder.name.setText(c.getFullName());
|
||||
holder.address.setText(a);
|
||||
|
@ -180,14 +197,14 @@ public class SearchContactsListAdapter extends BaseAdapter {
|
|||
}
|
||||
if (holder.isSelect != null) {
|
||||
if (contact.isSelect()) {
|
||||
holder.isSelect.setImageResource(R.drawable.check_selected);
|
||||
holder.isSelect.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.isSelect.setImageResource(R.drawable.check_unselected);
|
||||
holder.isSelect.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
view.setTag(R.id.contact_search_name, a);
|
||||
view.setOnClickListener(listener);
|
||||
|
||||
if (listener != null)
|
||||
view.setOnClickListener(listener);
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue