Performance fix for diff utils in chat rooms list, using library's chat room sort & filter
This commit is contained in:
parent
e8ad6bd39f
commit
6ba56bb8f2
7 changed files with 11 additions and 76 deletions
|
@ -1,4 +1,4 @@
|
||||||
[](https://gitlab.linphone.org/BC/public/linphone-android/commits/master)
|
[](https://gitlab.linphone.org/BC/public/linphone-android/commits/master)
|
||||||
|
|
||||||
Linphone is a free VoIP and video softphone based on the SIP protocol.
|
Linphone is a free VoIP and video softphone based on the SIP protocol.
|
||||||
|
|
||||||
|
|
|
@ -25,13 +25,9 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import androidx.recyclerview.widget.DiffUtil;
|
import androidx.recyclerview.widget.DiffUtil;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.linphone.LinphoneManager;
|
import org.linphone.LinphoneManager;
|
||||||
import org.linphone.R;
|
|
||||||
import org.linphone.core.ChatRoom;
|
import org.linphone.core.ChatRoom;
|
||||||
import org.linphone.utils.LinphoneUtils;
|
|
||||||
import org.linphone.utils.SelectableAdapter;
|
import org.linphone.utils.SelectableAdapter;
|
||||||
import org.linphone.utils.SelectableHelper;
|
import org.linphone.utils.SelectableHelper;
|
||||||
|
|
||||||
|
@ -75,23 +71,7 @@ public class ChatRoomsAdapter extends SelectableAdapter<ChatRoomViewHolder> {
|
||||||
|
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
ChatRoom[] rooms = LinphoneManager.getCore().getChatRooms();
|
ChatRoom[] rooms = LinphoneManager.getCore().getChatRooms();
|
||||||
List<ChatRoom> roomsList;
|
List<ChatRoom> roomsList = Arrays.asList(rooms);
|
||||||
if (mContext.getResources().getBoolean(R.bool.hide_empty_one_to_one_chat_rooms)) {
|
|
||||||
roomsList = LinphoneUtils.removeEmptyOneToOneChatRooms(rooms);
|
|
||||||
} else {
|
|
||||||
roomsList = Arrays.asList(rooms);
|
|
||||||
}
|
|
||||||
|
|
||||||
Collections.sort(
|
|
||||||
roomsList,
|
|
||||||
new Comparator<ChatRoom>() {
|
|
||||||
public int compare(ChatRoom cr1, ChatRoom cr2) {
|
|
||||||
long timeDiff = cr1.getLastUpdateTime() - cr2.getLastUpdateTime();
|
|
||||||
if (timeDiff > 0) return -1;
|
|
||||||
else if (timeDiff == 0) return 0;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
DiffUtil.DiffResult diffResult =
|
DiffUtil.DiffResult diffResult =
|
||||||
DiffUtil.calculateDiff(new ChatRoomDiffCallback(roomsList, mRooms));
|
DiffUtil.calculateDiff(new ChatRoomDiffCallback(roomsList, mRooms));
|
||||||
|
@ -99,11 +79,6 @@ public class ChatRoomsAdapter extends SelectableAdapter<ChatRoomViewHolder> {
|
||||||
mRooms = roomsList;
|
mRooms = roomsList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
|
||||||
mRooms.clear();
|
|
||||||
// Do not notify data set changed, we don't want the list to empty when fragment is paused
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Adapter's methods */
|
/** Adapter's methods */
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
|
@ -112,7 +87,8 @@ public class ChatRoomsAdapter extends SelectableAdapter<ChatRoomViewHolder> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getItem(int position) {
|
public Object getItem(int position) {
|
||||||
return mRooms.get(position);
|
if (position < mRooms.size()) return mRooms.get(position);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -141,15 +117,12 @@ public class ChatRoomsAdapter extends SelectableAdapter<ChatRoomViewHolder> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
|
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
|
||||||
ChatRoom oldRoom = oldChatRooms.get(oldItemPosition);
|
return oldChatRooms.get(oldItemPosition) == (newChatRooms.get(newItemPosition));
|
||||||
ChatRoom newRoom = newChatRooms.get(newItemPosition);
|
|
||||||
return oldRoom.getLocalAddress().weakEqual(newRoom.getLocalAddress())
|
|
||||||
&& oldRoom.getPeerAddress().weakEqual(newRoom.getPeerAddress());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
|
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
|
||||||
return oldChatRooms.get(oldItemPosition).equals(newChatRooms.get(newItemPosition));
|
return newChatRooms.get(newItemPosition).getUnreadMessagesCount() > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,6 @@ import org.linphone.core.ChatRoomListenerStub;
|
||||||
import org.linphone.core.Core;
|
import org.linphone.core.Core;
|
||||||
import org.linphone.core.CoreListenerStub;
|
import org.linphone.core.CoreListenerStub;
|
||||||
import org.linphone.core.ProxyConfig;
|
import org.linphone.core.ProxyConfig;
|
||||||
import org.linphone.utils.LinphoneUtils;
|
|
||||||
import org.linphone.utils.SelectableHelper;
|
import org.linphone.utils.SelectableHelper;
|
||||||
import org.linphone.views.LinphoneLinearLayoutManager;
|
import org.linphone.views.LinphoneLinearLayoutManager;
|
||||||
|
|
||||||
|
@ -79,12 +78,7 @@ public class ChatRoomsFragment extends Fragment
|
||||||
mNoChatHistory = view.findViewById(R.id.noChatHistory);
|
mNoChatHistory = view.findViewById(R.id.noChatHistory);
|
||||||
|
|
||||||
ChatRoom[] rooms = LinphoneManager.getCore().getChatRooms();
|
ChatRoom[] rooms = LinphoneManager.getCore().getChatRooms();
|
||||||
List<ChatRoom> mRooms;
|
List<ChatRoom> mRooms = Arrays.asList(rooms);
|
||||||
if (getResources().getBoolean(R.bool.hide_empty_one_to_one_chat_rooms)) {
|
|
||||||
mRooms = LinphoneUtils.removeEmptyOneToOneChatRooms(rooms);
|
|
||||||
} else {
|
|
||||||
mRooms = Arrays.asList(rooms);
|
|
||||||
}
|
|
||||||
|
|
||||||
mSelectionHelper = new SelectableHelper(view, this);
|
mSelectionHelper = new SelectableHelper(view, this);
|
||||||
mChatRoomsAdapter =
|
mChatRoomsAdapter =
|
||||||
|
@ -244,7 +238,6 @@ public class ChatRoomsFragment extends Fragment
|
||||||
core.removeListener(mListener);
|
core.removeListener(mListener);
|
||||||
}
|
}
|
||||||
ContactsManager.getInstance().removeContactsListener(this);
|
ContactsManager.getInstance().removeContactsListener(this);
|
||||||
mChatRoomsAdapter.clear();
|
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,6 @@ import android.content.Context;
|
||||||
import android.content.pm.ShortcutInfo;
|
import android.content.pm.ShortcutInfo;
|
||||||
import android.content.pm.ShortcutManager;
|
import android.content.pm.ShortcutManager;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import org.linphone.LinphoneManager;
|
import org.linphone.LinphoneManager;
|
||||||
import org.linphone.contacts.ContactsManager;
|
import org.linphone.contacts.ContactsManager;
|
||||||
import org.linphone.contacts.LinphoneContact;
|
import org.linphone.contacts.LinphoneContact;
|
||||||
|
@ -37,7 +35,6 @@ import org.linphone.core.ChatRoomCapabilities;
|
||||||
import org.linphone.core.tools.Log;
|
import org.linphone.core.tools.Log;
|
||||||
import org.linphone.settings.LinphonePreferences;
|
import org.linphone.settings.LinphonePreferences;
|
||||||
import org.linphone.utils.LinphoneShortcutManager;
|
import org.linphone.utils.LinphoneShortcutManager;
|
||||||
import org.linphone.utils.LinphoneUtils;
|
|
||||||
|
|
||||||
@TargetApi(25)
|
@TargetApi(25)
|
||||||
class ApiTwentyFivePlus {
|
class ApiTwentyFivePlus {
|
||||||
|
@ -57,24 +54,11 @@ class ApiTwentyFivePlus {
|
||||||
ArrayList<ShortcutInfo> shortcuts = new ArrayList<>();
|
ArrayList<ShortcutInfo> shortcuts = new ArrayList<>();
|
||||||
|
|
||||||
ChatRoom[] rooms = LinphoneManager.getCore().getChatRooms();
|
ChatRoom[] rooms = LinphoneManager.getCore().getChatRooms();
|
||||||
ArrayList<ChatRoom> notEmptyOneToOneRooms =
|
|
||||||
LinphoneUtils.removeEmptyOneToOneChatRooms(rooms);
|
|
||||||
Collections.sort(
|
|
||||||
notEmptyOneToOneRooms,
|
|
||||||
new Comparator<ChatRoom>() {
|
|
||||||
public int compare(ChatRoom cr1, ChatRoom cr2) {
|
|
||||||
long timeDiff = cr1.getLastUpdateTime() - cr2.getLastUpdateTime();
|
|
||||||
if (timeDiff > 0) return -1;
|
|
||||||
else if (timeDiff == 0) return 0;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int maxShortcuts =
|
int maxShortcuts = min(rooms.length, shortcutManager.getMaxShortcutCountPerActivity());
|
||||||
min(notEmptyOneToOneRooms.size(), shortcutManager.getMaxShortcutCountPerActivity());
|
|
||||||
ArrayList<LinphoneContact> contacts = new ArrayList<>();
|
ArrayList<LinphoneContact> contacts = new ArrayList<>();
|
||||||
for (ChatRoom room : notEmptyOneToOneRooms) {
|
for (ChatRoom room : rooms) {
|
||||||
// Android can only have around 4-5 shortcuts at a time
|
// Android can only have around 4-5 shortcuts at a time
|
||||||
if (i >= maxShortcuts) break;
|
if (i >= maxShortcuts) break;
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ import com.google.firebase.messaging.RemoteMessage;
|
||||||
import org.linphone.LinphoneManager;
|
import org.linphone.LinphoneManager;
|
||||||
import org.linphone.LinphoneService;
|
import org.linphone.LinphoneService;
|
||||||
import org.linphone.core.Core;
|
import org.linphone.core.Core;
|
||||||
|
import org.linphone.core.tools.Log;
|
||||||
import org.linphone.settings.LinphonePreferences;
|
import org.linphone.settings.LinphonePreferences;
|
||||||
import org.linphone.utils.LinphoneUtils;
|
import org.linphone.utils.LinphoneUtils;
|
||||||
|
|
||||||
|
@ -57,7 +58,7 @@ public class FirebaseMessaging extends FirebaseMessagingService {
|
||||||
intent.putExtra("PushNotification", true);
|
intent.putExtra("PushNotification", true);
|
||||||
startService(intent);
|
startService(intent);
|
||||||
} else {
|
} else {
|
||||||
android.util.Log.i("FirebaseMessaging", "[Push Notification] Notifying Core");
|
Log.i("[Push Notification] Notifying Core");
|
||||||
if (LinphoneManager.getInstance() != null) {
|
if (LinphoneManager.getInstance() != null) {
|
||||||
Core core = LinphoneManager.getCore();
|
Core core = LinphoneManager.getCore();
|
||||||
if (core != null) {
|
if (core != null) {
|
||||||
|
|
|
@ -39,7 +39,6 @@ import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
@ -49,8 +48,6 @@ import org.linphone.R;
|
||||||
import org.linphone.core.Address;
|
import org.linphone.core.Address;
|
||||||
import org.linphone.core.Call;
|
import org.linphone.core.Call;
|
||||||
import org.linphone.core.CallLog;
|
import org.linphone.core.CallLog;
|
||||||
import org.linphone.core.ChatRoom;
|
|
||||||
import org.linphone.core.ChatRoomCapabilities;
|
|
||||||
import org.linphone.core.Core;
|
import org.linphone.core.Core;
|
||||||
import org.linphone.core.Factory;
|
import org.linphone.core.Factory;
|
||||||
import org.linphone.core.LogCollectionState;
|
import org.linphone.core.LogCollectionState;
|
||||||
|
@ -343,18 +340,6 @@ public final class LinphoneUtils {
|
||||||
return Html.fromHtml(text);
|
return Html.fromHtml(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<ChatRoom> removeEmptyOneToOneChatRooms(ChatRoom[] rooms) {
|
|
||||||
ArrayList<ChatRoom> newRooms = new ArrayList<>();
|
|
||||||
for (ChatRoom room : rooms) {
|
|
||||||
// Hide 1-1 chat rooms without messages
|
|
||||||
if (!(room.hasCapability(ChatRoomCapabilities.OneToOne.toInt())
|
|
||||||
&& room.getHistorySize() == 0)) {
|
|
||||||
newRooms.add(room);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return newRooms;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void showTrustDeniedDialog(Context context) {
|
public static void showTrustDeniedDialog(Context context) {
|
||||||
final Dialog dialog = new Dialog(context);
|
final Dialog dialog = new Dialog(context);
|
||||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
|
|
|
@ -93,7 +93,6 @@
|
||||||
<bool name="send_multiple_images_as_different_messages">true</bool>
|
<bool name="send_multiple_images_as_different_messages">true</bool>
|
||||||
<bool name="use_big_pictures_to_preview_images_file_transfers">true</bool>
|
<bool name="use_big_pictures_to_preview_images_file_transfers">true</bool>
|
||||||
<bool name="show_sip_uri_in_chat">false</bool>
|
<bool name="show_sip_uri_in_chat">false</bool>
|
||||||
<bool name="hide_empty_one_to_one_chat_rooms">true</bool>
|
|
||||||
<bool name="create_most_recent_chat_rooms_shortcuts">true</bool>
|
<bool name="create_most_recent_chat_rooms_shortcuts">true</bool>
|
||||||
<bool name="force_end_to_end_encryption_in_chat">false</bool>
|
<bool name="force_end_to_end_encryption_in_chat">false</bool>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue