Started rewrite of ChatListFragment
This commit is contained in:
parent
7b5142b8c6
commit
b9c9ad83fe
4 changed files with 323 additions and 239 deletions
|
@ -453,7 +453,7 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
((ContactsListFragment) fragment).displayFirstContact();
|
((ContactsListFragment) fragment).displayFirstContact();
|
||||||
break;
|
break;
|
||||||
case CHAT_LIST:
|
case CHAT_LIST:
|
||||||
((ChatListFragment) fragment).displayFirstChat();
|
//TODO((ChatListFragment) fragment).displayFirstChat();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -880,7 +880,7 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
public void onMessageSent(String to, String message) {
|
public void onMessageSent(String to, String message) {
|
||||||
Fragment fragment = getFragmentManager().findFragmentById(R.id.fragmentContainer);
|
Fragment fragment = getFragmentManager().findFragmentById(R.id.fragmentContainer);
|
||||||
if (fragment.getClass() == ChatListFragment.class) {
|
if (fragment.getClass() == ChatListFragment.class) {
|
||||||
((ChatListFragment)fragment).refresh();
|
////TODO ((ChatListFragment)fragment).refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,25 +19,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
package org.linphone.chat;
|
package org.linphone.chat;
|
||||||
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.graphics.Typeface;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.ContextMenu;
|
|
||||||
import android.view.ContextMenu.ContextMenuInfo;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AbsListView;
|
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.BaseAdapter;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.CheckBox;
|
|
||||||
import android.widget.CompoundButton;
|
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
@ -47,25 +35,17 @@ import org.linphone.contacts.ContactsManager;
|
||||||
import org.linphone.receivers.ContactsUpdatedListener;
|
import org.linphone.receivers.ContactsUpdatedListener;
|
||||||
import org.linphone.fragments.FragmentsAvailable;
|
import org.linphone.fragments.FragmentsAvailable;
|
||||||
import org.linphone.activities.LinphoneActivity;
|
import org.linphone.activities.LinphoneActivity;
|
||||||
import org.linphone.contacts.LinphoneContact;
|
|
||||||
import org.linphone.LinphoneManager;
|
import org.linphone.LinphoneManager;
|
||||||
import org.linphone.LinphoneUtils;
|
|
||||||
import org.linphone.R;
|
import org.linphone.R;
|
||||||
import org.linphone.core.Address;
|
|
||||||
import org.linphone.core.ChatMessage;
|
import org.linphone.core.ChatMessage;
|
||||||
import org.linphone.core.ChatRoom;
|
import org.linphone.core.ChatRoom;
|
||||||
import org.linphone.core.Core;
|
import org.linphone.core.Core;
|
||||||
import org.linphone.core.Factory;
|
|
||||||
import org.linphone.core.CoreListenerStub;
|
import org.linphone.core.CoreListenerStub;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.linphone.fragments.FragmentsAvailable.CHAT_LIST;
|
import static org.linphone.fragments.FragmentsAvailable.CHAT_LIST;
|
||||||
|
|
||||||
public class ChatListFragment extends Fragment implements OnClickListener, OnItemClickListener, ContactsUpdatedListener {
|
public class ChatListFragment extends Fragment implements OnItemClickListener, ContactsUpdatedListener {
|
||||||
private LayoutInflater mInflater;
|
private LayoutInflater mInflater;
|
||||||
private List<String> mConversations;
|
|
||||||
private ListView chatList;
|
private ListView chatList;
|
||||||
private TextView noChatHistory;
|
private TextView noChatHistory;
|
||||||
private ImageView edit, selectAll, deselectAll, delete, newDiscussion, cancel, backInCall;
|
private ImageView edit, selectAll, deselectAll, delete, newDiscussion, cancel, backInCall;
|
||||||
|
@ -74,14 +54,13 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
private CoreListenerStub mListener;
|
private CoreListenerStub mListener;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
Bundle savedInstanceState) {
|
|
||||||
mInflater = inflater;
|
mInflater = inflater;
|
||||||
|
|
||||||
View view = inflater.inflate(R.layout.chatlist, container, false);
|
View view = inflater.inflate(R.layout.chatlist, container, false);
|
||||||
chatList = view.findViewById(R.id.chatList);
|
chatList = view.findViewById(R.id.chatList);
|
||||||
|
chatList.setAdapter(new ChatRoomsAdapter(getActivity(), this, mInflater));
|
||||||
chatList.setOnItemClickListener(this);
|
chatList.setOnItemClickListener(this);
|
||||||
registerForContextMenu(chatList);
|
|
||||||
|
|
||||||
noChatHistory = view.findViewById(R.id.noChatHistory);
|
noChatHistory = view.findViewById(R.id.noChatHistory);
|
||||||
|
|
||||||
|
@ -89,47 +68,91 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
topbar = view.findViewById(R.id.top_bar);
|
topbar = view.findViewById(R.id.top_bar);
|
||||||
|
|
||||||
cancel = view.findViewById(R.id.cancel);
|
cancel = view.findViewById(R.id.cancel);
|
||||||
cancel.setOnClickListener(this);
|
cancel.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
edit = view.findViewById(R.id.edit);
|
edit = view.findViewById(R.id.edit);
|
||||||
edit.setOnClickListener(this);
|
edit.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
newDiscussion = view.findViewById(R.id.new_discussion);
|
newDiscussion = view.findViewById(R.id.new_discussion);
|
||||||
newDiscussion.setOnClickListener(this);
|
newDiscussion.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
LinphoneActivity.instance().goToChatCreator(null, false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
selectAll = view.findViewById(R.id.select_all);
|
selectAll = view.findViewById(R.id.select_all);
|
||||||
selectAll.setOnClickListener(this);
|
selectAll.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
deselectAll = view.findViewById(R.id.deselect_all);
|
deselectAll = view.findViewById(R.id.deselect_all);
|
||||||
deselectAll.setOnClickListener(this);
|
deselectAll.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
backInCall = view.findViewById(R.id.back_in_call);
|
backInCall = view.findViewById(R.id.back_in_call);
|
||||||
backInCall.setOnClickListener(this);
|
backInCall.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
LinphoneActivity.instance().resetClassicMenuLayoutAndGoBackToCallIfStillRunning();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
delete = view.findViewById(R.id.delete);
|
delete = view.findViewById(R.id.delete);
|
||||||
delete.setOnClickListener(this);
|
delete.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
mListener = new CoreListenerStub() {
|
mListener = new CoreListenerStub() {
|
||||||
@Override
|
@Override
|
||||||
public void onMessageReceived(Core lc, ChatRoom cr, ChatMessage message) {
|
public void onMessageReceived(Core lc, ChatRoom cr, ChatMessage message) {
|
||||||
refresh();
|
refreshChatRoomsList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChatRoomInstantiated(Core lc, ChatRoom cr) {
|
||||||
|
refreshChatRoomsList();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*ChatFragment.createIfNotExist();
|
/*ChatFragment.createIfNotExist();
|
||||||
ChatFragment.addChatListener(this);*/
|
ChatFragment.addChatListener(this);*/
|
||||||
//TODO
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void selectAllList(boolean isSelectAll){
|
private void refreshChatRoomsList() {
|
||||||
|
((ChatRoomsAdapter)chatList.getAdapter()).refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*private void selectAllList(boolean isSelectAll){
|
||||||
int size = chatList.getAdapter().getCount();
|
int size = chatList.getAdapter().getCount();
|
||||||
for(int i=0; i<size; i++) {
|
for(int i=0; i<size; i++) {
|
||||||
chatList.setItemChecked(i,isSelectAll);
|
chatList.setItemChecked(i,isSelectAll);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
private void removeChatsConversation() {
|
/*private void removeChatsConversation() {
|
||||||
int size = chatList.getAdapter().getCount();
|
int size = chatList.getAdapter().getCount();
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
if (chatList.isItemChecked(i)) {
|
if (chatList.isItemChecked(i)) {
|
||||||
|
@ -144,9 +167,9 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
}
|
}
|
||||||
quitEditMode();
|
quitEditMode();
|
||||||
LinphoneActivity.instance().updateMissedChatCount();
|
LinphoneActivity.instance().updateMissedChatCount();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public void quitEditMode(){
|
/*public void quitEditMode(){
|
||||||
isEditMode = false;
|
isEditMode = false;
|
||||||
editList.setVisibility(View.GONE);
|
editList.setVisibility(View.GONE);
|
||||||
topbar.setVisibility(View.VISIBLE);
|
topbar.setVisibility(View.VISIBLE);
|
||||||
|
@ -154,9 +177,9 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
if(getResources().getBoolean(R.bool.isTablet)){
|
if(getResources().getBoolean(R.bool.isTablet)){
|
||||||
displayFirstChat();
|
displayFirstChat();
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public int getNbItemsChecked(){
|
/*public int getNbItemsChecked(){
|
||||||
int size = chatList.getAdapter().getCount();
|
int size = chatList.getAdapter().getCount();
|
||||||
int nb = 0;
|
int nb = 0;
|
||||||
for(int i=0; i<size; i++) {
|
for(int i=0; i<size; i++) {
|
||||||
|
@ -165,9 +188,9 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nb;
|
return nb;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public void enabledDeleteButton(Boolean enabled){
|
/*public void enabledDeleteButton(Boolean enabled){
|
||||||
if(enabled){
|
if(enabled){
|
||||||
delete.setEnabled(true);
|
delete.setEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -175,9 +198,9 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
delete.setEnabled(false);
|
delete.setEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
private void hideAndDisplayMessageIfNoChat() {
|
/*private void hideAndDisplayMessageIfNoChat() {
|
||||||
if (mConversations.size() == 0) {
|
if (mConversations.size() == 0) {
|
||||||
noChatHistory.setVisibility(View.VISIBLE);
|
noChatHistory.setVisibility(View.VISIBLE);
|
||||||
chatList.setVisibility(View.GONE);
|
chatList.setVisibility(View.GONE);
|
||||||
|
@ -186,31 +209,23 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
noChatHistory.setVisibility(View.GONE);
|
noChatHistory.setVisibility(View.GONE);
|
||||||
chatList.setVisibility(View.VISIBLE);
|
chatList.setVisibility(View.VISIBLE);
|
||||||
chatList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
chatList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
||||||
chatList.setAdapter(new ChatListAdapter());
|
chatList.setAdapter(new ChatRoomsAdapter(getActivity(), this, mInflater));
|
||||||
edit.setEnabled(true);
|
edit.setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
private void refreshConversations() {
|
/*public void refresh() {
|
||||||
mConversations = new ArrayList<>();
|
refreshChatRoomsList();
|
||||||
ChatRoom[] chats = LinphoneManager.getLc().getChatRooms();
|
|
||||||
for (ChatRoom room : chats) {
|
|
||||||
mConversations.add(room.getPeerAddress().asStringUriOnly());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void refresh() {
|
|
||||||
refreshConversations();
|
|
||||||
hideAndDisplayMessageIfNoChat();
|
hideAndDisplayMessageIfNoChat();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public void displayFirstChat(){
|
/*public void displayFirstChat(){
|
||||||
if (mConversations != null && mConversations.size() > 0) {
|
if (mConversations != null && mConversations.size() > 0) {
|
||||||
LinphoneActivity.instance().displayChat(mConversations.get(0), null, null);
|
LinphoneActivity.instance().displayChat(mConversations.get(0), null, null);
|
||||||
} else {
|
} else {
|
||||||
LinphoneActivity.instance().displayEmptyFragment();
|
LinphoneActivity.instance().displayEmptyFragment();
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
|
@ -233,7 +248,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
lc.addListener(mListener);
|
lc.addListener(mListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh();
|
refreshChatRoomsList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -251,19 +266,28 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
if (!LinphoneActivity.isInstanciated() || LinphoneActivity.instance().getCurrentFragment() != CHAT_LIST)
|
if (!LinphoneActivity.isInstanciated() || LinphoneActivity.instance().getCurrentFragment() != CHAT_LIST)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ChatListAdapter adapter = (ChatListAdapter)chatList.getAdapter();
|
ChatRoomsAdapter adapter = (ChatRoomsAdapter)chatList.getAdapter();
|
||||||
if (adapter != null) {
|
if (adapter != null) {
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetInvalidated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
|
||||||
|
String sipUri = chatList.getAdapter().getItem(position).toString();
|
||||||
|
|
||||||
|
if (LinphoneActivity.isInstanciated() && !isEditMode) {
|
||||||
|
LinphoneActivity.instance().goToChat(sipUri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*@Override
|
||||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
||||||
super.onCreateContextMenu(menu, v, menuInfo);
|
super.onCreateContextMenu(menu, v, menuInfo);
|
||||||
menu.add(0, v.getId(), 0, getString(R.string.delete));
|
menu.add(0, v.getId(), 0, getString(R.string.delete));
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@Override
|
/*@Override
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
|
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
|
||||||
if (info == null || info.targetView == null) {
|
if (info == null || info.targetView == null) {
|
||||||
|
@ -272,22 +296,18 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
String sipUri = chatList.getAdapter().getItem(info.position).toString();
|
String sipUri = chatList.getAdapter().getItem(info.position).toString();
|
||||||
|
|
||||||
LinphoneActivity.instance().removeFromChatList(sipUri);
|
LinphoneActivity.instance().removeFromChatList(sipUri);
|
||||||
refreshConversations();
|
refreshChatRoomsList();
|
||||||
if (getResources().getBoolean(R.bool.isTablet)) {
|
if (getResources().getBoolean(R.bool.isTablet)) {
|
||||||
quitEditMode();
|
quitEditMode();
|
||||||
}
|
}
|
||||||
hideAndDisplayMessageIfNoChat();
|
hideAndDisplayMessageIfNoChat();
|
||||||
return true;
|
return true;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@Override
|
/*@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
int id = v.getId();
|
int id = v.getId();
|
||||||
|
|
||||||
if (id == R.id.back_in_call) {
|
|
||||||
LinphoneActivity.instance().resetClassicMenuLayoutAndGoBackToCallIfStillRunning();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (id == R.id.select_all) {
|
if (id == R.id.select_all) {
|
||||||
deselectAll.setVisibility(View.VISIBLE);
|
deselectAll.setVisibility(View.VISIBLE);
|
||||||
|
@ -340,173 +360,12 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
hideAndDisplayMessageIfNoChat();
|
hideAndDisplayMessageIfNoChat();
|
||||||
enabledDeleteButton(false);
|
enabledDeleteButton(false);
|
||||||
}
|
}
|
||||||
else if (id == R.id.new_discussion) {
|
}*/
|
||||||
LinphoneActivity.instance().goToChatCreator(null, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
/*@Override
|
||||||
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
|
|
||||||
String sipUri = chatList.getAdapter().getItem(position).toString();
|
|
||||||
|
|
||||||
if (LinphoneActivity.isInstanciated() && !isEditMode) {
|
|
||||||
LinphoneActivity.instance().displayChat(sipUri, null, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//@Override
|
|
||||||
public void onChatUpdated() {
|
public void onChatUpdated() {
|
||||||
refresh();
|
refreshChatRoomsList();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
class ChatListAdapter extends BaseAdapter {
|
|
||||||
private class ViewHolder {
|
|
||||||
public TextView lastMessageView;
|
|
||||||
public TextView date;
|
|
||||||
public TextView displayName;
|
|
||||||
public TextView unreadMessages;
|
|
||||||
public CheckBox select;
|
|
||||||
public ImageView contactPicture;
|
|
||||||
|
|
||||||
public ViewHolder(View view) {
|
|
||||||
lastMessageView = view.findViewById(R.id.lastMessage);
|
|
||||||
date = view.findViewById(R.id.date);
|
|
||||||
displayName = view.findViewById(R.id.sipUri);
|
|
||||||
unreadMessages = view.findViewById(R.id.unreadMessages);
|
|
||||||
select = view.findViewById(R.id.delete_chatroom);
|
|
||||||
contactPicture = view.findViewById(R.id.contact_picture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ChatListAdapter() {}
|
|
||||||
|
|
||||||
public int getCount() {
|
|
||||||
return mConversations.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getItem(int position) {
|
|
||||||
return mConversations.get(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getItemId(int position) {
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
|
||||||
View view = null;
|
|
||||||
ViewHolder holder = null;
|
|
||||||
String sipUri = mConversations.get(position);
|
|
||||||
|
|
||||||
if (convertView != null) {
|
|
||||||
view = convertView;
|
|
||||||
holder = (ViewHolder) view.getTag();
|
|
||||||
} else {
|
|
||||||
view = mInflater.inflate(R.layout.chatlist_cell, parent, false);
|
|
||||||
holder = new ViewHolder(view);
|
|
||||||
view.setTag(holder);
|
|
||||||
}
|
|
||||||
|
|
||||||
Address address;
|
|
||||||
address = Factory.instance().createAddress(sipUri);
|
|
||||||
|
|
||||||
LinphoneContact contact = null;
|
|
||||||
String message = "";
|
|
||||||
Long time;
|
|
||||||
|
|
||||||
ChatRoom chatRoom = LinphoneManager.getLc().getChatRoom(address);
|
|
||||||
int unreadMessagesCount = chatRoom.getUnreadMessagesCount();
|
|
||||||
ChatMessage[] history = chatRoom.getHistory(1);
|
|
||||||
|
|
||||||
if (history.length > 0) {
|
|
||||||
ChatMessage msg = history[0];
|
|
||||||
if (msg.getFileTransferInformation() != null || msg.getExternalBodyUrl() != null || msg.getAppdata() != null) {
|
|
||||||
holder.lastMessageView.setBackgroundResource(R.drawable.chat_file_message);
|
|
||||||
time = msg.getTime();
|
|
||||||
holder.date.setText(LinphoneUtils.timestampToHumanDate(getActivity(), time, R.string.messages_list_date_format));
|
|
||||||
holder.lastMessageView.setText("");
|
|
||||||
} else if (msg.getText() != null && msg.getText().length() > 0 ){
|
|
||||||
message = msg.getText();
|
|
||||||
holder.lastMessageView.setBackgroundResource(0);
|
|
||||||
time = msg.getTime();
|
|
||||||
holder.date.setText(LinphoneUtils.timestampToHumanDate(getActivity(), time, R.string.messages_list_date_format));
|
|
||||||
holder.lastMessageView.setText(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
holder.displayName.setSelected(true); // For animation
|
|
||||||
|
|
||||||
if (!chatRoom.canHandleParticipants()) {
|
|
||||||
contact = ContactsManager.getInstance().findContactFromAddress(address);
|
|
||||||
if (contact != null) {
|
|
||||||
holder.displayName.setText(contact.getFullName());
|
|
||||||
LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), holder.contactPicture, contact.getThumbnailUri());
|
|
||||||
} else {
|
|
||||||
holder.displayName.setText(LinphoneUtils.getAddressDisplayName(address));
|
|
||||||
holder.contactPicture.setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap());
|
|
||||||
}
|
|
||||||
} else if (chatRoom.getNbParticipants() == 1 && getString(R.string.dummy_group_chat_subject).equals(chatRoom.getSubject())) {
|
|
||||||
contact = ContactsManager.getInstance().findContactFromAddress(chatRoom.getParticipants()[0].getAddress());
|
|
||||||
if (contact != null) {
|
|
||||||
holder.displayName.setText(contact.getFullName());
|
|
||||||
LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), holder.contactPicture, contact.getThumbnailUri());
|
|
||||||
} else {
|
|
||||||
holder.displayName.setText(LinphoneUtils.getAddressDisplayName(chatRoom.getParticipants()[0].getAddress()));
|
|
||||||
holder.contactPicture.setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
holder.displayName.setText(chatRoom.getSubject());
|
|
||||||
holder.contactPicture.setImageResource(R.drawable.chat_group_avatar);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unreadMessagesCount > 0) {
|
|
||||||
holder.unreadMessages.setVisibility(View.VISIBLE);
|
|
||||||
holder.unreadMessages.setText(String.valueOf(unreadMessagesCount));
|
|
||||||
if (unreadMessagesCount > 99) {
|
|
||||||
holder.unreadMessages.setTextSize(12);
|
|
||||||
}
|
|
||||||
holder.displayName.setTypeface(null, Typeface.BOLD);
|
|
||||||
} else {
|
|
||||||
holder.unreadMessages.setVisibility(View.GONE);
|
|
||||||
holder.displayName.setTypeface(null, Typeface.NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isEditMode) {
|
|
||||||
holder.unreadMessages.setVisibility(View.GONE);
|
|
||||||
holder.select.setVisibility(View.VISIBLE);
|
|
||||||
holder.select.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
|
||||||
chatList.setItemChecked(position, b);
|
|
||||||
if (getNbItemsChecked() == getCount()) {
|
|
||||||
deselectAll.setVisibility(View.VISIBLE);
|
|
||||||
selectAll.setVisibility(View.GONE);
|
|
||||||
enabledDeleteButton(true);
|
|
||||||
} else {
|
|
||||||
if (getNbItemsChecked() == 0) {
|
|
||||||
deselectAll.setVisibility(View.GONE);
|
|
||||||
selectAll.setVisibility(View.VISIBLE);
|
|
||||||
enabledDeleteButton(false);
|
|
||||||
} else {
|
|
||||||
deselectAll.setVisibility(View.GONE);
|
|
||||||
selectAll.setVisibility(View.VISIBLE);
|
|
||||||
enabledDeleteButton(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (chatList.isItemChecked(position)) {
|
|
||||||
holder.select.setChecked(true);
|
|
||||||
} else {
|
|
||||||
holder.select.setChecked(false);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (unreadMessagesCount > 0) {
|
|
||||||
holder.unreadMessages.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
225
src/android/org/linphone/chat/ChatRoomsAdapter.java
Normal file
225
src/android/org/linphone/chat/ChatRoomsAdapter.java
Normal file
|
@ -0,0 +1,225 @@
|
||||||
|
/*
|
||||||
|
ChatRoomsAdapter.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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.linphone.chat;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Typeface;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.BaseAdapter;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.linphone.LinphoneManager;
|
||||||
|
import org.linphone.LinphoneUtils;
|
||||||
|
import org.linphone.R;
|
||||||
|
import org.linphone.activities.LinphoneActivity;
|
||||||
|
import org.linphone.contacts.ContactsManager;
|
||||||
|
import org.linphone.contacts.LinphoneContact;
|
||||||
|
import org.linphone.core.Address;
|
||||||
|
import org.linphone.core.ChatMessage;
|
||||||
|
import org.linphone.core.ChatRoom;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ChatRoomsAdapter extends BaseAdapter {
|
||||||
|
private class ChatRoomViewHolder {
|
||||||
|
public TextView lastMessageView;
|
||||||
|
public TextView date;
|
||||||
|
public TextView displayName;
|
||||||
|
public TextView unreadMessages;
|
||||||
|
public CheckBox select;
|
||||||
|
public ImageView contactPicture;
|
||||||
|
|
||||||
|
public ChatRoomViewHolder(View view) {
|
||||||
|
lastMessageView = view.findViewById(R.id.lastMessage);
|
||||||
|
date = view.findViewById(R.id.date);
|
||||||
|
displayName = view.findViewById(R.id.sipUri);
|
||||||
|
unreadMessages = view.findViewById(R.id.unreadMessages);
|
||||||
|
select = view.findViewById(R.id.delete_chatroom);
|
||||||
|
contactPicture = view.findViewById(R.id.contact_picture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
ChatListFragment mFragment;
|
||||||
|
private List<ChatRoom> mRooms;
|
||||||
|
private LayoutInflater mLayoutInflater;
|
||||||
|
private Bitmap mDefaultBitmap;
|
||||||
|
|
||||||
|
public ChatRoomsAdapter(Context context, ChatListFragment fragment, LayoutInflater inflater) {
|
||||||
|
mContext = context;
|
||||||
|
mFragment = fragment;
|
||||||
|
mLayoutInflater = inflater;
|
||||||
|
mRooms = new ArrayList<>();
|
||||||
|
mDefaultBitmap = ContactsManager.getInstance().getDefaultAvatarBitmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refresh() {
|
||||||
|
mRooms = new ArrayList<>(Arrays.asList(LinphoneManager.getLc().getChatRooms()));
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List edition
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adapter's methods
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return mRooms.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getItem(int position) {
|
||||||
|
return mRooms.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getItemId(int position) {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View convertView, ViewGroup viewGroup) {
|
||||||
|
View view = null;
|
||||||
|
ChatRoomViewHolder holder = null;
|
||||||
|
|
||||||
|
if (convertView != null) {
|
||||||
|
view = convertView;
|
||||||
|
holder = (ChatRoomViewHolder) view.getTag();
|
||||||
|
} else {
|
||||||
|
view = mLayoutInflater.inflate(R.layout.chatlist_cell, viewGroup, false);
|
||||||
|
holder = new ChatRoomViewHolder(view);
|
||||||
|
view.setTag(holder);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatRoom chatRoom = mRooms.get(position);
|
||||||
|
Address remoteAddress = chatRoom.getPeerAddress();
|
||||||
|
Address contactAddress = remoteAddress;
|
||||||
|
if (chatRoom.getNbParticipants() == 1 && mContext.getString(R.string.dummy_group_chat_subject).equals(chatRoom.getSubject())) {
|
||||||
|
contactAddress = chatRoom.getParticipants()[0].getAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
LinphoneContact contact = null;
|
||||||
|
String message = "";
|
||||||
|
Long time;
|
||||||
|
|
||||||
|
int unreadMessagesCount = chatRoom.getUnreadMessagesCount();
|
||||||
|
ChatMessage[] history = chatRoom.getHistory(1);
|
||||||
|
|
||||||
|
if (history.length > 0) {
|
||||||
|
ChatMessage msg = history[0];
|
||||||
|
if (msg.getFileTransferInformation() != null || msg.getExternalBodyUrl() != null || msg.getAppdata() != null) {
|
||||||
|
holder.lastMessageView.setBackgroundResource(R.drawable.chat_file_message);
|
||||||
|
time = msg.getTime();
|
||||||
|
holder.date.setText(LinphoneUtils.timestampToHumanDate(mContext, time, R.string.messages_list_date_format));
|
||||||
|
holder.lastMessageView.setText("");
|
||||||
|
} else if (msg.getText() != null && msg.getText().length() > 0 ){
|
||||||
|
message = msg.getText();
|
||||||
|
holder.lastMessageView.setBackgroundResource(0);
|
||||||
|
time = msg.getTime();
|
||||||
|
holder.date.setText(LinphoneUtils.timestampToHumanDate(mContext, time, R.string.messages_list_date_format));
|
||||||
|
holder.lastMessageView.setText(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
holder.displayName.setSelected(true); // For animation
|
||||||
|
|
||||||
|
if (!chatRoom.canHandleParticipants()) {
|
||||||
|
contact = ContactsManager.getInstance().findContactFromAddress(contactAddress);
|
||||||
|
if (contact != null) {
|
||||||
|
holder.displayName.setText(contact.getFullName());
|
||||||
|
LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), holder.contactPicture, contact.getThumbnailUri());
|
||||||
|
} else {
|
||||||
|
holder.displayName.setText(LinphoneUtils.getAddressDisplayName(contactAddress));
|
||||||
|
holder.contactPicture.setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap());
|
||||||
|
}
|
||||||
|
} else if (chatRoom.getNbParticipants() == 1 && mContext.getString(R.string.dummy_group_chat_subject).equals(chatRoom.getSubject())) {
|
||||||
|
contact = ContactsManager.getInstance().findContactFromAddress(chatRoom.getParticipants()[0].getAddress());
|
||||||
|
if (contact != null) {
|
||||||
|
holder.displayName.setText(contact.getFullName());
|
||||||
|
LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), holder.contactPicture, contact.getThumbnailUri());
|
||||||
|
} else {
|
||||||
|
holder.displayName.setText(LinphoneUtils.getAddressDisplayName(chatRoom.getParticipants()[0].getAddress()));
|
||||||
|
holder.contactPicture.setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
holder.displayName.setText(chatRoom.getSubject());
|
||||||
|
holder.contactPicture.setImageResource(R.drawable.chat_group_avatar);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unreadMessagesCount > 0) {
|
||||||
|
holder.unreadMessages.setVisibility(View.VISIBLE);
|
||||||
|
holder.unreadMessages.setText(String.valueOf(unreadMessagesCount));
|
||||||
|
if (unreadMessagesCount > 99) {
|
||||||
|
holder.unreadMessages.setTextSize(12);
|
||||||
|
}
|
||||||
|
holder.displayName.setTypeface(null, Typeface.BOLD);
|
||||||
|
} else {
|
||||||
|
holder.unreadMessages.setVisibility(View.GONE);
|
||||||
|
holder.displayName.setTypeface(null, Typeface.NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if (isEditMode) {
|
||||||
|
holder.unreadMessages.setVisibility(View.GONE);
|
||||||
|
holder.select.setVisibility(View.VISIBLE);
|
||||||
|
holder.select.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||||
|
chatList.setItemChecked(position, b);
|
||||||
|
if (getNbItemsChecked() == getCount()) {
|
||||||
|
deselectAll.setVisibility(View.VISIBLE);
|
||||||
|
selectAll.setVisibility(View.GONE);
|
||||||
|
enabledDeleteButton(true);
|
||||||
|
} else {
|
||||||
|
if (getNbItemsChecked() == 0) {
|
||||||
|
deselectAll.setVisibility(View.GONE);
|
||||||
|
selectAll.setVisibility(View.VISIBLE);
|
||||||
|
enabledDeleteButton(false);
|
||||||
|
} else {
|
||||||
|
deselectAll.setVisibility(View.GONE);
|
||||||
|
selectAll.setVisibility(View.VISIBLE);
|
||||||
|
enabledDeleteButton(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (chatList.isItemChecked(position)) {
|
||||||
|
holder.select.setChecked(true);
|
||||||
|
} else {
|
||||||
|
holder.select.setChecked(false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (unreadMessagesCount > 0) {
|
||||||
|
holder.unreadMessages.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
}
|
|
@ -448,7 +448,7 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
|
||||||
private void initChatRoom() {
|
private void initChatRoom() {
|
||||||
Core core = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
Core core = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||||
if (mRemoteSipAddress == null || mRemoteSipUri == null || mRemoteSipUri.length() == 0 || core == null) {
|
if (mRemoteSipAddress == null || mRemoteSipUri == null || mRemoteSipUri.length() == 0 || core == null) {
|
||||||
LinphoneActivity.instance().goToDialerFragment();
|
//TODO error
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue