mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-20 21:18:07 +00:00
[presence] listener added and genereic clac avatarWithPresence
This commit is contained in:
parent
4103eb9fba
commit
8f930b173d
6 changed files with 141 additions and 115 deletions
32
res/layout/avatar_with_presence.xml
Normal file
32
res/layout/avatar_with_presence.xml
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/contact_picture_layout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/contact_picture"
|
||||
android:src="@drawable/avatar"
|
||||
android:contentDescription="@string/content_description_contact_picture"
|
||||
android:layout_width="35dp"
|
||||
android:layout_height="35dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_marginLeft="5dp"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/friendStatus"
|
||||
android:visibility="visible"
|
||||
android:layout_width="10dp"
|
||||
android:layout_height="10dp"
|
||||
android:layout_alignBottom="@+id/contact_picture"
|
||||
android:layout_alignRight="@+id/contact_picture"
|
||||
android:adjustViewBounds="true"
|
||||
android:layout_marginRight="2dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@drawable/presence_unregistered" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
@ -23,35 +23,12 @@
|
|||
android:layout_margin="5dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/contact_picture_layout"
|
||||
android:layout_width="wrap_content"
|
||||
<org.linphone.ui.AvatarWithPresenceImage
|
||||
android:id="@+id/avatar_with_presence"
|
||||
android:layout_width="35dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/contact_picture"
|
||||
android:src="@drawable/avatar"
|
||||
android:contentDescription="@string/content_description_contact_picture"
|
||||
android:layout_width="35dp"
|
||||
android:layout_height="35dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_marginLeft="5dp"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/friendStatus"
|
||||
android:visibility="visible"
|
||||
android:layout_width="10dp"
|
||||
android:layout_height="10dp"
|
||||
android:layout_alignBottom="@+id/contact_picture"
|
||||
android:layout_alignRight="@+id/contact_picture"
|
||||
android:adjustViewBounds="true"
|
||||
android:layout_marginRight="3dp"
|
||||
android:layout_marginBottom="3dp"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@drawable/presence_unregistered" />
|
||||
</RelativeLayout>
|
||||
android:gravity="center_vertical"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
|
|
@ -59,10 +36,10 @@
|
|||
style="@style/font2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toRightOf="@id/contact_picture_layout"
|
||||
android:layout_toRightOf="@id/avatar_with_presence"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toLeftOf="@id/delete"
|
||||
android:layout_marginLeft="10dp" />
|
||||
android:layout_marginLeft="40dp" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/delete"
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import org.linphone.core.PresenceActivityType;
|
|||
import org.linphone.core.PresenceBasicStatus;
|
||||
import org.linphone.core.PresenceModel;
|
||||
import org.linphone.mediastream.Log;
|
||||
import org.linphone.ui.AvatarWithPresenceImage;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.Fragment;
|
||||
|
|
@ -101,40 +102,9 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
|||
contactsList = (ListView) view.findViewById(R.id.contactsList);
|
||||
contactsList.setOnItemClickListener(this);
|
||||
|
||||
/* allContacts = (ImageView) view.findViewById(R.id.all_contacts);
|
||||
allContacts.setOnClickListener(this);
|
||||
|
||||
linphoneContacts = (ImageView) view.findViewById(R.id.linphone_contacts);
|
||||
linphoneContacts.setOnClickListener(this);
|
||||
|
||||
allContactsSelected = view.findViewById(R.id.all_contacts_select);
|
||||
linphoneContactsSelected = view.findViewById(R.id.linphone_contacts_select);
|
||||
|
||||
newContact = (ImageView) view.findViewById(R.id.newContact);
|
||||
newContact.setOnClickListener(this);
|
||||
newContact.setEnabled(LinphoneManager.getLc().getCallsNb() == 0);
|
||||
|
||||
allContacts.setEnabled(onlyDisplayLinphoneContacts);
|
||||
linphoneContacts.setEnabled(!allContacts.isEnabled());
|
||||
|
||||
selectAll = (ImageView) view.findViewById(R.id.select_all);
|
||||
selectAll.setOnClickListener(this);
|
||||
|
||||
deselectAll = (ImageView) view.findViewById(R.id.deselect_all);
|
||||
deselectAll.setOnClickListener(this);
|
||||
|
||||
delete = (ImageView) view.findViewById(R.id.delete);
|
||||
delete.setOnClickListener(this);
|
||||
*/
|
||||
editList = (LinearLayout) view.findViewById(R.id.edit_list);
|
||||
topbar = (LinearLayout) view.findViewById(R.id.top_bar);
|
||||
/*
|
||||
cancel = (ImageView) view.findViewById(R.id.cancel);
|
||||
cancel.setOnClickListener(this);
|
||||
|
||||
edit = (ImageView) view.findViewById(R.id.edit);
|
||||
edit.setOnClickListener(this);
|
||||
*/
|
||||
clearSearchField = (ImageView) view.findViewById(R.id.clearSearchField);
|
||||
clearSearchField.setOnClickListener(this);
|
||||
|
||||
|
|
@ -236,23 +206,7 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
|||
enabledDeleteButton(false);
|
||||
isEditMode = true;
|
||||
}
|
||||
|
||||
/* if (id == R.id.all_contacts) {
|
||||
onlyDisplayLinphoneContacts = false;
|
||||
allContactsSelected.setVisibility(View.VISIBLE);
|
||||
allContacts.setEnabled(false);
|
||||
linphoneContacts.setEnabled(true);
|
||||
linphoneContactsSelected.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
else if (id == R.id.linphone_contacts) {
|
||||
allContactsSelected.setVisibility(View.INVISIBLE);
|
||||
linphoneContactsSelected.setVisibility(View.VISIBLE);
|
||||
linphoneContacts.setEnabled(false);
|
||||
allContacts.setEnabled(true);
|
||||
onlyDisplayLinphoneContacts = true;
|
||||
|
||||
}
|
||||
*/
|
||||
if(isEditMode){
|
||||
deselectAll.setVisibility(View.GONE);
|
||||
selectAll.setVisibility(View.VISIBLE);
|
||||
|
|
@ -264,12 +218,6 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
|||
changeContactsAdapter();
|
||||
}
|
||||
|
||||
/* if (id == R.id.newContact) {
|
||||
editConsumed = true;
|
||||
LinphoneActivity.instance().addContact(null, sipAddressToAdd);
|
||||
}
|
||||
else
|
||||
*/
|
||||
if (id == R.id.clearSearchField) {
|
||||
searchField.setText("");
|
||||
}
|
||||
|
|
@ -495,27 +443,9 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
|||
icon.setImageResource(R.drawable.avatar);
|
||||
}
|
||||
|
||||
if (contact != null) {
|
||||
ImageView friendStatus = (ImageView) view.findViewById(R.id.friendStatus);
|
||||
if (contact.isLinphoneFriend() && contact.getFriendPresenceModel() != null){
|
||||
PresenceModel presenceModel = contact.getFriendPresenceModel();
|
||||
PresenceBasicStatus basicStatus = presenceModel.getBasicStatus();
|
||||
String presenceStatus = "";
|
||||
if (basicStatus == PresenceBasicStatus.Open || basicStatus == PresenceBasicStatus.Open)
|
||||
presenceStatus = basicStatus.toString();
|
||||
Log.e("===>>> updateAvatarPresence status = " + presenceStatus + " - vs basicStatus = " + basicStatus);
|
||||
|
||||
if (basicStatus == PresenceBasicStatus.Closed) {
|
||||
friendStatus.setImageResource(R.drawable.presence_unregistered);
|
||||
} else if (presenceStatus == OnlineStatus.Online.toString()) {
|
||||
friendStatus.setImageResource(R.drawable.presence_online);
|
||||
} else {
|
||||
friendStatus.setImageResource(R.drawable.presence_offline);
|
||||
}
|
||||
} else{
|
||||
Log.e("===>>> updateAvatarPresence friend is null ");
|
||||
friendStatus.setImageResource(R.drawable.presence_unregistered);
|
||||
}
|
||||
AvatarWithPresenceImage avatarWithPresenceImage = (AvatarWithPresenceImage) view.findViewById(R.id.avatar_with_presence);
|
||||
if(contact != null && contact.isLinphoneFriend() && contact.getFriendPresenceModel() != null) {
|
||||
avatarWithPresenceImage.setLinphoneContact(contact);
|
||||
}
|
||||
|
||||
return view;
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ import org.linphone.core.LinphoneProxyConfig;
|
|||
import org.linphone.core.Reason;
|
||||
import org.linphone.mediastream.Log;
|
||||
import org.linphone.ui.AddressText;
|
||||
import org.linphone.ui.AvatarWithPresenceImage;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
|
|
@ -118,7 +119,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
private boolean isAnimationDisabled = false, preferLinphoneContacts = false, emptyFragment = false, permissionAsked = false;
|
||||
private OrientationEventListener mOrientationHelper;
|
||||
private LinphoneCoreListenerBase mListener;
|
||||
private LinearLayout mTabBar;
|
||||
private LinearLayout mTabBar;
|
||||
|
||||
private DrawerLayout sideMenu;
|
||||
private String[] sideMenuItems;
|
||||
|
|
@ -127,6 +128,8 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
private ImageView menu;
|
||||
private boolean fetchedContactsOnce = false;
|
||||
|
||||
private ArrayList<AvatarWithPresenceImage> listeners;
|
||||
|
||||
static final boolean isInstanciated() {
|
||||
return instance != null;
|
||||
}
|
||||
|
|
@ -201,7 +204,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
}
|
||||
}
|
||||
|
||||
mListener = new LinphoneCoreListenerBase(){
|
||||
mListener = new LinphoneCoreListenerBase(){
|
||||
@Override
|
||||
public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) {
|
||||
if(!displayChatMessageNotification(message.getFrom().asStringUriOnly())) {
|
||||
|
|
@ -279,15 +282,11 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
|
||||
@Override
|
||||
public void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf) {
|
||||
// if(currentFragment == FragmentsAvailable.HISTORY_DETAIL || currentFragment == FragmentsAvailable.HISTORY_LIST || currentFragment == FragmentsAvailable.CONTACTS_LIST
|
||||
// || currentFragment == FragmentsAvailable.CONTACT_DETAIL || currentFragment == FragmentsAvailable.CONTACT_EDITOR || currentFragment == FragmentsAvailable.CHAT_LIST
|
||||
// || currentFragment == FragmentsAvailable.CHAT){
|
||||
|
||||
if(currentFragment == FragmentsAvailable.CONTACTS_LIST){
|
||||
if (contactListFragment != null && contactListFragment.isVisible()) {
|
||||
((ContactsListFragment) contactListFragment).invalidate();
|
||||
}
|
||||
}
|
||||
for(AvatarWithPresenceImage listener : listeners){
|
||||
if(listener.isThisFriend(lf)){
|
||||
listener.updatePresenceIcon(lc, lf);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -418,6 +417,11 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
missedChats = (TextView) findViewById(R.id.missed_chats);
|
||||
}
|
||||
|
||||
|
||||
public void addPresenceUpdatedListener(AvatarWithPresenceImage aWPI){
|
||||
listeners.add(aWPI);
|
||||
}
|
||||
|
||||
private boolean isTablet() {
|
||||
return getResources().getBoolean(R.bool.isTablet);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -437,6 +437,10 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
else return null;
|
||||
}
|
||||
|
||||
public boolean compareFriend(LinphoneFriend mFriend){
|
||||
return this.friend == mFriend;
|
||||
}
|
||||
|
||||
public static LinphoneContact createContact() {
|
||||
if (ContactsManager.getInstance().hasContactsAccess()) {
|
||||
return createAndroidContact();
|
||||
|
|
|
|||
79
src/org/linphone/ui/AvatarWithPresenceImage.java
Normal file
79
src/org/linphone/ui/AvatarWithPresenceImage.java
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
package org.linphone.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import org.linphone.LinphoneActivity;
|
||||
import org.linphone.LinphoneContact;
|
||||
import org.linphone.R;
|
||||
import org.linphone.core.LinphoneCore;
|
||||
import org.linphone.core.LinphoneFriend;
|
||||
import org.linphone.core.OnlineStatus;
|
||||
import org.linphone.core.PresenceBasicStatus;
|
||||
import org.linphone.core.PresenceModel;
|
||||
import org.linphone.mediastream.Log;
|
||||
|
||||
/**
|
||||
* Created by brieucviel on 15/04/2016.
|
||||
*/
|
||||
|
||||
|
||||
public class AvatarWithPresenceImage extends RelativeLayout implements onPresenceUpdated {
|
||||
|
||||
private LinphoneContact contact;
|
||||
private ImageView friendStatus;
|
||||
|
||||
public AvatarWithPresenceImage(Context context, AttributeSet attrs) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
inflate(getContext(), R.layout.avatar_with_presence, this);
|
||||
ImageView friendStatus = (ImageView) this.findViewById(R.id.friendStatus);
|
||||
friendStatus.setImageResource(R.drawable.presence_unregistered);
|
||||
LinphoneActivity.instance().addPresenceUpdatedListener(this);
|
||||
}
|
||||
|
||||
public void setLinphoneContact(LinphoneContact mContact){
|
||||
this.contact = mContact;
|
||||
}
|
||||
|
||||
public boolean isThisFriend(LinphoneFriend myFriend){
|
||||
return this.contact.compareFriend(myFriend);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePresenceIcon (LinphoneCore lc, LinphoneFriend friend){
|
||||
|
||||
if (contact != null) {
|
||||
if (contact.isLinphoneFriend() && contact.getFriendPresenceModel() != null){
|
||||
PresenceModel presenceModel = contact.getFriendPresenceModel();
|
||||
PresenceBasicStatus basicStatus = presenceModel.getBasicStatus();
|
||||
String presenceStatus = "";
|
||||
if (basicStatus == PresenceBasicStatus.Open || basicStatus == PresenceBasicStatus.Open)
|
||||
presenceStatus = basicStatus.toString();
|
||||
Log.e("===>>> updateAvatarPresence status = " + presenceStatus + " - vs basicStatus = " + basicStatus);
|
||||
|
||||
if (basicStatus == PresenceBasicStatus.Closed) {
|
||||
friendStatus.setImageResource(R.drawable.presence_unregistered);
|
||||
} else if (presenceStatus == OnlineStatus.Online.toString()) {
|
||||
friendStatus.setImageResource(R.drawable.presence_online);
|
||||
} else {
|
||||
friendStatus.setImageResource(R.drawable.presence_offline);
|
||||
}
|
||||
} else{
|
||||
Log.e("===>>> updateAvatarPresence friend is null ");
|
||||
friendStatus.setImageResource(R.drawable.presence_unregistered);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
interface onPresenceUpdated {
|
||||
void updatePresenceIcon (LinphoneCore lc, LinphoneFriend friend);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue