Commentaires et nettoyage effectuÃe
This commit is contained in:
parent
6faa06a6b0
commit
20c82860bd
6 changed files with 149 additions and 424 deletions
|
@ -54,7 +54,7 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<include layout="@layout/edit_list"/>
|
<include layout="@layout/edit_list"/>
|
||||||
<!--<include layout="@layout/context_bar"></include>-->
|
|
||||||
<android.support.v7.widget.RecyclerView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/chatList"
|
android:id="@+id/chatList"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"-->
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="https://schemas.android.com/apk/res-auto"
|
|
||||||
android:id="@+id/edit_list_menu"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:background="@color/colorA"
|
|
||||||
android:height="1dp"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="1dp"
|
|
||||||
android:visibility="gone"
|
|
||||||
>
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/delete"
|
|
||||||
android:icon="@drawable/delete"
|
|
||||||
app:showAsAction="ifRoom"
|
|
||||||
android:orderInCategory="1000"
|
|
||||||
android:title=""/>
|
|
||||||
<item
|
|
||||||
android:id="@+id/select_all"
|
|
||||||
android:icon="@drawable/select_all"
|
|
||||||
app:showAsAction="ifRoom"
|
|
||||||
android:orderInCategory="100"
|
|
||||||
android:title=""/>
|
|
||||||
<item
|
|
||||||
android:id="@+id/deselect_all"
|
|
||||||
android:icon="@drawable/deselect_all"
|
|
||||||
app:showAsAction="ifRoom"
|
|
||||||
android:orderInCategory="100"
|
|
||||||
android:visible="false"
|
|
||||||
android:title=""/>
|
|
||||||
|
|
||||||
</menu>
|
|
|
@ -6,47 +6,29 @@
|
||||||
<item name="android:fastScrollTextColor">@android:color/white</item>
|
<item name="android:fastScrollTextColor">@android:color/white</item>
|
||||||
<item name="android:fastScrollPreviewBackgroundRight">@drawable/fast_scroll_preview</item>
|
<item name="android:fastScrollPreviewBackgroundRight">@drawable/fast_scroll_preview</item>
|
||||||
<item name="android:windowActionModeOverlay">true</item>
|
<item name="android:windowActionModeOverlay">true</item>
|
||||||
<!--<item name="windowActionBar">false</item>-->
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="NoTitle.ActionMode" parent="@style/Widget.AppCompat.ActionMode">
|
<style name="NoTitle.ActionMode" parent="@style/Widget.AppCompat.ActionMode">
|
||||||
|
<!--Invisible ContextActionBar-->
|
||||||
<item name="android:background"></item>
|
<item name="android:background"></item>
|
||||||
<item name="android:height">1dp</item>
|
<item name="android:height">1dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="ActionModeButtonStyle" parent="Widget.AppCompat.ActionButton">
|
|
||||||
<item name="android:minWidth">1dp</item>
|
|
||||||
<item name="android:maxWidth">1dp</item>
|
|
||||||
<item name="android:width">1dp</item>
|
|
||||||
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<style name="NoCloseButton" parent="@android:style/Widget.ActionButton.CloseMode">
|
|
||||||
<!--<item name="android:visibility">invisible</item>-->
|
|
||||||
<item name="android:maxWidth">10dp</item>
|
|
||||||
<item name="android:minWidth">10dp</item>
|
|
||||||
<item name="android:width">10dp</item>
|
|
||||||
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<style name="NoTitle" parent="android:Theme.Holo.Light.NoActionBar">
|
<style name="NoTitle" parent="android:Theme.Holo.Light.NoActionBar">
|
||||||
<item name="android:actionButtonStyle">@style/ActionModeButtonStyle</item>
|
|
||||||
<item name="android:actionModeStyle">@style/NoTitle.ActionMode</item>
|
<item name="android:actionModeStyle">@style/NoTitle.ActionMode</item>
|
||||||
<item name="android:actionModeCloseDrawable">@drawable/cancel_with_padding</item>
|
<item name="android:actionModeCloseDrawable">@drawable/cancel_with_padding</item>
|
||||||
<item name="android:actionModeCloseButtonStyle">@style/NoCloseButton</item>
|
|
||||||
<!--<item name="android:actionModeBackground">@color/colorE</item>-->
|
|
||||||
<item name="android:fastScrollThumbDrawable">@drawable/fast_scroll</item>
|
<item name="android:fastScrollThumbDrawable">@drawable/fast_scroll</item>
|
||||||
<item name="android:fastScrollTextColor">@android:color/white</item>
|
<item name="android:fastScrollTextColor">@android:color/white</item>
|
||||||
<item name="android:fastScrollPreviewBackgroundRight">@drawable/fast_scroll_preview</item>
|
<item name="android:fastScrollPreviewBackgroundRight">@drawable/fast_scroll_preview</item>
|
||||||
<item name="android:windowActionModeOverlay">true</item>
|
<item name="android:windowActionModeOverlay">true</item>
|
||||||
<!--<item name="windowActionBar">true</item>-->
|
<!--windowActionModeOverlay prevents the CAB to push all others layouts to bottom-->
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
<style name="FullScreen" parent="android:Theme.Holo.Light.NoActionBar">
|
<style name="FullScreen" parent="android:Theme.Holo.Light.NoActionBar">
|
||||||
<item name="android:fastScrollThumbDrawable">@drawable/fast_scroll</item>
|
<item name="android:fastScrollThumbDrawable">@drawable/fast_scroll</item>
|
||||||
<item name="android:fastScrollTextColor">@android:color/white</item>
|
<item name="android:fastScrollTextColor">@android:color/white</item>
|
||||||
<item name="android:fastScrollPreviewBackgroundRight">@drawable/fast_scroll_preview</item>
|
<item name="android:fastScrollPreviewBackgroundRight">@drawable/fast_scroll_preview</item>
|
||||||
<item name="android:windowActionModeOverlay">true</item>
|
<item name="android:windowActionModeOverlay">true</item>
|
||||||
<!--<item name="windowActionBar">false</item>-->
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="font1" parent="@android:style/TextAppearance.Medium">
|
<style name="font1" parent="@android:style/TextAppearance.Medium">
|
||||||
|
|
|
@ -19,13 +19,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
package org.linphone.chat;
|
package org.linphone.chat;
|
||||||
|
|
||||||
//import android.support.v7.view.ActionMode;
|
|
||||||
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.widget.DrawerLayout;
|
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||||
|
@ -60,24 +57,21 @@ import java.util.List;
|
||||||
|
|
||||||
import static org.linphone.fragments.FragmentsAvailable.CHAT_LIST;
|
import static org.linphone.fragments.FragmentsAvailable.CHAT_LIST;
|
||||||
|
|
||||||
//import android.widget.Toolbar;
|
/*
|
||||||
|
* Sources: Linphone + https://enoent.fr/blog/2015/01/18/recyclerview-basics/
|
||||||
|
* */
|
||||||
|
|
||||||
//public class ChatListFragment extends Fragment implements ContactsUpdatedListener, ListSelectionHelper.DeleteListener {
|
|
||||||
public class ChatListFragment extends Fragment implements ContactsUpdatedListener, ChatRoomsAdapter.ChatRoomViewHolder.ClickListener {
|
public class ChatListFragment extends Fragment implements ContactsUpdatedListener, ChatRoomsAdapter.ChatRoomViewHolder.ClickListener {
|
||||||
|
|
||||||
//public class ChatListFragment extends Fragment {
|
|
||||||
private ActionModeCallback actionModeCallback = new ActionModeCallback();
|
private ActionModeCallback actionModeCallback = new ActionModeCallback();
|
||||||
private ActionMode actionMode;
|
private ActionMode actionMode;
|
||||||
|
private LinearLayout mEditTopBar, mTopBar;
|
||||||
private LinearLayout mTabBar, mEditTopBar, mTopBar;
|
|
||||||
private DrawerLayout mSideMenu;
|
|
||||||
private ImageView mEditButton, mSelectAllButton, mDeselectAllButton,mDeleteButton, mCancelButton;
|
private ImageView mEditButton, mSelectAllButton, mDeselectAllButton,mDeleteButton, mCancelButton;
|
||||||
private RecyclerView mChatRoomsList;
|
private RecyclerView mChatRoomsList;
|
||||||
private TextView mNoChatHistory;
|
private TextView mNoChatHistory;
|
||||||
private ImageView mNewDiscussionButton, mBackToCallButton;
|
private ImageView mNewDiscussionButton, mBackToCallButton;
|
||||||
private ChatRoomsAdapter mChatRoomsAdapter;
|
private ChatRoomsAdapter mChatRoomsAdapter;
|
||||||
private CoreListenerStub mListener;
|
private CoreListenerStub mListener;
|
||||||
// private ListSelectionHelper mSelectionHelper;
|
|
||||||
private RelativeLayout mWaitLayout;
|
private RelativeLayout mWaitLayout;
|
||||||
private int mChatRoomDeletionPendingCount;
|
private int mChatRoomDeletionPendingCount;
|
||||||
private ChatRoomListenerStub mChatRoomListener;
|
private ChatRoomListenerStub mChatRoomListener;
|
||||||
|
@ -86,43 +80,42 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
// mInflater = inflater;
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
//We get back all ChatRooms from the LinphoneManager and store them
|
||||||
setHasOptionsMenu(true);
|
|
||||||
mRooms = new ArrayList<>(Arrays.asList(LinphoneManager.getLc().getChatRooms()));
|
mRooms = new ArrayList<>(Arrays.asList(LinphoneManager.getLc().getChatRooms()));
|
||||||
|
|
||||||
this.mContext = getActivity().getApplicationContext();
|
this.mContext = getActivity().getApplicationContext();
|
||||||
View view = inflater.inflate(R.layout.chatlist, container, false);
|
View view = inflater.inflate(R.layout.chatlist, container, false);
|
||||||
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(mContext);
|
|
||||||
|
|
||||||
// Toolbar toolbar = this.getActivity().findViewById(R.id.context_bar);
|
|
||||||
|
|
||||||
// mChatRoomsAdapter = new ChatRoomsAdapter(mContext, R.layout.chatlist_cell, mRooms);
|
|
||||||
mChatRoomsAdapter = new ChatRoomsAdapter(mContext, R.layout.chatlist_cell, mRooms,this);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// mSelectionHelper = new ListSelectionHelper(view, this);
|
|
||||||
// mChatRoomsAdapter = new ChatRoomsAdapter(this, mSelectionHelper, mRooms);
|
|
||||||
// mSelectionHelper.setAdapter(mChatRoomsAdapter);
|
|
||||||
// mSelectionHelper.setDialogMessage(R.string.chat_room_delete_dialog);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Views definition
|
||||||
|
mChatRoomsList = view.findViewById(R.id.chatList);
|
||||||
mWaitLayout = view.findViewById(R.id.waitScreen);
|
mWaitLayout = view.findViewById(R.id.waitScreen);
|
||||||
|
mEditTopBar = view.findViewById(R.id.edit_list);
|
||||||
|
mTopBar = view.findViewById(R.id.top_bar);
|
||||||
|
mSelectAllButton = view.findViewById(R.id.select_all);
|
||||||
|
mDeselectAllButton = view.findViewById(R.id.deselect_all);
|
||||||
|
mDeleteButton= view.findViewById(R.id.delete);
|
||||||
|
mEditButton = view.findViewById(R.id.edit);
|
||||||
|
mCancelButton = view.findViewById(R.id.cancel);
|
||||||
|
mNewDiscussionButton = view.findViewById(R.id.new_discussion);
|
||||||
|
mBackToCallButton = view.findViewById(R.id.back_in_call);
|
||||||
|
|
||||||
|
//Creation and affectation of adapter to the RecyclerView
|
||||||
|
mChatRoomsAdapter = new ChatRoomsAdapter(mContext, R.layout.chatlist_cell, mRooms,this);
|
||||||
|
mChatRoomsList.setAdapter(mChatRoomsAdapter);
|
||||||
|
|
||||||
|
//Initialize the LayoutManager
|
||||||
|
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(mContext);
|
||||||
|
mChatRoomsList.setLayoutManager(layoutManager);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mWaitLayout.setVisibility(View.GONE);
|
mWaitLayout.setVisibility(View.GONE);
|
||||||
|
|
||||||
mChatRoomsList = view.findViewById(R.id.chatList);
|
|
||||||
mChatRoomsList.setAdapter(mChatRoomsAdapter);
|
//Actions allowed by swipe buttons
|
||||||
mChatRoomsList.setLayoutManager(layoutManager);
|
|
||||||
// mNoChatHistory = view.findViewById(R.id.noChatHistory);
|
|
||||||
|
|
||||||
final SwipeController swipeController = new SwipeController(new SwipeControllerActions() {
|
final SwipeController swipeController = new SwipeController(new SwipeControllerActions() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -133,14 +126,15 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
||||||
@Override
|
@Override
|
||||||
public void onRightClicked(int position) {
|
public void onRightClicked(int position) {
|
||||||
mChatRoomsAdapter.removeItem(position);
|
mChatRoomsAdapter.removeItem(position);
|
||||||
// mChatRoomsAdapter.mRooms.remove(position);
|
|
||||||
// mChatRoomsAdapter.notifyItemRemoved(position);
|
|
||||||
// mChatRoomsAdapter.notifyItemRangeChanged(position, mChatRoomsAdapter.getItemCount());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Initialize swipe detection
|
||||||
|
|
||||||
ItemTouchHelper itemTouchhelper = new ItemTouchHelper(swipeController);
|
ItemTouchHelper itemTouchhelper = new ItemTouchHelper(swipeController);
|
||||||
itemTouchhelper.attachToRecyclerView(mChatRoomsList);
|
itemTouchhelper.attachToRecyclerView(mChatRoomsList);
|
||||||
|
|
||||||
|
//Add swipe buttons
|
||||||
mChatRoomsList.addItemDecoration(new RecyclerView.ItemDecoration() {
|
mChatRoomsList.addItemDecoration(new RecyclerView.ItemDecoration() {
|
||||||
@Override
|
@Override
|
||||||
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
||||||
|
@ -149,34 +143,16 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Buttons onClickListeners definitions
|
||||||
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
mDeselectAllButton = view.findViewById(R.id.deselect_all);
|
|
||||||
mDeleteButton= view.findViewById(R.id.delete);
|
|
||||||
mEditButton = view.findViewById(R.id.edit);
|
|
||||||
mEditButton.setOnClickListener(new View.OnClickListener() {
|
mEditButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
actionMode = getActivity().startActionMode(actionModeCallback);
|
//Start selection mode
|
||||||
}
|
actionMode = getActivity().startActionMode(actionModeCallback);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mCancelButton = view.findViewById(R.id.cancel);
|
|
||||||
// mCancelButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
// @Override
|
|
||||||
// public void onClick(View v) {
|
|
||||||
// actionMode.invalidate();
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// mSelectAllButton = view.findViewById(R.id.select_all);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mNewDiscussionButton = view.findViewById(R.id.new_discussion);
|
|
||||||
mNewDiscussionButton.setOnClickListener(new View.OnClickListener() {
|
mNewDiscussionButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
@ -184,7 +160,6 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mBackToCallButton = view.findViewById(R.id.back_in_call);
|
|
||||||
mBackToCallButton.setOnClickListener(new View.OnClickListener() {
|
mBackToCallButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
@ -192,6 +167,8 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
//Update ChatRoomsList on change
|
||||||
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) {
|
||||||
|
@ -206,7 +183,6 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
mChatRoomListener = new ChatRoomListenerStub() {
|
mChatRoomListener = new ChatRoomListenerStub() {
|
||||||
@Override
|
@Override
|
||||||
public void onStateChanged(ChatRoom room, ChatRoom.State state) {
|
public void onStateChanged(ChatRoom room, ChatRoom.State state) {
|
||||||
|
@ -229,8 +205,6 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemClicked(int position) {
|
public void onItemClicked(int position) {
|
||||||
if (actionMode != null) {
|
if (actionMode != null) {
|
||||||
|
@ -244,40 +218,38 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemLongClicked(int position) {
|
public boolean onItemLongClicked(int position) {
|
||||||
if (actionMode == null) {
|
if (actionMode == null) {
|
||||||
|
//Start selection mode
|
||||||
actionMode = getActivity().startActionMode(actionModeCallback);
|
actionMode = getActivity().startActionMode(actionModeCallback);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleSelection(position);
|
toggleSelection(position);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*Switch selection state of an item and handle
|
||||||
|
* selection buttons visibility
|
||||||
|
*/
|
||||||
private void toggleSelection(int position) {
|
private void toggleSelection(int position) {
|
||||||
|
|
||||||
mChatRoomsAdapter.toggleSelection(position);
|
mChatRoomsAdapter.toggleSelection(position);
|
||||||
//
|
|
||||||
int count = mChatRoomsAdapter.getSelectedItemCount();
|
int count = mChatRoomsAdapter.getSelectedItemCount();
|
||||||
|
if (count < mChatRoomsAdapter.getItemCount()) {
|
||||||
if (count < mChatRoomsAdapter.getItemCount()/* || (mChatRoomsAdapter.getItemCount()==1 && count == 1)*/) {
|
|
||||||
// actionMode.finish();
|
|
||||||
mDeselectAllButton.setVisibility(View.GONE);
|
mDeselectAllButton.setVisibility(View.GONE);
|
||||||
mSelectAllButton.setVisibility(View.VISIBLE);
|
mSelectAllButton.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
} /*else if (mChatRoomsAdapter.getItemCount()==1 && count == 1){
|
}else{
|
||||||
|
|
||||||
// actionMode.setTitle(String.valueOf(count));
|
|
||||||
mSelectAllButton.setVisibility(View.VISIBLE);
|
|
||||||
mDeselectAllButton.setVisibility(View.GONE);
|
|
||||||
} */else{
|
|
||||||
mSelectAllButton.setVisibility(View.GONE);
|
mSelectAllButton.setVisibility(View.GONE);
|
||||||
mDeselectAllButton.setVisibility(View.VISIBLE);
|
mDeselectAllButton.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
mChatRoomsAdapter.notifyItemChanged(position);
|
mChatRoomsAdapter.notifyItemChanged(position);
|
||||||
actionMode.invalidate();
|
actionMode.invalidate();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Selection mode (ActionMode)
|
||||||
|
|
||||||
private class ActionModeCallback implements ActionMode.Callback {
|
private class ActionModeCallback implements ActionMode.Callback {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private final String TAG = ActionModeCallback.class.getSimpleName();
|
private final String TAG = ActionModeCallback.class.getSimpleName();
|
||||||
|
@ -285,24 +257,33 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||||
actionMode=mode;
|
actionMode=mode;
|
||||||
for (Integer i = 0; i <= mChatRoomsAdapter.getItemCount(); i++) {
|
|
||||||
mChatRoomsAdapter.setEditionMode(mode);
|
|
||||||
}
|
|
||||||
mTopBar.setVisibility(View.GONE);
|
mTopBar.setVisibility(View.GONE);
|
||||||
mEditTopBar.setVisibility(View.VISIBLE);
|
mEditTopBar.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
// mode.getMenuInflater().inflate (R.menu.edit_list_menu, menu);
|
//Transmits ActionMode current state to the adapter
|
||||||
|
for (Integer i = 0; i <= mChatRoomsAdapter.getItemCount(); i++) {
|
||||||
|
mChatRoomsAdapter.setEditionMode(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Inflate custom menu, example for future plans
|
||||||
|
*mode.getMenuInflater().inflate (R.menu.edit_list_menu, menu);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
mCancelButton.setOnClickListener(new View.OnClickListener() {
|
mCancelButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
actionMode.finish();
|
actionMode.finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// mTabBar = (LinearLayout) getActivity().findViewById(R.id.footer);
|
|
||||||
// mTabBar.setVisibility(View.GONE);
|
|
||||||
// mSideMenu=(DrawerLayout) getActivity().findViewById(R.id.side_menu);
|
/*Way to disable the sliding menu (left)
|
||||||
//
|
* mSideMenu=(DrawerLayout) getActivity().findViewById(R.id.side_menu);
|
||||||
// mSideMenu.setDrawerLockMode(1);
|
* mSideMenu.setDrawerLockMode(1);
|
||||||
|
* */
|
||||||
|
|
||||||
|
|
||||||
//Add all non-selected items to the selection
|
//Add all non-selected items to the selection
|
||||||
mSelectAllButton.setOnClickListener(new View.OnClickListener() {
|
mSelectAllButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@ -335,23 +316,11 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
||||||
actionMode.finish();
|
actionMode.finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
||||||
// int cpt = 0;
|
|
||||||
// while (cpt <= mChatRoomsAdapter.getItemCount()) {
|
|
||||||
// mChatRoomsAdapter.setEditionMode(mode);
|
|
||||||
// cpt++;
|
|
||||||
// }
|
|
||||||
// final MenuItem alertMenuItem = menu.findItem(R.id.menu_search);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,34 +328,16 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
||||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
|
|
||||||
// case R.id.delete:
|
/*
|
||||||
// // TODO: actually remove items
|
Meant to execute actions as Contextual Action Bar item is clicked,
|
||||||
//// Log.d(TAG, "menu_remove");
|
unused in our case as the CAB isn't used.
|
||||||
// mChatRoomsAdapter.removeItems(mChatRoomsAdapter.getSelectedItems());
|
No need for clickListeners.
|
||||||
// mode.finish();
|
Example below for future evolution.
|
||||||
// return true;
|
|
||||||
//
|
|
||||||
// case R.id.select_all:
|
|
||||||
// //Add all non-selected items to the selection
|
|
||||||
// for (Integer i = 0; i < mChatRoomsAdapter.getItemCount(); i++) {
|
|
||||||
// if (!mChatRoomsAdapter.isSelected(i)) {
|
|
||||||
// toggleSelection(i);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return true;
|
|
||||||
|
|
||||||
// case R.id.deselect_all:
|
case R.id.delete:
|
||||||
// for (Integer i = 0; i < mChatRoomsAdapter.getItemCount(); i++) {
|
return true
|
||||||
// if (mChatRoomsAdapter.isSelected(i)) {
|
*/
|
||||||
// toggleSelection(i);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return true;
|
|
||||||
// case R.id.cancel:
|
|
||||||
// mode.finish();
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -395,30 +346,20 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
||||||
public void onDestroyActionMode(ActionMode mode) {
|
public void onDestroyActionMode(ActionMode mode) {
|
||||||
|
|
||||||
mChatRoomsAdapter.clearSelection();
|
mChatRoomsAdapter.clearSelection();
|
||||||
// mTabBar.setVisibility(View.VISIBLE);
|
|
||||||
mTopBar.setVisibility(View.VISIBLE);
|
mTopBar.setVisibility(View.VISIBLE);
|
||||||
mEditTopBar.setVisibility(View.GONE);
|
mEditTopBar.setVisibility(View.GONE);
|
||||||
mSideMenu.setDrawerLockMode(0);
|
|
||||||
|
|
||||||
mChatRoomsAdapter.clearSelection();
|
|
||||||
actionMode = null;
|
actionMode = null;
|
||||||
mChatRoomsAdapter.setEditionMode(actionMode);
|
mChatRoomsAdapter.setEditionMode(actionMode);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ActionMode ending
|
||||||
|
|
||||||
|
//Existing functions before RecyclerView conversion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void refreshChatRoomsList() {
|
private void refreshChatRoomsList() {
|
||||||
mChatRoomsAdapter.refresh();
|
mChatRoomsAdapter.refresh();
|
||||||
// mNoChatHistory.setVisibility(mChatRoomsAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
//mNoChatHistory.setVisibility(mChatRoomsAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayFirstChat() {
|
public void displayFirstChat() {
|
||||||
|
@ -465,40 +406,10 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// mChatRoomsAdapter.clear();
|
mChatRoomsAdapter.clear();
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public void onDeleteSelection(Object[] objectsToDelete) {
|
|
||||||
// Core lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
|
||||||
// mChatRoomDeletionPendingCount = objectsToDelete.length;
|
|
||||||
// for (Object obj : objectsToDelete) {
|
|
||||||
// ChatRoom room = (ChatRoom)obj;
|
|
||||||
//
|
|
||||||
// for (EventLog eventLog : room.getHistoryEvents(0)) {
|
|
||||||
// if (eventLog.getType() == EventLog.Type.ConferenceChatMessage) {
|
|
||||||
// ChatMessage message = eventLog.getChatMessage();
|
|
||||||
// if (message.getAppdata() != null && !message.isOutgoing()) {
|
|
||||||
// File file = new File(message.getAppdata());
|
|
||||||
// if (file.exists()) {
|
|
||||||
// file.delete(); // Delete downloaded file from incoming message that will be deleted
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// room.addListener(mChatRoomListener);
|
|
||||||
// lc.deleteChatRoom(room);
|
|
||||||
// }
|
|
||||||
// if (mChatRoomDeletionPendingCount > 0) {
|
|
||||||
// mWaitLayout.setVisibility(View.VISIBLE);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onContactsUpdated() {
|
public void onContactsUpdated() {
|
||||||
if (!LinphoneActivity.isInstanciated() || LinphoneActivity.instance().getCurrentFragment() != CHAT_LIST)
|
if (!LinphoneActivity.isInstanciated() || LinphoneActivity.instance().getCurrentFragment() != CHAT_LIST)
|
||||||
|
@ -506,7 +417,7 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
||||||
|
|
||||||
ChatRoomsAdapter adapter = (ChatRoomsAdapter) mChatRoomsList.getAdapter();
|
ChatRoomsAdapter adapter = (ChatRoomsAdapter) mChatRoomsList.getAdapter();
|
||||||
if (adapter != null) {
|
if (adapter != null) {
|
||||||
// adapter.notifyDataSetInvalidated();
|
adapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,24 +38,23 @@ import org.linphone.R;
|
||||||
import org.linphone.activities.LinphoneActivity;
|
import org.linphone.activities.LinphoneActivity;
|
||||||
import org.linphone.contacts.ContactsManager;
|
import org.linphone.contacts.ContactsManager;
|
||||||
import org.linphone.contacts.LinphoneContact;
|
import org.linphone.contacts.LinphoneContact;
|
||||||
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.ChatRoomListener;
|
||||||
import org.linphone.core.ChatRoomListenerStub;
|
import org.linphone.core.ChatRoomListenerStub;
|
||||||
import org.linphone.core.Core;
|
import org.linphone.core.Core;
|
||||||
|
import org.linphone.core.EventLog;
|
||||||
import org.linphone.ui.SelectableAdapter;
|
import org.linphone.ui.SelectableAdapter;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
//import org.linphone.Chat;
|
|
||||||
|
|
||||||
public class ChatRoomsAdapter extends RecyclerView.Adapter<ChatRoomsAdapter.ChatRoomViewHolder> {
|
public class ChatRoomsAdapter extends SelectableAdapter<ChatRoomsAdapter.ChatRoomViewHolder> {
|
||||||
|
|
||||||
public static class ChatRoomViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener{
|
public static class ChatRoomViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener{
|
||||||
public TextView lastMessageSenderView;
|
public TextView lastMessageSenderView;
|
||||||
|
@ -68,8 +67,6 @@ public class ChatRoomsAdapter extends RecyclerView.Adapter<ChatRoomsAdapter.Chat
|
||||||
public Context mContext;
|
public Context mContext;
|
||||||
public ChatRoom mRoom;
|
public ChatRoom mRoom;
|
||||||
public ClickListener listener;
|
public ClickListener listener;
|
||||||
public RelativeLayout viewBackground, viewForeground;
|
|
||||||
|
|
||||||
|
|
||||||
public ChatRoomViewHolder(Context context,View itemView, ClickListener listener) {
|
public ChatRoomViewHolder(Context context,View itemView, ClickListener listener) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
|
@ -81,7 +78,6 @@ public class ChatRoomsAdapter extends RecyclerView.Adapter<ChatRoomsAdapter.Chat
|
||||||
this.unreadMessages = itemView.findViewById(R.id.unreadMessages);
|
this.unreadMessages = itemView.findViewById(R.id.unreadMessages);
|
||||||
this.delete = itemView.findViewById(R.id.delete_chatroom);
|
this.delete = itemView.findViewById(R.id.delete_chatroom);
|
||||||
this.contactPicture = itemView.findViewById(R.id.contact_picture);
|
this.contactPicture = itemView.findViewById(R.id.contact_picture);
|
||||||
//this.selectedOverlay = itemView.findViewById(R.id.selected_overlay);
|
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
|
|
||||||
itemView.setOnClickListener(this);
|
itemView.setOnClickListener(this);
|
||||||
|
@ -89,40 +85,33 @@ public class ChatRoomsAdapter extends RecyclerView.Adapter<ChatRoomsAdapter.Chat
|
||||||
}
|
}
|
||||||
public void bindChatRoom(ChatRoom room) {
|
public void bindChatRoom(ChatRoom room) {
|
||||||
|
|
||||||
// 4. Bind the data to the ViewHolder
|
//Bind the data to the ViewHolder
|
||||||
this.mRoom = room;
|
this.mRoom = room;
|
||||||
this.lastMessageSenderView.setText(getSender(mRoom));
|
this.lastMessageSenderView.setText(getSender(mRoom));
|
||||||
this.lastMessageView.setText(mRoom.getLastMessageInHistory() != null ? mRoom.getLastMessageInHistory().getTextContent(): "");
|
this.lastMessageView.setText(mRoom.getLastMessageInHistory() != null ? mRoom.getLastMessageInHistory().getTextContent(): "");
|
||||||
this.date.setText(mRoom.getLastMessageInHistory()!=null ? LinphoneUtils.timestampToHumanDate(this.mContext, mRoom.getLastUpdateTime(), R.string.messages_list_date_format) : "");
|
this.date.setText(mRoom.getLastMessageInHistory()!=null ? LinphoneUtils.timestampToHumanDate(this.mContext, mRoom.getLastUpdateTime(), R.string.messages_list_date_format) : "");
|
||||||
this.displayName.setText(getContact(mRoom));
|
this.displayName.setText(getContact(mRoom));
|
||||||
this.unreadMessages.setText(String.valueOf(LinphoneManager.getInstance().getUnreadCountForChatRoom(mRoom)));
|
this.unreadMessages.setText(String.valueOf(LinphoneManager.getInstance().getUnreadCountForChatRoom(mRoom)));
|
||||||
// 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);
|
getAvatar(mRoom);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Handle the onClick/onLongClick event for the ViewHolder
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
if (listener != null) {
|
||||||
// 5. Handle the onClick event for the ViewHolder
|
listener.onItemClicked(getAdapterPosition());
|
||||||
if (this.mRoom != null) {
|
|
||||||
LinphoneActivity.instance().goToChat(mRoom.getPeerAddress().asString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onLongClick(View v) {
|
public boolean onLongClick(View v) {
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
|
|
||||||
return listener.onItemLongClicked(getAdapterPosition());
|
return listener.onItemLongClicked(getAdapterPosition());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Functions to get messages datas
|
||||||
|
|
||||||
public String getSender(ChatRoom mRoom){
|
public String getSender(ChatRoom mRoom){
|
||||||
if (mRoom.getLastMessageInHistory() != null) {
|
if (mRoom.getLastMessageInHistory() != null) {
|
||||||
|
@ -139,7 +128,6 @@ public class ChatRoomsAdapter extends RecyclerView.Adapter<ChatRoomsAdapter.Chat
|
||||||
|
|
||||||
public String getContact(ChatRoom mRoom) {
|
public String getContact(ChatRoom mRoom) {
|
||||||
LinphoneContact contact;
|
LinphoneContact contact;
|
||||||
// contact = ContactsManager.getInstance().findContactFromAddress(mRoom.getPeerAddress());
|
|
||||||
contact = ContactsManager.getInstance().findContactFromAddress(mRoom.getLastMessageInHistory().getFromAddress());
|
contact = ContactsManager.getInstance().findContactFromAddress(mRoom.getLastMessageInHistory().getFromAddress());
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
|
|
||||||
|
@ -149,32 +137,6 @@ public class ChatRoomsAdapter extends RecyclerView.Adapter<ChatRoomsAdapter.Chat
|
||||||
return (LinphoneUtils.getAddressDisplayName(mRoom.getLastMessageInHistory().getFromAddress()));
|
return (LinphoneUtils.getAddressDisplayName(mRoom.getLastMessageInHistory().getFromAddress()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//// Address remoteAddress = chatRoom.getPeerAddress();
|
|
||||||
//// Address contactAddress = remoteAddress;
|
|
||||||
// if (chatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) {
|
|
||||||
// LinphoneContact contact;
|
|
||||||
// if (chatRoom.getParticipants().length > 0) {
|
|
||||||
// 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()));
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// 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));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// holder.displayName.setText(chatRoom.getSubject());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void getAvatar(ChatRoom mRoom) {
|
public void getAvatar(ChatRoom mRoom) {
|
||||||
mDefaultBitmap = ContactsManager.getInstance().getDefaultAvatarBitmap();
|
mDefaultBitmap = ContactsManager.getInstance().getDefaultAvatarBitmap();
|
||||||
|
@ -188,20 +150,28 @@ public class ChatRoomsAdapter extends RecyclerView.Adapter<ChatRoomsAdapter.Chat
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public interface ClickListener {
|
||||||
|
void onItemClicked(int position);
|
||||||
|
boolean onItemLongClicked(int position);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
} //Holder ending
|
||||||
|
|
||||||
|
//Adapter beginning
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
public List<ChatRoom> mRooms;
|
public List<ChatRoom> mRooms;
|
||||||
private LayoutInflater mLayoutInflater;
|
private static Bitmap mDefaultBitmap;
|
||||||
private Bitmap mDefaultBitmap, mDefaultGroupBitmap;
|
//private Bitmap mDefaultGroupBitmap;
|
||||||
private ChatRoomListenerStub mListener;
|
private ChatRoomListenerStub mListener;
|
||||||
private int itemResource;
|
private int itemResource;
|
||||||
private ChatRoomViewHolder.ClickListener clickListener;
|
private ChatRoomViewHolder.ClickListener clickListener;
|
||||||
private boolean editionMode;
|
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, ChatRoomViewHolder.ClickListener clickListener) {
|
||||||
|
|
||||||
super();
|
super();
|
||||||
|
@ -211,54 +181,49 @@ public class ChatRoomsAdapter extends RecyclerView.Adapter<ChatRoomsAdapter.Chat
|
||||||
this.mContext = context;
|
this.mContext = context;
|
||||||
this.itemResource = itemResource;
|
this.itemResource = itemResource;
|
||||||
mContext = context;
|
mContext = context;
|
||||||
//mLayoutInflater = inflater;
|
|
||||||
mDefaultBitmap = ContactsManager.getInstance().getDefaultAvatarBitmap();
|
mDefaultBitmap = ContactsManager.getInstance().getDefaultAvatarBitmap();
|
||||||
mDefaultGroupBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.chat_group_avatar);
|
//mDefaultGroupBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.chat_group_avatar);
|
||||||
|
|
||||||
// mListener = new ChatRoomListenerStub() {
|
|
||||||
// @Override
|
|
||||||
// public void onSubjectChanged(ChatRoom cr, EventLog eventLog) {
|
|
||||||
// ChatRoomViewHolder holder = (ChatRoomViewHolder) cr.getUserData();
|
|
||||||
// holder.displayName.setText(cr.getSubject());
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChatRoomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public ChatRoomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
|
||||||
// 3. Inflate the view and return the new ViewHolder
|
// Inflate the view and return the new ViewHolder
|
||||||
View view = LayoutInflater.from(parent.getContext())
|
View view = LayoutInflater.from(parent.getContext())
|
||||||
.inflate(this.itemResource, parent, false);
|
.inflate(this.itemResource, parent, false);
|
||||||
return new ChatRoomViewHolder(this.mContext, view);
|
|
||||||
|
return new ChatRoomViewHolder(this.mContext, view, clickListener);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(ChatRoomViewHolder holder, int position) {
|
public void onBindViewHolder(ChatRoomViewHolder holder, int position) {
|
||||||
|
//Bind datas to the ViewHolder
|
||||||
// 5. Use position to access the correct Bakery object
|
|
||||||
ChatRoom room = this.mRooms.get(position);
|
ChatRoom room = this.mRooms.get(position);
|
||||||
|
//Shows checkboxes when ActionMode enabled
|
||||||
//Colors the item when selected
|
|
||||||
holder.delete.setVisibility(this.editionMode == true ? View.VISIBLE : View.INVISIBLE);
|
holder.delete.setVisibility(this.editionMode == true ? View.VISIBLE : View.INVISIBLE);
|
||||||
holder.unreadMessages.setVisibility(this.editionMode == false ? View.VISIBLE : View.INVISIBLE);
|
holder.unreadMessages.setVisibility(this.editionMode == false ? View.VISIBLE : View.INVISIBLE);
|
||||||
|
//Set checkbox checked if item selected
|
||||||
holder.delete.setChecked(isSelected(position) ? true : false);
|
holder.delete.setChecked(isSelected(position) ? true : false);
|
||||||
// holder.unreadMessages.setVisibility(View.VISIBLE);
|
//Bind the chatroom object to the holder
|
||||||
// 6. Bind the bakery object to the holder
|
|
||||||
holder.bindChatRoom(room);
|
holder.bindChatRoom(room);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Let know the adapter if ActionMode is enabled
|
||||||
public void setEditionMode(ActionMode actionMode) {
|
public void setEditionMode(ActionMode actionMode) {
|
||||||
if ( actionMode != null) {
|
if ( actionMode != null) {
|
||||||
this.editionMode=true;
|
this.editionMode=true;
|
||||||
this.notifyDataSetChanged();
|
this.notifyDataSetChanged(); //Needed to update the whole list checkboxes
|
||||||
} else {
|
} else {
|
||||||
this.editionMode=false;
|
this.editionMode=false;
|
||||||
this.notifyDataSetChanged();
|
this.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
mRooms = new ArrayList<>(Arrays.asList(LinphoneManager.getLc().getChatRooms()));
|
mRooms = new ArrayList<>(Arrays.asList(LinphoneManager.getLc().getChatRooms()));
|
||||||
Collections.sort(mRooms, new Comparator<ChatRoom>() {
|
Collections.sort(mRooms, new Comparator<ChatRoom>() {
|
||||||
|
@ -283,7 +248,7 @@ public class ChatRoomsAdapter extends RecyclerView.Adapter<ChatRoomsAdapter.Chat
|
||||||
public void removeItem(int position) {
|
public void removeItem(int position) {
|
||||||
|
|
||||||
Core lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
Core lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||||
// mRooms.get(position).addListener(mChatRoomListener);
|
cleanRoom(position);
|
||||||
lc.deleteChatRoom(mRooms.get(position));
|
lc.deleteChatRoom(mRooms.get(position));
|
||||||
mRooms.remove(position);
|
mRooms.remove(position);
|
||||||
notifyItemRemoved(position);
|
notifyItemRemoved(position);
|
||||||
|
@ -326,12 +291,28 @@ public class ChatRoomsAdapter extends RecyclerView.Adapter<ChatRoomsAdapter.Chat
|
||||||
private void removeRange(int positionStart, int itemCount) {
|
private void removeRange(int positionStart, int itemCount) {
|
||||||
for (int i = 0; i < itemCount; ++i) {
|
for (int i = 0; i < itemCount; ++i) {
|
||||||
Core lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
Core lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||||
|
cleanRoom(positionStart);
|
||||||
lc.deleteChatRoom(mRooms.get(positionStart));
|
lc.deleteChatRoom(mRooms.get(positionStart));
|
||||||
mRooms.remove(positionStart);
|
mRooms.remove(positionStart);
|
||||||
}
|
}
|
||||||
notifyItemRangeRemoved(positionStart, itemCount);
|
notifyItemRangeRemoved(positionStart, itemCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Delete downloaded file from incoming message that will be deleted
|
||||||
|
private void cleanRoom (int position) {
|
||||||
|
|
||||||
|
for (EventLog eventLog : mRooms.get(position).getHistoryEvents(0)) {
|
||||||
|
if (eventLog.getType() == EventLog.Type.ConferenceChatMessage) {
|
||||||
|
ChatMessage message = eventLog.getChatMessage();
|
||||||
|
if (message.getAppdata() != null && !message.isOutgoing()) {
|
||||||
|
File file = new File(message.getAppdata());
|
||||||
|
if (file.exists()) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -339,20 +320,19 @@ public class ChatRoomsAdapter extends RecyclerView.Adapter<ChatRoomsAdapter.Chat
|
||||||
* Adapter's methods
|
* Adapter's methods
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// oldVersion, kept in case of calls from other classes
|
||||||
// @Override
|
// @Override
|
||||||
// public int getCount() {
|
// public int getCount() {
|
||||||
// return mRooms.size();
|
// return mRooms.size();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
Core lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
|
||||||
|
|
||||||
return this.mRooms.size();
|
return this.mRooms.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//@Override
|
|
||||||
public Object getItem(int position) {
|
public Object getItem(int position) {
|
||||||
return mRooms.get(position);
|
return mRooms.get(position);
|
||||||
}
|
}
|
||||||
|
@ -361,122 +341,4 @@ public class ChatRoomsAdapter extends RecyclerView.Adapter<ChatRoomsAdapter.Chat
|
||||||
public long getItemId(int position) {
|
public long getItemId(int position) {
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public View getView(final int position, View convertView, ViewGroup viewGroup) {
|
|
||||||
// View view;
|
|
||||||
// ChatRoomViewHolder holder;
|
|
||||||
//
|
|
||||||
// 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.hasCapability(ChatRoomCapabilities.OneToOne.toInt()) && chatRoom.getParticipants().length > 0) {
|
|
||||||
// contactAddress = chatRoom.getParticipants()[0].getAddress();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (chatRoom.hasCapability(ChatRoomCapabilities.Conference.toInt()) && chatRoom.getState() == ChatRoom.State.Created) { // Only set for state Created otherwise it will conflict with removal listener
|
|
||||||
// chatRoom.addListener(mListener);
|
|
||||||
// chatRoom.setUserData(holder);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// int unreadMessagesCount = LinphoneManager.getInstance().getUnreadCountForChatRoom(chatRoom);
|
|
||||||
// ChatMessage lastMessage = chatRoom.getLastMessageInHistory();
|
|
||||||
// holder.lastMessageView.setText("");
|
|
||||||
// holder.lastMessageSenderView.setText("");
|
|
||||||
// holder.date.setText(LinphoneUtils.timestampToHumanDate(mContext, chatRoom.getLastUpdateTime(), R.string.messages_list_date_format));
|
|
||||||
//
|
|
||||||
// if (lastMessage != null) {
|
|
||||||
// if (lastMessage.getFileTransferInformation() != null || lastMessage.getExternalBodyUrl() != null || lastMessage.getAppdata() != null) {
|
|
||||||
// holder.lastMessageView.setBackgroundResource(R.drawable.chat_file_message);
|
|
||||||
// } else if (lastMessage.getTextContent() != null && lastMessage.getTextContent().length() > 0) {
|
|
||||||
// holder.lastMessageView.setBackgroundResource(0);
|
|
||||||
// holder.lastMessageView.setText(lastMessage.getTextContent());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Address lastMessageSenderAddress = lastMessage.getFromAddress();
|
|
||||||
// LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(lastMessageSenderAddress);
|
|
||||||
// if (contact != null) {
|
|
||||||
// holder.lastMessageSenderView.setText(contact.getFullName() + mContext.getString(R.string.separator));
|
|
||||||
// } else {
|
|
||||||
// holder.lastMessageSenderView.setText(LinphoneUtils.getAddressDisplayName(lastMessageSenderAddress) + mContext.getString(R.string.separator));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// holder.displayName.setSelected(true); // For animation
|
|
||||||
// holder.contactPicture.setImageBitmap(mDefaultBitmap);
|
|
||||||
//
|
|
||||||
// if (chatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) {
|
|
||||||
// LinphoneContact contact;
|
|
||||||
// if (chatRoom.getParticipants().length > 0) {
|
|
||||||
// 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()));
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// 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));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// holder.displayName.setText(chatRoom.getSubject());
|
|
||||||
// holder.contactPicture.setImageBitmap(mDefaultGroupBitmap);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (unreadMessagesCount > 0) {
|
|
||||||
// holder.unreadMessages.setVisibility(View.VISIBLE);
|
|
||||||
// holder.unreadMessages.setText(String.valueOf(unreadMessagesCount));
|
|
||||||
// if (unreadMessagesCount > 99) {
|
|
||||||
// holder.unreadMessages.setTextSize(12);
|
|
||||||
// }
|
|
||||||
// holder.unreadMessages.setVisibility(View.VISIBLE);
|
|
||||||
// holder.displayName.setTypeface(null, Typeface.BOLD);
|
|
||||||
// } else {
|
|
||||||
// holder.unreadMessages.setVisibility(View.GONE);
|
|
||||||
// holder.displayName.setTypeface(null, Typeface.NORMAL);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (isEditionEnabled()) {
|
|
||||||
// view.setOnClickListener(new View.OnClickListener() {
|
|
||||||
// @Override
|
|
||||||
// public void onClick(View v) {
|
|
||||||
// ChatRoomViewHolder holder = (ChatRoomViewHolder)v.getTag();
|
|
||||||
// holder.delete.setChecked(!holder.delete.isChecked());
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// holder.unreadMessages.setVisibility(View.GONE);
|
|
||||||
// holder.delete.setOnCheckedChangeListener(null);
|
|
||||||
// holder.delete.setVisibility(View.VISIBLE);
|
|
||||||
// holder.delete.setChecked(getSelectedItemsPosition().contains(position));
|
|
||||||
// holder.delete.setTag(position);
|
|
||||||
// holder.delete.setOnCheckedChangeListener(getDeleteListener());
|
|
||||||
// } else {
|
|
||||||
// view.setOnClickListener(new View.OnClickListener() {
|
|
||||||
// @Override
|
|
||||||
// public void onClick(View v) {
|
|
||||||
// ChatRoom chatRoom = mRooms.get(position);
|
|
||||||
// LinphoneActivity.instance().goToChat(chatRoom.getPeerAddress().asString());
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// holder.delete.setVisibility(isEditionEnabled() ? View.VISIBLE : View.GONE);
|
|
||||||
// }
|
|
||||||
// return view;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,10 @@ enum ButtonsState {
|
||||||
LEFT_VISIBLE,
|
LEFT_VISIBLE,
|
||||||
RIGHT_VISIBLE
|
RIGHT_VISIBLE
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* Taken from https://github.com/FanFataL/swipe-controller-demo
|
||||||
|
* https://codeburst.io/android-swipe-menu-with-recyclerview-8f28a235ff28
|
||||||
|
* */
|
||||||
|
|
||||||
public class SwipeController extends Callback {
|
public class SwipeController extends Callback {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue