Selection des items achevÃee, selection totale, annulation, affichage des boutons contextuels. A ajouter la suppression, deselection totale.
This commit is contained in:
parent
8006231a69
commit
10565fd636
3 changed files with 214 additions and 7 deletions
|
@ -14,6 +14,7 @@
|
|||
android:contentDescription="@string/content_description_delete"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"
|
||||
android:adjustViewBounds="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
|
|
|
@ -27,9 +27,11 @@ import android.support.v7.widget.RecyclerView;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
@ -59,12 +61,16 @@ import static org.linphone.fragments.FragmentsAvailable.CHAT_LIST;
|
|||
public class ChatListFragment extends Fragment implements ContactsUpdatedListener, ListSelectionHelper.DeleteListener {
|
||||
//public class ChatListFragment extends Fragment {
|
||||
// private LayoutInflater mInflater;
|
||||
private ActionModeCallback actionModeCallback = new ActionModeCallback();
|
||||
private ActionMode actionMode;
|
||||
private LinearLayout mEditTopBar, mTopBar;
|
||||
private ImageView mEditButton, mSelectAllButton, mDeselectAllButton, mDeleteSelectionButton, mCancelButton;
|
||||
private RecyclerView mChatRoomsList;
|
||||
private TextView mNoChatHistory;
|
||||
private ImageView mNewDiscussionButton, mBackToCallButton;
|
||||
private ChatRoomsAdapter mChatRoomsAdapter;
|
||||
private CoreListenerStub mListener;
|
||||
private ListSelectionHelper mSelectionHelper;
|
||||
// private ListSelectionHelper mSelectionHelper;
|
||||
private RelativeLayout mWaitLayout;
|
||||
private int mChatRoomDeletionPendingCount;
|
||||
private ChatRoomListenerStub mChatRoomListener;
|
||||
|
@ -76,6 +82,8 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
|||
// mInflater = inflater;
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
mRooms = new ArrayList<>(Arrays.asList(LinphoneManager.getLc().getChatRooms()));
|
||||
this.mContext = getActivity().getApplicationContext();
|
||||
View view = inflater.inflate(R.layout.chatlist, container, false);
|
||||
|
@ -87,14 +95,43 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
|||
// mSelectionHelper.setAdapter(mChatRoomsAdapter);
|
||||
// mSelectionHelper.setDialogMessage(R.string.chat_room_delete_dialog);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
mWaitLayout = view.findViewById(R.id.waitScreen);
|
||||
mWaitLayout.setVisibility(View.GONE);
|
||||
|
||||
mChatRoomsList = view.findViewById(R.id.chatList);
|
||||
mChatRoomsList.setAdapter(mChatRoomsAdapter);
|
||||
mChatRoomsList.setLayoutManager(layoutManager);
|
||||
mNoChatHistory = view.findViewById(R.id.noChatHistory);
|
||||
mNoChatHistory.setVisibility(View.GONE);
|
||||
// mNoChatHistory = view.findViewById(R.id.noChatHistory);
|
||||
|
||||
// mNoChatHistory.setVisibility(View.GONE);
|
||||
mEditTopBar = view.findViewById(R.id.edit_list);
|
||||
mTopBar = view.findViewById(R.id.top_bar);
|
||||
mSelectAllButton = view.findViewById(R.id.select_all);
|
||||
mEditButton = view.findViewById(R.id.edit);
|
||||
mEditButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
actionMode = getActivity().startActionMode(actionModeCallback);
|
||||
// mChatRoomsAdapter.setEditionMode(actionMode);
|
||||
// mTopBar.setVisibility(View.GONE);
|
||||
// mEditTopBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
mCancelButton = view.findViewById(R.id.cancel);
|
||||
// mCancelButton.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// actionMode.invalidate();
|
||||
// }
|
||||
// });
|
||||
mDeselectAllButton = view.findViewById(R.id.deselect_all);
|
||||
|
||||
|
||||
|
||||
mNewDiscussionButton = view.findViewById(R.id.new_discussion);
|
||||
mNewDiscussionButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
@ -148,9 +185,135 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
|||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClicked(int position) {
|
||||
if (actionMode != null) {
|
||||
toggleSelection(position);
|
||||
}else{
|
||||
ChatRoom room = (ChatRoom) mChatRoomsAdapter.getItem(position);
|
||||
LinphoneActivity.instance().goToChat(room.getPeerAddress().asString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemLongClicked(int position) {
|
||||
if (actionMode == null) {
|
||||
|
||||
actionMode = getActivity().startActionMode(actionModeCallback);
|
||||
}
|
||||
|
||||
toggleSelection(position);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void toggleSelection(int position) {
|
||||
mChatRoomsAdapter.toggleSelection(position);
|
||||
//
|
||||
int count = mChatRoomsAdapter.getSelectedItemCount();
|
||||
|
||||
if (count <= mChatRoomsAdapter.getItemCount()) {
|
||||
// actionMode.finish();
|
||||
mDeselectAllButton.setVisibility(View.GONE);
|
||||
mSelectAllButton.setVisibility(View.VISIBLE);
|
||||
actionMode.invalidate();
|
||||
} else {
|
||||
|
||||
// actionMode.setTitle(String.valueOf(count));
|
||||
mSelectAllButton.setVisibility(View.GONE);
|
||||
mDeselectAllButton.setVisibility(View.VISIBLE);
|
||||
actionMode.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private class ActionModeCallback implements ActionMode.Callback {
|
||||
@SuppressWarnings("unused")
|
||||
private final String TAG = ActionModeCallback.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||
mTopBar.setVisibility(View.GONE);
|
||||
mEditTopBar.setVisibility(View.VISIBLE);
|
||||
|
||||
|
||||
for (Integer i = 0; i <= mChatRoomsAdapter.getItemCount(); i++) {
|
||||
mChatRoomsAdapter.setEditionMode(mode);
|
||||
}
|
||||
mode.getMenuInflater().inflate (R.menu.edit_list_menu, menu);
|
||||
|
||||
mCancelButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
actionMode.finish();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//Add all non-selected items to the selection
|
||||
mSelectAllButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
for (Integer i = 0; i <= mChatRoomsAdapter.getItemCount(); i++) {
|
||||
if (!mChatRoomsAdapter.isSelected(i)) {
|
||||
toggleSelection(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
||||
// int cpt = 0;
|
||||
// while (cpt <= mChatRoomsAdapter.getItemCount()) {
|
||||
// mChatRoomsAdapter.setEditionMode(mode);
|
||||
// cpt++;
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.delete_button:
|
||||
// TODO: actually remove items
|
||||
Log.d(TAG, "menu_remove");
|
||||
mode.finish();
|
||||
return true;
|
||||
case R.id.cancel:
|
||||
mode.finish();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyActionMode(ActionMode mode) {
|
||||
mTopBar.setVisibility(View.VISIBLE);
|
||||
mEditTopBar.setVisibility(View.GONE);
|
||||
|
||||
mChatRoomsAdapter.clearSelection();
|
||||
actionMode = null;
|
||||
mChatRoomsAdapter.setEditionMode(actionMode);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void refreshChatRoomsList() {
|
||||
mChatRoomsAdapter.refresh();
|
||||
mNoChatHistory.setVisibility(mChatRoomsAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||
// mNoChatHistory.setVisibility(mChatRoomsAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
public void displayFirstChat() {
|
||||
|
@ -232,7 +395,7 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
|||
|
||||
ChatRoomsAdapter adapter = (ChatRoomsAdapter) mChatRoomsList.getAdapter();
|
||||
if (adapter != null) {
|
||||
//adapter.notifyDataSetInvalidated();
|
||||
// adapter.notifyDataSetInvalidated();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import android.graphics.BitmapFactory;
|
|||
import android.net.Uri;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.ActionMode;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -66,7 +67,8 @@ public class ChatRoomsAdapter extends RecyclerView.Adapter<ChatRoomsAdapter.Chat
|
|||
public Context mContext;
|
||||
public ChatRoom mRoom;
|
||||
|
||||
public ChatRoomViewHolder(Context context,View itemView) {
|
||||
|
||||
public ChatRoomViewHolder(Context context,View itemView, ClickListener listener) {
|
||||
super(itemView);
|
||||
this.mContext= context;
|
||||
this.lastMessageSenderView = itemView.findViewById(R.id.lastMessageSender);
|
||||
|
@ -76,6 +78,9 @@ public class ChatRoomsAdapter extends RecyclerView.Adapter<ChatRoomsAdapter.Chat
|
|||
this.unreadMessages = itemView.findViewById(R.id.unreadMessages);
|
||||
this.delete = itemView.findViewById(R.id.delete_chatroom);
|
||||
this.contactPicture = itemView.findViewById(R.id.contact_picture);
|
||||
//this.selectedOverlay = itemView.findViewById(R.id.selected_overlay);
|
||||
this.listener = listener;
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
}
|
||||
public void bindChatRoom(ChatRoom room) {
|
||||
|
@ -87,7 +92,11 @@ public class ChatRoomsAdapter extends RecyclerView.Adapter<ChatRoomsAdapter.Chat
|
|||
this.date.setText(mRoom.getLastMessageInHistory()!=null ? LinphoneUtils.timestampToHumanDate(this.mContext, mRoom.getLastUpdateTime(), R.string.messages_list_date_format) : "");
|
||||
this.displayName.setText(getContact(mRoom));
|
||||
this.unreadMessages.setText(String.valueOf(LinphoneManager.getInstance().getUnreadCountForChatRoom(mRoom)));
|
||||
this.delete.setChecked(!this.delete.isChecked());
|
||||
// this.delete.setChecked(!this.delete.isChecked());
|
||||
// this.delete.setChecked(!this.delete.isChecked());
|
||||
// this.delete.setVisibility(this.editionMode == true ? View.VISIBLE : View.INVISIBLE);
|
||||
// this.unreadMessages.setVisibility(this.editionMode == false ? View.VISIBLE : View.INVISIBLE);
|
||||
|
||||
getAvatar(mRoom);
|
||||
|
||||
}
|
||||
|
@ -101,6 +110,16 @@ public class ChatRoomsAdapter extends RecyclerView.Adapter<ChatRoomsAdapter.Chat
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
if (listener != null) {
|
||||
|
||||
return listener.onItemLongClicked(getAdapterPosition());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public String getSender(ChatRoom mRoom){
|
||||
if (mRoom.getLastMessageInHistory() != null) {
|
||||
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(mRoom.getLastMessageInHistory().getFromAddress());
|
||||
|
@ -138,6 +157,7 @@ public class ChatRoomsAdapter extends RecyclerView.Adapter<ChatRoomsAdapter.Chat
|
|||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private Context mContext;
|
||||
|
@ -146,9 +166,16 @@ public class ChatRoomsAdapter extends RecyclerView.Adapter<ChatRoomsAdapter.Chat
|
|||
private Bitmap mDefaultBitmap, mDefaultGroupBitmap;
|
||||
private ChatRoomListenerStub mListener;
|
||||
private int itemResource;
|
||||
private ChatRoomViewHolder.ClickListener clickListener;
|
||||
private boolean editionMode;
|
||||
|
||||
// public ChatRoomsAdapter(Context context, int itemResource, List<ChatRoom> mRooms) {
|
||||
public ChatRoomsAdapter(Context context, int itemResource, List<ChatRoom> mRooms, ChatRoomViewHolder.ClickListener clickListener) {
|
||||
|
||||
public ChatRoomsAdapter(Context context, int itemResource, List<ChatRoom> mRooms) {
|
||||
super();
|
||||
this.editionMode = false;
|
||||
this.clickListener = clickListener;
|
||||
this.mRooms = mRooms;
|
||||
this.mContext = context;
|
||||
this.itemResource = itemResource;
|
||||
|
@ -182,10 +209,25 @@ public class ChatRoomsAdapter extends RecyclerView.Adapter<ChatRoomsAdapter.Chat
|
|||
// 5. Use position to access the correct Bakery object
|
||||
ChatRoom room = this.mRooms.get(position);
|
||||
|
||||
//Colors the item when selected
|
||||
holder.delete.setVisibility(this.editionMode == true ? View.VISIBLE : View.INVISIBLE);
|
||||
holder.unreadMessages.setVisibility(this.editionMode == false ? View.VISIBLE : View.INVISIBLE);
|
||||
|
||||
holder.delete.setChecked(isSelected(position) ? true : false);
|
||||
// holder.unreadMessages.setVisibility(View.VISIBLE);
|
||||
// 6. Bind the bakery object to the holder
|
||||
holder.bindChatRoom(room);
|
||||
}
|
||||
public void setEditionMode(ActionMode actionMode) {
|
||||
if ( actionMode != null) {
|
||||
this.editionMode=true;
|
||||
this.notifyDataSetChanged();
|
||||
} else {
|
||||
this.editionMode=false;
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
}
|
||||
public void refresh() {
|
||||
mRooms = new ArrayList<>(Arrays.asList(LinphoneManager.getLc().getChatRooms()));
|
||||
Collections.sort(mRooms, new Comparator<ChatRoom>() {
|
||||
|
@ -232,6 +274,7 @@ public class ChatRoomsAdapter extends RecyclerView.Adapter<ChatRoomsAdapter.Chat
|
|||
return position;
|
||||
}
|
||||
|
||||
|
||||
// @Override
|
||||
// public View getView(final int position, View convertView, ViewGroup viewGroup) {
|
||||
// View view;
|
||||
|
|
Loading…
Reference in a new issue