Renamed private fields in ChatCreationFragment

This commit is contained in:
Sylvain Berfini 2017-11-13 13:50:26 +01:00
parent 9c8409de3c
commit 9ed0a318ae
2 changed files with 108 additions and 111 deletions

View file

@ -53,19 +53,17 @@ import java.util.List;
public class ChatCreationFragment extends Fragment implements View.OnClickListener, AdapterView.OnItemClickListener, ContactsUpdatedListener { public class ChatCreationFragment extends Fragment implements View.OnClickListener, AdapterView.OnItemClickListener, ContactsUpdatedListener {
private LayoutInflater mInflater; private LayoutInflater mInflater;
private ListView contactsList; private ListView mContactsList;
private LinearLayout contactsSelectedLayout; private LinearLayout mContactsSelectedLayout;
private HorizontalScrollView contactsSelectLayout; private HorizontalScrollView mContactsSelectLayout;
private ArrayList<ContactAddress> contactsSelected; private ArrayList<ContactAddress> mContactsSelected;
private ImageView allContacts, linphoneContacts; private ImageView mAllContactsButton, mLinphoneContactsButton, mClearSearchFieldButton, mBackButton, mNextButton;
private boolean onlyDisplayLinphoneContacts; private boolean mOnlyDisplayLinphoneContacts;
private View allContactsSelected, linphoneContactsSelected; private View mAllContactsSelected, mLinphoneContactsSelected;
private RelativeLayout searchLayout, waitLayout; private RelativeLayout mSearchLayout, mWaitLayout;
private ImageView clearSearchField; private EditText mSearchField;
private EditText searchField; private ProgressBar mContactsFetchInProgress;
private ProgressBar contactsFetchInProgress; private SearchContactsListAdapter mSearchAdapter;
private SearchContactsListAdapter searchAdapter;
private ImageView back, next;
private String mChatRoomSubject, mChatRoomAddress; private String mChatRoomSubject, mChatRoomAddress;
@Override @Override
@ -73,51 +71,51 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
mInflater = inflater; mInflater = inflater;
View view = inflater.inflate(R.layout.chat_create, container, false); View view = inflater.inflate(R.layout.chat_create, container, false);
contactsSelected = new ArrayList<>(); mContactsSelected = new ArrayList<>();
mChatRoomSubject = null; mChatRoomSubject = null;
mChatRoomAddress = null; mChatRoomAddress = null;
if (getArguments() != null) { if (getArguments() != null) {
if (getArguments().getSerializable("selectedContacts") != null) { if (getArguments().getSerializable("selectedContacts") != null) {
contactsSelected = (ArrayList<ContactAddress>) getArguments().getSerializable("selectedContacts"); mContactsSelected = (ArrayList<ContactAddress>) getArguments().getSerializable("selectedContacts");
} }
mChatRoomSubject = getArguments().getString("subject"); mChatRoomSubject = getArguments().getString("subject");
mChatRoomAddress = getArguments().getString("groupChatRoomAddress"); mChatRoomAddress = getArguments().getString("groupChatRoomAddress");
} }
waitLayout = view.findViewById(R.id.waitScreen); mWaitLayout = view.findViewById(R.id.waitScreen);
waitLayout.setVisibility(View.GONE); mWaitLayout.setVisibility(View.GONE);
contactsList = view.findViewById(R.id.contactsList); mContactsList = view.findViewById(R.id.contactsList);
contactsSelectedLayout = view.findViewById(R.id.contactsSelected); mContactsSelectedLayout = view.findViewById(R.id.contactsSelected);
contactsSelectLayout = view.findViewById(R.id.layoutContactsSelected); mContactsSelectLayout = view.findViewById(R.id.layoutContactsSelected);
allContacts = view.findViewById(R.id.all_contacts); mAllContactsButton = view.findViewById(R.id.all_contacts);
allContacts.setOnClickListener(this); mAllContactsButton.setOnClickListener(this);
linphoneContacts = view.findViewById(R.id.linphone_contacts); mLinphoneContactsButton = view.findViewById(R.id.linphone_contacts);
linphoneContacts.setOnClickListener(this); mLinphoneContactsButton.setOnClickListener(this);
allContactsSelected = view.findViewById(R.id.all_contacts_select); mAllContactsSelected = view.findViewById(R.id.all_contacts_select);
linphoneContactsSelected = view.findViewById(R.id.linphone_contacts_select); mLinphoneContactsSelected = view.findViewById(R.id.linphone_contacts_select);
back = view.findViewById(R.id.back); mBackButton = view.findViewById(R.id.back);
back.setOnClickListener(this); mBackButton.setOnClickListener(this);
next = view.findViewById(R.id.next); mNextButton = view.findViewById(R.id.next);
next.setOnClickListener(this); mNextButton.setOnClickListener(this);
next.setEnabled(false); mNextButton.setEnabled(false);
searchLayout = view.findViewById(R.id.layoutSearchField); mSearchLayout = view.findViewById(R.id.layoutSearchField);
clearSearchField = view.findViewById(R.id.clearSearchField); mClearSearchFieldButton = view.findViewById(R.id.clearSearchField);
clearSearchField.setOnClickListener(this); mClearSearchFieldButton.setOnClickListener(this);
contactsFetchInProgress = view.findViewById(R.id.contactsFetchInProgress); mContactsFetchInProgress = view.findViewById(R.id.contactsFetchInProgress);
contactsFetchInProgress.setVisibility(View.VISIBLE); mContactsFetchInProgress.setVisibility(View.VISIBLE);
searchAdapter = new SearchContactsListAdapter(null, mInflater, contactsFetchInProgress); mSearchAdapter = new SearchContactsListAdapter(null, mInflater, mContactsFetchInProgress);
searchField = view.findViewById(R.id.searchField); mSearchField = view.findViewById(R.id.searchField);
searchField.addTextChangedListener(new TextWatcher() { mSearchField.addTextChangedListener(new TextWatcher() {
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
@ -130,18 +128,18 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
searchAdapter.searchContacts(searchField.getText().toString(), contactsList); mSearchAdapter.searchContacts(mSearchField.getText().toString(), mContactsList);
} }
}); });
contactsList.setAdapter(searchAdapter); mContactsList.setAdapter(mSearchAdapter);
contactsList.setOnItemClickListener(this); mContactsList.setOnItemClickListener(this);
if (savedInstanceState != null && savedInstanceState.getStringArrayList("contactsSelected") != null) { if (savedInstanceState != null && savedInstanceState.getStringArrayList("mContactsSelected") != null) {
// We need to get all contacts not only sip // We need to get all contacts not only sip
for (String uri : savedInstanceState.getStringArrayList("contactsSelected")) { for (String uri : savedInstanceState.getStringArrayList("mContactsSelected")) {
for (ContactAddress ca : searchAdapter.getContactsList()) { for (ContactAddress ca : mSearchAdapter.getContactsList()) {
if (ca.getAddress().compareTo(uri) == 0) { if (ca.getAddress().compareTo(uri) == 0) {
updateContactsClick(ca, searchAdapter.getContactsSelectedList()); updateContactsClick(ca, mSearchAdapter.getContactsSelectedList());
break; break;
} }
} }
@ -151,10 +149,10 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
} }
if (savedInstanceState != null ) { if (savedInstanceState != null ) {
onlyDisplayLinphoneContacts = savedInstanceState.getBoolean("onlySipContact"); mOnlyDisplayLinphoneContacts = savedInstanceState.getBoolean("onlySipContact");
updateList(); updateList();
} }
searchAdapter.setOnlySipContact(onlyDisplayLinphoneContacts); mSearchAdapter.setOnlySipContact(mOnlyDisplayLinphoneContacts);
displayChatCreation(); displayChatCreation();
@ -162,43 +160,43 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
} }
private void displayChatCreation() { private void displayChatCreation() {
next.setVisibility(View.VISIBLE); mNextButton.setVisibility(View.VISIBLE);
next.setEnabled(contactsSelected.size() > 0); mNextButton.setEnabled(mContactsSelected.size() > 0);
contactsList.setVisibility(View.VISIBLE); mContactsList.setVisibility(View.VISIBLE);
searchLayout.setVisibility(View.VISIBLE); mSearchLayout.setVisibility(View.VISIBLE);
allContacts.setVisibility(View.VISIBLE); mAllContactsButton.setVisibility(View.VISIBLE);
linphoneContacts.setVisibility(View.VISIBLE); mLinphoneContactsButton.setVisibility(View.VISIBLE);
if (onlyDisplayLinphoneContacts) { if (mOnlyDisplayLinphoneContacts) {
allContactsSelected.setVisibility(View.INVISIBLE); mAllContactsSelected.setVisibility(View.INVISIBLE);
linphoneContactsSelected.setVisibility(View.VISIBLE); mLinphoneContactsSelected.setVisibility(View.VISIBLE);
} else { } else {
allContactsSelected.setVisibility(View.VISIBLE); mAllContactsSelected.setVisibility(View.VISIBLE);
linphoneContactsSelected.setVisibility(View.INVISIBLE); mLinphoneContactsSelected.setVisibility(View.INVISIBLE);
} }
allContacts.setEnabled(onlyDisplayLinphoneContacts); mAllContactsButton.setEnabled(mOnlyDisplayLinphoneContacts);
linphoneContacts.setEnabled(!allContacts.isEnabled()); mLinphoneContactsButton.setEnabled(!mAllContactsButton.isEnabled());
if (contactsSelected.size() > 0) { if (mContactsSelected.size() > 0) {
searchAdapter.setContactsSelectedList(contactsSelected); mSearchAdapter.setContactsSelectedList(mContactsSelected);
for (ContactAddress ca : contactsSelected) { for (ContactAddress ca : mContactsSelected) {
addSelectedContactAddress(ca); addSelectedContactAddress(ca);
} }
} }
} }
private void updateList() { private void updateList() {
searchAdapter.searchContacts(searchField.getText().toString(), contactsList); mSearchAdapter.searchContacts(mSearchField.getText().toString(), mContactsList);
searchAdapter.notifyDataSetChanged(); mSearchAdapter.notifyDataSetChanged();
} }
private void updateListSelected() { private void updateListSelected() {
if (contactsSelected.size() > 0) { if (mContactsSelected.size() > 0) {
contactsSelectLayout.invalidate(); mContactsSelectLayout.invalidate();
next.setEnabled(true); mNextButton.setEnabled(true);
} else { } else {
next.setEnabled(false); mNextButton.setEnabled(false);
} }
} }
@ -222,8 +220,8 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
removeContact.setOnClickListener(this); removeContact.setOnClickListener(this);
viewContact.setOnClickListener(this); viewContact.setOnClickListener(this);
ca.setView(viewContact); ca.setView(viewContact);
contactsSelectedLayout.addView(viewContact); mContactsSelectedLayout.addView(viewContact);
contactsSelectedLayout.invalidate(); mContactsSelectedLayout.invalidate();
} }
private void updateContactsClick(ContactAddress ca, List<ContactAddress> caSelectedList) { private void updateContactsClick(ContactAddress ca, List<ContactAddress> caSelectedList) {
@ -232,38 +230,38 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
ContactSelectView csv = new ContactSelectView(LinphoneActivity.instance()); ContactSelectView csv = new ContactSelectView(LinphoneActivity.instance());
csv.setListener(this); csv.setListener(this);
csv.setContactName(ca); csv.setContactName(ca);
contactsSelected.add(ca); mContactsSelected.add(ca);
addSelectedContactAddress(ca); addSelectedContactAddress(ca);
} else { } else {
contactsSelected.remove(getIndexOfCa(ca, contactsSelected)); mContactsSelected.remove(getIndexOfCa(ca, mContactsSelected));
contactsSelectedLayout.removeAllViews(); mContactsSelectedLayout.removeAllViews();
for (ContactAddress contactAddress : contactsSelected) { for (ContactAddress contactAddress : mContactsSelected) {
if (contactAddress.getView() != null) if (contactAddress.getView() != null)
contactsSelectedLayout.addView(contactAddress.getView()); mContactsSelectedLayout.addView(contactAddress.getView());
} }
} }
searchAdapter.setContactsSelectedList(contactsSelected); mSearchAdapter.setContactsSelectedList(mContactsSelected);
contactsSelectedLayout.invalidate(); mContactsSelectedLayout.invalidate();
} }
private void removeContactFromSelection(ContactAddress ca) { private void removeContactFromSelection(ContactAddress ca) {
updateContactsClick(ca, searchAdapter.getContactsSelectedList()); updateContactsClick(ca, mSearchAdapter.getContactsSelectedList());
searchAdapter.notifyDataSetInvalidated(); mSearchAdapter.notifyDataSetInvalidated();
updateListSelected(); updateListSelected();
} }
@Override @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
if (contactsSelected != null && contactsSelected.size() > 0) { if (mContactsSelected != null && mContactsSelected.size() > 0) {
ArrayList<String> listUri = new ArrayList<String>(); ArrayList<String> listUri = new ArrayList<String>();
for (ContactAddress ca : contactsSelected) { for (ContactAddress ca : mContactsSelected) {
listUri.add(ca.getAddress()); listUri.add(ca.getAddress());
} }
outState.putStringArrayList("contactsSelected", listUri); outState.putStringArrayList("mContactsSelected", listUri);
} }
outState.putBoolean("onlySipContact", onlyDisplayLinphoneContacts); outState.putBoolean("onlySipContact", mOnlyDisplayLinphoneContacts);
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
} }
@ -272,28 +270,28 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
public void onClick(View view) { public void onClick(View view) {
int id = view.getId(); int id = view.getId();
if (id == R.id.all_contacts) { if (id == R.id.all_contacts) {
searchAdapter.setOnlySipContact(onlyDisplayLinphoneContacts = false); mSearchAdapter.setOnlySipContact(mOnlyDisplayLinphoneContacts = false);
allContactsSelected.setVisibility(View.VISIBLE); mAllContactsSelected.setVisibility(View.VISIBLE);
allContacts.setEnabled(false); mAllContactsButton.setEnabled(false);
linphoneContacts.setEnabled(true); mLinphoneContactsButton.setEnabled(true);
linphoneContactsSelected.setVisibility(View.INVISIBLE); mLinphoneContactsSelected.setVisibility(View.INVISIBLE);
updateList(); updateList();
} else if (id == R.id.linphone_contacts) { } else if (id == R.id.linphone_contacts) {
searchAdapter.setOnlySipContact(true); mSearchAdapter.setOnlySipContact(true);
linphoneContactsSelected.setVisibility(View.VISIBLE); mLinphoneContactsSelected.setVisibility(View.VISIBLE);
linphoneContacts.setEnabled(false); mLinphoneContactsButton.setEnabled(false);
allContacts.setEnabled(onlyDisplayLinphoneContacts = true); mAllContactsButton.setEnabled(mOnlyDisplayLinphoneContacts = true);
allContactsSelected.setVisibility(View.INVISIBLE); mAllContactsSelected.setVisibility(View.INVISIBLE);
updateList(); updateList();
} else if (id == R.id.back) { } else if (id == R.id.back) {
contactsSelectedLayout.removeAllViews(); mContactsSelectedLayout.removeAllViews();
LinphoneActivity.instance().popBackStack(); LinphoneActivity.instance().popBackStack();
} else if (id == R.id.next) { } else if (id == R.id.next) {
if (mChatRoomAddress == null && mChatRoomSubject == null) { if (mChatRoomAddress == null && mChatRoomSubject == null) {
if (contactsSelected.size() == 1) { if (mContactsSelected.size() == 1) {
contactsSelectedLayout.removeAllViews(); mContactsSelectedLayout.removeAllViews();
waitLayout.setVisibility(View.VISIBLE); mWaitLayout.setVisibility(View.VISIBLE);
//LinphoneActivity.instance().displayChat(contactsSelected.get(0).getAddress(), "", ""); //LinphoneActivity.instance().displayChat(mContactsSelected.get(0).getAddress(), "", "");
//TODO create group chat room with only two participants ? //TODO create group chat room with only two participants ?
//TODO what subject to set ? //TODO what subject to set ?
ChatRoom chatRoom = LinphoneManager.getLc().createClientGroupChatRoom(getString(R.string.dummy_group_chat_subject)); ChatRoom chatRoom = LinphoneManager.getLc().createClientGroupChatRoom(getString(R.string.dummy_group_chat_subject));
@ -301,10 +299,10 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
@Override @Override
public void onStateChanged(ChatRoom cr, ChatRoom.State newState) { public void onStateChanged(ChatRoom cr, ChatRoom.State newState) {
if (newState == ChatRoom.State.Created) { if (newState == ChatRoom.State.Created) {
waitLayout.setVisibility(View.GONE); mWaitLayout.setVisibility(View.GONE);
LinphoneActivity.instance().goToChat(cr.getConferenceAddress().asStringUriOnly()); LinphoneActivity.instance().goToChat(cr.getConferenceAddress().asStringUriOnly());
} else if (newState == ChatRoom.State.CreationFailed) { } else if (newState == ChatRoom.State.CreationFailed) {
waitLayout.setVisibility(View.GONE); mWaitLayout.setVisibility(View.GONE);
//TODO display error //TODO display error
Log.e("Group chat room for address " + cr.getConferenceAddress() + " has failed !"); Log.e("Group chat room for address " + cr.getConferenceAddress() + " has failed !");
} }
@ -312,19 +310,19 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
}); });
Address addresses[] = new Address[1]; Address addresses[] = new Address[1];
String addr = contactsSelected.get(0).getAddress(); String addr = mContactsSelected.get(0).getAddress();
addresses[0] = LinphoneManager.getLc().interpretUrl(addr); addresses[0] = LinphoneManager.getLc().interpretUrl(addr);
chatRoom.addParticipants(addresses); chatRoom.addParticipants(addresses);
} else { } else {
contactsSelectedLayout.removeAllViews(); mContactsSelectedLayout.removeAllViews();
LinphoneActivity.instance().goToChatGroupInfos(null, contactsSelected, null, true, false); LinphoneActivity.instance().goToChatGroupInfos(null, mContactsSelected, null, true, false);
} }
} else { } else {
LinphoneActivity.instance().goToChatGroupInfos(mChatRoomAddress, contactsSelected, mChatRoomSubject, true, true); LinphoneActivity.instance().goToChatGroupInfos(mChatRoomAddress, mContactsSelected, mChatRoomSubject, true, true);
} }
} else if (id == R.id.clearSearchField) { } else if (id == R.id.clearSearchField) {
searchField.setText(""); mSearchField.setText("");
searchAdapter.searchContacts("", contactsList); mSearchAdapter.searchContacts("", mContactsList);
} else if (id == R.id.contactChatDelete) { } else if (id == R.id.contactChatDelete) {
ContactAddress ca = (ContactAddress) view.getTag(); ContactAddress ca = (ContactAddress) view.getTag();
removeContactFromSelection(ca); removeContactFromSelection(ca);
@ -333,12 +331,12 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
@Override @Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
ContactAddress ca = searchAdapter.getContacts().get(i); ContactAddress ca = mSearchAdapter.getContacts().get(i);
removeContactFromSelection(ca); removeContactFromSelection(ca);
} }
@Override @Override
public void onContactsUpdated() { public void onContactsUpdated() {
searchAdapter.searchContacts(searchField.getText().toString(), contactsList); mSearchAdapter.searchContacts(mSearchField.getText().toString(), mContactsList);
} }
} }

View file

@ -262,7 +262,6 @@ public class GroupInfoFragment extends Fragment implements ChatRoomListener {
mWaitLayout.setVisibility(View.GONE); mWaitLayout.setVisibility(View.GONE);
if (mChatRoom != null) { if (mChatRoom != null) {
//
mChatRoom.setListener(this); mChatRoom.setListener(this);
} }