Fix assistant link + contacts
This commit is contained in:
parent
e3efead597
commit
f75de58f3d
7 changed files with 115 additions and 78 deletions
|
@ -22,10 +22,12 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.linphone.LinphonePreferences.AccountBuilder;
|
||||
import org.linphone.assistant.AssistantActivity;
|
||||
import org.linphone.core.LinphoneCoreException;
|
||||
import org.linphone.mediastream.Log;
|
||||
import org.linphone.ui.PreferencesListFragment;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.EditTextPreference;
|
||||
|
@ -244,7 +246,10 @@ public class AccountPreferencesFragment extends PreferencesListFragment {
|
|||
OnPreferenceClickListener linkAccountListener = new OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
LinphoneActivity.instance().displayLinkPhoneNumber();
|
||||
Intent assistant = new Intent();
|
||||
assistant.setClass(LinphoneActivity.instance(), AssistantActivity.class);
|
||||
assistant.putExtra("LinkPhoneNumber", true);
|
||||
startActivity(assistant);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -631,10 +631,12 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
}
|
||||
|
||||
public void displayLinkPhoneNumber() {
|
||||
Intent assistant = new Intent();
|
||||
assistant.setClass(this, AssistantActivity.class);
|
||||
assistant.putExtra("LinkPhoneNumber", true);
|
||||
startActivity(assistant);
|
||||
LinphoneAccountCreator accountCreator;
|
||||
accountCreator = LinphoneCoreFactory.instance().createAccountCreator(LinphoneManager.getLc(), LinphonePreferences.instance().getXmlrpcUrl());
|
||||
accountCreator.setDomain(getResources().getString(R.string.default_domain));
|
||||
accountCreator.setListener(this);
|
||||
accountCreator.setUsername(LinphonePreferences.instance().getAccountUsername(LinphonePreferences.instance().getDefaultAccountIndex()));
|
||||
accountCreator.isAccountLinked();
|
||||
}
|
||||
|
||||
public void displayInapp() {
|
||||
|
@ -1243,8 +1245,11 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
int readContactsI = -1;
|
||||
for (int i = 0; i < permissions.length; i++) {
|
||||
Log.i("[Permission] " + permissions[i] + " is " + (grantResults[i] == PackageManager.PERMISSION_GRANTED ? "granted" : "denied"));
|
||||
if (permissions[i] == Manifest.permission.READ_CONTACTS)
|
||||
readContactsI = i;
|
||||
}
|
||||
|
||||
switch (requestCode) {
|
||||
|
@ -1256,7 +1261,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
}
|
||||
break;
|
||||
case PERMISSIONS_REQUEST_CONTACTS:
|
||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
if (readContactsI >= 0 && grantResults[readContactsI] == PackageManager.PERMISSION_GRANTED) {
|
||||
ContactsManager.getInstance().enableContactsAccess();
|
||||
}
|
||||
checkAndRequestReadPhoneStatePermission();
|
||||
|
@ -1315,6 +1320,12 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
Log.i("[Permission] Asking for contacts");
|
||||
permissionsList.add(Manifest.permission.READ_CONTACTS);
|
||||
}
|
||||
} else {
|
||||
if (!fetchedContactsOnce) {
|
||||
ContactsManager.getInstance().enableContactsAccess();
|
||||
ContactsManager.getInstance().fetchContactsAsync();
|
||||
fetchedContactsOnce = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (permissionsList.size() > 0) {
|
||||
|
@ -1826,8 +1837,8 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
|
||||
@Override
|
||||
public void onAccountCreatorIsAccountUsed(LinphoneAccountCreator accountCreator, LinphoneAccountCreator.Status status) {
|
||||
if(status.equals(LinphoneAccountCreator.Status.AccountExist)){
|
||||
askLinkWithPhoneNumber();
|
||||
if (status.equals(LinphoneAccountCreator.Status.AccountExist)) {
|
||||
accountCreator.isAccountLinked();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1851,12 +1862,13 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
|
||||
@Override
|
||||
public void onAccountCreatorIsAccountLinked(LinphoneAccountCreator accountCreator, LinphoneAccountCreator.Status status) {
|
||||
|
||||
if (status.equals(LinphoneAccountCreator.Status.AccountNotLinked)) {
|
||||
askLinkWithPhoneNumber();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccountCreatorIsPhoneNumberUsed(LinphoneAccountCreator accountCreator, LinphoneAccountCreator.Status status) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1253,7 +1253,6 @@ public class SettingsFragment extends PreferencesListFragment {
|
|||
|
||||
if (LinphoneActivity.isInstanciated()) {
|
||||
LinphoneActivity.instance().selectMenu(FragmentsAvailable.SETTINGS);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ private static AssistantActivity instance;
|
|||
setContentView(R.layout.assistant);
|
||||
initUI();
|
||||
|
||||
if(getIntent().getBooleanExtra("LinkPhoneNumber",false)){
|
||||
if (getIntent().getBooleanExtra("LinkPhoneNumber",false)) {
|
||||
isLink = true;
|
||||
displayCreateAccount();
|
||||
} else {
|
||||
|
|
|
@ -212,6 +212,8 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
|
|||
createAccount.setText(getResources().getString(R.string.link_account));
|
||||
assisstantTitle.setText(getResources().getString(R.string.link_account));
|
||||
}
|
||||
accountCreator.setLanguage(Locale.getDefault().toLanguageTag());
|
||||
|
||||
addUsernameHandler(usernameEdit, null);
|
||||
|
||||
createAccount.setEnabled(true);
|
||||
|
@ -297,7 +299,11 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
|
|||
}
|
||||
|
||||
case R.id.assistant_create: {
|
||||
accountCreator.isAccountUsed();
|
||||
createAccount.setEnabled(false);
|
||||
if (linkAccount)
|
||||
addAlias();
|
||||
else
|
||||
accountCreator.isAccountUsed();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -322,6 +328,7 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
|
|||
if (isOk) {
|
||||
accountCreator.linkPhoneNumberWithAccount();
|
||||
} else {
|
||||
createAccount.setEnabled(true);
|
||||
LinphoneUtils.displayErrorAlert(LinphoneUtils.errorForStatus(status), getContext());
|
||||
LinphoneUtils.displayError(isOk, phoneNumberError, LinphoneUtils.errorForStatus(status));
|
||||
}
|
||||
|
@ -566,6 +573,7 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
|
|||
, LinphoneUtils.getCountryCode(dialCode), false);
|
||||
}
|
||||
} else {
|
||||
createAccount.setEnabled(true);
|
||||
LinphoneUtils.displayErrorAlert(LinphoneUtils.errorForStatus(status), getContext());
|
||||
}
|
||||
}
|
||||
|
@ -602,6 +610,7 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
|
|||
accountCreator.recoverPhoneAccount(); // Resend SMS
|
||||
}
|
||||
} else {
|
||||
createAccount.setEnabled(true);
|
||||
LinphoneUtils.displayErrorAlert(LinphoneUtils.errorForStatus(status), getContext());
|
||||
}
|
||||
}
|
||||
|
@ -612,6 +621,7 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
|
|||
AssistantActivity.instance().displayAssistantCodeConfirm(getUsername()
|
||||
, dialCode.getText().toString() , phoneNumberEdit.getText().toString(), false);
|
||||
} else {
|
||||
createAccount.setEnabled(true);
|
||||
//SMS error
|
||||
LinphoneUtils.displayErrorAlert(getString(R.string.request_failed), getContext());
|
||||
}
|
||||
|
@ -624,10 +634,12 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
|
|||
@Override
|
||||
public void onAccountCreatorIsPhoneNumberUsed(LinphoneAccountCreator ac, Status status) {
|
||||
if (status.equals(Status.PhoneNumberUsedAccount) || status.equals(Status.PhoneNumberUsedAlias)) {
|
||||
if (accountCreator.getPhoneNumber().compareTo(accountCreator.getUsername()) == 0)
|
||||
if (accountCreator.getPhoneNumber().compareTo(accountCreator.getUsername()) == 0) {
|
||||
accountCreator.isAccountActivated();
|
||||
else
|
||||
} else {
|
||||
createAccount.setEnabled(true);
|
||||
LinphoneUtils.displayErrorAlert(LinphoneUtils.errorForStatus(status), getContext());
|
||||
}
|
||||
} else {
|
||||
accountCreator.isAccountActivated();
|
||||
}
|
||||
|
|
|
@ -44,6 +44,9 @@ import android.widget.EditText;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author Sylvain Berfini
|
||||
*/
|
||||
|
@ -146,6 +149,8 @@ public class LinphoneLoginFragment extends Fragment implements CompoundButton.On
|
|||
passwordLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
accountCreator.setLanguage(Locale.getDefault().toLanguageTag());
|
||||
|
||||
addPhoneNumberHandler(dialCode, null);
|
||||
addPhoneNumberHandler(phoneNumberEdit, null);
|
||||
|
||||
|
@ -166,9 +171,11 @@ public class LinphoneLoginFragment extends Fragment implements CompoundButton.On
|
|||
public void linphoneLogIn() {
|
||||
if (login.getText() == null || login.length() == 0 || password.getText() == null || password.length() == 0) {
|
||||
LinphoneUtils.displayErrorAlert(getString(R.string.first_launch_no_login_password), getContext());
|
||||
apply.setEnabled(true);
|
||||
return;
|
||||
}
|
||||
AssistantActivity.instance().linphoneLogIn(login.getText().toString(), password.getText().toString(), null, null, getResources().getBoolean(R.bool.assistant_account_validation_mandatory));
|
||||
apply.setEnabled(true);
|
||||
}
|
||||
|
||||
private LinphoneAccountCreator.Status getPhoneNumberStatus() {
|
||||
|
@ -213,6 +220,7 @@ public class LinphoneLoginFragment extends Fragment implements CompoundButton.On
|
|||
|
||||
switch(id) {
|
||||
case R.id.assistant_apply: {
|
||||
apply.setEnabled(false);
|
||||
if (recoverAccount) {
|
||||
recoverAccount();
|
||||
} else {
|
||||
|
@ -243,10 +251,12 @@ public class LinphoneLoginFragment extends Fragment implements CompoundButton.On
|
|||
if (isOk) {
|
||||
accountCreator.recoverPhoneAccount();
|
||||
} else {
|
||||
apply.setEnabled(true);
|
||||
LinphoneUtils.displayErrorAlert(LinphoneUtils.errorForStatus(status), getContext());
|
||||
LinphoneUtils.displayError(isOk, phoneNumberError, LinphoneUtils.errorForStatus(status));
|
||||
}
|
||||
} else {
|
||||
apply.setEnabled(true);
|
||||
LinphoneUtils.displayErrorAlert(getString(R.string.assistant_create_account_part_1), getContext());
|
||||
}
|
||||
}
|
||||
|
@ -337,7 +347,6 @@ public class LinphoneLoginFragment extends Fragment implements CompoundButton.On
|
|||
|
||||
@Override
|
||||
public void onAccountCreatorIsAccountLinked(LinphoneAccountCreator accountCreator, LinphoneAccountCreator.Status status) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 1faa826dea91566eb7598cd34873017753e2b8ed
|
||||
Subproject commit 3e7b6b90b5f5c70847b55b406221cd27c8ea307f
|
Loading…
Reference in a new issue