Improved memory again (and a few other things along the way)

This commit is contained in:
Sylvain Berfini 2016-05-12 12:03:45 +02:00
parent ac6bf5dfe2
commit cebe5d9b00
6 changed files with 40 additions and 98 deletions

View file

@ -39,7 +39,6 @@ import org.linphone.core.LinphoneCoreListenerBase;
import org.linphone.mediastream.Log;
import org.linphone.ui.BubbleChat;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
@ -47,7 +46,6 @@ import android.app.Fragment;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.database.Cursor;
import android.graphics.Bitmap;
@ -89,8 +87,6 @@ import android.widget.Toast;
public class ChatFragment extends Fragment implements OnClickListener, LinphoneChatMessage.LinphoneChatMessageListener {
private static ChatFragment instance;
private static final int ADD_PHOTO = 1337;
private static final int MENU_DELETE_MESSAGE = 0;
private static final int MENU_PICTURE_SMALL = 2;
@ -128,14 +124,9 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
private ByteArrayInputStream mUploadingImageStream;
private boolean newChatConversation = false;
public static boolean isInstanciated() {
return instance != null;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
instance = this;
final View view = inflater.inflate(R.layout.chat, container, false);
LinphoneManager.addListener(this);
@ -219,6 +210,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) {
LinphoneAddress from = cr.getPeerAddress();
if (from.asStringUriOnly().equals(sipUri)) {
LinphoneService.instance().removeMessageNotification();
cr.markAsRead();
invalidate();
messagesList.setSelection(adapter.getCount()-1);
@ -257,10 +250,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
return view;
}
public static ChatFragment instance() {
return instance;
}
public String getSipUri() {
return sipUri;
}
@ -567,10 +556,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
LinphoneService.instance().removeMessageNotification();
if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().updateChatFragment(null);
}
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc != null) {
lc.removeListener(mListener);
@ -598,7 +583,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().selectMenu(FragmentsAvailable.CHAT);
LinphoneActivity.instance().updateChatFragment(this);
}
if(LinphoneManager.getLc().isIncall()){

View file

@ -22,8 +22,10 @@ import java.util.List;
import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneChatMessage;
import org.linphone.core.LinphoneChatRoom;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LinphoneCoreListenerBase;
import org.linphone.mediastream.Log;
import android.app.Dialog;
@ -61,6 +63,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
private ImageView edit, selectAll, deselectAll, delete, newDiscussion, cancel, backInCall;
private LinearLayout editList, topbar;
private boolean isEditMode = false;
private LinphoneCoreListenerBase mListener;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
@ -97,6 +100,13 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
delete = (ImageView) view.findViewById(R.id.delete);
delete.setOnClickListener(this);
mListener = new LinphoneCoreListenerBase() {
@Override
public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) {
refresh();
}
};
return view;
}
@ -194,12 +204,25 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().selectMenu(FragmentsAvailable.CHAT_LIST);
LinphoneActivity.instance().updateChatListFragment(this);
LinphoneActivity.instance().hideTabBar(false);
}
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc != null) {
lc.addListener(mListener);
}
refresh();
}
@Override
public void onPause() {
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc != null) {
lc.removeListener(mListener);
}
super.onPause();
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
@ -381,7 +404,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
displayName.setText(contact == null ? LinphoneUtils.getAddressDisplayName(address) : contact.getFullName());
if(contact != null){
if (contact != null) {
LinphoneUtils.setImagePictureFromUri(view.getContext(), contactPicture, contact.getPhotoUri(), contact.getThumbnailUri());
} else {
contactPicture.setImageResource(R.drawable.avatar);

View file

@ -144,14 +144,6 @@ public class ContactEditorFragment extends Fragment {
contact.addOrUpdateNumberOrAddress(numberOrAddress);
}
contact.save();
if (!isNewContact) {
if (LinphoneActivity.instance().getResources().getBoolean(R.bool.isTablet)) {
if(ContactsListFragment.isInstanciated()) {
ContactsListFragment.instance().invalidate();
}
}
}
getFragmentManager().popBackStackImmediate();
}
});

View file

