2014-08-15 15:31:24 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
2018-03-04 10:43:58 +00:00
|
|
|
import android.app.Activity;
|
2014-08-15 15:31:24 +00:00
|
|
|
import android.app.PendingIntent;
|
2016-04-29 11:58:37 +00:00
|
|
|
import android.content.ActivityNotFoundException;
|
2015-07-07 17:36:22 +00:00
|
|
|
import android.content.DialogInterface;
|
2014-08-15 15:31:24 +00:00
|
|
|
import android.content.Intent;
|
2018-03-04 10:43:58 +00:00
|
|
|
import android.content.IntentSender;
|
2016-01-25 20:17:53 +00:00
|
|
|
import android.content.SharedPreferences;
|
2018-02-18 08:06:37 +00:00
|
|
|
import android.databinding.DataBindingUtil;
|
2015-10-11 11:11:50 +00:00
|
|
|
import android.graphics.Bitmap;
|
2016-01-11 10:17:45 +00:00
|
|
|
import android.net.Uri;
|
2014-08-15 15:31:24 +00:00
|
|
|
import android.os.Bundle;
|
2018-02-17 06:09:21 +00:00
|
|
|
import android.os.Handler;
|
2018-03-03 11:27:46 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2016-01-11 10:17:45 +00:00
|
|
|
import android.provider.Settings;
|
2015-10-11 13:48:58 +00:00
|
|
|
import android.security.KeyChain;
|
|
|
|
import android.security.KeyChainAliasCallback;
|
2018-02-18 03:20:02 +00:00
|
|
|
import android.support.design.widget.TextInputLayout;
|
2018-02-16 11:30:46 +00:00
|
|
|
import android.support.v7.app.ActionBar;
|
2018-02-17 06:09:21 +00:00
|
|
|
import android.support.v7.app.AlertDialog;
|
|
|
|
import android.support.v7.app.AlertDialog.Builder;
|
2018-03-18 08:30:22 +00:00
|
|
|
import android.support.v7.widget.Toolbar;
|
2014-10-05 10:05:27 +00:00
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.TextWatcher;
|
2018-03-03 11:27:46 +00:00
|
|
|
import android.util.Log;
|
2014-11-03 21:47:07 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
2014-08-15 15:31:24 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.CompoundButton;
|
2014-11-03 21:47:07 +00:00
|
|
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
2014-08-15 15:31:24 +00:00
|
|
|
import android.widget.EditText;
|
2014-10-03 13:55:06 +00:00
|
|
|
import android.widget.ImageButton;
|
2014-11-03 21:47:07 +00:00
|
|
|
import android.widget.ImageView;
|
2014-08-19 13:06:50 +00:00
|
|
|
import android.widget.LinearLayout;
|
2014-10-13 12:36:19 +00:00
|
|
|
import android.widget.RelativeLayout;
|
2014-10-21 20:22:01 +00:00
|
|
|
import android.widget.TableLayout;
|
2016-02-12 10:39:27 +00:00
|
|
|
import android.widget.TableRow;
|
2014-08-19 13:06:50 +00:00
|
|
|
import android.widget.TextView;
|
2014-10-03 13:55:06 +00:00
|
|
|
import android.widget.Toast;
|
2014-11-03 21:47:07 +00:00
|
|
|
|
2017-05-04 11:02:46 +00:00
|
|
|
import org.openintents.openpgp.util.OpenPgpUtils;
|
|
|
|
|
2017-12-08 13:23:38 +00:00
|
|
|
import java.net.URL;
|
2016-02-09 12:01:17 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
2015-07-07 17:36:22 +00:00
|
|
|
import java.util.Set;
|
2016-02-09 12:01:17 +00:00
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
2015-07-07 17:36:22 +00:00
|
|
|
|
2015-07-21 23:00:20 +00:00
|
|
|
import eu.siacs.conversations.Config;
|
2014-08-15 15:31:24 +00:00
|
|
|
import eu.siacs.conversations.R;
|
2015-09-06 17:40:28 +00:00
|
|
|
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
|
2016-11-18 20:49:52 +00:00
|
|
|
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
|
2018-02-18 08:06:37 +00:00
|
|
|
import eu.siacs.conversations.databinding.ActivityEditAccountBinding;
|
2018-03-03 11:27:46 +00:00
|
|
|
import eu.siacs.conversations.databinding.DialogPresenceBinding;
|
2014-08-15 15:31:24 +00:00
|
|
|
import eu.siacs.conversations.entities.Account;
|
2018-03-04 10:43:58 +00:00
|
|
|
import eu.siacs.conversations.entities.Presence;
|
2018-03-03 11:27:46 +00:00
|
|
|
import eu.siacs.conversations.entities.PresenceTemplate;
|
2016-11-22 21:31:46 +00:00
|
|
|
import eu.siacs.conversations.services.BarcodeProvider;
|
2015-10-11 13:48:58 +00:00
|
|
|
import eu.siacs.conversations.services.XmppConnectionService;
|
2014-08-15 15:31:24 +00:00
|
|
|
import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
|
2018-02-17 06:09:21 +00:00
|
|
|
import eu.siacs.conversations.services.XmppConnectionService.OnCaptchaRequested;
|
2014-08-15 15:31:24 +00:00
|
|
|
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
|
2018-03-03 11:27:46 +00:00
|
|
|
import eu.siacs.conversations.ui.adapter.PresenceTemplateAdapter;
|
2018-03-04 10:43:58 +00:00
|
|
|
import eu.siacs.conversations.ui.util.PendingItem;
|
2018-01-10 15:57:54 +00:00
|
|
|
import eu.siacs.conversations.ui.widget.DisabledActionModeCallback;
|
2014-11-15 23:20:20 +00:00
|
|
|
import eu.siacs.conversations.utils.CryptoHelper;
|
2014-08-19 13:06:50 +00:00
|
|
|
import eu.siacs.conversations.utils.UIHelper;
|
2016-11-28 14:11:44 +00:00
|
|
|
import eu.siacs.conversations.utils.XmppUri;
|
2016-02-09 12:01:17 +00:00
|
|
|
import eu.siacs.conversations.xml.Element;
|
2015-07-21 12:18:16 +00:00
|
|
|
import eu.siacs.conversations.xmpp.OnKeyStatusUpdated;
|
2016-12-03 22:49:00 +00:00
|
|
|
import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
|
2016-02-19 19:54:53 +00:00
|
|
|
import eu.siacs.conversations.xmpp.XmppConnection;
|
2014-08-23 13:56:30 +00:00
|
|
|
import eu.siacs.conversations.xmpp.XmppConnection.Features;
|
2015-10-11 11:11:50 +00:00
|
|
|
import eu.siacs.conversations.xmpp.forms.Data;
|
2014-08-15 15:31:24 +00:00
|
|
|
import eu.siacs.conversations.xmpp.pep.Avatar;
|
2018-03-05 17:30:40 +00:00
|
|
|
import rocks.xmpp.addr.Jid;
|
2014-08-15 15:31:24 +00:00
|
|
|
|
2016-12-03 22:49:00 +00:00
|
|
|
public class EditAccountActivity extends OmemoActivity implements OnAccountUpdate, OnUpdateBlocklist,
|
2016-02-09 12:01:17 +00:00
|
|
|
OnKeyStatusUpdated, OnCaptchaRequested, KeyChainAliasCallback, XmppConnectionService.OnShowErrorToast, XmppConnectionService.OnMamPreferencesFetched {
|
2014-08-15 15:31:24 +00:00
|
|
|
|
2018-02-25 12:22:52 +00:00
|
|
|
private static final int REQUEST_DATA_SAVER = 0xf244;
|
2018-03-04 10:43:58 +00:00
|
|
|
private static final int REQUEST_CHANGE_STATUS = 0xee11;
|
2018-02-18 03:20:02 +00:00
|
|
|
private TextInputLayout mAccountJidLayout;
|
2014-08-15 15:31:24 +00:00
|
|
|
private EditText mPassword;
|
2018-02-18 03:20:02 +00:00
|
|
|
private TextInputLayout mPasswordLayout;
|
2014-08-15 15:31:24 +00:00
|
|
|
private Button mCancelButton;
|
|
|
|
private Button mSaveButton;
|
2016-11-07 09:49:43 +00:00
|
|
|
private Button mDisableOsOptimizationsButton;
|
|
|
|
private TextView getmDisableOsOptimizationsBody;
|
2014-10-21 20:22:01 +00:00
|
|
|
private TableLayout mMoreTable;
|
2014-08-15 15:31:24 +00:00
|
|
|
|
2015-07-07 17:36:22 +00:00
|
|
|
private TextView mAxolotlFingerprint;
|
2017-05-04 11:02:46 +00:00
|
|
|
private TextView mPgpFingerprint;
|
2016-07-17 18:31:04 +00:00
|
|
|
private TextView mOwnFingerprintDesc;
|
2017-05-04 11:02:46 +00:00
|
|
|
private TextView getmPgpFingerprintDesc;
|
2014-11-04 16:38:41 +00:00
|
|
|
private ImageView mAvatar;
|
2015-07-07 17:36:22 +00:00
|
|
|
private RelativeLayout mAxolotlFingerprintBox;
|
2017-05-04 11:02:46 +00:00
|
|
|
private RelativeLayout mPgpFingerprintBox;
|
2015-07-07 17:36:22 +00:00
|
|
|
private ImageButton mAxolotlFingerprintToClipboardButton;
|
2017-05-04 11:02:46 +00:00
|
|
|
private ImageButton mPgpDeleteFingerprintButton;
|
2015-07-19 12:09:49 +00:00
|
|
|
private LinearLayout keys;
|
2015-11-28 19:11:38 +00:00
|
|
|
private LinearLayout mNamePort;
|
|
|
|
private EditText mHostname;
|
2018-02-18 03:20:02 +00:00
|
|
|
private TextInputLayout mHostnameLayout;
|
2015-11-28 19:11:38 +00:00
|
|
|
private EditText mPort;
|
2018-02-18 03:20:02 +00:00
|
|
|
private TextInputLayout mPortLayout;
|
2015-10-11 11:11:50 +00:00
|
|
|
private AlertDialog mCaptchaDialog = null;
|
2014-08-19 13:06:50 +00:00
|
|
|
|
2014-11-06 19:33:13 +00:00
|
|
|
private Jid jidToEdit;
|
2015-10-09 11:37:08 +00:00
|
|
|
private boolean mInitMode = false;
|
2016-05-02 08:37:28 +00:00
|
|
|
private boolean mUsernameMode = Config.DOMAIN_LOCK != null;
|
2016-01-25 20:17:53 +00:00
|
|
|
private boolean mShowOptions = false;
|
2014-08-15 15:31:24 +00:00
|
|
|
private Account mAccount;
|
2015-07-29 18:21:37 +00:00
|
|
|
private String messageFingerprint;
|
2014-08-15 15:31:24 +00:00
|
|
|
|
2018-03-04 10:43:58 +00:00
|
|
|
private final PendingItem<PresenceTemplate> mPendingPresenceTemplate = new PendingItem<>();
|
|
|
|
|
2014-08-15 15:31:24 +00:00
|
|
|
private boolean mFetchingAvatar = false;
|
2014-08-19 13:06:50 +00:00
|
|
|
|
2014-12-23 22:19:00 +00:00
|
|
|
private final OnClickListener mSaveButtonClickListener = new OnClickListener() {
|
2014-08-15 15:31:24 +00:00
|
|
|
|
|
|
|
@Override
|
2014-12-23 18:23:13 +00:00
|
|
|
public void onClick(final View v) {
|
2016-04-26 21:23:48 +00:00
|
|
|
final String password = mPassword.getText().toString();
|
2017-06-19 18:02:41 +00:00
|
|
|
final boolean wasDisabled = mAccount != null && mAccount.getStatus() == Account.State.DISABLED;
|
2016-04-26 21:23:48 +00:00
|
|
|
|
|
|
|
if (!mInitMode && passwordChangedInMagicCreateMode()) {
|
|
|
|
gotoChangePassword(password);
|
|
|
|
return;
|
|
|
|
}
|
2015-10-09 11:37:08 +00:00
|
|
|
if (mInitMode && mAccount != null) {
|
|
|
|
mAccount.setOption(Account.OPTION_DISABLED, false);
|
|
|
|
}
|
2015-04-14 13:00:49 +00:00
|
|
|
if (mAccount != null && mAccount.getStatus() == Account.State.DISABLED && !accountInfoEdited()) {
|
2014-10-05 10:05:27 +00:00
|
|
|
mAccount.setOption(Account.OPTION_DISABLED, false);
|
2016-09-07 12:34:58 +00:00
|
|
|
if (!xmppConnectionService.updateAccount(mAccount)) {
|
2018-02-18 08:06:37 +00:00
|
|
|
Toast.makeText(EditAccountActivity.this, R.string.unable_to_update_account, Toast.LENGTH_SHORT).show();
|
2016-09-07 12:34:58 +00:00
|
|
|
}
|
2014-10-05 10:05:27 +00:00
|
|
|
return;
|
2014-12-25 21:08:13 +00:00
|
|
|
}
|
2018-03-13 10:54:34 +00:00
|
|
|
final boolean registerNewAccount = binding.accountRegisterNew.isChecked() && !Config.DISALLOW_REGISTRATION_IN_UI;
|
2018-02-18 08:06:37 +00:00
|
|
|
if (mUsernameMode && binding.accountJid.getText().toString().contains("@")) {
|
2018-02-18 03:20:02 +00:00
|
|
|
mAccountJidLayout.setError(getString(R.string.invalid_username));
|
2018-02-18 07:33:33 +00:00
|
|
|
removeErrorsOnAllBut(mAccountJidLayout);
|
2018-02-18 08:06:37 +00:00
|
|
|
binding.accountJid.requestFocus();
|
2015-08-03 20:58:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-06-19 18:02:41 +00:00
|
|
|
|
|
|
|
XmppConnection connection = mAccount == null ? null : mAccount.getXmppConnection();
|
2017-12-08 13:23:38 +00:00
|
|
|
boolean openRegistrationUrl = registerNewAccount && mAccount != null && mAccount.getStatus() == Account.State.REGISTRATION_WEB;
|
|
|
|
boolean openPaymentUrl = mAccount != null && mAccount.getStatus() == Account.State.PAYMENT_REQUIRED;
|
|
|
|
final boolean redirectionWorthyStatus = openPaymentUrl || openRegistrationUrl;
|
|
|
|
URL url = connection != null && redirectionWorthyStatus ? connection.getRedirectionUrl() : null;
|
|
|
|
if (url != null && redirectionWorthyStatus && !wasDisabled) {
|
2017-06-19 18:02:41 +00:00
|
|
|
try {
|
2017-12-08 13:23:38 +00:00
|
|
|
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url.toString())));
|
2017-06-19 18:02:41 +00:00
|
|
|
return;
|
|
|
|
} catch (ActivityNotFoundException e) {
|
2018-02-18 08:06:37 +00:00
|
|
|
Toast.makeText(EditAccountActivity.this, R.string.application_found_to_open_website, Toast.LENGTH_SHORT);
|
2017-06-19 18:02:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-03 09:52:55 +00:00
|
|
|
final Jid jid;
|
|
|
|
try {
|
2016-05-02 08:37:28 +00:00
|
|
|
if (mUsernameMode) {
|
2018-03-05 17:30:40 +00:00
|
|
|
jid = Jid.of(binding.accountJid.getText().toString(), getUserModeDomain(), null);
|
2015-08-03 20:58:17 +00:00
|
|
|
} else {
|
2018-03-05 17:30:40 +00:00
|
|
|
jid = Jid.of(binding.accountJid.getText().toString());
|
2015-08-03 20:58:17 +00:00
|
|
|
}
|
2018-03-05 17:30:40 +00:00
|
|
|
} catch (final IllegalArgumentException e) {
|
2016-05-02 08:37:28 +00:00
|
|
|
if (mUsernameMode) {
|
2018-02-18 03:20:02 +00:00
|
|
|
mAccountJidLayout.setError(getString(R.string.invalid_username));
|
2015-08-03 20:58:17 +00:00
|
|
|
} else {
|
2018-02-18 03:20:02 +00:00
|
|
|
mAccountJidLayout.setError(getString(R.string.invalid_jid));
|
2015-08-03 20:58:17 +00:00
|
|
|
}
|
2018-02-18 08:06:37 +00:00
|
|
|
binding.accountJid.requestFocus();
|
2018-02-18 07:33:33 +00:00
|
|
|
removeErrorsOnAllBut(mAccountJidLayout);
|
2014-12-03 09:52:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-11-29 14:44:45 +00:00
|
|
|
String hostname = null;
|
|
|
|
int numericPort = 5222;
|
2016-01-25 20:17:53 +00:00
|
|
|
if (mShowOptions) {
|
2018-02-18 08:06:37 +00:00
|
|
|
hostname = mHostname.getText().toString().replaceAll("\\s", "");
|
|
|
|
final String port = mPort.getText().toString().replaceAll("\\s", "");
|
2015-11-29 14:44:45 +00:00
|
|
|
if (hostname.contains(" ")) {
|
2018-02-18 03:20:02 +00:00
|
|
|
mHostnameLayout.setError(getString(R.string.not_valid_hostname));
|
2015-11-29 14:44:45 +00:00
|
|
|
mHostname.requestFocus();
|
2018-02-18 07:33:33 +00:00
|
|
|
removeErrorsOnAllBut(mHostnameLayout);
|
2015-11-29 14:44:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
numericPort = Integer.parseInt(port);
|
|
|
|
if (numericPort < 0 || numericPort > 65535) {
|
2018-02-18 03:20:02 +00:00
|
|
|
mPortLayout.setError(getString(R.string.not_a_valid_port));
|
2018-02-18 07:33:33 +00:00
|
|
|
removeErrorsOnAllBut(mPortLayout);
|
2015-11-29 14:44:45 +00:00
|
|
|
mPort.requestFocus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (NumberFormatException e) {
|
2018-02-18 03:20:02 +00:00
|
|
|
mPortLayout.setError(getString(R.string.not_a_valid_port));
|
2018-02-18 07:33:33 +00:00
|
|
|
removeErrorsOnAllBut(mPortLayout);
|
2015-11-29 14:44:45 +00:00
|
|
|
mPort.requestFocus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-05 17:30:40 +00:00
|
|
|
if (jid.getLocal() == null) {
|
2016-05-02 08:37:28 +00:00
|
|
|
if (mUsernameMode) {
|
2018-02-18 03:20:02 +00:00
|
|
|
mAccountJidLayout.setError(getString(R.string.invalid_username));
|
2015-08-03 20:58:17 +00:00
|
|
|
} else {
|
2018-02-18 03:20:02 +00:00
|
|
|
mAccountJidLayout.setError(getString(R.string.invalid_jid));
|
2015-08-03 20:58:17 +00:00
|
|
|
}
|
2018-02-18 07:33:33 +00:00
|
|
|
removeErrorsOnAllBut(mAccountJidLayout);
|
2018-02-18 08:06:37 +00:00
|
|
|
binding.accountJid.requestFocus();
|
2014-12-23 22:35:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-08-15 15:31:24 +00:00
|
|
|
if (mAccount != null) {
|
2016-04-26 21:23:48 +00:00
|
|
|
if (mInitMode && mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE)) {
|
|
|
|
mAccount.setOption(Account.OPTION_MAGIC_CREATE, mAccount.getPassword().contains(password));
|
|
|
|
}
|
2015-10-09 11:37:08 +00:00
|
|
|
mAccount.setJid(jid);
|
2015-11-29 14:44:45 +00:00
|
|
|
mAccount.setPort(numericPort);
|
|
|
|
mAccount.setHostname(hostname);
|
2018-02-18 03:20:02 +00:00
|
|
|
mAccountJidLayout.setError(null);
|
2015-01-02 23:11:02 +00:00
|
|
|
mAccount.setPassword(password);
|
|
|
|
mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
|
2016-09-07 12:34:58 +00:00
|
|
|
if (!xmppConnectionService.updateAccount(mAccount)) {
|
2018-02-18 08:06:37 +00:00
|
|
|
Toast.makeText(EditAccountActivity.this, R.string.unable_to_update_account, Toast.LENGTH_SHORT).show();
|
2016-09-07 12:34:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-08-15 15:31:24 +00:00
|
|
|
} else {
|
2015-08-03 20:58:17 +00:00
|
|
|
if (xmppConnectionService.findAccountByJid(jid) != null) {
|
2018-02-18 03:20:02 +00:00
|
|
|
mAccountJidLayout.setError(getString(R.string.account_already_exists));
|
2018-02-18 07:33:33 +00:00
|
|
|
removeErrorsOnAllBut(mAccountJidLayout);
|
2018-02-18 08:06:37 +00:00
|
|
|
binding.accountJid.requestFocus();
|
2014-12-21 20:43:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-03-05 17:30:40 +00:00
|
|
|
mAccount = new Account(jid.asBareJid(), password);
|
2015-11-29 14:44:45 +00:00
|
|
|
mAccount.setPort(numericPort);
|
|
|
|
mAccount.setHostname(hostname);
|
2014-08-15 15:31:24 +00:00
|
|
|
mAccount.setOption(Account.OPTION_USETLS, true);
|
|
|
|
mAccount.setOption(Account.OPTION_USECOMPRESSION, true);
|
2014-08-20 09:32:49 +00:00
|
|
|
mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
|
2014-08-15 15:31:24 +00:00
|
|
|
xmppConnectionService.createAccount(mAccount);
|
|
|
|
}
|
2018-02-18 03:20:02 +00:00
|
|
|
mHostnameLayout.setError(null);
|
|
|
|
mPortLayout.setError(null);
|
2017-11-06 12:57:25 +00:00
|
|
|
if (mAccount.isEnabled()
|
2015-10-09 11:37:08 +00:00
|
|
|
&& !registerNewAccount
|
|
|
|
&& !mInitMode) {
|
2014-08-15 15:31:24 +00:00
|
|
|
finish();
|
|
|
|
} else {
|
|
|
|
updateSaveButton();
|
2015-07-16 11:42:52 +00:00
|
|
|
updateAccountInformation(true);
|
2014-08-15 15:31:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
2014-12-23 22:19:00 +00:00
|
|
|
private final OnClickListener mCancelButtonClickListener = new OnClickListener() {
|
2014-08-15 15:31:24 +00:00
|
|
|
|
|
|
|
@Override
|
2014-12-23 22:19:00 +00:00
|
|
|
public void onClick(final View v) {
|
2018-02-15 10:03:38 +00:00
|
|
|
deleteAccountAndReturnIfNecessary();
|
2014-08-15 15:31:24 +00:00
|
|
|
finish();
|
|
|
|
}
|
|
|
|
};
|
2016-02-09 12:01:17 +00:00
|
|
|
private Toast mFetchingMamPrefsToast;
|
2016-08-26 07:10:59 +00:00
|
|
|
private String mSavedInstanceAccount;
|
|
|
|
private boolean mSavedInstanceInit = false;
|
2016-11-18 20:49:52 +00:00
|
|
|
private Button mClearDevicesButton;
|
2017-12-15 17:25:21 +00:00
|
|
|
private XmppUri pendingUri = null;
|
2018-02-18 08:06:37 +00:00
|
|
|
private boolean mUseTor;
|
|
|
|
private ActivityEditAccountBinding binding;
|
2015-07-20 13:48:58 +00:00
|
|
|
|
2018-02-18 08:06:37 +00:00
|
|
|
public void refreshUiReal() {
|
2015-07-20 13:48:58 +00:00
|
|
|
invalidateOptionsMenu();
|
|
|
|
if (mAccount != null
|
|
|
|
&& mAccount.getStatus() != Account.State.ONLINE
|
|
|
|
&& mFetchingAvatar) {
|
|
|
|
startActivity(new Intent(getApplicationContext(),
|
2015-10-11 13:48:58 +00:00
|
|
|
ManageAccountActivity.class));
|
2015-07-20 13:48:58 +00:00
|
|
|
finish();
|
2015-10-09 11:37:08 +00:00
|
|
|
} else if (mInitMode && mAccount != null && mAccount.getStatus() == Account.State.ONLINE) {
|
2015-07-20 13:48:58 +00:00
|
|
|
if (!mFetchingAvatar) {
|
|
|
|
mFetchingAvatar = true;
|
2015-10-09 11:37:08 +00:00
|
|
|
xmppConnectionService.checkForAvatar(mAccount, mAvatarFetchCallback);
|
2015-07-20 13:48:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mAccount != null) {
|
|
|
|
updateAccountInformation(false);
|
|
|
|
}
|
2016-04-09 22:19:20 +00:00
|
|
|
updateSaveButton();
|
2015-07-20 13:48:58 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 17:16:41 +00:00
|
|
|
@Override
|
|
|
|
public boolean onNavigateUp() {
|
2018-02-15 10:03:38 +00:00
|
|
|
deleteAccountAndReturnIfNecessary();
|
2016-07-21 17:16:41 +00:00
|
|
|
return super.onNavigateUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
2018-02-15 10:03:38 +00:00
|
|
|
deleteAccountAndReturnIfNecessary();
|
2016-07-21 17:16:41 +00:00
|
|
|
super.onBackPressed();
|
|
|
|
}
|
|
|
|
|
2018-02-15 10:03:38 +00:00
|
|
|
private void deleteAccountAndReturnIfNecessary() {
|
|
|
|
if (mInitMode && mAccount != null && !mAccount.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY)) {
|
2016-07-21 17:16:41 +00:00
|
|
|
xmppConnectionService.deleteAccount(mAccount);
|
2018-02-15 10:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (xmppConnectionService.getAccounts().size() == 0) {
|
2017-12-16 19:38:14 +00:00
|
|
|
Intent intent = new Intent(EditAccountActivity.this, WelcomeActivity.class);
|
2018-02-14 15:55:45 +00:00
|
|
|
WelcomeActivity.addInviteUri(intent, getIntent());
|
2017-12-16 19:38:14 +00:00
|
|
|
startActivity(intent);
|
2016-07-21 17:16:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-21 20:43:58 +00:00
|
|
|
@Override
|
|
|
|
public void onAccountUpdate() {
|
2015-07-20 13:48:58 +00:00
|
|
|
refreshUi();
|
2014-12-21 20:43:58 +00:00
|
|
|
}
|
2015-10-11 13:48:58 +00:00
|
|
|
|
2014-12-23 22:19:00 +00:00
|
|
|
private final UiCallback<Avatar> mAvatarFetchCallback = new UiCallback<Avatar>() {
|
2014-08-19 13:06:50 +00:00
|
|
|
|
2014-08-15 15:31:24 +00:00
|
|
|
@Override
|
2014-12-23 22:19:00 +00:00
|
|
|
public void userInputRequried(final PendingIntent pi, final Avatar avatar) {
|
2014-08-15 15:31:24 +00:00
|
|
|
finishInitialSetup(avatar);
|
|
|
|
}
|
2014-08-19 13:06:50 +00:00
|
|
|
|
2014-08-15 15:31:24 +00:00
|
|
|
@Override
|
2014-12-23 22:19:00 +00:00
|
|
|
public void success(final Avatar avatar) {
|
2014-08-15 15:31:24 +00:00
|
|
|
finishInitialSetup(avatar);
|
|
|
|
}
|
2014-08-19 13:06:50 +00:00
|
|
|
|
2014-08-15 15:31:24 +00:00
|
|
|
@Override
|
2014-12-23 22:19:00 +00:00
|
|
|
public void error(final int errorCode, final Avatar avatar) {
|
2014-08-15 15:31:24 +00:00
|
|
|
finishInitialSetup(avatar);
|
|
|
|
}
|
|
|
|
};
|
2014-12-23 22:19:00 +00:00
|
|
|
private final TextWatcher mTextWatcher = new TextWatcher() {
|
2014-10-05 10:05:27 +00:00
|
|
|
|
|
|
|
@Override
|
2014-12-23 22:19:00 +00:00
|
|
|
public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
|
2014-10-05 10:05:27 +00:00
|
|
|
updateSaveButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-12-23 22:19:00 +00:00
|
|
|
public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) {
|
2014-10-05 10:05:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-12-23 22:19:00 +00:00
|
|
|
public void afterTextChanged(final Editable s) {
|
2014-12-25 21:28:19 +00:00
|
|
|
|
2014-10-05 10:05:27 +00:00
|
|
|
}
|
2015-01-02 23:11:02 +00:00
|
|
|
};
|
2014-12-25 21:28:19 +00:00
|
|
|
|
2018-02-18 08:06:37 +00:00
|
|
|
private View.OnFocusChangeListener mEditTextFocusListener = new View.OnFocusChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onFocusChange(View view, boolean b) {
|
|
|
|
EditText et = (EditText) view;
|
|
|
|
if (b) {
|
2018-02-17 06:09:21 +00:00
|
|
|
int resId = mUsernameMode ? R.string.username : R.string.account_settings_example_jabber_id;
|
|
|
|
if (view.getId() == R.id.hostname) {
|
2018-02-18 08:06:37 +00:00
|
|
|
resId = mUseTor ? R.string.hostname_or_onion : R.string.hostname_example;
|
|
|
|
}
|
|
|
|
final int res = resId;
|
|
|
|
new Handler().postDelayed(() -> et.setHint(res), 200);
|
|
|
|
} else {
|
|
|
|
et.setHint(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
private final OnClickListener mAvatarClickListener = new OnClickListener() {
|
2014-11-04 16:38:41 +00:00
|
|
|
@Override
|
2014-12-23 22:19:00 +00:00
|
|
|
public void onClick(final View view) {
|
|
|
|
if (mAccount != null) {
|
2015-10-09 11:37:08 +00:00
|
|
|
final Intent intent = new Intent(getApplicationContext(), PublishProfilePictureActivity.class);
|
2018-03-05 17:30:40 +00:00
|
|
|
intent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().asBareJid().toString());
|
2014-11-04 16:38:41 +00:00
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-08-15 15:31:24 +00:00
|
|
|
|
2014-08-16 07:44:37 +00:00
|
|
|
protected void finishInitialSetup(final Avatar avatar) {
|
2017-12-16 19:38:14 +00:00
|
|
|
runOnUiThread(() -> {
|
|
|
|
hideKeyboard();
|
|
|
|
final Intent intent;
|
|
|
|
final XmppConnection connection = mAccount.getXmppConnection();
|
|
|
|
final boolean wasFirstAccount = xmppConnectionService != null && xmppConnectionService.getAccounts().size() == 1;
|
|
|
|
if (avatar != null || (connection != null && !connection.getFeatures().pep())) {
|
|
|
|
intent = new Intent(getApplicationContext(), StartConversationActivity.class);
|
2016-04-27 08:35:08 +00:00
|
|
|
if (wasFirstAccount) {
|
2017-12-16 19:38:14 +00:00
|
|
|
intent.putExtra("init", true);
|
2016-04-27 08:35:08 +00:00
|
|
|
}
|
2017-12-16 19:38:14 +00:00
|
|
|
} else {
|
|
|
|
intent = new Intent(getApplicationContext(), PublishProfilePictureActivity.class);
|
2018-03-05 17:30:40 +00:00
|
|
|
intent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().asBareJid().toString());
|
2017-12-16 19:38:14 +00:00
|
|
|
intent.putExtra("setup", true);
|
2014-08-15 15:31:24 +00:00
|
|
|
}
|
2017-12-16 19:38:14 +00:00
|
|
|
if (wasFirstAccount) {
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
|
|
}
|
2018-02-14 15:55:45 +00:00
|
|
|
WelcomeActivity.addInviteUri(intent, getIntent());
|
2017-12-16 19:38:14 +00:00
|
|
|
startActivity(intent);
|
|
|
|
finish();
|
2014-08-15 15:31:24 +00:00
|
|
|
});
|
|
|
|
}
|
2014-08-19 13:06:50 +00:00
|
|
|
|
2016-01-11 10:17:45 +00:00
|
|
|
@Override
|
2016-11-28 14:11:44 +00:00
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
2016-01-11 10:17:45 +00:00
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
2016-11-07 09:49:43 +00:00
|
|
|
if (requestCode == REQUEST_BATTERY_OP || requestCode == REQUEST_DATA_SAVER) {
|
2016-01-11 10:17:45 +00:00
|
|
|
updateAccountInformation(mAccount == null);
|
|
|
|
}
|
2018-03-04 10:43:58 +00:00
|
|
|
if (requestCode == REQUEST_CHANGE_STATUS) {
|
|
|
|
PresenceTemplate template = mPendingPresenceTemplate.pop();
|
|
|
|
if (template != null && resultCode == Activity.RESULT_OK) {
|
|
|
|
generateSignature(data,template);
|
|
|
|
} else {
|
|
|
|
Log.d(Config.LOGTAG,"pgp result not ok");
|
|
|
|
}
|
|
|
|
}
|
2016-01-11 10:17:45 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 14:11:44 +00:00
|
|
|
@Override
|
|
|
|
protected void processFingerprintVerification(XmppUri uri) {
|
2018-02-18 08:06:37 +00:00
|
|
|
processFingerprintVerification(uri, true);
|
2017-12-15 17:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void processFingerprintVerification(XmppUri uri, boolean showWarningToast) {
|
2018-03-05 17:30:40 +00:00
|
|
|
if (mAccount != null && mAccount.getJid().asBareJid().equals(uri.getJid()) && uri.hasFingerprints()) {
|
2018-02-18 08:06:37 +00:00
|
|
|
if (xmppConnectionService.verifyFingerprints(mAccount, uri.getFingerprints())) {
|
|
|
|
Toast.makeText(this, R.string.verified_fingerprints, Toast.LENGTH_SHORT).show();
|
2016-11-28 14:11:44 +00:00
|
|
|
}
|
2017-12-15 17:25:21 +00:00
|
|
|
} else if (showWarningToast) {
|
2018-02-18 08:06:37 +00:00
|
|
|
Toast.makeText(this, R.string.invalid_barcode, Toast.LENGTH_SHORT).show();
|
2016-11-28 14:11:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-15 15:31:24 +00:00
|
|
|
protected void updateSaveButton() {
|
2016-04-26 21:23:48 +00:00
|
|
|
boolean accountInfoEdited = accountInfoEdited();
|
|
|
|
|
|
|
|
if (!mInitMode && passwordChangedInMagicCreateMode()) {
|
|
|
|
this.mSaveButton.setText(R.string.change_password);
|
|
|
|
this.mSaveButton.setEnabled(true);
|
|
|
|
} else if (accountInfoEdited && !mInitMode) {
|
2015-04-14 13:00:49 +00:00
|
|
|
this.mSaveButton.setText(R.string.save);
|
|
|
|
this.mSaveButton.setEnabled(true);
|
2016-04-09 22:19:20 +00:00
|
|
|
} else if (mAccount != null
|
2018-02-18 08:06:37 +00:00
|
|
|
&& (mAccount.getStatus() == Account.State.CONNECTING || mAccount.getStatus() == Account.State.REGISTRATION_SUCCESSFUL || mFetchingAvatar)) {
|
2014-08-15 15:31:24 +00:00
|
|
|
this.mSaveButton.setEnabled(false);
|
|
|
|
this.mSaveButton.setText(R.string.account_status_connecting);
|
2015-10-09 11:37:08 +00:00
|
|
|
} else if (mAccount != null && mAccount.getStatus() == Account.State.DISABLED && !mInitMode) {
|
2014-10-05 10:05:27 +00:00
|
|
|
this.mSaveButton.setEnabled(true);
|
|
|
|
this.mSaveButton.setText(R.string.enable);
|
2014-08-19 13:06:50 +00:00
|
|
|
} else {
|
2014-08-15 15:31:24 +00:00
|
|
|
this.mSaveButton.setEnabled(true);
|
2015-10-09 11:37:08 +00:00
|
|
|
if (!mInitMode) {
|
2014-12-23 22:19:00 +00:00
|
|
|
if (mAccount != null && mAccount.isOnlineAndConnected()) {
|
2014-08-29 08:24:25 +00:00
|
|
|
this.mSaveButton.setText(R.string.save);
|
2016-04-26 21:23:48 +00:00
|
|
|
if (!accountInfoEdited) {
|
2014-10-05 10:05:27 +00:00
|
|
|
this.mSaveButton.setEnabled(false);
|
|
|
|
}
|
2014-08-29 08:24:25 +00:00
|
|
|
} else {
|
2017-12-08 13:23:38 +00:00
|
|
|
XmppConnection connection = mAccount == null ? null : mAccount.getXmppConnection();
|
2018-02-18 08:06:37 +00:00
|
|
|
URL url = connection != null && mAccount.getStatus() == Account.State.PAYMENT_REQUIRED ? connection.getRedirectionUrl() : null;
|
2017-12-08 13:23:38 +00:00
|
|
|
if (url != null) {
|
|
|
|
this.mSaveButton.setText(R.string.open_website);
|
|
|
|
} else {
|
|
|
|
this.mSaveButton.setText(R.string.connect);
|
|
|
|
}
|
2014-08-29 08:24:25 +00:00
|
|
|
}
|
2014-08-16 07:44:37 +00:00
|
|
|
} else {
|
2017-06-19 18:02:41 +00:00
|
|
|
XmppConnection connection = mAccount == null ? null : mAccount.getXmppConnection();
|
2018-02-18 08:06:37 +00:00
|
|
|
URL url = connection != null && mAccount.getStatus() == Account.State.REGISTRATION_WEB ? connection.getRedirectionUrl() : null;
|
2018-03-13 10:54:34 +00:00
|
|
|
if (url != null && this.binding.accountRegisterNew.isChecked()) {
|
2017-06-19 18:02:41 +00:00
|
|
|
this.mSaveButton.setText(R.string.open_website);
|
|
|
|
} else {
|
|
|
|
this.mSaveButton.setText(R.string.next);
|
|
|
|
}
|
2014-08-16 07:44:37 +00:00
|
|
|
}
|
2014-08-15 15:31:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-05 10:05:27 +00:00
|
|
|
protected boolean accountInfoEdited() {
|
2015-08-03 20:58:17 +00:00
|
|
|
if (this.mAccount == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-26 21:23:48 +00:00
|
|
|
return jidEdited() ||
|
|
|
|
!this.mAccount.getPassword().equals(this.mPassword.getText().toString()) ||
|
|
|
|
!this.mAccount.getHostname().equals(this.mHostname.getText().toString()) ||
|
|
|
|
!String.valueOf(this.mAccount.getPort()).equals(this.mPort.getText().toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean jidEdited() {
|
2015-08-03 20:58:17 +00:00
|
|
|
final String unmodified;
|
2016-05-02 08:37:28 +00:00
|
|
|
if (mUsernameMode) {
|
2018-03-05 17:30:40 +00:00
|
|
|
unmodified = this.mAccount.getJid().getLocal();
|
2015-08-03 20:58:17 +00:00
|
|
|
} else {
|
2018-03-05 17:30:40 +00:00
|
|
|
unmodified = this.mAccount.getJid().asBareJid().toString();
|
2015-08-03 20:58:17 +00:00
|
|
|
}
|
2018-02-18 08:06:37 +00:00
|
|
|
return !unmodified.equals(this.binding.accountJid.getText().toString());
|
2016-04-26 21:23:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean passwordChangedInMagicCreateMode() {
|
|
|
|
return mAccount != null
|
|
|
|
&& mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE)
|
|
|
|
&& !this.mAccount.getPassword().equals(this.mPassword.getText().toString())
|
|
|
|
&& !this.jidEdited()
|
|
|
|
&& mAccount.isOnlineAndConnected();
|
2014-10-05 10:05:27 +00:00
|
|
|
}
|
|
|
|
|
2014-11-04 11:15:14 +00:00
|
|
|
@Override
|
2017-09-19 14:28:01 +00:00
|
|
|
protected String getShareableUri(boolean http) {
|
2015-10-11 13:48:58 +00:00
|
|
|
if (mAccount != null) {
|
2017-09-19 14:28:01 +00:00
|
|
|
return http ? mAccount.getShareableLink() : mAccount.getShareableUri();
|
2014-11-04 11:15:14 +00:00
|
|
|
} else {
|
2017-09-19 14:28:01 +00:00
|
|
|
return null;
|
2014-11-04 11:15:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-15 15:31:24 +00:00
|
|
|
@Override
|
2014-12-23 22:19:00 +00:00
|
|
|
protected void onCreate(final Bundle savedInstanceState) {
|
2014-08-15 15:31:24 +00:00
|
|
|
super.onCreate(savedInstanceState);
|
2016-08-26 07:10:59 +00:00
|
|
|
if (savedInstanceState != null) {
|
|
|
|
this.mSavedInstanceAccount = savedInstanceState.getString("account");
|
|
|
|
this.mSavedInstanceInit = savedInstanceState.getBoolean("initMode", false);
|
|
|
|
}
|
2018-02-18 08:06:37 +00:00
|
|
|
this.binding = DataBindingUtil.setContentView(this, R.layout.activity_edit_account);
|
2018-03-18 08:30:22 +00:00
|
|
|
setSupportActionBar((Toolbar) binding.toolbar);
|
|
|
|
configureActionBar(getSupportActionBar());
|
2018-02-18 08:06:37 +00:00
|
|
|
binding.accountJid.addTextChangedListener(this.mTextWatcher);
|
|
|
|
binding.accountJid.setOnFocusChangeListener(this.mEditTextFocusListener);
|
2018-02-18 03:20:02 +00:00
|
|
|
this.mAccountJidLayout = (TextInputLayout) findViewById(R.id.account_jid_layout);
|
2014-08-15 15:31:24 +00:00
|
|
|
this.mPassword = (EditText) findViewById(R.id.account_password);
|
2014-10-05 10:05:27 +00:00
|
|
|
this.mPassword.addTextChangedListener(this.mTextWatcher);
|
2018-02-18 03:20:02 +00:00
|
|
|
this.mPasswordLayout = (TextInputLayout) findViewById(R.id.account_password_layout);
|
2014-11-04 16:38:41 +00:00
|
|
|
this.mAvatar = (ImageView) findViewById(R.id.avater);
|
|
|
|
this.mAvatar.setOnClickListener(this.mAvatarClickListener);
|
2016-11-07 09:49:43 +00:00
|
|
|
this.mDisableOsOptimizationsButton = (Button) findViewById(R.id.os_optimization_disable);
|
|
|
|
this.getmDisableOsOptimizationsBody = (TextView) findViewById(R.id.os_optimization_body);
|
2017-05-04 11:02:46 +00:00
|
|
|
this.mPgpFingerprintBox = (RelativeLayout) findViewById(R.id.pgp_fingerprint_box);
|
|
|
|
this.mPgpFingerprint = (TextView) findViewById(R.id.pgp_fingerprint);
|
|
|
|
this.getmPgpFingerprintDesc = (TextView) findViewById(R.id.pgp_fingerprint_desc);
|
|
|
|
this.mPgpDeleteFingerprintButton = (ImageButton) findViewById(R.id.action_delete_pgp);
|
2015-07-07 17:36:22 +00:00
|
|
|
this.mAxolotlFingerprint = (TextView) findViewById(R.id.axolotl_fingerprint);
|
|
|
|
this.mAxolotlFingerprintBox = (RelativeLayout) findViewById(R.id.axolotl_fingerprint_box);
|
2015-07-10 04:08:44 +00:00
|
|
|
this.mAxolotlFingerprintToClipboardButton = (ImageButton) findViewById(R.id.action_copy_axolotl_to_clipboard);
|
2016-07-17 18:31:04 +00:00
|
|
|
this.mOwnFingerprintDesc = (TextView) findViewById(R.id.own_fingerprint_desc);
|
2015-07-19 12:09:49 +00:00
|
|
|
this.keys = (LinearLayout) findViewById(R.id.other_device_keys);
|
2015-11-28 19:11:38 +00:00
|
|
|
this.mNamePort = (LinearLayout) findViewById(R.id.name_port);
|
|
|
|
this.mHostname = (EditText) findViewById(R.id.hostname);
|
|
|
|
this.mHostname.addTextChangedListener(mTextWatcher);
|
2018-02-17 06:09:21 +00:00
|
|
|
this.mHostname.setOnFocusChangeListener(mEditTextFocusListener);
|
2018-02-18 08:06:37 +00:00
|
|
|
this.mHostnameLayout = (TextInputLayout) findViewById(R.id.hostname_layout);
|
2016-11-18 20:49:52 +00:00
|
|
|
this.mClearDevicesButton = (Button) findViewById(R.id.clear_devices);
|
2018-03-13 10:54:34 +00:00
|
|
|
this.mClearDevicesButton.setOnClickListener(v -> showWipePepDialog());
|
2015-11-28 19:11:38 +00:00
|
|
|
this.mPort = (EditText) findViewById(R.id.port);
|
|
|
|
this.mPort.setText("5222");
|
|
|
|
this.mPort.addTextChangedListener(mTextWatcher);
|
2018-02-18 08:06:37 +00:00
|
|
|
this.mPortLayout = (TextInputLayout) findViewById(R.id.port_layout);
|
2014-08-15 15:31:24 +00:00
|
|
|
this.mSaveButton = (Button) findViewById(R.id.save_button);
|
|
|
|
this.mCancelButton = (Button) findViewById(R.id.cancel_button);
|
|
|
|
this.mSaveButton.setOnClickListener(this.mSaveButtonClickListener);
|
|
|
|
this.mCancelButton.setOnClickListener(this.mCancelButtonClickListener);
|
2014-10-21 20:22:01 +00:00
|
|
|
this.mMoreTable = (TableLayout) findViewById(R.id.server_info_more);
|
2016-09-19 23:18:50 +00:00
|
|
|
if (savedInstanceState != null && savedInstanceState.getBoolean("showMoreTable")) {
|
|
|
|
changeMoreTableVisibility(true);
|
|
|
|
}
|
2014-12-23 22:19:00 +00:00
|
|
|
final OnCheckedChangeListener OnCheckedShowConfirmPassword = new OnCheckedChangeListener() {
|
|
|
|
@Override
|
2017-12-14 18:28:52 +00:00
|
|
|
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
|
2014-12-23 22:19:00 +00:00
|
|
|
updateSaveButton();
|
|
|
|
}
|
|
|
|
};
|
2018-03-13 10:54:34 +00:00
|
|
|
this.binding.accountRegisterNew.setOnCheckedChangeListener(OnCheckedShowConfirmPassword);
|
2015-08-03 20:58:17 +00:00
|
|
|
if (Config.DISALLOW_REGISTRATION_IN_UI) {
|
2018-03-13 10:54:34 +00:00
|
|
|
this.binding.accountRegisterNew.setVisibility(View.GONE);
|
2015-08-03 20:58:17 +00:00
|
|
|
}
|
2014-08-15 15:31:24 +00:00
|
|
|
}
|
|
|
|
|
2014-11-03 21:47:07 +00:00
|
|
|
@Override
|
2014-12-21 20:43:58 +00:00
|
|
|
public boolean onCreateOptionsMenu(final Menu menu) {
|
2014-11-03 21:47:07 +00:00
|
|
|
super.onCreateOptionsMenu(menu);
|
|
|
|
getMenuInflater().inflate(R.menu.editaccount, menu);
|
2014-12-21 20:43:58 +00:00
|
|
|
final MenuItem showBlocklist = menu.findItem(R.id.action_show_block_list);
|
2014-12-23 22:12:52 +00:00
|
|
|
final MenuItem showMoreInfo = menu.findItem(R.id.action_server_info_show_more);
|
2015-01-02 23:11:02 +00:00
|
|
|
final MenuItem changePassword = menu.findItem(R.id.action_change_password_on_server);
|
2015-10-11 13:48:58 +00:00
|
|
|
final MenuItem renewCertificate = menu.findItem(R.id.action_renew_certificate);
|
2016-02-09 12:01:17 +00:00
|
|
|
final MenuItem mamPrefs = menu.findItem(R.id.action_mam_prefs);
|
2016-04-22 19:25:06 +00:00
|
|
|
final MenuItem changePresence = menu.findItem(R.id.action_change_presence);
|
2016-12-01 12:07:18 +00:00
|
|
|
final MenuItem share = menu.findItem(R.id.action_share);
|
2015-10-11 13:48:58 +00:00
|
|
|
renewCertificate.setVisible(mAccount != null && mAccount.getPrivateKeyAlias() != null);
|
|
|
|
|
2016-12-01 12:07:18 +00:00
|
|
|
share.setVisible(mAccount != null && !mInitMode);
|
|
|
|
|
2015-02-27 16:03:13 +00:00
|
|
|
if (mAccount != null && mAccount.isOnlineAndConnected()) {
|
|
|
|
if (!mAccount.getXmppConnection().getFeatures().blocking()) {
|
|
|
|
showBlocklist.setVisible(false);
|
|
|
|
}
|
2017-03-04 19:31:41 +00:00
|
|
|
|
2015-02-27 16:03:13 +00:00
|
|
|
if (!mAccount.getXmppConnection().getFeatures().register()) {
|
|
|
|
changePassword.setVisible(false);
|
|
|
|
}
|
2016-02-09 12:01:17 +00:00
|
|
|
mamPrefs.setVisible(mAccount.getXmppConnection().getFeatures().mam());
|
2018-03-07 12:01:23 +00:00
|
|
|
changePresence.setVisible(!mInitMode);
|
2015-02-27 16:03:13 +00:00
|
|
|
} else {
|
2014-12-21 20:43:58 +00:00
|
|
|
showBlocklist.setVisible(false);
|
2014-12-23 22:12:52 +00:00
|
|
|
showMoreInfo.setVisible(false);
|
2015-01-02 23:11:02 +00:00
|
|
|
changePassword.setVisible(false);
|
2016-02-09 12:01:17 +00:00
|
|
|
mamPrefs.setVisible(false);
|
2016-04-23 10:33:56 +00:00
|
|
|
changePresence.setVisible(false);
|
2014-11-03 21:47:07 +00:00
|
|
|
}
|
2016-02-27 09:25:31 +00:00
|
|
|
return super.onCreateOptionsMenu(menu);
|
2014-11-03 21:47:07 +00:00
|
|
|
}
|
|
|
|
|
2016-09-19 23:18:50 +00:00
|
|
|
@Override
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
|
|
final MenuItem showMoreInfo = menu.findItem(R.id.action_server_info_show_more);
|
|
|
|
if (showMoreInfo.isVisible()) {
|
|
|
|
showMoreInfo.setChecked(mMoreTable.getVisibility() == View.VISIBLE);
|
|
|
|
}
|
|
|
|
return super.onPrepareOptionsMenu(menu);
|
|
|
|
}
|
|
|
|
|
2014-08-15 15:31:24 +00:00
|
|
|
@Override
|
|
|
|
protected void onStart() {
|
|
|
|
super.onStart();
|
2016-09-18 18:26:47 +00:00
|
|
|
final int theme = findTheme();
|
|
|
|
if (this.mTheme != theme) {
|
|
|
|
recreate();
|
|
|
|
} else if (getIntent() != null) {
|
2014-12-21 20:43:58 +00:00
|
|
|
try {
|
2018-03-05 17:30:40 +00:00
|
|
|
this.jidToEdit = Jid.of(getIntent().getStringExtra("jid"));
|
|
|
|
} catch (final IllegalArgumentException | NullPointerException ignored) {
|
2014-12-21 20:43:58 +00:00
|
|
|
this.jidToEdit = null;
|
|
|
|
}
|
2017-12-15 17:25:21 +00:00
|
|
|
if (jidToEdit != null && getIntent().getData() != null) {
|
|
|
|
final XmppUri uri = new XmppUri(getIntent().getData());
|
|
|
|
if (xmppConnectionServiceBound) {
|
|
|
|
processFingerprintVerification(uri, false);
|
|
|
|
} else {
|
|
|
|
this.pendingUri = uri;
|
|
|
|
}
|
|
|
|
}
|
2016-08-26 07:10:59 +00:00
|
|
|
boolean init = getIntent().getBooleanExtra("init", false);
|
|
|
|
this.mInitMode = init || this.jidToEdit == null;
|
2015-07-29 18:21:37 +00:00
|
|
|
this.messageFingerprint = getIntent().getStringExtra("fingerprint");
|
2015-10-09 11:37:08 +00:00
|
|
|
if (!mInitMode) {
|
2018-03-13 10:54:34 +00:00
|
|
|
this.binding.accountRegisterNew.setVisibility(View.GONE);
|
2018-02-16 11:30:46 +00:00
|
|
|
if (getSupportActionBar() != null) {
|
|
|
|
getSupportActionBar().setTitle(getString(R.string.account_details));
|
2014-12-21 20:43:58 +00:00
|
|
|
}
|
2014-08-15 15:31:24 +00:00
|
|
|
} else {
|
2014-11-04 16:38:41 +00:00
|
|
|
this.mAvatar.setVisibility(View.GONE);
|
2018-02-16 11:30:46 +00:00
|
|
|
ActionBar ab = getSupportActionBar();
|
2016-08-26 07:10:59 +00:00
|
|
|
if (ab != null) {
|
|
|
|
if (init && Config.MAGIC_CREATE_DOMAIN == null) {
|
|
|
|
ab.setDisplayShowHomeEnabled(false);
|
|
|
|
ab.setDisplayHomeAsUpEnabled(false);
|
|
|
|
}
|
|
|
|
ab.setTitle(R.string.action_add_account);
|
2014-12-21 20:43:58 +00:00
|
|
|
}
|
2014-08-15 15:31:24 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-25 20:17:53 +00:00
|
|
|
SharedPreferences preferences = getPreferences();
|
2018-02-18 08:06:37 +00:00
|
|
|
mUseTor = Config.FORCE_ORBOT || preferences.getBoolean("use_tor", false);
|
2018-02-17 06:09:21 +00:00
|
|
|
this.mShowOptions = mUseTor || preferences.getBoolean("show_connection_options", false);
|
2016-01-25 20:17:53 +00:00
|
|
|
this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE);
|
2014-08-15 15:31:24 +00:00
|
|
|
}
|
2014-08-23 19:31:27 +00:00
|
|
|
|
2017-12-15 17:25:21 +00:00
|
|
|
@Override
|
|
|
|
public void onNewIntent(Intent intent) {
|
|
|
|
if (intent != null && intent.getData() != null) {
|
|
|
|
final XmppUri uri = new XmppUri(intent.getData());
|
|
|
|
if (xmppConnectionServiceBound) {
|
|
|
|
processFingerprintVerification(uri, false);
|
|
|
|
} else {
|
|
|
|
this.pendingUri = uri;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-26 07:10:59 +00:00
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState(final Bundle savedInstanceState) {
|
|
|
|
if (mAccount != null) {
|
2018-03-05 17:30:40 +00:00
|
|
|
savedInstanceState.putString("account", mAccount.getJid().asBareJid().toString());
|
2016-08-26 07:10:59 +00:00
|
|
|
savedInstanceState.putBoolean("initMode", mInitMode);
|
2016-09-19 23:18:50 +00:00
|
|
|
savedInstanceState.putBoolean("showMoreTable", mMoreTable.getVisibility() == View.VISIBLE);
|
2016-08-26 07:10:59 +00:00
|
|
|
}
|
|
|
|
super.onSaveInstanceState(savedInstanceState);
|
|
|
|
}
|
|
|
|
|
2014-08-15 15:31:24 +00:00
|
|
|
protected void onBackendConnected() {
|
2016-08-26 19:48:14 +00:00
|
|
|
boolean init = true;
|
2016-08-26 07:10:59 +00:00
|
|
|
if (mSavedInstanceAccount != null) {
|
|
|
|
try {
|
2018-03-05 17:30:40 +00:00
|
|
|
this.mAccount = xmppConnectionService.findAccountByJid(Jid.of(mSavedInstanceAccount));
|
2016-08-26 07:10:59 +00:00
|
|
|
this.mInitMode = mSavedInstanceInit;
|
2016-08-26 19:48:14 +00:00
|
|
|
init = false;
|
2018-03-05 17:30:40 +00:00
|
|
|
} catch (IllegalArgumentException e) {
|
2016-08-26 07:10:59 +00:00
|
|
|
this.mAccount = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (this.jidToEdit != null) {
|
2014-08-15 15:31:24 +00:00
|
|
|
this.mAccount = xmppConnectionService.findAccountByJid(jidToEdit);
|
2016-08-26 07:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mAccount != null) {
|
|
|
|
this.mInitMode |= this.mAccount.isOptionSet(Account.OPTION_REGISTER);
|
|
|
|
this.mUsernameMode |= mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE) && mAccount.isOptionSet(Account.OPTION_REGISTER);
|
|
|
|
if (this.mAccount.getPrivateKeyAlias() != null) {
|
|
|
|
this.mPassword.setHint(R.string.authenticate_with_certificate);
|
|
|
|
if (this.mInitMode) {
|
|
|
|
this.mPassword.requestFocus();
|
2015-10-09 11:37:08 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-28 14:11:44 +00:00
|
|
|
if (mPendingFingerprintVerificationUri != null) {
|
2017-12-15 17:25:21 +00:00
|
|
|
processFingerprintVerification(mPendingFingerprintVerificationUri, false);
|
2016-11-28 14:11:44 +00:00
|
|
|
mPendingFingerprintVerificationUri = null;
|
|
|
|
}
|
2016-08-26 19:48:14 +00:00
|
|
|
updateAccountInformation(init);
|
2016-04-19 16:03:24 +00:00
|
|
|
}
|
2016-08-26 07:10:59 +00:00
|
|
|
|
|
|
|
|
2016-07-21 17:16:41 +00:00
|
|
|
if (Config.MAGIC_CREATE_DOMAIN == null && this.xmppConnectionService.getAccounts().size() == 0) {
|
2014-08-15 15:31:24 +00:00
|
|
|
this.mCancelButton.setEnabled(false);
|
|
|
|
}
|
2016-05-02 08:37:28 +00:00
|
|
|
if (mUsernameMode) {
|
2018-02-18 08:06:37 +00:00
|
|
|
this.binding.accountJid.setHint(R.string.username_hint);
|
2016-05-02 08:37:28 +00:00
|
|
|
} else {
|
2015-08-03 20:58:17 +00:00
|
|
|
final KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this,
|
2016-04-29 11:48:30 +00:00
|
|
|
R.layout.simple_list_item,
|
2015-08-03 20:58:17 +00:00
|
|
|
xmppConnectionService.getKnownHosts());
|
2018-02-18 08:06:37 +00:00
|
|
|
this.binding.accountJid.setAdapter(mKnownHostsAdapter);
|
2015-08-03 20:58:17 +00:00
|
|
|
}
|
2017-12-15 17:25:21 +00:00
|
|
|
|
|
|
|
if (pendingUri != null) {
|
|
|
|
processFingerprintVerification(pendingUri, false);
|
|
|
|
pendingUri = null;
|
|
|
|
}
|
|
|
|
|
2014-08-15 15:31:24 +00:00
|
|
|
updateSaveButton();
|
2015-10-25 21:46:06 +00:00
|
|
|
invalidateOptionsMenu();
|
2014-08-15 15:31:24 +00:00
|
|
|
}
|
|
|
|
|
2016-05-02 08:37:28 +00:00
|
|
|
private String getUserModeDomain() {
|
|
|
|
if (mAccount != null) {
|
2018-03-05 17:30:40 +00:00
|
|
|
return mAccount.getJid().getDomain();
|
2016-05-02 08:37:28 +00:00
|
|
|
} else {
|
|
|
|
return Config.DOMAIN_LOCK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-21 20:43:58 +00:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.action_show_block_list:
|
2015-01-02 23:11:02 +00:00
|
|
|
final Intent showBlocklistIntent = new Intent(this, BlocklistActivity.class);
|
2016-01-22 19:46:24 +00:00
|
|
|
showBlocklistIntent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toString());
|
2015-01-02 23:11:02 +00:00
|
|
|
startActivity(showBlocklistIntent);
|
2014-12-21 20:43:58 +00:00
|
|
|
break;
|
2014-10-21 20:22:01 +00:00
|
|
|
case R.id.action_server_info_show_more:
|
2016-09-19 23:18:50 +00:00
|
|
|
changeMoreTableVisibility(!item.isChecked());
|
2015-01-02 23:11:02 +00:00
|
|
|
break;
|
2016-11-22 21:31:46 +00:00
|
|
|
case R.id.action_share_barcode:
|
|
|
|
shareBarcode();
|
|
|
|
break;
|
|
|
|
case R.id.action_share_http:
|
|
|
|
shareLink(true);
|
|
|
|
break;
|
|
|
|
case R.id.action_share_uri:
|
|
|
|
shareLink(false);
|
|
|
|
break;
|
2015-01-02 23:11:02 +00:00
|
|
|
case R.id.action_change_password_on_server:
|
2016-04-26 21:23:48 +00:00
|
|
|
gotoChangePassword(null);
|
2015-01-02 23:11:02 +00:00
|
|
|
break;
|
2016-02-09 12:01:17 +00:00
|
|
|
case R.id.action_mam_prefs:
|
|
|
|
editMamPrefs();
|
|
|
|
break;
|
2015-10-11 13:48:58 +00:00
|
|
|
case R.id.action_renew_certificate:
|
|
|
|
renewCertificate();
|
|
|
|
break;
|
2016-04-22 19:25:06 +00:00
|
|
|
case R.id.action_change_presence:
|
|
|
|
changePresence();
|
|
|
|
break;
|
2014-12-21 20:43:58 +00:00
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
2016-11-22 21:31:46 +00:00
|
|
|
private void shareBarcode() {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
2018-02-18 08:06:37 +00:00
|
|
|
intent.putExtra(Intent.EXTRA_STREAM, BarcodeProvider.getUriForAccount(this, mAccount));
|
2016-11-22 21:31:46 +00:00
|
|
|
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
|
intent.setType("image/png");
|
|
|
|
startActivity(Intent.createChooser(intent, getText(R.string.share_with)));
|
|
|
|
}
|
|
|
|
|
2016-09-19 23:18:50 +00:00
|
|
|
private void changeMoreTableVisibility(boolean visible) {
|
|
|
|
mMoreTable.setVisibility(visible ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
|
|
|
|
2016-04-26 21:23:48 +00:00
|
|
|
private void gotoChangePassword(String newPassword) {
|
|
|
|
final Intent changePasswordIntent = new Intent(this, ChangePasswordActivity.class);
|
|
|
|
changePasswordIntent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toString());
|
|
|
|
if (newPassword != null) {
|
|
|
|
changePasswordIntent.putExtra("password", newPassword);
|
|
|
|
}
|
|
|
|
startActivity(changePasswordIntent);
|
|
|
|
}
|
|
|
|
|
2015-10-11 13:48:58 +00:00
|
|
|
private void renewCertificate() {
|
|
|
|
KeyChain.choosePrivateKeyAlias(this, this, null, null, null, -1, null);
|
|
|
|
}
|
|
|
|
|
2016-04-22 19:25:06 +00:00
|
|
|
private void changePresence() {
|
2018-03-03 11:27:46 +00:00
|
|
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
boolean manualStatus = sharedPreferences.getBoolean(SettingsActivity.MANUALLY_CHANGE_PRESENCE, getResources().getBoolean(R.bool.manually_change_presence));
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
final DialogPresenceBinding binding = DataBindingUtil.inflate(getLayoutInflater(),R.layout.dialog_presence,null,false);
|
2018-03-04 10:43:58 +00:00
|
|
|
String current = mAccount.getPresenceStatusMessage();
|
|
|
|
if (current != null && !current.trim().isEmpty()) {
|
|
|
|
binding.statusMessage.append(current);
|
|
|
|
}
|
|
|
|
setAvailabilityRadioButton(mAccount.getPresenceStatus(),binding);
|
2018-03-03 11:27:46 +00:00
|
|
|
binding.show.setVisibility(manualStatus ? View.VISIBLE : View.GONE);
|
|
|
|
List<PresenceTemplate> templates = xmppConnectionService.getPresenceTemplates(mAccount);
|
|
|
|
PresenceTemplateAdapter presenceTemplateAdapter = new PresenceTemplateAdapter(this,R.layout.simple_list_item,templates);
|
|
|
|
binding.statusMessage.setAdapter(presenceTemplateAdapter);
|
|
|
|
binding.statusMessage.setOnItemClickListener((parent, view, position, id) -> {
|
|
|
|
PresenceTemplate template = (PresenceTemplate) parent.getItemAtPosition(position);
|
2018-03-04 10:43:58 +00:00
|
|
|
setAvailabilityRadioButton(template.getStatus(), binding);
|
2018-03-03 11:27:46 +00:00
|
|
|
});
|
2018-03-04 10:43:58 +00:00
|
|
|
builder.setTitle(R.string.edit_status_message_title);
|
2018-03-03 11:27:46 +00:00
|
|
|
builder.setView(binding.getRoot());
|
|
|
|
builder.setNegativeButton(R.string.cancel,null);
|
2018-03-04 10:43:58 +00:00
|
|
|
builder.setPositiveButton(R.string.confirm, (dialog, which) -> {
|
|
|
|
PresenceTemplate template = new PresenceTemplate(getAvailabilityRadioButton(binding),binding.statusMessage.getText().toString().trim());
|
|
|
|
if (mAccount.getPgpId() != 0 && hasPgp()) {
|
|
|
|
generateSignature(null, template);
|
|
|
|
} else {
|
|
|
|
xmppConnectionService.changeStatus(mAccount, template, null);
|
|
|
|
}
|
|
|
|
});
|
2018-03-03 11:27:46 +00:00
|
|
|
builder.create().show();
|
2016-04-22 19:25:06 +00:00
|
|
|
}
|
|
|
|
|
2018-03-04 10:43:58 +00:00
|
|
|
private void generateSignature(Intent intent, PresenceTemplate template) {
|
|
|
|
xmppConnectionService.getPgpEngine().generateSignature(intent, mAccount, template.getStatusMessage(), new UiCallback<String>() {
|
|
|
|
@Override
|
|
|
|
public void success(String signature) {
|
|
|
|
xmppConnectionService.changeStatus(mAccount,template,signature);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void error(int errorCode, String object) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void userInputRequried(PendingIntent pi, String object) {
|
|
|
|
mPendingPresenceTemplate.push(template);
|
|
|
|
try {
|
|
|
|
startIntentSenderForResult(pi.getIntentSender(), REQUEST_CHANGE_STATUS, null, 0, 0, 0);
|
|
|
|
} catch (final IntentSender.SendIntentException ignored) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void setAvailabilityRadioButton(Presence.Status status, DialogPresenceBinding binding) {
|
|
|
|
if (status == null) {
|
|
|
|
binding.online.setChecked(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (status) {
|
|
|
|
case DND:
|
|
|
|
binding.dnd.setChecked(true);
|
|
|
|
break;
|
|
|
|
case XA:
|
|
|
|
binding.xa.setChecked(true);
|
|
|
|
break;
|
|
|
|
case AWAY:
|
|
|
|
binding.xa.setChecked(true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
binding.online.setChecked(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static Presence.Status getAvailabilityRadioButton(DialogPresenceBinding binding) {
|
|
|
|
if (binding.dnd.isChecked()) {
|
|
|
|
return Presence.Status.DND;
|
|
|
|
} else if (binding.xa.isChecked()) {
|
|
|
|
return Presence.Status.XA;
|
|
|
|
} else if (binding.away.isChecked()) {
|
|
|
|
return Presence.Status.AWAY;
|
|
|
|
} else {
|
|
|
|
return Presence.Status.ONLINE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-11 13:48:58 +00:00
|
|
|
@Override
|
|
|
|
public void alias(String alias) {
|
|
|
|
if (alias != null) {
|
|
|
|
xmppConnectionService.updateKeyInAccount(mAccount, alias);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-16 11:42:52 +00:00
|
|
|
private void updateAccountInformation(boolean init) {
|
|
|
|
if (init) {
|
2018-02-18 08:06:37 +00:00
|
|
|
this.binding.accountJid.getEditableText().clear();
|
2016-05-02 08:37:28 +00:00
|
|
|
if (mUsernameMode) {
|
2018-03-05 17:30:40 +00:00
|
|
|
this.binding.accountJid.getEditableText().append(this.mAccount.getJid().getLocal());
|
2015-08-03 20:58:17 +00:00
|
|
|
} else {
|
2018-03-05 17:30:40 +00:00
|
|
|
this.binding.accountJid.getEditableText().append(this.mAccount.getJid().asBareJid().toString());
|
2015-08-03 20:58:17 +00:00
|
|
|
}
|
2017-08-10 12:13:07 +00:00
|
|
|
this.mPassword.getEditableText().clear();
|
|
|
|
this.mPassword.getEditableText().append(this.mAccount.getPassword());
|
2015-11-28 19:11:38 +00:00
|
|
|
this.mHostname.setText("");
|
|
|
|
this.mHostname.getEditableText().append(this.mAccount.getHostname());
|
|
|
|
this.mPort.setText("");
|
|
|
|
this.mPort.getEditableText().append(String.valueOf(this.mAccount.getPort()));
|
2016-01-25 20:17:53 +00:00
|
|
|
this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE);
|
2015-11-28 19:11:38 +00:00
|
|
|
|
2015-07-16 11:42:52 +00:00
|
|
|
}
|
2016-02-27 09:25:31 +00:00
|
|
|
|
2017-08-10 12:13:07 +00:00
|
|
|
final boolean editable = !mAccount.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY);
|
2018-02-18 08:06:37 +00:00
|
|
|
this.binding.accountJid.setEnabled(editable);
|
|
|
|
this.binding.accountJid.setFocusable(editable);
|
|
|
|
this.binding.accountJid.setFocusableInTouchMode(editable);
|
2018-03-04 12:59:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE) || !mAccount.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY)) {
|
|
|
|
this.binding.accountPasswordLayout.setPasswordVisibilityToggleEnabled(true);
|
2018-01-10 15:57:54 +00:00
|
|
|
} else {
|
2018-03-04 12:59:36 +00:00
|
|
|
this.binding.accountPasswordLayout.setPasswordVisibilityToggleEnabled(false);
|
2018-01-10 15:57:54 +00:00
|
|
|
}
|
2017-08-10 12:13:07 +00:00
|
|
|
|
2015-10-09 11:37:08 +00:00
|
|
|
if (!mInitMode) {
|
2014-11-06 15:51:50 +00:00
|
|
|
this.mAvatar.setVisibility(View.VISIBLE);
|
|
|
|
this.mAvatar.setImageBitmap(avatarService().get(this.mAccount, getPixel(72)));
|
2016-04-09 22:19:20 +00:00
|
|
|
} else {
|
|
|
|
this.mAvatar.setVisibility(View.GONE);
|
2014-11-06 15:51:50 +00:00
|
|
|
}
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.accountRegisterNew.setChecked(this.mAccount.isOptionSet(Account.OPTION_REGISTER));
|
|
|
|
if (this.mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE)) {
|
|
|
|
if (this.mAccount.isOptionSet(Account.OPTION_REGISTER)) {
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
if (actionBar != null) {
|
|
|
|
actionBar.setTitle(R.string.create_account);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.binding.accountRegisterNew.setVisibility(View.GONE);
|
2018-03-13 10:54:34 +00:00
|
|
|
} else if (this.mAccount.isOptionSet(Account.OPTION_REGISTER)) {
|
|
|
|
this.binding.accountRegisterNew.setVisibility(View.VISIBLE);
|
2014-08-15 15:31:24 +00:00
|
|
|
} else {
|
2018-03-13 10:54:34 +00:00
|
|
|
this.binding.accountRegisterNew.setVisibility(View.GONE);
|
2014-08-15 15:31:24 +00:00
|
|
|
}
|
2014-12-25 21:28:19 +00:00
|
|
|
if (this.mAccount.isOnlineAndConnected() && !this.mFetchingAvatar) {
|
2016-03-06 14:53:49 +00:00
|
|
|
Features features = this.mAccount.getXmppConnection().getFeatures();
|
2018-02-18 08:06:37 +00:00
|
|
|
this.binding.stats.setVisibility(View.VISIBLE);
|
2017-11-12 18:22:39 +00:00
|
|
|
boolean showBatteryWarning = !xmppConnectionService.getPushManagementService().available(mAccount) && isOptimizingBattery();
|
2016-11-07 09:49:43 +00:00
|
|
|
boolean showDataSaverWarning = isAffectedByDataSaver();
|
2018-02-18 08:06:37 +00:00
|
|
|
showOsOptimizationWarning(showBatteryWarning, showDataSaverWarning);
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.sessionEst.setText(UIHelper.readableTimeDifferenceFull(this, this.mAccount.getXmppConnection()
|
2015-10-11 13:48:58 +00:00
|
|
|
.getLastSessionEstablished()));
|
2014-10-21 20:22:01 +00:00
|
|
|
if (features.rosterVersioning()) {
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.serverInfoRosterVersion.setText(R.string.server_info_available);
|
2014-10-21 20:22:01 +00:00
|
|
|
} else {
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.serverInfoRosterVersion.setText(R.string.server_info_unavailable);
|
2014-10-21 20:22:01 +00:00
|
|
|
}
|
2014-08-23 13:56:30 +00:00
|
|
|
if (features.carbons()) {
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.serverInfoCarbons.setText(R.string.server_info_available);
|
2014-08-23 13:56:30 +00:00
|
|
|
} else {
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.serverInfoCarbons.setText(R.string.server_info_unavailable);
|
2014-08-23 13:56:30 +00:00
|
|
|
}
|
2014-10-21 20:22:01 +00:00
|
|
|
if (features.mam()) {
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.serverInfoMam.setText(R.string.server_info_available);
|
2014-10-21 20:22:01 +00:00
|
|
|
} else {
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.serverInfoMam.setText(R.string.server_info_unavailable);
|
2014-10-21 20:22:01 +00:00
|
|
|
}
|
|
|
|
if (features.csi()) {
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.serverInfoCsi.setText(R.string.server_info_available);
|
2014-10-21 20:22:01 +00:00
|
|
|
} else {
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.serverInfoCsi.setText(R.string.server_info_unavailable);
|
2014-10-21 20:22:01 +00:00
|
|
|
}
|
|
|
|
if (features.blocking()) {
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.serverInfoBlocking.setText(R.string.server_info_available);
|
2014-10-21 20:22:01 +00:00
|
|
|
} else {
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.serverInfoBlocking.setText(R.string.server_info_unavailable);
|
2014-10-21 20:22:01 +00:00
|
|
|
}
|
2014-08-23 13:56:30 +00:00
|
|
|
if (features.sm()) {
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.serverInfoSm.setText(R.string.server_info_available);
|
2014-08-23 13:56:30 +00:00
|
|
|
} else {
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.serverInfoSm.setText(R.string.server_info_unavailable);
|
2014-08-23 13:56:30 +00:00
|
|
|
}
|
2017-09-09 11:34:44 +00:00
|
|
|
if (features.pep()) {
|
2015-09-06 17:40:28 +00:00
|
|
|
AxolotlService axolotlService = this.mAccount.getAxolotlService();
|
|
|
|
if (axolotlService != null && axolotlService.isPepBroken()) {
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.serverInfoPep.setText(R.string.server_info_broken);
|
2017-12-18 12:47:53 +00:00
|
|
|
} else if (features.pepPublishOptions() || features.pepOmemoWhitelisted()) {
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.serverInfoPep.setText(R.string.server_info_available);
|
2017-09-09 11:34:44 +00:00
|
|
|
} else {
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.serverInfoPep.setText(R.string.server_info_partial);
|
2015-09-06 17:40:28 +00:00
|
|
|
}
|
2014-08-23 13:56:30 +00:00
|
|
|
} else {
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.serverInfoPep.setText(R.string.server_info_unavailable);
|
2014-08-23 13:56:30 +00:00
|
|
|
}
|
2016-03-31 19:56:59 +00:00
|
|
|
if (features.httpUpload(0)) {
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.serverInfoHttpUpload.setText(R.string.server_info_available);
|
2015-08-14 20:24:05 +00:00
|
|
|
} else {
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.serverInfoHttpUpload.setText(R.string.server_info_unavailable);
|
2015-08-14 20:24:05 +00:00
|
|
|
}
|
2016-02-12 10:39:27 +00:00
|
|
|
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.pushRow.setVisibility(xmppConnectionService.getPushManagementService().isStub() ? View.GONE : View.VISIBLE);
|
2016-02-12 10:39:27 +00:00
|
|
|
|
2016-02-14 17:19:11 +00:00
|
|
|
if (xmppConnectionService.getPushManagementService().available(mAccount)) {
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.serverInfoPush.setText(R.string.server_info_available);
|
2016-02-12 10:39:27 +00:00
|
|
|
} else {
|
2018-03-08 14:18:44 +00:00
|
|
|
this.binding.serverInfoPush.setText(R.string.server_info_unavailable);
|
2016-02-12 10:39:27 +00:00
|
|
|
}
|
2017-05-04 11:02:46 +00:00
|
|
|
final long pgpKeyId = this.mAccount.getPgpId();
|
|
|
|
if (pgpKeyId != 0 && Config.supportOpenPgp()) {
|
2018-02-18 08:06:37 +00:00
|
|
|
OnClickListener openPgp = view -> launchOpenKeyChain(pgpKeyId);
|
|
|
|
OnClickListener delete = view -> showDeletePgpDialog();
|
2017-05-04 11:02:46 +00:00
|
|
|
this.mPgpFingerprintBox.setVisibility(View.VISIBLE);
|
|
|
|
this.mPgpFingerprint.setText(OpenPgpUtils.convertKeyIdToHex(pgpKeyId));
|
|
|
|
this.mPgpFingerprint.setOnClickListener(openPgp);
|
|
|
|
if ("pgp".equals(messageFingerprint)) {
|
2018-03-01 18:44:08 +00:00
|
|
|
this.getmPgpFingerprintDesc.setTextAppearance(this,R.style.TextAppearance_Conversations_Caption_Highlight);
|
2017-05-04 11:02:46 +00:00
|
|
|
}
|
|
|
|
this.getmPgpFingerprintDesc.setOnClickListener(openPgp);
|
|
|
|
this.mPgpDeleteFingerprintButton.setOnClickListener(delete);
|
|
|
|
} else {
|
|
|
|
this.mPgpFingerprintBox.setVisibility(View.GONE);
|
|
|
|
}
|
2016-05-25 20:12:13 +00:00
|
|
|
final String ownAxolotlFingerprint = this.mAccount.getAxolotlService().getOwnFingerprint();
|
|
|
|
if (ownAxolotlFingerprint != null && Config.supportOmemo()) {
|
2015-07-07 17:36:22 +00:00
|
|
|
this.mAxolotlFingerprintBox.setVisibility(View.VISIBLE);
|
2016-07-17 18:31:04 +00:00
|
|
|
if (ownAxolotlFingerprint.equals(messageFingerprint)) {
|
2018-03-01 18:44:08 +00:00
|
|
|
this.mOwnFingerprintDesc.setTextAppearance(this,R.style.TextAppearance_Conversations_Caption_Highlight);
|
2017-08-28 16:15:39 +00:00
|
|
|
this.mOwnFingerprintDesc.setText(R.string.omemo_fingerprint_selected_message);
|
2016-07-17 18:31:04 +00:00
|
|
|
} else {
|
2018-03-01 18:44:08 +00:00
|
|
|
this.mOwnFingerprintDesc.setTextAppearance(this,R.style.TextAppearance_Conversations_Caption);
|
2017-08-28 16:15:39 +00:00
|
|
|
this.mOwnFingerprintDesc.setText(R.string.omemo_fingerprint);
|
2016-07-17 18:31:04 +00:00
|
|
|
}
|
2016-05-25 20:12:13 +00:00
|
|
|
this.mAxolotlFingerprint.setText(CryptoHelper.prettifyFingerprint(ownAxolotlFingerprint.substring(2)));
|
2018-02-18 08:06:37 +00:00
|
|
|
this.mAxolotlFingerprintToClipboardButton.setVisibility(View.VISIBLE);
|
|
|
|
this.mAxolotlFingerprintToClipboardButton.setOnClickListener(v -> copyOmemoFingerprint(ownAxolotlFingerprint));
|
2015-07-07 17:36:22 +00:00
|
|
|
} else {
|
|
|
|
this.mAxolotlFingerprintBox.setVisibility(View.GONE);
|
|
|
|
}
|
2015-07-19 12:09:49 +00:00
|
|
|
boolean hasKeys = false;
|
|
|
|
keys.removeAllViews();
|
2018-02-18 08:06:37 +00:00
|
|
|
for (XmppAxolotlSession session : mAccount.getAxolotlService().findOwnSessions()) {
|
2016-11-18 20:49:52 +00:00
|
|
|
if (!session.getTrust().isCompromised()) {
|
|
|
|
boolean highlight = session.getFingerprint().equals(messageFingerprint);
|
2018-02-18 08:06:37 +00:00
|
|
|
addFingerprintRow(keys, session, highlight);
|
2016-11-18 20:49:52 +00:00
|
|
|
hasKeys = true;
|
2015-07-19 12:09:49 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-25 20:12:13 +00:00
|
|
|
if (hasKeys && Config.supportOmemo()) {
|
2018-02-18 08:06:37 +00:00
|
|
|
this.binding.otherDeviceKeysCard.setVisibility(View.VISIBLE);
|
2016-11-18 20:49:52 +00:00
|
|
|
Set<Integer> otherDevices = mAccount.getAxolotlService().getOwnDeviceIds();
|
|
|
|
if (otherDevices == null || otherDevices.isEmpty()) {
|
|
|
|
mClearDevicesButton.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
mClearDevicesButton.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2015-07-19 12:09:49 +00:00
|
|
|
} else {
|
2018-02-18 08:06:37 +00:00
|
|
|
this.binding.otherDeviceKeysCard.setVisibility(View.GONE);
|
2015-07-19 12:09:49 +00:00
|
|
|
}
|
2014-08-19 13:06:50 +00:00
|
|
|
} else {
|
2018-02-18 07:33:33 +00:00
|
|
|
final TextInputLayout errorLayout;
|
2014-08-19 13:06:50 +00:00
|
|
|
if (this.mAccount.errorStatus()) {
|
2016-01-25 20:17:53 +00:00
|
|
|
if (this.mAccount.getStatus() == Account.State.UNAUTHORIZED) {
|
2018-02-18 03:20:02 +00:00
|
|
|
errorLayout = this.mPasswordLayout;
|
2016-01-25 20:17:53 +00:00
|
|
|
} else if (mShowOptions
|
|
|
|
&& this.mAccount.getStatus() == Account.State.SERVER_NOT_FOUND
|
|
|
|
&& this.mHostname.getText().length() > 0) {
|
2018-02-18 03:20:02 +00:00
|
|
|
errorLayout = this.mHostnameLayout;
|
2016-01-25 20:17:53 +00:00
|
|
|
} else {
|
2018-02-18 03:20:02 +00:00
|
|
|
errorLayout = this.mAccountJidLayout;
|
2016-01-25 20:17:53 +00:00
|
|
|
}
|
2018-02-18 03:20:02 +00:00
|
|
|
errorLayout.setError(getString(this.mAccount.getStatus().getReadableId()));
|
2015-07-17 11:14:24 +00:00
|
|
|
if (init || !accountInfoEdited()) {
|
2018-02-18 03:20:02 +00:00
|
|
|
errorLayout.requestFocus();
|
2015-07-16 12:06:54 +00:00
|
|
|
}
|
2015-02-26 16:17:40 +00:00
|
|
|
} else {
|
2018-02-18 07:33:33 +00:00
|
|
|
errorLayout = null;
|
2014-08-19 13:06:50 +00:00
|
|
|
}
|
2018-02-18 07:33:33 +00:00
|
|
|
removeErrorsOnAllBut(errorLayout);
|
2018-02-18 08:06:37 +00:00
|
|
|
this.binding.stats.setVisibility(View.GONE);
|
|
|
|
this.binding.otherDeviceKeysCard.setVisibility(View.GONE);
|
2014-08-19 13:06:50 +00:00
|
|
|
}
|
2014-08-15 15:31:24 +00:00
|
|
|
}
|
2015-07-07 17:36:22 +00:00
|
|
|
|
2018-02-18 07:33:33 +00:00
|
|
|
private void removeErrorsOnAllBut(TextInputLayout exception) {
|
2018-02-18 08:06:37 +00:00
|
|
|
if (this.mAccountJidLayout != exception) {
|
2018-02-18 07:33:33 +00:00
|
|
|
this.mAccountJidLayout.setErrorEnabled(false);
|
|
|
|
this.mAccountJidLayout.setError(null);
|
|
|
|
}
|
|
|
|
if (this.mPasswordLayout != exception) {
|
|
|
|
this.mPasswordLayout.setErrorEnabled(false);
|
|
|
|
this.mPasswordLayout.setError(null);
|
|
|
|
}
|
|
|
|
if (this.mHostnameLayout != exception) {
|
|
|
|
this.mHostnameLayout.setErrorEnabled(false);
|
|
|
|
this.mHostnameLayout.setError(null);
|
|
|
|
}
|
|
|
|
if (this.mPortLayout != exception) {
|
|
|
|
this.mPortLayout.setErrorEnabled(false);
|
|
|
|
this.mPortLayout.setError(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-04 11:02:46 +00:00
|
|
|
private void showDeletePgpDialog() {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setTitle(R.string.unpublish_pgp);
|
|
|
|
builder.setMessage(R.string.unpublish_pgp_message);
|
2018-02-18 08:06:37 +00:00
|
|
|
builder.setNegativeButton(R.string.cancel, null);
|
|
|
|
builder.setPositiveButton(R.string.confirm, (dialogInterface, i) -> {
|
|
|
|
mAccount.setPgpSignId(0);
|
|
|
|
mAccount.unsetPgpSignature();
|
|
|
|
xmppConnectionService.databaseBackend.updateAccount(mAccount);
|
|
|
|
xmppConnectionService.sendPresence(mAccount);
|
|
|
|
refreshUiReal();
|
2017-05-04 11:02:46 +00:00
|
|
|
});
|
|
|
|
builder.create().show();
|
|
|
|
}
|
|
|
|
|
2016-11-07 09:49:43 +00:00
|
|
|
private void showOsOptimizationWarning(boolean showBatteryWarning, boolean showDataSaverWarning) {
|
2018-02-18 08:06:37 +00:00
|
|
|
this.binding.osOptimization.setVisibility(showBatteryWarning || showDataSaverWarning ? View.VISIBLE : View.GONE);
|
2016-11-07 09:49:43 +00:00
|
|
|
if (showDataSaverWarning) {
|
2018-02-18 08:06:37 +00:00
|
|
|
this.binding.osOptimizationHeadline.setText(R.string.data_saver_enabled);
|
2016-11-07 09:49:43 +00:00
|
|
|
this.getmDisableOsOptimizationsBody.setText(R.string.data_saver_enabled_explained);
|
|
|
|
this.mDisableOsOptimizationsButton.setText(R.string.allow);
|
2018-02-18 08:06:37 +00:00
|
|
|
this.mDisableOsOptimizationsButton.setOnClickListener(v -> {
|
|
|
|
Intent intent = new Intent(Settings.ACTION_IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS);
|
|
|
|
Uri uri = Uri.parse("package:" + getPackageName());
|
|
|
|
intent.setData(uri);
|
|
|
|
try {
|
|
|
|
startActivityForResult(intent, REQUEST_DATA_SAVER);
|
|
|
|
} catch (ActivityNotFoundException e) {
|
|
|
|
Toast.makeText(EditAccountActivity.this, R.string.device_does_not_support_data_saver, Toast.LENGTH_SHORT).show();
|
2016-11-07 09:49:43 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (showBatteryWarning) {
|
|
|
|
this.mDisableOsOptimizationsButton.setText(R.string.disable);
|
2018-02-18 08:06:37 +00:00
|
|
|
this.binding.osOptimizationHeadline.setText(R.string.battery_optimizations_enabled);
|
2016-11-07 09:49:43 +00:00
|
|
|
this.getmDisableOsOptimizationsBody.setText(R.string.battery_optimizations_enabled_explained);
|
2018-02-18 08:06:37 +00:00
|
|
|
this.mDisableOsOptimizationsButton.setOnClickListener(v -> {
|
|
|
|
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
|
|
|
|
Uri uri = Uri.parse("package:" + getPackageName());
|
|
|
|
intent.setData(uri);
|
|
|
|
try {
|
|
|
|
startActivityForResult(intent, REQUEST_BATTERY_OP);
|
|
|
|
} catch (ActivityNotFoundException e) {
|
|
|
|
Toast.makeText(EditAccountActivity.this, R.string.device_does_not_support_battery_op, Toast.LENGTH_SHORT).show();
|
2016-11-07 09:49:43 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-07 17:36:22 +00:00
|
|
|
public void showWipePepDialog() {
|
|
|
|
Builder builder = new Builder(this);
|
2015-07-19 21:35:03 +00:00
|
|
|
builder.setTitle(getString(R.string.clear_other_devices));
|
2015-07-07 17:36:22 +00:00
|
|
|
builder.setIconAttribute(android.R.attr.alertDialogIcon);
|
2015-07-19 21:35:03 +00:00
|
|
|
builder.setMessage(getString(R.string.clear_other_devices_desc));
|
2015-07-07 17:36:22 +00:00
|
|
|
builder.setNegativeButton(getString(R.string.cancel), null);
|
2015-07-19 21:35:03 +00:00
|
|
|
builder.setPositiveButton(getString(R.string.accept),
|
2018-02-18 08:06:37 +00:00
|
|
|
(dialog, which) -> mAccount.getAxolotlService().wipeOtherPepDevices());
|
2015-07-07 17:36:22 +00:00
|
|
|
builder.create().show();
|
|
|
|
}
|
2015-07-21 12:18:16 +00:00
|
|
|
|
2016-02-09 12:01:17 +00:00
|
|
|
private void editMamPrefs() {
|
|
|
|
this.mFetchingMamPrefsToast = Toast.makeText(this, R.string.fetching_mam_prefs, Toast.LENGTH_LONG);
|
|
|
|
this.mFetchingMamPrefsToast.show();
|
|
|
|
xmppConnectionService.fetchMamPreferences(mAccount, this);
|
|
|
|
}
|
|
|
|
|
2015-07-21 12:18:16 +00:00
|
|
|
@Override
|
2015-10-17 12:09:26 +00:00
|
|
|
public void onKeyStatusUpdated(AxolotlService.FetchStatus report) {
|
2015-07-21 12:18:16 +00:00
|
|
|
refreshUi();
|
|
|
|
}
|
2015-10-11 11:11:50 +00:00
|
|
|
|
|
|
|
@Override
|
2016-04-28 18:13:58 +00:00
|
|
|
public void onCaptchaRequested(final Account account, final String id, final Data data, final Bitmap captcha) {
|
2018-02-18 08:06:37 +00:00
|
|
|
runOnUiThread(() -> {
|
|
|
|
if (mCaptchaDialog != null && mCaptchaDialog.isShowing()) {
|
|
|
|
mCaptchaDialog.dismiss();
|
|
|
|
}
|
|
|
|
final Builder builder = new Builder(EditAccountActivity.this);
|
|
|
|
final View view = getLayoutInflater().inflate(R.layout.captcha, null);
|
|
|
|
final ImageView imageView = view.findViewById(R.id.captcha);
|
|
|
|
final EditText input = view.findViewById(R.id.input);
|
|
|
|
imageView.setImageBitmap(captcha);
|
|
|
|
|
|
|
|
builder.setTitle(getString(R.string.captcha_required));
|
|
|
|
builder.setView(view);
|
|
|
|
|
|
|
|
builder.setPositiveButton(getString(R.string.ok),
|
|
|
|
(dialog, which) -> {
|
|
|
|
String rc = input.getText().toString();
|
|
|
|
data.put("username", account.getUsername());
|
|
|
|
data.put("password", account.getPassword());
|
|
|
|
data.put("ocr", rc);
|
|
|
|
data.submit();
|
|
|
|
|
|
|
|
if (xmppConnectionServiceBound) {
|
|
|
|
xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, id, data);
|
2015-10-11 11:11:50 +00:00
|
|
|
}
|
2018-02-18 08:06:37 +00:00
|
|
|
});
|
|
|
|
builder.setNegativeButton(getString(R.string.cancel), (dialog, which) -> {
|
|
|
|
if (xmppConnectionService != null) {
|
|
|
|
xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null);
|
|
|
|
}
|
|
|
|
});
|
2015-10-11 11:11:50 +00:00
|
|
|
|
2018-02-18 08:06:37 +00:00
|
|
|
builder.setOnCancelListener(dialog -> {
|
|
|
|
if (xmppConnectionService != null) {
|
|
|
|
xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
mCaptchaDialog = builder.create();
|
|
|
|
mCaptchaDialog.show();
|
|
|
|
input.requestFocus();
|
2015-10-11 11:11:50 +00:00
|
|
|
});
|
|
|
|
}
|
2015-10-11 13:48:58 +00:00
|
|
|
|
|
|
|
public void onShowErrorToast(final int resId) {
|
2018-02-18 08:06:37 +00:00
|
|
|
runOnUiThread(() -> Toast.makeText(EditAccountActivity.this, resId, Toast.LENGTH_SHORT).show());
|
2015-10-11 13:48:58 +00:00
|
|
|
}
|
2016-02-09 12:01:17 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPreferencesFetched(final Element prefs) {
|
2018-02-18 08:06:37 +00:00
|
|
|
runOnUiThread(() -> {
|
|
|
|
if (mFetchingMamPrefsToast != null) {
|
|
|
|
mFetchingMamPrefsToast.cancel();
|
2016-02-09 12:01:17 +00:00
|
|
|
}
|
2018-02-18 08:06:37 +00:00
|
|
|
Builder builder = new Builder(EditAccountActivity.this);
|
|
|
|
builder.setTitle(R.string.server_side_mam_prefs);
|
|
|
|
String defaultAttr = prefs.getAttribute("default");
|
|
|
|
final List<String> defaults = Arrays.asList("never", "roster", "always");
|
|
|
|
final AtomicInteger choice = new AtomicInteger(Math.max(0, defaults.indexOf(defaultAttr)));
|
|
|
|
builder.setSingleChoiceItems(R.array.mam_prefs, choice.get(), (dialog, which) -> choice.set(which));
|
|
|
|
builder.setNegativeButton(R.string.cancel, null);
|
|
|
|
builder.setPositiveButton(R.string.ok, (dialog, which) -> {
|
|
|
|
prefs.setAttribute("default", defaults.get(choice.get()));
|
|
|
|
xmppConnectionService.pushMamPreferences(mAccount, prefs);
|
|
|
|
});
|
|
|
|
builder.create().show();
|
2016-02-09 12:01:17 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPreferencesFetchFailed() {
|
2018-02-18 08:06:37 +00:00
|
|
|
runOnUiThread(() -> {
|
|
|
|
if (mFetchingMamPrefsToast != null) {
|
|
|
|
mFetchingMamPrefsToast.cancel();
|
2016-02-09 12:01:17 +00:00
|
|
|
}
|
2018-02-18 08:06:37 +00:00
|
|
|
Toast.makeText(EditAccountActivity.this, R.string.unable_to_fetch_mam_prefs, Toast.LENGTH_LONG).show();
|
2016-02-09 12:01:17 +00:00
|
|
|
});
|
|
|
|
}
|
2016-12-03 22:49:00 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void OnUpdateBlocklist(Status status) {
|
|
|
|
refreshUi();
|
|
|
|
}
|
2014-08-15 15:31:24 +00:00
|
|
|
}
|