Fixed issues with link phone number to account dialog
This commit is contained in:
parent
b63b23a8b3
commit
7c244654b3
3 changed files with 143 additions and 149 deletions
|
@ -20,9 +20,7 @@
|
|||
package org.linphone;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
|
@ -33,20 +31,13 @@ import android.os.PowerManager;
|
|||
import android.os.PowerManager.WakeLock;
|
||||
import android.telephony.PhoneStateListener;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import java.io.File;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import org.linphone.assistant.PhoneAccountLinkingAssistantActivity;
|
||||
import org.linphone.call.AndroidAudioManager;
|
||||
import org.linphone.call.CallManager;
|
||||
import org.linphone.contacts.ContactsManager;
|
||||
import org.linphone.core.AccountCreator;
|
||||
import org.linphone.core.AccountCreatorListenerStub;
|
||||
import org.linphone.core.Call;
|
||||
import org.linphone.core.Call.State;
|
||||
import org.linphone.core.Core;
|
||||
|
@ -92,7 +83,6 @@ public class LinphoneManager implements SensorEventListener {
|
|||
private Core mCore;
|
||||
private CoreListenerStub mCoreListener;
|
||||
private AccountCreator mAccountCreator;
|
||||
private AccountCreatorListenerStub mAccountCreatorListener;
|
||||
|
||||
private boolean mExited;
|
||||
private boolean mCallGsmON;
|
||||
|
@ -223,39 +213,6 @@ public class LinphoneManager implements SensorEventListener {
|
|||
list.removeListener(ContactsManager.getInstance());
|
||||
}
|
||||
};
|
||||
|
||||
mAccountCreatorListener =
|
||||
new AccountCreatorListenerStub() {
|
||||
@Override
|
||||
public void onIsAccountExist(
|
||||
AccountCreator accountCreator,
|
||||
AccountCreator.Status status,
|
||||
String resp) {
|
||||
if (status.equals(AccountCreator.Status.AccountExist)) {
|
||||
accountCreator.isAccountLinked();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLinkAccount(
|
||||
AccountCreator accountCreator,
|
||||
AccountCreator.Status status,
|
||||
String resp) {
|
||||
if (status.equals(AccountCreator.Status.AccountNotLinked)) {
|
||||
askLinkWithPhoneNumber();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIsAccountLinked(
|
||||
AccountCreator accountCreator,
|
||||
AccountCreator.Status status,
|
||||
String resp) {
|
||||
if (status.equals(AccountCreator.Status.AccountNotLinked)) {
|
||||
askLinkWithPhoneNumber();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static synchronized LinphoneManager getInstance() {
|
||||
|
@ -452,7 +409,6 @@ public class LinphoneManager implements SensorEventListener {
|
|||
resetCameraFromPreferences();
|
||||
|
||||
mAccountCreator = mCore.createAccountCreator(LinphonePreferences.instance().getXmlrpcUrl());
|
||||
mAccountCreator.setListener(mAccountCreatorListener);
|
||||
mCallGsmON = false;
|
||||
|
||||
Log.i("[Manager] Core configured");
|
||||
|
@ -489,99 +445,10 @@ public class LinphoneManager implements SensorEventListener {
|
|||
Log.w("[Manager] Account creator shouldn't be null !");
|
||||
mAccountCreator =
|
||||
mCore.createAccountCreator(LinphonePreferences.instance().getXmlrpcUrl());
|
||||
mAccountCreator.setListener(mAccountCreatorListener);
|
||||
}
|
||||
return mAccountCreator;
|
||||
}
|
||||
|
||||
public void isAccountWithAlias() {
|
||||
if (mCore.getDefaultProxyConfig() != null) {
|
||||
long now = new Timestamp(new Date().getTime()).getTime();
|
||||
AccountCreator accountCreator = getAccountCreator();
|
||||
if (LinphonePreferences.instance().getLinkPopupTime() == null
|
||||
|| Long.parseLong(LinphonePreferences.instance().getLinkPopupTime()) < now) {
|
||||
accountCreator.reset();
|
||||
accountCreator.setUsername(
|
||||
LinphonePreferences.instance()
|
||||
.getAccountUsername(
|
||||
LinphonePreferences.instance().getDefaultAccountIndex()));
|
||||
accountCreator.isAccountExist();
|
||||
}
|
||||
} else {
|
||||
LinphonePreferences.instance().setLinkPopupTime(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void askLinkWithPhoneNumber() {
|
||||
if (!LinphonePreferences.instance().isLinkPopupEnabled()) return;
|
||||
|
||||
long now = new Timestamp(new Date().getTime()).getTime();
|
||||
if (LinphonePreferences.instance().getLinkPopupTime() != null
|
||||
&& Long.parseLong(LinphonePreferences.instance().getLinkPopupTime()) >= now) return;
|
||||
|
||||
ProxyConfig proxyConfig = mCore.getDefaultProxyConfig();
|
||||
if (proxyConfig == null) return;
|
||||
if (!proxyConfig.getDomain().equals(getString(R.string.default_domain))) return;
|
||||
|
||||
long future =
|
||||
new Timestamp(
|
||||
mContext.getResources()
|
||||
.getInteger(
|
||||
R.integer.phone_number_linking_popup_time_interval))
|
||||
.getTime();
|
||||
long newDate = now + future;
|
||||
|
||||
LinphonePreferences.instance().setLinkPopupTime(String.valueOf(newDate));
|
||||
|
||||
final Dialog dialog =
|
||||
LinphoneUtils.getDialog(
|
||||
mContext,
|
||||
String.format(
|
||||
getString(R.string.link_account_popup),
|
||||
proxyConfig.getIdentityAddress().asStringUriOnly()));
|
||||
Button delete = dialog.findViewById(R.id.dialog_delete_button);
|
||||
delete.setVisibility(View.GONE);
|
||||
Button ok = dialog.findViewById(R.id.dialog_ok_button);
|
||||
ok.setText(getString(R.string.link));
|
||||
ok.setVisibility(View.VISIBLE);
|
||||
Button cancel = dialog.findViewById(R.id.dialog_cancel_button);
|
||||
cancel.setText(getString(R.string.maybe_later));
|
||||
|
||||
dialog.findViewById(R.id.dialog_do_not_ask_again_layout).setVisibility(View.VISIBLE);
|
||||
final CheckBox doNotAskAgain = dialog.findViewById(R.id.doNotAskAgain);
|
||||
dialog.findViewById(R.id.doNotAskAgainLabel)
|
||||
.setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
doNotAskAgain.setChecked(!doNotAskAgain.isChecked());
|
||||
}
|
||||
});
|
||||
|
||||
ok.setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent assistant = new Intent();
|
||||
assistant.setClass(mContext, PhoneAccountLinkingAssistantActivity.class);
|
||||
mContext.startActivity(assistant);
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
cancel.setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (doNotAskAgain.isChecked()) {
|
||||
LinphonePreferences.instance().enableLinkPopup(false);
|
||||
}
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
/* Presence stuff */
|
||||
|
||||
private boolean isPresenceModelActivitySet() {
|
||||
|
|
|
@ -43,10 +43,13 @@ import android.widget.TextView;
|
|||
import android.widget.Toast;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import org.linphone.LinphoneContext;
|
||||
import org.linphone.LinphoneManager;
|
||||
import org.linphone.R;
|
||||
import org.linphone.assistant.PhoneAccountLinkingAssistantActivity;
|
||||
import org.linphone.call.CallActivity;
|
||||
import org.linphone.call.CallIncomingActivity;
|
||||
import org.linphone.call.CallOutgoingActivity;
|
||||
|
@ -55,8 +58,9 @@ import org.linphone.compatibility.Compatibility;
|
|||
import org.linphone.contacts.ContactsActivity;
|
||||
import org.linphone.contacts.ContactsManager;
|
||||
import org.linphone.contacts.LinphoneContact;
|
||||
import org.linphone.core.AccountCreator;
|
||||
import org.linphone.core.AccountCreatorListenerStub;
|
||||
import org.linphone.core.Address;
|
||||
import org.linphone.core.AuthInfo;
|
||||
import org.linphone.core.Call;
|
||||
import org.linphone.core.ChatMessage;
|
||||
import org.linphone.core.ChatRoom;
|
||||
|
@ -99,6 +103,7 @@ public abstract class MainActivity extends LinphoneGenericActivity
|
|||
protected String[] mPermissionsToHave;
|
||||
|
||||
private CoreListenerStub mListener;
|
||||
private AccountCreatorListenerStub mAccountCreatorListener;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -228,15 +233,10 @@ public abstract class MainActivity extends LinphoneGenericActivity
|
|||
MainActivity.this);
|
||||
|
||||
if (getResources().getBoolean(R.bool.use_phone_number_validation)) {
|
||||
AuthInfo authInfo =
|
||||
core.findAuthInfo(
|
||||
proxyConfig.getRealm(),
|
||||
proxyConfig.getIdentityAddress().getUsername(),
|
||||
proxyConfig.getDomain());
|
||||
if (authInfo != null
|
||||
&& authInfo.getDomain()
|
||||
.equals(getString(R.string.default_domain))) {
|
||||
LinphoneManager.getInstance().isAccountWithAlias();
|
||||
if (proxyConfig
|
||||
.getDomain()
|
||||
.equals(getString(R.string.default_domain))) {
|
||||
isAccountWithAlias();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,6 +269,39 @@ public abstract class MainActivity extends LinphoneGenericActivity
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
mAccountCreatorListener =
|
||||
new AccountCreatorListenerStub() {
|
||||
@Override
|
||||
public void onIsAccountExist(
|
||||
AccountCreator accountCreator,
|
||||
AccountCreator.Status status,
|
||||
String resp) {
|
||||
if (status.equals(AccountCreator.Status.AccountExist)) {
|
||||
accountCreator.isAccountLinked();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLinkAccount(
|
||||
AccountCreator accountCreator,
|
||||
AccountCreator.Status status,
|
||||
String resp) {
|
||||
if (status.equals(AccountCreator.Status.AccountNotLinked)) {
|
||||
askLinkWithPhoneNumber();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIsAccountLinked(
|
||||
AccountCreator accountCreator,
|
||||
AccountCreator.Status status,
|
||||
String resp) {
|
||||
if (status.equals(AccountCreator.Status.AccountNotLinked)) {
|
||||
askLinkWithPhoneNumber();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -814,6 +847,101 @@ public abstract class MainActivity extends LinphoneGenericActivity
|
|||
dialog.show();
|
||||
}
|
||||
|
||||
public void isAccountWithAlias() {
|
||||
if (LinphoneManager.getCore().getDefaultProxyConfig() != null) {
|
||||
long now = new Timestamp(new Date().getTime()).getTime();
|
||||
AccountCreator accountCreator = LinphoneManager.getInstance().getAccountCreator();
|
||||
accountCreator.setListener(mAccountCreatorListener);
|
||||
if (LinphonePreferences.instance().getLinkPopupTime() == null
|
||||
|| Long.parseLong(LinphonePreferences.instance().getLinkPopupTime()) < now) {
|
||||
accountCreator.reset();
|
||||
accountCreator.setUsername(
|
||||
LinphonePreferences.instance()
|
||||
.getAccountUsername(
|
||||
LinphonePreferences.instance().getDefaultAccountIndex()));
|
||||
accountCreator.isAccountExist();
|
||||
}
|
||||
} else {
|
||||
LinphonePreferences.instance().setLinkPopupTime(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void askLinkWithPhoneNumber() {
|
||||
if (!LinphonePreferences.instance().isLinkPopupEnabled()) return;
|
||||
|
||||
long now = new Timestamp(new Date().getTime()).getTime();
|
||||
if (LinphonePreferences.instance().getLinkPopupTime() != null
|
||||
&& Long.parseLong(LinphonePreferences.instance().getLinkPopupTime()) >= now) return;
|
||||
|
||||
ProxyConfig proxyConfig = LinphoneManager.getCore().getDefaultProxyConfig();
|
||||
if (proxyConfig == null) return;
|
||||
if (!proxyConfig.getDomain().equals(getString(R.string.default_domain))) return;
|
||||
|
||||
final Dialog dialog =
|
||||
LinphoneUtils.getDialog(
|
||||
this,
|
||||
String.format(
|
||||
getString(R.string.link_account_popup),
|
||||
proxyConfig.getIdentityAddress().asStringUriOnly()));
|
||||
Button delete = dialog.findViewById(R.id.dialog_delete_button);
|
||||
delete.setVisibility(View.GONE);
|
||||
Button ok = dialog.findViewById(R.id.dialog_ok_button);
|
||||
ok.setText(getString(R.string.link));
|
||||
ok.setVisibility(View.VISIBLE);
|
||||
Button cancel = dialog.findViewById(R.id.dialog_cancel_button);
|
||||
cancel.setText(getString(R.string.maybe_later));
|
||||
|
||||
dialog.findViewById(R.id.dialog_do_not_ask_again_layout).setVisibility(View.VISIBLE);
|
||||
final CheckBox doNotAskAgain = dialog.findViewById(R.id.doNotAskAgain);
|
||||
dialog.findViewById(R.id.doNotAskAgainLabel)
|
||||
.setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
doNotAskAgain.setChecked(!doNotAskAgain.isChecked());
|
||||
}
|
||||
});
|
||||
|
||||
ok.setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent assistant = new Intent();
|
||||
assistant.setClass(
|
||||
MainActivity.this, PhoneAccountLinkingAssistantActivity.class);
|
||||
startActivity(assistant);
|
||||
updatePopupTimestamp();
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
cancel.setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (doNotAskAgain.isChecked()) {
|
||||
LinphonePreferences.instance().enableLinkPopup(false);
|
||||
}
|
||||
updatePopupTimestamp();
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void updatePopupTimestamp() {
|
||||
long future =
|
||||
new Timestamp(
|
||||
getResources()
|
||||
.getInteger(
|
||||
R.integer.phone_number_linking_popup_time_interval))
|
||||
.getTime();
|
||||
long now = new Timestamp(new Date().getTime()).getTime();
|
||||
long newDate = now + future;
|
||||
|
||||
LinphonePreferences.instance().setLinkPopupTime(String.valueOf(newDate));
|
||||
}
|
||||
|
||||
// Logs
|
||||
|
||||
private void shareUploadedLogsUrl(String info) {
|
||||
|
|
|
@ -52,8 +52,11 @@ public class PhoneAccountLinkingAssistantActivity extends AssistantActivity {
|
|||
|
||||
setContentView(R.layout.assistant_phone_account_linking);
|
||||
|
||||
if (getIntent() != null && getIntent().hasExtra("AccountNumber")) {
|
||||
int proxyConfigIndex = getIntent().getExtras().getInt("AccountNumber");
|
||||
if (getIntent() != null) {
|
||||
int proxyConfigIndex = 0;
|
||||
if (getIntent().hasExtra("AccountNumber"))
|
||||
proxyConfigIndex = getIntent().getExtras().getInt("AccountNumber");
|
||||
|
||||
Core core = LinphoneManager.getCore();
|
||||
if (core == null) {
|
||||
Log.e("[Account Linking Assistant] Core not available");
|
||||
|
@ -96,10 +99,6 @@ public class PhoneAccountLinkingAssistantActivity extends AssistantActivity {
|
|||
unexpectedError();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Log.e("[Account Linking Assistant] Proxy config index not found");
|
||||
unexpectedError();
|
||||
return;
|
||||
}
|
||||
|
||||
mCountryPicker = findViewById(R.id.select_country);
|
||||
|
|
Loading…
Reference in a new issue