@ -68,16 +68,6 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
private ImageView clearSearchField;
private EditText searchField;
private static ContactsListFragment instance;
static final boolean isInstanciated() {
return instance != null;
}
public static final ContactsListFragment instance() {
return instance;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mInflater = inflater;
@ -379,7 +369,6 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
@Override
public void onResume() {
instance = this;
ContactsManager.addContactsListener(this);
super.onResume();
@ -399,7 +388,6 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
@Override
public void onPause() {
instance = null;
ContactsManager.removeContactsListener(this);
super.onPause();
}

View file

@ -112,8 +112,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
private ImageView cancel;
private FragmentsAvailable currentFragment, nextFragment;
private List<FragmentsAvailable> fragmentsHistory;
private Fragment dialerFragment, chatListFragment, historyListFragment, contactListFragment;
private ChatFragment chatFragment;
private Fragment dialerFragment;
private Fragment.SavedState dialerSavedState;
private boolean newProxyConfig;
private boolean isAnimationDisabled = true, emptyFragment = false, permissionAsked = false;
@ -195,13 +194,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
mListener = new LinphoneCoreListenerBase(){
@Override
public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) {
if(!displayChatMessageNotification(message.getFrom().asStringUriOnly())) {
cr.markAsRead();
}
displayMissedChats(getUnreadMessageCount());
if (chatListFragment != null && chatListFragment.isVisible()) {
((ChatListFragment) chatListFragment).refresh();
}
}
@Override
@ -373,14 +366,18 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
switch (newFragmentType) {
case HISTORY_LIST:
newFragment = new HistoryListFragment();
historyListFragment = newFragment;
if (isTablet()) {
((HistoryListFragment) newFragment).displayFirstLog();
}
break;
case HISTORY_DETAIL:
newFragment = new HistoryDetailFragment();
break;
case CONTACTS_LIST:
newFragment = new ContactsListFragment();
contactListFragment = newFragment;
if (isTablet()) {
((ContactsListFragment) newFragment).displayFirstContact();
}
break;
case CONTACT_DETAIL:
newFragment = new ContactDetailsFragment();
@ -409,7 +406,9 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
break;
case CHAT_LIST:
newFragment = new ChatListFragment();
chatListFragment = newFragment;
if (isTablet()) {
((ChatListFragment) newFragment).displayFirstChat();
}
break;
case CHAT:
newFragment = new ChatFragment();
@ -642,15 +641,6 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
startActivity(new Intent(LinphoneActivity.this, AssistantActivity.class));
}
public boolean displayChatMessageNotification(String address){
if(chatFragment != null) {
if(chatFragment.getSipUri().equals(address)) {
return false;
}
}
return true;
}
public int getUnreadMessageCount() {
int count = 0;
LinphoneChatRoom[] chats = LinphoneManager.getLc().getChatRooms();
@ -718,10 +708,6 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
}
}
if (chatListFragment != null && chatListFragment.isVisible()) {
((ChatListFragment) chatListFragment).refresh();
}
LinphoneService.instance().resetMessageNotifCount();
LinphoneService.instance().removeMessageNotification();
displayMissedChats(getUnreadMessageCount());
@ -737,30 +723,15 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
history_selected.setVisibility(View.VISIBLE);
LinphoneManager.getLc().resetMissedCallsCount();
displayMissedCalls(0);
if(isTablet()) {
if (historyListFragment != null && historyListFragment.isVisible()) {
((HistoryListFragment) historyListFragment).displayFirstLog();
}
}
} else if (id == R.id.contacts) {
changeCurrentFragment(FragmentsAvailable.CONTACTS_LIST, null);
contacts_selected.setVisibility(View.VISIBLE);
if(isTablet()) {
if (contactListFragment != null && contactListFragment.isVisible()) {
((ContactsListFragment) contactListFragment).displayFirstContact();
}
}
} else if (id == R.id.dialer) {
changeCurrentFragment(FragmentsAvailable.DIALER, null);
dialer_selected.setVisibility(View.VISIBLE);
} else if (id == R.id.chat) {
changeCurrentFragment(FragmentsAvailable.CHAT_LIST, null);
chat_selected.setVisibility(View.VISIBLE);
if(isTablet()) {
if (chatListFragment != null && chatListFragment.isVisible()) {
((ChatListFragment) chatListFragment).displayFirstChat();
}
}
} else if (id == R.id.cancel){
hideTopBar();
displayDialer();
@ -825,14 +796,6 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
public void updateChatFragment(ChatFragment fragment) {
chatFragment = fragment;
}
public void updateChatListFragment(ChatListFragment fragment) {
chatListFragment = fragment;
}
public void updateStatusFragment(StatusFragment fragment) {
statusFragment = fragment;
}
@ -884,10 +847,6 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
public int onMessageSent(String to, String message) {
getChatStorage().deleteDraft(to);
if (chatListFragment != null && chatListFragment.isVisible()) {
((ChatListFragment) chatListFragment).refresh();
}
return getChatStorage().saveTextMessage("", to, message, System.currentTimeMillis());
}

View file

@ -864,14 +864,10 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
try {
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(from);
if (!mServiceContext.getResources().getBoolean(R.bool.disable_chat_message_notification)) {
if (LinphoneActivity.isInstanciated() && !LinphoneActivity.instance().displayChatMessageNotification(from.asStringUriOnly())) {
return;
if (contact != null) {
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), contact.getFullName(), textMessage);
} else {
if (contact != null) {
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), contact.getFullName(), textMessage);
} else {
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), from.getUserName(), textMessage);
}
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), from.getUserName(), textMessage);
}
}
} catch (Exception e) {