Reduced number of time ChatRoom.getUnreadMessageCount is called
This commit is contained in:
parent
6be8df9ff8
commit
17920ed822
6 changed files with 63 additions and 40 deletions
|
@ -139,6 +139,8 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
@ -200,6 +202,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
||||||
public String wizardLoginViewDomain = null;
|
public String wizardLoginViewDomain = null;
|
||||||
|
|
||||||
protected LinphoneManager(final Context c) {
|
protected LinphoneManager(final Context c) {
|
||||||
|
mUnreadChatsPerRoom = new HashMap();
|
||||||
sExited = false;
|
sExited = false;
|
||||||
echoTesterIsRunning = false;
|
echoTesterIsRunning = false;
|
||||||
mServiceContext = c;
|
mServiceContext = c;
|
||||||
|
@ -236,6 +239,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
||||||
private final String mFriendsDatabaseFile;
|
private final String mFriendsDatabaseFile;
|
||||||
private byte[] mUploadingImage;
|
private byte[] mUploadingImage;
|
||||||
private Timer mTimer;
|
private Timer mTimer;
|
||||||
|
private Map<String, Integer> mUnreadChatsPerRoom;
|
||||||
|
|
||||||
private void routeAudioToSpeakerHelper(boolean speakerOn) {
|
private void routeAudioToSpeakerHelper(boolean speakerOn) {
|
||||||
Log.w("Routing audio to " + (speakerOn ? "speaker" : "earpiece") + ", disabling bluetooth audio route");
|
Log.w("Routing audio to " + (speakerOn ? "speaker" : "earpiece") + ", disabling bluetooth audio route");
|
||||||
|
@ -784,6 +788,8 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
||||||
accountCreator = LinphoneManager.getLc().createAccountCreator(LinphonePreferences.instance().getXmlrpcUrl());
|
accountCreator = LinphoneManager.getLc().createAccountCreator(LinphonePreferences.instance().getXmlrpcUrl());
|
||||||
accountCreator.setListener(this);
|
accountCreator.setListener(this);
|
||||||
callGsmON = false;
|
callGsmON = false;
|
||||||
|
|
||||||
|
updateMissedChatCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHandsetMode(Boolean on){
|
public void setHandsetMode(Boolean on){
|
||||||
|
@ -1089,6 +1095,8 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
increaseUnreadCountForChatRoom(cr);
|
||||||
|
|
||||||
Address from = message.getFromAddress();
|
Address from = message.getFromAddress();
|
||||||
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(from);
|
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(from);
|
||||||
String textMessage = (message.getFileTransferInformation() != null) ? getString(R.string.content_description_incoming_file) : message.getTextContent();
|
String textMessage = (message.getFileTransferInformation() != null) ? getString(R.string.content_description_incoming_file) : message.getTextContent();
|
||||||
|
@ -1748,4 +1756,45 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
||||||
public void onUpdateAccount(AccountCreator accountCreator, AccountCreator.Status status, String resp) {
|
public void onUpdateAccount(AccountCreator accountCreator, AccountCreator.Status status, String resp) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateMissedChatCount() {
|
||||||
|
for (ChatRoom cr : LinphoneManager.getLc().getChatRooms()) {
|
||||||
|
updateUnreadCountForChatRoom(cr, cr.getUnreadMessagesCount());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getUnreadMessageCount() {
|
||||||
|
int count = 0;
|
||||||
|
for (Integer unread : mUnreadChatsPerRoom.values()) {
|
||||||
|
count += unread;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateUnreadCountForChatRoom(String key, Integer value) {
|
||||||
|
mUnreadChatsPerRoom.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void updateUnreadCountForChatRoom(ChatRoom cr, Integer value) {
|
||||||
|
String key = cr.getPeerAddress().asStringUriOnly();
|
||||||
|
updateUnreadCountForChatRoom(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getUnreadCountForChatRoom(ChatRoom cr) {
|
||||||
|
String key = cr.getPeerAddress().asStringUriOnly();
|
||||||
|
if (mUnreadChatsPerRoom.containsKey(key)) {
|
||||||
|
return mUnreadChatsPerRoom.get(key);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void increaseUnreadCountForChatRoom(ChatRoom cr) {
|
||||||
|
String key = cr.getPeerAddress().asStringUriOnly();
|
||||||
|
if (mUnreadChatsPerRoom.containsKey(key)) {
|
||||||
|
mUnreadChatsPerRoom.put(key, mUnreadChatsPerRoom.get(key) + 1);
|
||||||
|
} else {
|
||||||
|
mUnreadChatsPerRoom.put(key, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ import org.linphone.contacts.LinphoneContact;
|
||||||
import org.linphone.core.Address;
|
import org.linphone.core.Address;
|
||||||
import org.linphone.core.Call;
|
import org.linphone.core.Call;
|
||||||
import org.linphone.core.Call.State;
|
import org.linphone.core.Call.State;
|
||||||
import org.linphone.core.Call.Status;
|
|
||||||
import org.linphone.core.Core;
|
import org.linphone.core.Core;
|
||||||
import org.linphone.core.GlobalState;
|
import org.linphone.core.GlobalState;
|
||||||
import org.linphone.core.RegistrationState;
|
import org.linphone.core.RegistrationState;
|
||||||
|
|
|
@ -233,7 +233,7 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
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) {
|
||||||
displayMissedChats(getUnreadMessageCount());
|
displayMissedChats(LinphoneManager.getInstance().getUnreadMessageCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -666,30 +666,6 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
startActivity(new Intent(LinphoneActivity.this, InAppPurchaseActivity.class));
|
startActivity(new Intent(LinphoneActivity.this, InAppPurchaseActivity.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUnreadMessageCount() {
|
|
||||||
int count = 0;
|
|
||||||
ChatRoom[] chats = LinphoneManager.getLc().getChatRooms();
|
|
||||||
for (ChatRoom chatroom : chats) {
|
|
||||||
count += chatroom.getUnreadMessagesCount();
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void displayInfoChat(List<ContactAddress> list) {
|
|
||||||
Bundle extras = new Bundle();
|
|
||||||
ArrayList<String> listUri = new ArrayList<String>();
|
|
||||||
if (LinphoneManager.isInstanciated() && LinphoneManager.getLc() != null
|
|
||||||
&& LinphoneManager.getLc().getDefaultProxyConfig() != null
|
|
||||||
&& LinphoneManager.getLc().getDefaultProxyConfig().getIdentityAddress() != null) {
|
|
||||||
listUri.add(LinphoneManager.getLc().getDefaultProxyConfig().getIdentityAddress().asStringUriOnly());
|
|
||||||
}
|
|
||||||
for (ContactAddress ca : list) {
|
|
||||||
listUri.add(ca.getAddressAsDisplayableString());
|
|
||||||
}
|
|
||||||
extras.putStringArrayList("contactsSelected", listUri);
|
|
||||||
changeCurrentFragment(FragmentsAvailable.INFO_GROUP_CHAT, extras);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void displayChat(String sipUri, String message, String fileUri, String pictureUri, String thumbnailUri, String displayName, Address lAddress) {
|
private void displayChat(String sipUri, String message, String fileUri, String pictureUri, String thumbnailUri, String displayName, Address lAddress) {
|
||||||
Bundle extras = new Bundle();
|
Bundle extras = new Bundle();
|
||||||
extras.putString("SipUri", sipUri);
|
extras.putString("SipUri", sipUri);
|
||||||
|
@ -728,7 +704,8 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
|
|
||||||
LinphoneService.instance().resetMessageNotifCount();
|
LinphoneService.instance().resetMessageNotifCount();
|
||||||
LinphoneService.instance().removeMessageNotification();
|
LinphoneService.instance().removeMessageNotification();
|
||||||
displayMissedChats(getUnreadMessageCount());
|
LinphoneManager.getInstance().updateUnreadCountForChatRoom(sipUri, 0);
|
||||||
|
displayMissedChats(LinphoneManager.getInstance().getUnreadMessageCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void goToChatGroupInfos(String address, ArrayList<ContactAddress> contacts, String subject, boolean isEditionEnabled, boolean isGoBack) {
|
public void goToChatGroupInfos(String address, ArrayList<ContactAddress> contacts, String subject, boolean isEditionEnabled, boolean isGoBack) {
|
||||||
|
@ -789,7 +766,8 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
|
|
||||||
LinphoneService.instance().resetMessageNotifCount();
|
LinphoneService.instance().resetMessageNotifCount();
|
||||||
LinphoneService.instance().removeMessageNotification();
|
LinphoneService.instance().removeMessageNotification();
|
||||||
displayMissedChats(getUnreadMessageCount());
|
LinphoneManager.getInstance().updateUnreadCountForChatRoom(sipUri, 0);
|
||||||
|
displayMissedChats(LinphoneManager.getInstance().getUnreadMessageCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -912,8 +890,8 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
return statusFragment;
|
return statusFragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateMissedChatCount() {
|
public void refreshMissedChatCountDisplay() {
|
||||||
displayMissedChats(getUnreadMessageCount());
|
displayMissedChats(LinphoneManager.getInstance().getUnreadMessageCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayMissedCalls(final int missedCallsCount) {
|
public void displayMissedCalls(final int missedCallsCount) {
|
||||||
|
@ -1433,8 +1411,7 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
isTrialAccount();
|
isTrialAccount();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateMissedChatCount();
|
displayMissedChats(LinphoneManager.getInstance().getUnreadMessageCount());
|
||||||
|
|
||||||
displayMissedCalls(LinphoneManager.getLc().getMissedCallsCount());
|
displayMissedCalls(LinphoneManager.getLc().getMissedCallsCount());
|
||||||
|
|
||||||
LinphoneManager.getInstance().changeStatusToOnline();
|
LinphoneManager.getInstance().changeStatusToOnline();
|
||||||
|
|
|
@ -1573,11 +1573,7 @@ public class CallActivity extends LinphoneGenericActivity implements OnClickList
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayMissedChats() {
|
private void displayMissedChats() {
|
||||||
int count = 0;
|
int count = LinphoneManager.getInstance().getUnreadMessageCount();
|
||||||
ChatRoom[] chats = LinphoneManager.getLc().getChatRooms();
|
|
||||||
for (ChatRoom chatroom : chats) {
|
|
||||||
count += chatroom.getUnreadMessagesCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
missedChats.setText(count + "");
|
missedChats.setText(count + "");
|
||||||
|
|
|
@ -162,7 +162,7 @@ public class ChatRoomsAdapter extends ListSelectionAdapter {
|
||||||
chatRoom.setUserData(holder);
|
chatRoom.setUserData(holder);
|
||||||
}
|
}
|
||||||
|
|
||||||
int unreadMessagesCount = chatRoom.getUnreadMessagesCount();
|
int unreadMessagesCount = LinphoneManager.getInstance().getUnreadCountForChatRoom(chatRoom);
|
||||||
ChatMessage lastMessage = chatRoom.getLastMessageInHistory();
|
ChatMessage lastMessage = chatRoom.getLastMessageInHistory();
|
||||||
holder.lastMessageView.setText("");
|
holder.lastMessageView.setText("");
|
||||||
holder.lastMessageSenderView.setText("");
|
holder.lastMessageSenderView.setText("");
|
||||||
|
|
|
@ -398,7 +398,8 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
|
||||||
}
|
}
|
||||||
mChatRoom.addListener(this);
|
mChatRoom.addListener(this);
|
||||||
mChatRoom.markAsRead();
|
mChatRoom.markAsRead();
|
||||||
LinphoneActivity.instance().updateMissedChatCount();
|
LinphoneManager.getInstance().updateUnreadCountForChatRoom(mChatRoom, 0);
|
||||||
|
LinphoneActivity.instance().refreshMissedChatCountDisplay();
|
||||||
|
|
||||||
mRemoteParticipantAddress = mRemoteSipAddress;
|
mRemoteParticipantAddress = mRemoteSipAddress;
|
||||||
if (mChatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt()) && mChatRoom.getParticipants().length > 0) {
|
if (mChatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt()) && mChatRoom.getParticipants().length > 0) {
|
||||||
|
@ -653,7 +654,8 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
|
||||||
@Override
|
@Override
|
||||||
public void onChatMessageReceived(ChatRoom cr, EventLog event) {
|
public void onChatMessageReceived(ChatRoom cr, EventLog event) {
|
||||||
cr.markAsRead();
|
cr.markAsRead();
|
||||||
LinphoneActivity.instance().updateMissedChatCount();
|
LinphoneManager.getInstance().updateUnreadCountForChatRoom(mChatRoom, 0);
|
||||||
|
LinphoneActivity.instance().refreshMissedChatCountDisplay();
|
||||||
|
|
||||||
ChatMessage msg = event.getChatMessage();
|
ChatMessage msg = event.getChatMessage();
|
||||||
if (msg.getErrorInfo() != null && msg.getErrorInfo().getReason() == Reason.UnsupportedContent) {
|
if (msg.getErrorInfo() != null && msg.getErrorInfo().getReason() == Reason.UnsupportedContent) {
|
||||||
|
|
Loading…
Reference in a new issue