Switched to multi listener for chat rooms
This commit is contained in:
parent
2ae5908827
commit
984c8aca2a
6 changed files with 113 additions and 71 deletions
|
@ -67,6 +67,8 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
|
||||||
private ProgressBar mContactsFetchInProgress;
|
private ProgressBar mContactsFetchInProgress;
|
||||||
private SearchContactsListAdapter mSearchAdapter;
|
private SearchContactsListAdapter mSearchAdapter;
|
||||||
private String mChatRoomSubject, mChatRoomAddress;
|
private String mChatRoomSubject, mChatRoomAddress;
|
||||||
|
private ChatRoom mChatRoom;
|
||||||
|
private ChatRoomListenerStub mChatRoomCreationListener;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
@ -161,9 +163,31 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
|
||||||
|
|
||||||
displayChatCreation();
|
displayChatCreation();
|
||||||
|
|
||||||
|
mChatRoomCreationListener = new ChatRoomListenerStub() {
|
||||||
|
@Override
|
||||||
|
public void onStateChanged(ChatRoom cr, ChatRoom.State newState) {
|
||||||
|
if (newState == ChatRoom.State.Created) {
|
||||||
|
mWaitLayout.setVisibility(View.GONE);
|
||||||
|
LinphoneActivity.instance().goToChat(cr.getPeerAddress().asStringUriOnly());
|
||||||
|
} else if (newState == ChatRoom.State.CreationFailed) {
|
||||||
|
mWaitLayout.setVisibility(View.GONE);
|
||||||
|
LinphoneActivity.instance().displayChatRoomError();
|
||||||
|
Log.e("Group chat room for address " + cr.getPeerAddress() + " has failed !");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
if (mChatRoom != null) {
|
||||||
|
mChatRoom.removeListener(mChatRoomCreationListener);
|
||||||
|
}
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
private void displayChatCreation() {
|
private void displayChatCreation() {
|
||||||
mNextButton.setVisibility(View.VISIBLE);
|
mNextButton.setVisibility(View.VISIBLE);
|
||||||
mNextButton.setEnabled(mContactsSelected.size() > 0);
|
mNextButton.setEnabled(mContactsSelected.size() > 0);
|
||||||
|
@ -301,24 +325,9 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
|
||||||
Address participant = mContactsSelected.get(0).getAddress();
|
Address participant = mContactsSelected.get(0).getAddress();
|
||||||
ChatRoom chatRoom = lc.findOneToOneChatRoom(lc.getDefaultProxyConfig().getContact(), participant);
|
ChatRoom chatRoom = lc.findOneToOneChatRoom(lc.getDefaultProxyConfig().getContact(), participant);
|
||||||
if (chatRoom == null) {
|
if (chatRoom == null) {
|
||||||
chatRoom = lc.createClientGroupChatRoom(getString(R.string.dummy_group_chat_subject));
|
mChatRoom = lc.createClientGroupChatRoom(getString(R.string.dummy_group_chat_subject));
|
||||||
chatRoom.setListener(new ChatRoomListenerStub() {
|
mChatRoom.addListener(mChatRoomCreationListener);
|
||||||
@Override
|
mChatRoom.addParticipant(participant);
|
||||||
public void onStateChanged(ChatRoom cr, ChatRoom.State newState) {
|
|
||||||
if (newState == ChatRoom.State.Created) {
|
|
||||||
cr.setListener(null);
|
|
||||||
mWaitLayout.setVisibility(View.GONE);
|
|
||||||
LinphoneActivity.instance().goToChat(cr.getPeerAddress().asStringUriOnly());
|
|
||||||
} else if (newState == ChatRoom.State.CreationFailed) {
|
|
||||||
cr.setListener(null);
|
|
||||||
mWaitLayout.setVisibility(View.GONE);
|
|
||||||
LinphoneActivity.instance().displayChatRoomError();
|
|
||||||
Log.e("Group chat room for address " + cr.getPeerAddress() + " has failed !");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
chatRoom.addParticipant(participant);
|
|
||||||
} else {
|
} else {
|
||||||
LinphoneActivity.instance().goToChat(chatRoom.getPeerAddress().asStringUriOnly());
|
LinphoneActivity.instance().goToChat(chatRoom.getPeerAddress().asStringUriOnly());
|
||||||
}
|
}
|
||||||
|
|
|
@ -233,7 +233,7 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
|
||||||
ContactsManager.removeContactsListener(this);
|
ContactsManager.removeContactsListener(this);
|
||||||
removeVirtualKeyboardVisiblityListener();
|
removeVirtualKeyboardVisiblityListener();
|
||||||
LinphoneManager.getInstance().setCurrentChatRoomAddress(null);
|
LinphoneManager.getInstance().setCurrentChatRoomAddress(null);
|
||||||
if (mChatRoom != null) mChatRoom.setListener(null);
|
if (mChatRoom != null) mChatRoom.removeListener(this);
|
||||||
mEventsAdapter.clear();
|
mEventsAdapter.clear();
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
@ -390,7 +390,7 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
|
||||||
if (mChatRoom == null) {
|
if (mChatRoom == null) {
|
||||||
mChatRoom = core.getChatRoomFromUri(mRemoteSipAddress.asStringUriOnly());
|
mChatRoom = core.getChatRoomFromUri(mRemoteSipAddress.asStringUriOnly());
|
||||||
}
|
}
|
||||||
mChatRoom.setListener(this);
|
mChatRoom.addListener(this);
|
||||||
mChatRoom.markAsRead();
|
mChatRoom.markAsRead();
|
||||||
LinphoneActivity.instance().updateMissedChatCount();
|
LinphoneActivity.instance().updateMissedChatCount();
|
||||||
|
|
||||||
|
|
|
@ -66,8 +66,9 @@ public class GroupInfoFragment extends Fragment implements ChatRoomListener {
|
||||||
private boolean mIsEditionEnabled;
|
private boolean mIsEditionEnabled;
|
||||||
private ArrayList<ContactAddress> mParticipants;
|
private ArrayList<ContactAddress> mParticipants;
|
||||||
private String mSubject;
|
private String mSubject;
|
||||||
private ChatRoom mChatRoom;
|
private ChatRoom mChatRoom, mTempChatRoom;
|
||||||
private Dialog mAdminStateChangedDialog;
|
private Dialog mAdminStateChangedDialog;
|
||||||
|
private ChatRoomListenerStub mChatRoomCreationListener;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
@ -195,27 +196,27 @@ public class GroupInfoFragment extends Fragment implements ChatRoomListener {
|
||||||
});
|
});
|
||||||
mSubjectField.setText(mSubject);
|
mSubjectField.setText(mSubject);
|
||||||
|
|
||||||
mConfirmButton.setOnClickListener(new View.OnClickListener() {
|
mChatRoomCreationListener = new ChatRoomListenerStub() {
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
if (!mIsAlreadyCreatedGroup) {
|
|
||||||
mWaitLayout.setVisibility(View.VISIBLE);
|
|
||||||
ChatRoom chatRoom = LinphoneManager.getLc().createClientGroupChatRoom(mSubjectField.getText().toString());
|
|
||||||
chatRoom.setListener(new ChatRoomListenerStub() {
|
|
||||||
@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) {
|
||||||
cr.setListener(null);
|
|
||||||
mWaitLayout.setVisibility(View.GONE);
|
mWaitLayout.setVisibility(View.GONE);
|
||||||
LinphoneActivity.instance().goToChat(cr.getPeerAddress().asStringUriOnly());
|
LinphoneActivity.instance().goToChat(cr.getPeerAddress().asStringUriOnly());
|
||||||
} else if (newState == ChatRoom.State.CreationFailed) {
|
} else if (newState == ChatRoom.State.CreationFailed) {
|
||||||
cr.setListener(null);
|
|
||||||
mWaitLayout.setVisibility(View.GONE);
|
mWaitLayout.setVisibility(View.GONE);
|
||||||
LinphoneActivity.instance().displayChatRoomError();
|
LinphoneActivity.instance().displayChatRoomError();
|
||||||
Log.e("Group chat room for address " + cr.getPeerAddress() + " has failed !");
|
Log.e("Group chat room for address " + cr.getPeerAddress() + " has failed !");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
mConfirmButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
if (!mIsAlreadyCreatedGroup) {
|
||||||
|
mWaitLayout.setVisibility(View.VISIBLE);
|
||||||
|
mTempChatRoom = LinphoneManager.getLc().createClientGroupChatRoom(mSubjectField.getText().toString());
|
||||||
|
mTempChatRoom.addListener(mChatRoomCreationListener);
|
||||||
|
|
||||||
Address addresses[] = new Address[mParticipants.size()];
|
Address addresses[] = new Address[mParticipants.size()];
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
@ -223,7 +224,7 @@ public class GroupInfoFragment extends Fragment implements ChatRoomListener {
|
||||||
addresses[index] = ca.getAddress();
|
addresses[index] = ca.getAddress();
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
chatRoom.addParticipants(addresses);
|
mTempChatRoom.addParticipants(addresses);
|
||||||
} else {
|
} else {
|
||||||
// Subject
|
// Subject
|
||||||
String newSubject = mSubjectField.getText().toString();
|
String newSubject = mSubjectField.getText().toString();
|
||||||
|
@ -292,16 +293,24 @@ 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.addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
if (mTempChatRoom != null) {
|
||||||
|
mTempChatRoom.removeListener(mChatRoomCreationListener);
|
||||||
|
}
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
if (mChatRoom != null) {
|
if (mChatRoom != null) {
|
||||||
mChatRoom.setListener(null);
|
mChatRoom.removeListener(this);
|
||||||
}
|
}
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,8 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
|
||||||
private LayoutInflater inflater;
|
private LayoutInflater inflater;
|
||||||
private View view;
|
private View view;
|
||||||
private boolean displayChatAddressOnly = false;
|
private boolean displayChatAddressOnly = false;
|
||||||
|
private ChatRoom mChatRoom;
|
||||||
|
private ChatRoomListenerStub mChatRoomCreationListener;
|
||||||
|
|
||||||
private OnClickListener dialListener = new OnClickListener() {
|
private OnClickListener dialListener = new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -77,21 +79,9 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
|
||||||
LinphoneActivity.instance().goToChat(room.getPeerAddress().asStringUriOnly());
|
LinphoneActivity.instance().goToChat(room.getPeerAddress().asStringUriOnly());
|
||||||
} else {
|
} else {
|
||||||
mWaitLayout.setVisibility(View.VISIBLE);
|
mWaitLayout.setVisibility(View.VISIBLE);
|
||||||
room = LinphoneManager.getLc().createClientGroupChatRoom(getString(R.string.dummy_group_chat_subject));
|
mChatRoom = lc.createClientGroupChatRoom(getString(R.string.dummy_group_chat_subject));
|
||||||
room.setListener(new ChatRoomListenerStub() {
|
mChatRoom.addListener(mChatRoomCreationListener);
|
||||||
@Override
|
mChatRoom.addParticipant(participant);
|
||||||
public void onStateChanged(ChatRoom cr, ChatRoom.State newState) {
|
|
||||||
if (newState == ChatRoom.State.Created) {
|
|
||||||
mWaitLayout.setVisibility(View.GONE);
|
|
||||||
LinphoneActivity.instance().goToChat(cr.getPeerAddress().asStringUriOnly());
|
|
||||||
} else if (newState == ChatRoom.State.CreationFailed) {
|
|
||||||
mWaitLayout.setVisibility(View.GONE);
|
|
||||||
LinphoneActivity.instance().displayChatRoomError();
|
|
||||||
Log.e("Group chat room for address " + cr.getPeerAddress() + " has failed !");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
room.addParticipant(participant);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,9 +122,31 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
|
||||||
back.setOnClickListener(this);
|
back.setOnClickListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mChatRoomCreationListener = new ChatRoomListenerStub() {
|
||||||
|
@Override
|
||||||
|
public void onStateChanged(ChatRoom cr, ChatRoom.State newState) {
|
||||||
|
if (newState == ChatRoom.State.Created) {
|
||||||
|
mWaitLayout.setVisibility(View.GONE);
|
||||||
|
LinphoneActivity.instance().goToChat(cr.getPeerAddress().asStringUriOnly());
|
||||||
|
} else if (newState == ChatRoom.State.CreationFailed) {
|
||||||
|
mWaitLayout.setVisibility(View.GONE);
|
||||||
|
LinphoneActivity.instance().displayChatRoomError();
|
||||||
|
Log.e("Group chat room for address " + cr.getPeerAddress() + " has failed !");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
if (mChatRoom != null) {
|
||||||
|
mChatRoom.removeListener(mChatRoomCreationListener);
|
||||||
|
}
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
public void changeDisplayedContact(LinphoneContact newContact) {
|
public void changeDisplayedContact(LinphoneContact newContact) {
|
||||||
contact = newContact;
|
contact = newContact;
|
||||||
displayContact(inflater, view);
|
displayContact(inflater, view);
|
||||||
|
|
|
@ -51,6 +51,8 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
|
||||||
private String sipUri, displayName, pictureUri;
|
private String sipUri, displayName, pictureUri;
|
||||||
private RelativeLayout mWaitLayout;
|
private RelativeLayout mWaitLayout;
|
||||||
private LinphoneContact contact;
|
private LinphoneContact contact;
|
||||||
|
private ChatRoom mChatRoom;
|
||||||
|
private ChatRoomListenerStub mChatRoomCreationListener;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
@ -100,9 +102,31 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
|
||||||
|
|
||||||
displayHistory(status, callTime, callDate);
|
displayHistory(status, callTime, callDate);
|
||||||
|
|
||||||
|
mChatRoomCreationListener = new ChatRoomListenerStub() {
|
||||||
|
@Override
|
||||||
|
public void onStateChanged(ChatRoom cr, ChatRoom.State newState) {
|
||||||
|
if (newState == ChatRoom.State.Created) {
|
||||||
|
mWaitLayout.setVisibility(View.GONE);
|
||||||
|
LinphoneActivity.instance().goToChat(cr.getPeerAddress().asStringUriOnly());
|
||||||
|
} else if (newState == ChatRoom.State.CreationFailed) {
|
||||||
|
mWaitLayout.setVisibility(View.GONE);
|
||||||
|
LinphoneActivity.instance().displayChatRoomError();
|
||||||
|
Log.e("Group chat room for address " + cr.getPeerAddress() + " has failed !");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
if (mChatRoom != null) {
|
||||||
|
mChatRoom.removeListener(mChatRoomCreationListener);
|
||||||
|
}
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
private void displayHistory(String status, String callTime, String callDate) {
|
private void displayHistory(String status, String callTime, String callDate) {
|
||||||
if (status.equals(getResources().getString(R.string.missed))) {
|
if (status.equals(getResources().getString(R.string.missed))) {
|
||||||
callDirection.setImageResource(R.drawable.call_missed);
|
callDirection.setImageResource(R.drawable.call_missed);
|
||||||
|
@ -176,21 +200,9 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
|
||||||
LinphoneActivity.instance().goToChat(room.getPeerAddress().asStringUriOnly());
|
LinphoneActivity.instance().goToChat(room.getPeerAddress().asStringUriOnly());
|
||||||
} else {
|
} else {
|
||||||
mWaitLayout.setVisibility(View.VISIBLE);
|
mWaitLayout.setVisibility(View.VISIBLE);
|
||||||
room = lc.createClientGroupChatRoom(getString(R.string.dummy_group_chat_subject));
|
mChatRoom = lc.createClientGroupChatRoom(getString(R.string.dummy_group_chat_subject));
|
||||||
room.setListener(new ChatRoomListenerStub() {
|
mChatRoom.addListener(mChatRoomCreationListener);
|
||||||
@Override
|
mChatRoom.addParticipant(participant);
|
||||||
public void onStateChanged(ChatRoom cr, ChatRoom.State newState) {
|
|
||||||
if (newState == ChatRoom.State.Created) {
|
|
||||||
mWaitLayout.setVisibility(View.GONE);
|
|
||||||
LinphoneActivity.instance().goToChat(cr.getPeerAddress().asStringUriOnly());
|
|
||||||
} else if (newState == ChatRoom.State.CreationFailed) {
|
|
||||||
mWaitLayout.setVisibility(View.GONE);
|
|
||||||
LinphoneActivity.instance().displayChatRoomError();
|
|
||||||
Log.e("Group chat room for address " + cr.getPeerAddress() + " has failed !");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
room.addParticipant(participant);
|
|
||||||
}
|
}
|
||||||
} else if (id == R.id.add_contact) {
|
} else if (id == R.id.add_contact) {
|
||||||
Address addr = Factory.instance().createAddress(sipUri);
|
Address addr = Factory.instance().createAddress(sipUri);
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 2e8f7dade9dc7ec316a656094fa8e115d99b197b
|
Subproject commit 4ba2aa8af07c3a3ed3c20ff32fcd264561198c3a
|
Loading…
Reference in a new issue