Rework new conversation display
This commit is contained in:
parent
b93c885b7e
commit
b691e107e3
3 changed files with 87 additions and 65 deletions
|
@ -132,20 +132,31 @@
|
||||||
android:layout_margin="10dp"
|
android:layout_margin="10dp"
|
||||||
android:layout_below="@+id/top_bar"/>
|
android:layout_below="@+id/top_bar"/>
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
|
||||||
<AutoCompleteTextView
|
|
||||||
android:id="@+id/search_contact_field"
|
android:id="@+id/search_contact_field"
|
||||||
android:background="@drawable/resizable_textfield"
|
android:contentDescription="@string/content_description_search"
|
||||||
android:hint="@string/search"
|
|
||||||
android:inputType="textPersonName"
|
|
||||||
android:completionThreshold="1"
|
|
||||||
android:textCursorDrawable="@null"
|
android:textCursorDrawable="@null"
|
||||||
android:visibility="gone"
|
|
||||||
android:layout_margin="10dp"
|
|
||||||
android:layout_below="@id/top_bar"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="40dp"
|
android:layout_height="40dp"
|
||||||
android:paddingRight="5dp"/>
|
android:visibility="gone"
|
||||||
|
android:textColor="@android:color/black"
|
||||||
|
android:background="@drawable/resizable_textfield"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_margin="5dp"
|
||||||
|
android:layout_below="@id/top_bar"
|
||||||
|
android:inputType="textPersonName"/>
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/result_contacts"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:divider="@color/colorE"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_below="@id/search_contact_field"
|
||||||
|
android:fastScrollAlwaysVisible="true"
|
||||||
|
android:fastScrollEnabled="true"
|
||||||
|
android:dividerHeight="1dp"
|
||||||
|
android:layout_above="@+id/footer"/>
|
||||||
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
|
@ -28,7 +28,6 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
android:textColor="@color/colorB"
|
android:textColor="@color/colorB"
|
||||||
android:text="@string/draft"
|
|
||||||
android:layout_marginLeft="5dp"
|
android:layout_marginLeft="5dp"
|
||||||
android:layout_marginRight="5dp" />
|
android:layout_marginRight="5dp" />
|
||||||
|
|
||||||
|
|
|
@ -73,14 +73,11 @@ import android.view.ViewTreeObserver;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.AbsListView;
|
import android.widget.AbsListView;
|
||||||
import android.widget.AutoCompleteTextView;
|
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.Filter;
|
|
||||||
import android.widget.Filterable;
|
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
@ -113,10 +110,12 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
private ImageView edit, selectAll, deselectAll, startCall, delete, sendImage, sendMessage, cancel;
|
private ImageView edit, selectAll, deselectAll, startCall, delete, sendImage, sendMessage, cancel;
|
||||||
private TextView contactName, remoteComposing;
|
private TextView contactName, remoteComposing;
|
||||||
private ImageView back, backToCall;
|
private ImageView back, backToCall;
|
||||||
private AutoCompleteTextView searchContactField;
|
private EditText searchContactField;
|
||||||
private LinearLayout topBar, editList;
|
private LinearLayout topBar, editList;
|
||||||
private LinearLayout textLayout;
|
private LinearLayout textLayout;
|
||||||
private ListView messagesList;
|
private SearchContactsListAdapter searchAdapter;
|
||||||
|
private ListView messagesList, resultContactsSearch;
|
||||||
|
private LayoutInflater inflater;
|
||||||
|
|
||||||
private boolean isEditMode = false;
|
private boolean isEditMode = false;
|
||||||
private Contact contact;
|
private Contact contact;
|
||||||
|
@ -144,6 +143,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
// Retain the fragment across configuration changes
|
// Retain the fragment across configuration changes
|
||||||
setRetainInstance(true);
|
setRetainInstance(true);
|
||||||
|
|
||||||
|
this.inflater = inflater;
|
||||||
|
|
||||||
if(getArguments() == null || getArguments().getString("SipUri") == null) {
|
if(getArguments() == null || getArguments().getString("SipUri") == null) {
|
||||||
newChatConversation = true;
|
newChatConversation = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -156,7 +157,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
//Initialize UI
|
//Initialize UI
|
||||||
contactName = (TextView) view.findViewById(R.id.contact_name);
|
contactName = (TextView) view.findViewById(R.id.contact_name);
|
||||||
messagesList = (ListView) view.findViewById(R.id.chat_message_list);
|
messagesList = (ListView) view.findViewById(R.id.chat_message_list);
|
||||||
searchContactField = (AutoCompleteTextView) view.findViewById(R.id.search_contact_field);
|
searchContactField = (EditText) view.findViewById(R.id.search_contact_field);
|
||||||
|
resultContactsSearch = (ListView) view.findViewById(R.id.result_contacts);
|
||||||
|
|
||||||
editList = (LinearLayout) view.findViewById(R.id.edit_list);
|
editList = (LinearLayout) view.findViewById(R.id.edit_list);
|
||||||
textLayout = (LinearLayout) view.findViewById(R.id.message_layout);
|
textLayout = (LinearLayout) view.findViewById(R.id.message_layout);
|
||||||
|
@ -190,14 +192,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
delete.setOnClickListener(this);
|
delete.setOnClickListener(this);
|
||||||
|
|
||||||
if (newChatConversation) {
|
if (newChatConversation) {
|
||||||
messagesList.setVisibility(View.GONE);
|
initNewChatConversation();
|
||||||
searchContactField.setVisibility(View.VISIBLE);
|
|
||||||
searchContactField.setAdapter(new SearchContactsListAdapter(inflater));
|
|
||||||
searchContactField.showDropDown();
|
|
||||||
searchContactField.requestFocus();
|
|
||||||
edit.setVisibility(View.INVISIBLE);
|
|
||||||
startCall.setVisibility(View.INVISIBLE);
|
|
||||||
contactName.setVisibility(View.INVISIBLE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Manage multiline
|
//Manage multiline
|
||||||
|
@ -608,6 +603,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
|
|
||||||
if(!newChatConversation) {
|
if(!newChatConversation) {
|
||||||
initChatRoom(sipUri);
|
initChatRoom(sipUri);
|
||||||
|
searchContactField.setVisibility(View.GONE);
|
||||||
|
resultContactsSearch.setVisibility(View.GONE);
|
||||||
remoteComposing.setVisibility(chatRoom.isRemoteComposing() ? View.VISIBLE : View.GONE);
|
remoteComposing.setVisibility(chatRoom.isRemoteComposing() ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
@ -955,6 +952,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
private void exitNewConversationMode(Contact c, String address, String username){
|
private void exitNewConversationMode(Contact c, String address, String username){
|
||||||
sipUri = address;
|
sipUri = address;
|
||||||
searchContactField.setVisibility(View.GONE);
|
searchContactField.setVisibility(View.GONE);
|
||||||
|
resultContactsSearch.setVisibility(View.GONE);
|
||||||
messagesList.setVisibility(View.VISIBLE);
|
messagesList.setVisibility(View.VISIBLE);
|
||||||
contactName.setVisibility(View.VISIBLE);
|
contactName.setVisibility(View.VISIBLE);
|
||||||
edit.setVisibility(View.VISIBLE);
|
edit.setVisibility(View.VISIBLE);
|
||||||
|
@ -964,6 +962,31 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
initChatRoom(sipUri);
|
initChatRoom(sipUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initNewChatConversation(){
|
||||||
|
messagesList.setVisibility(View.GONE);
|
||||||
|
edit.setVisibility(View.INVISIBLE);
|
||||||
|
startCall.setVisibility(View.INVISIBLE);
|
||||||
|
contactName.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
resultContactsSearch.setVisibility(View.VISIBLE);
|
||||||
|
searchAdapter = new SearchContactsListAdapter(null);
|
||||||
|
resultContactsSearch.setAdapter(searchAdapter);
|
||||||
|
searchContactField.setVisibility(View.VISIBLE);
|
||||||
|
searchContactField.addTextChangedListener(new TextWatcher() {
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeTextChanged(CharSequence s, int start, int count,
|
||||||
|
int after) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterTextChanged(Editable s) {
|
||||||
|
searchContacts(searchContactField.getText().toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private class ContactAddress {
|
private class ContactAddress {
|
||||||
Contact contact;
|
Contact contact;
|
||||||
String address;
|
String address;
|
||||||
|
@ -974,49 +997,38 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SearchContactsListAdapter extends BaseAdapter implements Filterable {
|
private void searchContacts(String search) {
|
||||||
|
if (search == null || search.length() == 0) {
|
||||||
|
resultContactsSearch.setAdapter(new SearchContactsListAdapter(null));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ContactAddress> result = new ArrayList<ContactAddress>();
|
||||||
|
if(search != null) {
|
||||||
|
for (ContactAddress c : searchAdapter.contacts) {
|
||||||
|
String address = c.address;
|
||||||
|
if(address.startsWith("sip:")) address = address.substring(4);
|
||||||
|
if (c.contact.getName().toLowerCase().startsWith(search) || address.toLowerCase().startsWith(search)) {
|
||||||
|
result.add(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resultContactsSearch.setAdapter(new SearchContactsListAdapter(result));
|
||||||
|
searchAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
class SearchContactsListAdapter extends BaseAdapter {
|
||||||
private List<ContactAddress> contacts;
|
private List<ContactAddress> contacts;
|
||||||
private LayoutInflater mInflater;
|
private LayoutInflater mInflater;
|
||||||
|
|
||||||
SearchContactsListAdapter(LayoutInflater inflater) {
|
SearchContactsListAdapter(List<ContactAddress> contactsList) {
|
||||||
mInflater = inflater;
|
mInflater = inflater;
|
||||||
contacts = getContactsList();
|
if(contactsList == null){
|
||||||
}
|
contacts = getContactsList();
|
||||||
|
} else {
|
||||||
@Override
|
contacts = contactsList;
|
||||||
public Filter getFilter() {
|
}
|
||||||
return new Filter() {
|
|
||||||
@Override
|
|
||||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
|
||||||
if (results.count > 0) {
|
|
||||||
contacts.clear();
|
|
||||||
contacts = (List<ContactAddress>) results.values;
|
|
||||||
notifyDataSetChanged();
|
|
||||||
} else {
|
|
||||||
contacts.clear();
|
|
||||||
contacts = getContactsList();
|
|
||||||
notifyDataSetInvalidated();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected FilterResults performFiltering(CharSequence constraint) {
|
|
||||||
List<ContactAddress> result = new ArrayList<ContactAddress>();
|
|
||||||
if(constraint != null) {
|
|
||||||
for (ContactAddress c : contacts) {
|
|
||||||
String address = c.address;
|
|
||||||
if(address.startsWith("sip:")) address = address.substring(4);
|
|
||||||
if (c.contact.getName().toLowerCase().startsWith(constraint.toString()) || address.toLowerCase().startsWith(constraint.toString())) {
|
|
||||||
result.add(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
FilterResults r = new FilterResults();
|
|
||||||
r.values = result;
|
|
||||||
r.count = result.size();
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ContactAddress>getContactsList(){
|
public List<ContactAddress>getContactsList(){
|
||||||
|
|
Loading…
Reference in a new issue