Add friendlist subscription
This commit is contained in:
parent
516b37bc8d
commit
4ade655473
11 changed files with 102 additions and 7 deletions
|
@ -95,6 +95,19 @@
|
|||
android:scaleType="centerInside"
|
||||
android:src="@drawable/led_connected" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/friendLinphone"
|
||||
android:visibility="gone"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:adjustViewBounds="true"
|
||||
android:layout_marginRight="20dp"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@drawable/linphone_user" />
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -7,6 +7,8 @@ contact="Linphone Android" <sip:linphone.android@unknown-host>
|
|||
use_info=0
|
||||
use_ipv6=0
|
||||
keepalive_period=30000
|
||||
rls_uri=sip:rls@sip1.linphone.org
|
||||
use_rls_presence=1
|
||||
|
||||
[video]
|
||||
size=qvga
|
||||
|
|
|
@ -71,6 +71,7 @@
|
|||
<string name="pref_bandwidth_limit_key">pref_bandwidth_limit_key</string>
|
||||
<string name="pref_animation_enable_key">pref_animation_enable_key</string>
|
||||
<string name="pref_escape_plus_key">pref_escape_plus_key</string>
|
||||
<string name="pref_friendlist_subscribe_key">pref_friendlist_subscribe_key</string>
|
||||
<string name="pref_echo_cancellation_key">pref_echo_cancellation_key</string>
|
||||
<string name="pref_autostart_key">pref_autostart_key</string>
|
||||
<string name="pref_enable_outbound_proxy_key">Outbound proxy</string>
|
||||
|
|
|
@ -204,6 +204,7 @@
|
|||
<string name="pref_avpf">AVPF</string>
|
||||
<string name="pref_avpf_rr_interval"> AVPF regular RTCP interval in seconds (between 1 and 5)</string>
|
||||
<string name="pref_escape_plus">Replace + by 00</string>
|
||||
<string name="pref_friendlist_subscribe">Friendlist subscribe</string>
|
||||
<string name="pref_auth_userid">Auth userid</string>
|
||||
<string name="pref_help_auth_userid">Enter authentication userid (optional)</string>
|
||||
<string name="pref_display_name">Display name</string>
|
||||
|
|
|
@ -72,6 +72,10 @@
|
|||
<CheckBoxPreference
|
||||
android:title="@string/pref_escape_plus"
|
||||
android:key="@string/pref_escape_plus_key"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:title="@string/pref_friendlist_subscribe"
|
||||
android:key="@string/pref_friendlist_subscribe_key"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ public class AccountPreferencesFragment extends PreferencesListFragment {
|
|||
}
|
||||
preference.setSummary(newValue.toString());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
OnPreferenceChangeListener prefixChangedListener = new OnPreferenceChangeListener() {
|
||||
@Override
|
||||
|
@ -234,6 +234,14 @@ public class AccountPreferencesFragment extends PreferencesListFragment {
|
|||
return true;
|
||||
}
|
||||
};
|
||||
OnPreferenceChangeListener friendlistSubscribeListener = new OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
boolean value = (Boolean) newValue;
|
||||
LinphoneManager.getInstance().subscribeFriendList(value);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
OnPreferenceChangeListener disableChangedListener = new OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
|
@ -365,6 +373,12 @@ public class AccountPreferencesFragment extends PreferencesListFragment {
|
|||
if(!isNewAccount){
|
||||
escape.setChecked(mPrefs.getReplacePlusByZeroZero(n));
|
||||
}
|
||||
|
||||
CheckBoxPreference friendlistSubscribe = (CheckBoxPreference) advanced.getPreference(8);
|
||||
friendlistSubscribe.setOnPreferenceChangeListener(friendlistSubscribeListener);
|
||||
if(!isNewAccount){
|
||||
escape.setChecked(mPrefs.getReplacePlusByZeroZero(n));
|
||||
}
|
||||
|
||||
PreferenceCategory manage = (PreferenceCategory) getPreferenceScreen().findPreference(getString(R.string.pref_manage_key));
|
||||
final CheckBoxPreference disable = (CheckBoxPreference) manage.getPreference(0);
|
||||
|
|
|
@ -459,6 +459,7 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
|||
}
|
||||
|
||||
CheckBox delete = (CheckBox) view.findViewById(R.id.delete);
|
||||
ImageView linphoneFriend = (ImageView) view.findViewById(R.id.friendLinphone);
|
||||
|
||||
TextView name = (TextView) view.findViewById(R.id.name);
|
||||
name.setText(contact.getFullName());
|
||||
|
@ -474,7 +475,13 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
|||
separatorText.setText(String.valueOf(fullName.charAt(0)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(contact.isInLinphoneFriendList()){
|
||||
linphoneFriend.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
linphoneFriend.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
ImageView icon = (ImageView) view.findViewById(R.id.contact_picture);
|
||||
if (contact.hasPhoto()) {
|
||||
LinphoneUtils.setImagePictureFromUri(getActivity(), icon, contact.getPhotoUri(), contact.getThumbnailUri());
|
||||
|
|
|
@ -50,13 +50,16 @@ import org.linphone.ui.AddressText;
|
|||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.Dialog;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
|
@ -1122,6 +1125,9 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
protected void onPause() {
|
||||
getIntent().putExtra("PreviousActivity", 0);
|
||||
|
||||
if(LinphonePreferences.instance().isFriendlistsubscriptionEnabled()){
|
||||
LinphoneManager.getInstance().subscribeFriendList(!isApplicationBroughtToBackground(this));
|
||||
}
|
||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||
if (lc != null) {
|
||||
lc.removeListener(mListener);
|
||||
|
@ -1129,7 +1135,28 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
|
||||
public static boolean isApplicationBroughtToBackground(final Activity activity) {
|
||||
ActivityManager activityManager = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
List<ActivityManager.RunningTaskInfo> tasks = activityManager.getRunningTasks(1);
|
||||
|
||||
// Check the top Activity against the list of Activities contained in the Application's package.
|
||||
if (!tasks.isEmpty()) {
|
||||
ComponentName topActivity = tasks.get(0).topActivity;
|
||||
try {
|
||||
PackageInfo pi = activity.getPackageManager().getPackageInfo(activity.getPackageName(), PackageManager.GET_ACTIVITIES);
|
||||
for (ActivityInfo activityInfo : pi.activities) {
|
||||
if(topActivity.getClassName().equals(activityInfo.name)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} catch( PackageManager.NameNotFoundException e) {
|
||||
return false; // Never happens.
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void checkAndRequestExternalStoragePermission() {
|
||||
if (LinphonePreferences.instance().writeExternalStoragePermAsked()) {
|
||||
return;
|
||||
|
@ -1171,7 +1198,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
|
||||
public void checkAndRequestPermission(String permission, int result) {
|
||||
if (getPackageManager().checkPermission(permission, getPackageName()) != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(this, new String[]{ permission }, result);
|
||||
ActivityCompat.requestPermissions(this, new String[]{permission}, result);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1244,6 +1271,9 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
refreshAccounts();
|
||||
|
||||
updateMissedChatCount();
|
||||
if(LinphonePreferences.instance().isFriendlistsubscriptionEnabled()){
|
||||
LinphoneManager.getInstance().subscribeFriendList(true);
|
||||
}
|
||||
|
||||
displayMissedCalls(LinphoneManager.getLc().getMissedCallsCount());
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.linphone.core.LinphoneCoreException;
|
|||
import org.linphone.core.LinphoneCoreFactory;
|
||||
import org.linphone.core.LinphoneFriend;
|
||||
import org.linphone.core.LinphoneFriend.SubscribePolicy;
|
||||
import org.linphone.core.PresenceBasicStatus;
|
||||
import org.linphone.mediastream.Log;
|
||||
|
||||
import android.content.ContentProviderOperation;
|
||||
|
@ -446,6 +447,10 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
return friend != null;
|
||||
}
|
||||
|
||||
public boolean isInLinphoneFriendList() {
|
||||
return (friend != null && friend.getPresenceModel() != null && friend.getPresenceModel().getBasicStatus().equals(PresenceBasicStatus.Open));
|
||||
}
|
||||
|
||||
public void setFriend(LinphoneFriend f) {
|
||||
friend = f;
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
|
|||
userAgent.append("LinphoneAndroid/" + mServiceContext.getPackageManager().getPackageInfo(mServiceContext.getPackageName(),0).versionCode);
|
||||
userAgent.append(" (");
|
||||
userAgent.append("Linphone/" + LinphoneManager.getLc().getVersion() + "; ");
|
||||
userAgent.append(Build.DEVICE + " " + Build.MODEL + " Android/" + Build.VERSION.SDK_INT);
|
||||
userAgent.append(Build.DEVICE + " " + Build.MODEL + " Android/" + Build.VERSION.SDK_INT);
|
||||
userAgent.append(")");
|
||||
return userAgent.toString();
|
||||
}
|
||||
|
@ -379,6 +379,15 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
|
|||
}
|
||||
}
|
||||
|
||||
public void subscribeFriendList(boolean enabled){
|
||||
LinphoneCore lc = getLcIfManagerNotDestroyedOrNull();
|
||||
if(lc != null ) {
|
||||
LinphoneFriendList mFriendList = (lc.getFriendLists())[0];
|
||||
mFriendList.enableSubscriptions(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static synchronized final LinphoneManager getInstance() {
|
||||
if (instance != null) return instance;
|
||||
|
||||
|
@ -667,6 +676,7 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
|
|||
mLc.setCallLogsDatabasePath(mCallLogDatabaseFile);
|
||||
mLc.setFriendsDatabasePath(mFriendsDatabaseFile);
|
||||
mLc.setUserCertificatesPath(mUserCertificatePath);
|
||||
subscribeFriendList(mPrefs.isFriendlistsubscriptionEnabled());
|
||||
//mLc.setCallErrorTone(Reason.NotFound, mErrorToneFile);
|
||||
|
||||
int availableCores = Runtime.getRuntime().availableProcessors();
|
||||
|
@ -897,7 +907,7 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
|
|||
Log.i("New global state [",state,"]");
|
||||
if (state == GlobalState.GlobalOn){
|
||||
try {
|
||||
initLiblinphone(lc);
|
||||
initLiblinphone(lc);
|
||||
} catch (LinphoneCoreException e) {
|
||||
Log.e(e);
|
||||
}
|
||||
|
@ -1032,7 +1042,6 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (state == State.CallUpdatedByRemote) {
|
||||
// If the correspondent proposes video while audio call
|
||||
boolean remoteVideo = call.getRemoteParams().getVideoEnabled();
|
||||
|
|
|
@ -662,6 +662,15 @@ public class LinphonePreferences {
|
|||
prxCfg.done();
|
||||
}
|
||||
|
||||
public boolean isFriendlistsubscriptionEnabled() {
|
||||
return getConfig().getBool("app", "friendlist_subscription_enabled", false);
|
||||
}
|
||||
|
||||
public void enabledFriendlistSubscription(boolean enabled) {
|
||||
getConfig().setBool("app", "friendlist_subscription_enabled", enabled);
|
||||
|
||||
}
|
||||
|
||||
public void setDefaultAccount(int accountIndex) {
|
||||
LinphoneProxyConfig[] prxCfgs = getLc().getProxyConfigList();
|
||||
if (accountIndex >= 0 && accountIndex < prxCfgs.length)
|
||||
|
|
Loading…
Reference in a new issue