Fixing rotation on create chat view
This commit is contained in:
parent
f8bf1b24c5
commit
b211b25efc
5 changed files with 63 additions and 41 deletions
|
@ -1,26 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/layout"
|
||||
android:background="@drawable/list_selector"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:padding="5dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/contact_name"
|
||||
style="@style/font6"
|
||||
android:lines="1"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/contact_address"
|
||||
style="@style/font2"
|
||||
android:lines="1"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
|
@ -144,9 +144,9 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:divider="@color/colorE"
|
||||
android:fastScrollEnabled="true"
|
||||
android:dividerHeight="1dp"
|
||||
android:fastScrollAlwaysVisible="true"
|
||||
android:dividerHeight="1dp" />
|
||||
android:fastScrollEnabled="true"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/contactsFetchInProgress"
|
||||
|
|
|
@ -22,18 +22,20 @@
|
|||
<TextView
|
||||
android:id="@+id/contact_name"
|
||||
style="@style/font6"
|
||||
android:lines="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true" />
|
||||
android:layout_centerVertical="true"
|
||||
android:gravity="top|left"
|
||||
android:lines="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/contact_address"
|
||||
style="@style/font2"
|
||||
android:lines="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"/>
|
||||
android:layout_centerVertical="true"
|
||||
android:gravity="bottom|left"
|
||||
android:lines="1"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -80,9 +80,6 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
|
|||
allContactsSelected = view.findViewById(R.id.all_contacts_select);
|
||||
linphoneContactsSelected = view.findViewById(R.id.linphone_contacts_select);
|
||||
|
||||
allContacts.setEnabled(onlyDisplayLinphoneContacts);
|
||||
linphoneContacts.setEnabled(!allContacts.isEnabled());
|
||||
|
||||
back = (ImageView) view.findViewById(R.id.back);
|
||||
back.setOnClickListener(this);
|
||||
|
||||
|
@ -96,9 +93,6 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
|
|||
contactsFetchInProgress.setVisibility(View.VISIBLE);
|
||||
|
||||
searchAdapter = new SearchContactsListAdapter(null, mInflater, contactsFetchInProgress);
|
||||
contactsList.setAdapter(searchAdapter);
|
||||
contactsList.setOnItemClickListener(this);
|
||||
|
||||
|
||||
searchField = (EditText) view.findViewById(R.id.searchField);
|
||||
searchField.addTextChangedListener(new TextWatcher() {
|
||||
|
@ -119,6 +113,38 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
|
|||
}
|
||||
});
|
||||
|
||||
contactsList.setAdapter(searchAdapter);
|
||||
contactsList.setOnItemClickListener(this);
|
||||
if (savedInstanceState != null && savedInstanceState.getStringArrayList("contactsSelected") != null) {
|
||||
// We need to get all contacts not only sip
|
||||
for (String uri : savedInstanceState.getStringArrayList("contactsSelected")) {
|
||||
for (ContactAddress ca : searchAdapter.getContactsList()) {
|
||||
if (ca.getAddress() == uri) {
|
||||
updateContactsClick(ca);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
updateList();
|
||||
updateListSelected();
|
||||
}
|
||||
|
||||
if (savedInstanceState != null ) {
|
||||
onlyDisplayLinphoneContacts = savedInstanceState.getBoolean("onlySipContact");
|
||||
if (onlyDisplayLinphoneContacts) {
|
||||
allContactsSelected.setVisibility(View.INVISIBLE);
|
||||
linphoneContactsSelected.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
allContactsSelected.setVisibility(View.VISIBLE);
|
||||
linphoneContactsSelected.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
updateList();
|
||||
}
|
||||
|
||||
searchAdapter.setOnlySipContact(onlyDisplayLinphoneContacts);
|
||||
allContacts.setEnabled(onlyDisplayLinphoneContacts);
|
||||
linphoneContacts.setEnabled(!allContacts.isEnabled());
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@ -130,12 +156,14 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
|
|||
private void updateListSelected() {
|
||||
if (contactsSelected.size() > 0) {
|
||||
contactsSelectLayout.setVisibility(View.VISIBLE);
|
||||
contactsSelectLayout.invalidate();
|
||||
} else {
|
||||
contactsSelectLayout.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateContactsClick(ContactAddress ca) {
|
||||
ca.setSelect(!ca.isSelect());
|
||||
if(ca.isSelect()) {
|
||||
ContactSelectView csv = new ContactSelectView(LinphoneActivity.instance());
|
||||
csv.setListener(this);
|
||||
|
@ -144,12 +172,14 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
|
|||
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);
|
||||
viewContact.setOnClickListener(this);
|
||||
ca.setView(viewContact);
|
||||
contactsSelectedLayout.addView(viewContact);
|
||||
} else {
|
||||
contactsSelected.remove(ca);
|
||||
contactsSelectedLayout.removeAllViews();
|
||||
for (ContactAddress contactAddress : contactsSelected) {
|
||||
if (contactAddress.getView() != null)
|
||||
contactsSelectedLayout.addView(contactAddress.getView());
|
||||
}
|
||||
}
|
||||
|
@ -166,6 +196,21 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
if (contactsSelected != null && contactsSelected.size() > 0) {
|
||||
ArrayList<String> listUri = new ArrayList<String>();
|
||||
for (ContactAddress ca : contactsSelected) {
|
||||
listUri.add(ca.getAddress());
|
||||
}
|
||||
outState.putStringArrayList("contactsSelected", listUri);
|
||||
}
|
||||
|
||||
outState.putBoolean("onlySipContact", onlyDisplayLinphoneContacts);
|
||||
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int id = view.getId();
|
||||
|
@ -200,7 +245,6 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
|
|||
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();
|
||||
|
|
|
@ -21,7 +21,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
|
||||
import android.view.View;
|
||||
|
||||
public class ContactAddress {
|
||||
import java.io.Serializable;
|
||||
|
||||
public class ContactAddress implements Serializable {
|
||||
private LinphoneContact contact;
|
||||
private String address;
|
||||
private boolean isLinphoneContact;
|
||||
|
|
Loading…
Reference in a new issue