Invalidate history & chat lists when contacts are udpated

This commit is contained in:
Sylvain Berfini 2016-07-21 14:17:29 +02:00
parent 34e6b15e32
commit 502a70f128
3 changed files with 31 additions and 5 deletions

View file

@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
import java.util.List;
import org.linphone.HistoryListFragment.CallHistoryAdapter;
import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneChatMessage;
import org.linphone.core.LinphoneChatRoom;
@ -55,7 +56,7 @@ import android.widget.TextView;
/**
* @author Sylvain Berfini
*/
public class ChatListFragment extends Fragment implements OnClickListener, OnItemClickListener {
public class ChatListFragment extends Fragment implements OnClickListener, OnItemClickListener, ContactsUpdatedListener {
private LayoutInflater mInflater;
private List<String> mConversations;
private ListView chatList;
@ -193,6 +194,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
@Override
public void onResume() {
super.onResume();
ContactsManager.addContactsListener(this);
if (LinphoneManager.getLc().getCallsNb() > 0) {
backInCall.setVisibility(View.VISIBLE);
@ -219,9 +221,15 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
if (lc != null) {
lc.removeListener(mListener);
}
ContactsManager.removeContactsListener(this);
super.onPause();
}
@Override
public void onContactsUpdated() {
hideAndDisplayMessageIfNoChat();
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);

View file

@ -52,7 +52,7 @@ import android.widget.TextView;
/**
* @author Sylvain Berfini
*/
public class HistoryListFragment extends Fragment implements OnClickListener, OnItemClickListener {
public class HistoryListFragment extends Fragment implements OnClickListener, OnItemClickListener, ContactsUpdatedListener {
private ListView historyList;
private LayoutInflater mInflater;
private TextView noCallHistory, noMissedCallHistory;
@ -198,6 +198,7 @@ public class HistoryListFragment extends Fragment implements OnClickListener, On
@Override
public void onResume() {
super.onResume();
ContactsManager.addContactsListener(this);
if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().selectMenu(FragmentsAvailable.HISTORY_LIST);
@ -212,6 +213,17 @@ public class HistoryListFragment extends Fragment implements OnClickListener, On
}
}
@Override
public void onPause() {
ContactsManager.removeContactsListener(this);
super.onPause();
}
@Override
public void onContactsUpdated() {
historyList.setAdapter(new CallHistoryAdapter(getActivity().getApplicationContext()));
}
@Override
public void onClick(View v) {
int id = v.getId();
@ -327,18 +339,20 @@ public class HistoryListFragment extends Fragment implements OnClickListener, On
topBar.setVisibility(View.VISIBLE);
refresh();
if (!hideHistoryListAndDisplayMessageIfEmpty()){
if (!hideHistoryListAndDisplayMessageIfEmpty()) {
historyList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
historyList.setAdapter(new CallHistoryAdapter(getActivity().getApplicationContext()));
}
if(getResources().getBoolean(R.bool.isTablet)){
if (getResources().getBoolean(R.bool.isTablet)) {
displayFirstLog();
}
}
class CallHistoryAdapter extends BaseAdapter {
CallHistoryAdapter(Context aContext) {
}
public int getCount() {
return mLogs.size();
}

View file

@ -400,7 +400,11 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
if (lc.findFriendByAddress(friend.getAddress().asString()) == null) {
try {
lc.addFriend(friend);
ContactsManager.getInstance().fetchContactsAsync();
if (!ContactsManager.getInstance().hasContactsAccess()) {
// This refresh is only needed if app has no contacts permission to refresh the list of LinphoneFriends.
// Otherwise contacts will be refreshed due to changes in native contact and the handler in ContactsManager
ContactsManager.getInstance().fetchContactsAsync();
}
} catch (LinphoneCoreException e) {
Log.e(e);
}