2014-08-15 11:31:24 -04:00
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
2015-10-11 07:11:50 -04:00
|
|
|
import android.app.AlertDialog;
|
2015-07-07 13:36:22 -04:00
|
|
|
import android.app.AlertDialog.Builder;
|
2014-08-15 11:31:24 -04:00
|
|
|
import android.app.PendingIntent;
|
2016-04-29 07:58:37 -04:00
|
|
|
import android.content.ActivityNotFoundException;
|
2015-07-07 13:36:22 -04:00
|
|
|
import android.content.DialogInterface;
|
2014-08-15 11:31:24 -04:00
|
|
|
import android.content.Intent;
|
2016-01-25 15:17:53 -05:00
|
|
|
import android.content.SharedPreferences;
|
2015-10-11 07:11:50 -04:00
|
|
|
import android.graphics.Bitmap;
|
2016-01-11 05:17:45 -05:00
|
|
|
import android.net.Uri;
|
2014-08-15 11:31:24 -04:00
|
|
|
import android.os.Bundle;
|
2016-01-11 05:17:45 -05:00
|
|
|
import android.provider.Settings;
|
2015-10-11 09:48:58 -04:00
|
|
|
import android.security.KeyChain;
|
|
|
|
import android.security.KeyChainAliasCallback;
|
2014-10-05 06:05:27 -04:00
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.TextWatcher;
|
2014-11-03 16:47:07 -05:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
2014-08-15 11:31:24 -04:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.widget.AutoCompleteTextView;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.CompoundButton;
|
2014-11-03 16:47:07 -05:00
|
|
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
2014-08-15 11:31:24 -04:00
|
|
|
import android.widget.EditText;
|
2014-10-03 09:55:06 -04:00
|
|
|
import android.widget.ImageButton;
|
2014-11-03 16:47:07 -05:00
|
|
|
import android.widget.ImageView;
|
2014-08-19 09:06:50 -04:00
|
|
|
import android.widget.LinearLayout;
|
2014-10-13 08:36:19 -04:00
|
|
|
import android.widget.RelativeLayout;
|
2014-10-21 16:22:01 -04:00
|
|
|
import android.widget.TableLayout;
|
2016-02-12 05:39:27 -05:00
|
|
|
import android.widget.TableRow;
|
2014-08-19 09:06:50 -04:00
|
|
|
import android.widget.TextView;
|
2014-10-03 09:55:06 -04:00
|
|
|
import android.widget.Toast;
|
2014-11-03 16:47:07 -05:00
|
|
|
|
2016-04-26 17:23:48 -04:00
|
|
|
import android.util.Log;
|
|
|
|
|
2016-02-09 07:01:17 -05:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
2015-07-07 13:36:22 -04:00
|
|
|
import java.util.Set;
|
2016-02-09 07:01:17 -05:00
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
2015-07-07 13:36:22 -04:00
|
|
|
|
2015-07-21 19:00:20 -04:00
|
|
|
import eu.siacs.conversations.Config;
|
2014-08-15 11:31:24 -04:00
|
|
|
import eu.siacs.conversations.R;
|
2015-09-06 13:40:28 -04:00
|
|
|
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
|
2014-08-15 11:31:24 -04:00
|
|
|
import eu.siacs.conversations.entities.Account;
|
2015-10-11 07:11:50 -04:00
|
|
|
import eu.siacs.conversations.services.XmppConnectionService.OnCaptchaRequested;
|
2015-10-11 09:48:58 -04:00
|
|
|
import eu.siacs.conversations.services.XmppConnectionService;
|
2014-08-15 11:31:24 -04:00
|
|
|
import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
|
|
|
|
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
|
2014-11-15 18:20:20 -05:00
|
|
|
import eu.siacs.conversations.utils.CryptoHelper;
|
2014-08-19 09:06:50 -04:00
|
|
|
import eu.siacs.conversations.utils.UIHelper;
|
2016-02-09 07:01:17 -05:00
|
|
|
import eu.siacs.conversations.xml.Element;
|
2015-07-21 08:18:16 -04:00
|
|
|
import eu.siacs.conversations.xmpp.OnKeyStatusUpdated;
|
2016-02-19 14:54:53 -05:00
|
|
|
import eu.siacs.conversations.xmpp.XmppConnection;
|
2014-08-23 09:56:30 -04:00
|
|
|
import eu.siacs.conversations.xmpp.XmppConnection.Features;
|
2015-10-11 07:11:50 -04:00
|
|
|
import eu.siacs.conversations.xmpp.forms.Data;
|
2014-11-06 14:33:13 -05:00
|
|
|
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
|
|
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
2014-08-15 11:31:24 -04:00
|
|
|
import eu.siacs.conversations.xmpp.pep.Avatar;
|
|
|
|
|
2015-10-11 07:11:50 -04:00
|
|
|
public class EditAccountActivity extends XmppActivity implements OnAccountUpdate,
|
2016-02-09 07:01:17 -05:00
|
|
|
OnKeyStatusUpdated, OnCaptchaRequested, KeyChainAliasCallback, XmppConnectionService.OnShowErrorToast, XmppConnectionService.OnMamPreferencesFetched {
|
2014-08-15 11:31:24 -04:00
|
|
|
|
|
|
|
private AutoCompleteTextView mAccountJid;
|
|
|
|
private EditText mPassword;
|
|
|
|
private EditText mPasswordConfirm;
|
|
|
|
private CheckBox mRegisterNew;
|
|
|
|
private Button mCancelButton;
|
|
|
|
private Button mSaveButton;
|
2016-01-11 05:17:45 -05:00
|
|
|
private Button mDisableBatterOptimizations;
|
2014-10-21 16:22:01 -04:00
|
|
|
private TableLayout mMoreTable;
|
2014-08-15 11:31:24 -04:00
|
|
|
|
2014-08-19 09:06:50 -04:00
|
|
|
private LinearLayout mStats;
|
2016-01-11 05:17:45 -05:00
|
|
|
private RelativeLayout mBatteryOptimizations;
|
2014-08-23 09:56:30 -04:00
|
|
|
private TextView mServerInfoSm;
|
2014-10-21 16:22:01 -04:00
|
|
|
private TextView mServerInfoRosterVersion;
|
2014-08-23 09:56:30 -04:00
|
|
|
private TextView mServerInfoCarbons;
|
2014-10-21 16:22:01 -04:00
|
|
|
private TextView mServerInfoMam;
|
|
|
|
private TextView mServerInfoCSI;
|
|
|
|
private TextView mServerInfoBlocking;
|
2014-08-23 09:56:30 -04:00
|
|
|
private TextView mServerInfoPep;
|
2015-08-14 16:24:05 -04:00
|
|
|
private TextView mServerInfoHttpUpload;
|
2016-02-12 05:39:27 -05:00
|
|
|
private TextView mServerInfoPush;
|
2014-08-19 09:06:50 -04:00
|
|
|
private TextView mSessionEst;
|
2014-08-20 05:32:49 -04:00
|
|
|
private TextView mOtrFingerprint;
|
2015-07-07 13:36:22 -04:00
|
|
|
private TextView mAxolotlFingerprint;
|
2015-08-03 16:58:17 -04:00
|
|
|
private TextView mAccountJidLabel;
|
2014-11-04 11:38:41 -05:00
|
|
|
private ImageView mAvatar;
|
2014-10-13 08:36:19 -04:00
|
|
|
private RelativeLayout mOtrFingerprintBox;
|
2015-07-07 13:36:22 -04:00
|
|
|
private RelativeLayout mAxolotlFingerprintBox;
|
2014-10-03 09:55:06 -04:00
|
|
|
private ImageButton mOtrFingerprintToClipboardButton;
|
2015-07-07 13:36:22 -04:00
|
|
|
private ImageButton mAxolotlFingerprintToClipboardButton;
|
|
|
|
private ImageButton mRegenerateAxolotlKeyButton;
|
2015-07-19 08:09:49 -04:00
|
|
|
private LinearLayout keys;
|
|
|
|
private LinearLayout keysCard;
|
2015-11-28 14:11:38 -05:00
|
|
|
private LinearLayout mNamePort;
|
|
|
|
private EditText mHostname;
|
|
|
|
private EditText mPort;
|
2015-10-11 07:11:50 -04:00
|
|
|
private AlertDialog mCaptchaDialog = null;
|
2014-08-19 09:06:50 -04:00
|
|
|
|
2014-11-06 14:33:13 -05:00
|
|
|
private Jid jidToEdit;
|
2015-10-09 07:37:08 -04:00
|
|
|
private boolean mInitMode = false;
|
2016-01-25 15:17:53 -05:00
|
|
|
private boolean mShowOptions = false;
|
2014-08-15 11:31:24 -04:00
|
|
|
private Account mAccount;
|
2015-07-29 14:21:37 -04:00
|
|
|
private String messageFingerprint;
|
2014-08-15 11:31:24 -04:00
|
|
|
|
|
|
|
private boolean mFetchingAvatar = false;
|
2014-08-19 09:06:50 -04:00
|
|
|
|
2014-12-23 17:19:00 -05:00
|
|
|
private final OnClickListener mSaveButtonClickListener = new OnClickListener() {
|
2014-08-15 11:31:24 -04:00
|
|
|
|
|
|
|
@Override
|
2014-12-23 13:23:13 -05:00
|
|
|
public void onClick(final View v) {
|
2016-04-26 17:23:48 -04:00
|
|
|
final String password = mPassword.getText().toString();
|
|
|
|
final String passwordConfirm = mPasswordConfirm.getText().toString();
|
|
|
|
|
|
|
|
if (!mInitMode && passwordChangedInMagicCreateMode()) {
|
|
|
|
gotoChangePassword(password);
|
|
|
|
return;
|
|
|
|
}
|
2015-10-09 07:37:08 -04:00
|
|
|
if (mInitMode && mAccount != null) {
|
|
|
|
mAccount.setOption(Account.OPTION_DISABLED, false);
|
|
|
|
}
|
2015-04-14 09:00:49 -04:00
|
|
|
if (mAccount != null && mAccount.getStatus() == Account.State.DISABLED && !accountInfoEdited()) {
|
2014-10-05 06:05:27 -04:00
|
|
|
mAccount.setOption(Account.OPTION_DISABLED, false);
|
|
|
|
xmppConnectionService.updateAccount(mAccount);
|
|
|
|
return;
|
2014-12-25 16:08:13 -05:00
|
|
|
}
|
2015-08-03 16:58:17 -04:00
|
|
|
final boolean registerNewAccount = mRegisterNew.isChecked() && !Config.DISALLOW_REGISTRATION_IN_UI;
|
|
|
|
if (Config.DOMAIN_LOCK != null && mAccountJid.getText().toString().contains("@")) {
|
|
|
|
mAccountJid.setError(getString(R.string.invalid_username));
|
|
|
|
mAccountJid.requestFocus();
|
|
|
|
return;
|
|
|
|
}
|
2014-12-03 04:52:55 -05:00
|
|
|
final Jid jid;
|
|
|
|
try {
|
2015-08-03 16:58:17 -04:00
|
|
|
if (Config.DOMAIN_LOCK != null) {
|
2015-10-11 09:48:58 -04:00
|
|
|
jid = Jid.fromParts(mAccountJid.getText().toString(), Config.DOMAIN_LOCK, null);
|
2015-08-03 16:58:17 -04:00
|
|
|
} else {
|
|
|
|
jid = Jid.fromString(mAccountJid.getText().toString());
|
|
|
|
}
|
2014-12-03 04:52:55 -05:00
|
|
|
} catch (final InvalidJidException e) {
|
2015-08-03 16:58:17 -04:00
|
|
|
if (Config.DOMAIN_LOCK != null) {
|
|
|
|
mAccountJid.setError(getString(R.string.invalid_username));
|
|
|
|
} else {
|
|
|
|
mAccountJid.setError(getString(R.string.invalid_jid));
|
|
|
|
}
|
2014-12-03 04:52:55 -05:00
|
|
|
mAccountJid.requestFocus();
|
|
|
|
return;
|
|
|
|
}
|
2015-11-29 09:44:45 -05:00
|
|
|
String hostname = null;
|
|
|
|
int numericPort = 5222;
|
2016-01-25 15:17:53 -05:00
|
|
|
if (mShowOptions) {
|
2015-11-29 09:44:45 -05:00
|
|
|
hostname = mHostname.getText().toString();
|
|
|
|
final String port = mPort.getText().toString();
|
|
|
|
if (hostname.contains(" ")) {
|
|
|
|
mHostname.setError(getString(R.string.not_valid_hostname));
|
|
|
|
mHostname.requestFocus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
numericPort = Integer.parseInt(port);
|
|
|
|
if (numericPort < 0 || numericPort > 65535) {
|
|
|
|
mPort.setError(getString(R.string.not_a_valid_port));
|
|
|
|
mPort.requestFocus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
mPort.setError(getString(R.string.not_a_valid_port));
|
|
|
|
mPort.requestFocus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-23 17:35:36 -05:00
|
|
|
if (jid.isDomainJid()) {
|
2015-08-03 16:58:17 -04:00
|
|
|
if (Config.DOMAIN_LOCK != null) {
|
|
|
|
mAccountJid.setError(getString(R.string.invalid_username));
|
|
|
|
} else {
|
|
|
|
mAccountJid.setError(getString(R.string.invalid_jid));
|
|
|
|
}
|
2014-12-23 17:35:36 -05:00
|
|
|
mAccountJid.requestFocus();
|
|
|
|
return;
|
|
|
|
}
|
2015-01-02 18:11:02 -05:00
|
|
|
if (registerNewAccount) {
|
2014-08-15 11:31:24 -04:00
|
|
|
if (!password.equals(passwordConfirm)) {
|
2014-12-25 16:28:19 -05:00
|
|
|
mPasswordConfirm.setError(getString(R.string.passwords_do_not_match));
|
2014-08-20 05:32:49 -04:00
|
|
|
mPasswordConfirm.requestFocus();
|
2014-08-15 11:31:24 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mAccount != null) {
|
2016-04-26 17:23:48 -04:00
|
|
|
if (mInitMode && mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE)) {
|
|
|
|
mAccount.setOption(Account.OPTION_MAGIC_CREATE, mAccount.getPassword().contains(password));
|
|
|
|
}
|
2015-10-09 07:37:08 -04:00
|
|
|
mAccount.setJid(jid);
|
2015-11-29 09:44:45 -05:00
|
|
|
mAccount.setPort(numericPort);
|
|
|
|
mAccount.setHostname(hostname);
|
2015-02-26 11:17:40 -05:00
|
|
|
mAccountJid.setError(null);
|
|
|
|
mPasswordConfirm.setError(null);
|
2015-01-02 18:11:02 -05:00
|
|
|
mAccount.setPassword(password);
|
|
|
|
mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
|
|
|
|
xmppConnectionService.updateAccount(mAccount);
|
2014-08-15 11:31:24 -04:00
|
|
|
} else {
|
2015-08-03 16:58:17 -04:00
|
|
|
if (xmppConnectionService.findAccountByJid(jid) != null) {
|
|
|
|
mAccountJid.setError(getString(R.string.account_already_exists));
|
|
|
|
mAccountJid.requestFocus();
|
2014-12-21 15:43:58 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
mAccount = new Account(jid.toBareJid(), password);
|
2015-11-29 09:44:45 -05:00
|
|
|
mAccount.setPort(numericPort);
|
|
|
|
mAccount.setHostname(hostname);
|
2014-08-15 11:31:24 -04:00
|
|
|
mAccount.setOption(Account.OPTION_USETLS, true);
|
|
|
|
mAccount.setOption(Account.OPTION_USECOMPRESSION, true);
|
2014-08-20 05:32:49 -04:00
|
|
|
mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
|
2014-08-15 11:31:24 -04:00
|
|
|
xmppConnectionService.createAccount(mAccount);
|
|
|
|
}
|
2015-11-29 09:44:45 -05:00
|
|
|
mHostname.setError(null);
|
|
|
|
mPort.setError(null);
|
2015-10-09 07:37:08 -04:00
|
|
|
if (!mAccount.isOptionSet(Account.OPTION_DISABLED)
|
|
|
|
&& !registerNewAccount
|
|
|
|
&& !mInitMode) {
|
2014-08-15 11:31:24 -04:00
|
|
|
finish();
|
|
|
|
} else {
|
|
|
|
updateSaveButton();
|
2015-07-16 07:42:52 -04:00
|
|
|
updateAccountInformation(true);
|
2014-08-15 11:31:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
2014-12-23 17:19:00 -05:00
|
|
|
private final OnClickListener mCancelButtonClickListener = new OnClickListener() {
|
2014-08-15 11:31:24 -04:00
|
|
|
|
|
|
|
@Override
|
2014-12-23 17:19:00 -05:00
|
|
|
public void onClick(final View v) {
|
2014-08-15 11:31:24 -04:00
|
|
|
finish();
|
|
|
|
}
|
|
|
|
};
|
2016-02-09 07:01:17 -05:00
|
|
|
private Toast mFetchingMamPrefsToast;
|
2016-02-12 05:39:27 -05:00
|
|
|
private TableRow mPushRow;
|
2015-07-20 09:48:58 -04:00
|
|
|
|
|
|
|
public void refreshUiReal() {
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
if (mAccount != null
|
|
|
|
&& mAccount.getStatus() != Account.State.ONLINE
|
|
|
|
&& mFetchingAvatar) {
|
|
|
|
startActivity(new Intent(getApplicationContext(),
|
2015-10-11 09:48:58 -04:00
|
|
|
ManageAccountActivity.class));
|
2015-07-20 09:48:58 -04:00
|
|
|
finish();
|
2015-10-09 07:37:08 -04:00
|
|
|
} else if (mInitMode && mAccount != null && mAccount.getStatus() == Account.State.ONLINE) {
|
2015-07-20 09:48:58 -04:00
|
|
|
if (!mFetchingAvatar) {
|
|
|
|
mFetchingAvatar = true;
|
2015-10-09 07:37:08 -04:00
|
|
|
xmppConnectionService.checkForAvatar(mAccount, mAvatarFetchCallback);
|
2015-07-20 09:48:58 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mAccount != null) {
|
|
|
|
updateAccountInformation(false);
|
|
|
|
}
|
2016-04-09 18:19:20 -04:00
|
|
|
updateSaveButton();
|
2015-07-20 09:48:58 -04:00
|
|
|
}
|
|
|
|
|
2014-12-21 15:43:58 -05:00
|
|
|
@Override
|
|
|
|
public void onAccountUpdate() {
|
2015-07-20 09:48:58 -04:00
|
|
|
refreshUi();
|
2014-12-21 15:43:58 -05:00
|
|
|
}
|
2015-10-11 09:48:58 -04:00
|
|
|
|
2014-12-23 17:19:00 -05:00
|
|
|
private final UiCallback<Avatar> mAvatarFetchCallback = new UiCallback<Avatar>() {
|
2014-08-19 09:06:50 -04:00
|
|
|
|
2014-08-15 11:31:24 -04:00
|
|
|
@Override
|
2014-12-23 17:19:00 -05:00
|
|
|
public void userInputRequried(final PendingIntent pi, final Avatar avatar) {
|
2014-08-15 11:31:24 -04:00
|
|
|
finishInitialSetup(avatar);
|
|
|
|
}
|
2014-08-19 09:06:50 -04:00
|
|
|
|
2014-08-15 11:31:24 -04:00
|
|
|
@Override
|
2014-12-23 17:19:00 -05:00
|
|
|
public void success(final Avatar avatar) {
|
2014-08-15 11:31:24 -04:00
|
|
|
finishInitialSetup(avatar);
|
|
|
|
}
|
2014-08-19 09:06:50 -04:00
|
|
|
|
2014-08-15 11:31:24 -04:00
|
|
|
@Override
|
2014-12-23 17:19:00 -05:00
|
|
|
public void error(final int errorCode, final Avatar avatar) {
|
2014-08-15 11:31:24 -04:00
|
|
|
finishInitialSetup(avatar);
|
|
|
|
}
|
|
|
|
};
|
2014-12-23 17:19:00 -05:00
|
|
|
private final TextWatcher mTextWatcher = new TextWatcher() {
|
2014-10-05 06:05:27 -04:00
|
|
|
|
|
|
|
@Override
|
2014-12-23 17:19:00 -05:00
|
|
|
public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
|
2014-10-05 06:05:27 -04:00
|
|
|
updateSaveButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-12-23 17:19:00 -05:00
|
|
|
public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) {
|
2014-10-05 06:05:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-12-23 17:19:00 -05:00
|
|
|
public void afterTextChanged(final Editable s) {
|
2014-12-25 16:28:19 -05:00
|
|
|
|
2014-10-05 06:05:27 -04:00
|
|
|
}
|
2015-01-02 18:11:02 -05:00
|
|
|
};
|
2014-12-25 16:28:19 -05:00
|
|
|
|
2014-12-23 17:19:00 -05:00
|
|
|
private final OnClickListener mAvatarClickListener = new OnClickListener() {
|
2014-11-04 11:38:41 -05:00
|
|
|
@Override
|
2014-12-23 17:19:00 -05:00
|
|
|
public void onClick(final View view) {
|
|
|
|
if (mAccount != null) {
|
2015-10-09 07:37:08 -04:00
|
|
|
final Intent intent = new Intent(getApplicationContext(), PublishProfilePictureActivity.class);
|
2016-01-22 14:46:24 -05:00
|
|
|
intent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toBareJid().toString());
|
2014-11-04 11:38:41 -05:00
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-08-15 11:31:24 -04:00
|
|
|
|
2014-08-16 03:44:37 -04:00
|
|
|
protected void finishInitialSetup(final Avatar avatar) {
|
2014-08-15 11:31:24 -04:00
|
|
|
runOnUiThread(new Runnable() {
|
2014-08-19 09:06:50 -04:00
|
|
|
|
2014-08-15 11:31:24 -04:00
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-12-23 17:19:00 -05:00
|
|
|
final Intent intent;
|
2016-02-19 14:54:53 -05:00
|
|
|
final XmppConnection connection = mAccount.getXmppConnection();
|
2016-04-27 04:35:08 -04:00
|
|
|
final boolean wasFirstAccount = xmppConnectionService != null && xmppConnectionService.getAccounts().size() == 1;
|
2016-02-19 14:54:53 -05:00
|
|
|
if (avatar != null || (connection != null && !connection.getFeatures().pep())) {
|
|
|
|
intent = new Intent(getApplicationContext(), StartConversationActivity.class);
|
2016-04-27 04:35:08 -04:00
|
|
|
if (wasFirstAccount) {
|
2015-05-15 07:58:11 -04:00
|
|
|
intent.putExtra("init", true);
|
|
|
|
}
|
2014-08-16 03:44:37 -04:00
|
|
|
} else {
|
2016-02-19 14:54:53 -05:00
|
|
|
intent = new Intent(getApplicationContext(), PublishProfilePictureActivity.class);
|
2016-01-22 14:46:24 -05:00
|
|
|
intent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toBareJid().toString());
|
2014-08-23 14:00:05 -04:00
|
|
|
intent.putExtra("setup", true);
|
2014-08-16 03:44:37 -04:00
|
|
|
}
|
2016-04-27 04:35:08 -04:00
|
|
|
if (wasFirstAccount) {
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
|
|
}
|
2014-08-16 03:44:37 -04:00
|
|
|
startActivity(intent);
|
|
|
|
finish();
|
2014-08-15 11:31:24 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-08-19 09:06:50 -04:00
|
|
|
|
2016-01-11 05:17:45 -05:00
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
if (requestCode == REQUEST_BATTERY_OP) {
|
|
|
|
updateAccountInformation(mAccount == null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-15 11:31:24 -04:00
|
|
|
protected void updateSaveButton() {
|
2016-04-26 17:23:48 -04:00
|
|
|
boolean accountInfoEdited = accountInfoEdited();
|
|
|
|
|
|
|
|
if (!mInitMode && passwordChangedInMagicCreateMode()) {
|
|
|
|
this.mSaveButton.setText(R.string.change_password);
|
|
|
|
this.mSaveButton.setEnabled(true);
|
|
|
|
this.mSaveButton.setTextColor(getPrimaryTextColor());
|
|
|
|
} else if (accountInfoEdited && !mInitMode) {
|
2015-04-14 09:00:49 -04:00
|
|
|
this.mSaveButton.setText(R.string.save);
|
|
|
|
this.mSaveButton.setEnabled(true);
|
|
|
|
this.mSaveButton.setTextColor(getPrimaryTextColor());
|
2016-04-09 18:19:20 -04:00
|
|
|
} else if (mAccount != null
|
|
|
|
&& (mAccount.getStatus() == Account.State.CONNECTING || mAccount.getStatus() == Account.State.REGISTRATION_SUCCESSFUL|| mFetchingAvatar)) {
|
2014-08-15 11:31:24 -04:00
|
|
|
this.mSaveButton.setEnabled(false);
|
|
|
|
this.mSaveButton.setTextColor(getSecondaryTextColor());
|
|
|
|
this.mSaveButton.setText(R.string.account_status_connecting);
|
2015-10-09 07:37:08 -04:00
|
|
|
} else if (mAccount != null && mAccount.getStatus() == Account.State.DISABLED && !mInitMode) {
|
2014-10-05 06:05:27 -04:00
|
|
|
this.mSaveButton.setEnabled(true);
|
|
|
|
this.mSaveButton.setTextColor(getPrimaryTextColor());
|
|
|
|
this.mSaveButton.setText(R.string.enable);
|
2014-08-19 09:06:50 -04:00
|
|
|
} else {
|
2014-08-15 11:31:24 -04:00
|
|
|
this.mSaveButton.setEnabled(true);
|
|
|
|
this.mSaveButton.setTextColor(getPrimaryTextColor());
|
2015-10-09 07:37:08 -04:00
|
|
|
if (!mInitMode) {
|
2014-12-23 17:19:00 -05:00
|
|
|
if (mAccount != null && mAccount.isOnlineAndConnected()) {
|
2014-08-29 04:24:25 -04:00
|
|
|
this.mSaveButton.setText(R.string.save);
|
2016-04-26 17:23:48 -04:00
|
|
|
if (!accountInfoEdited) {
|
2014-10-05 06:05:27 -04:00
|
|
|
this.mSaveButton.setEnabled(false);
|
|
|
|
this.mSaveButton.setTextColor(getSecondaryTextColor());
|
|
|
|
}
|
2014-08-29 04:24:25 -04:00
|
|
|
} else {
|
|
|
|
this.mSaveButton.setText(R.string.connect);
|
|
|
|
}
|
2014-08-16 03:44:37 -04:00
|
|
|
} else {
|
|
|
|
this.mSaveButton.setText(R.string.next);
|
|
|
|
}
|
2014-08-15 11:31:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-05 06:05:27 -04:00
|
|
|
protected boolean accountInfoEdited() {
|
2015-08-03 16:58:17 -04:00
|
|
|
if (this.mAccount == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-26 17:23:48 -04: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 16:58:17 -04:00
|
|
|
final String unmodified;
|
|
|
|
if (Config.DOMAIN_LOCK != null) {
|
|
|
|
unmodified = this.mAccount.getJid().getLocalpart();
|
|
|
|
} else {
|
|
|
|
unmodified = this.mAccount.getJid().toBareJid().toString();
|
|
|
|
}
|
2016-04-26 17:23:48 -04:00
|
|
|
return !unmodified.equals(this.mAccountJid.getText().toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
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 06:05:27 -04:00
|
|
|
}
|
|
|
|
|
2014-11-04 06:15:14 -05:00
|
|
|
@Override
|
|
|
|
protected String getShareableUri() {
|
2015-10-11 09:48:58 -04:00
|
|
|
if (mAccount != null) {
|
2014-11-15 18:20:20 -05:00
|
|
|
return mAccount.getShareableUri();
|
2014-11-04 06:15:14 -05:00
|
|
|
} else {
|
2014-11-04 11:10:35 -05:00
|
|
|
return "";
|
2014-11-04 06:15:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-15 11:31:24 -04:00
|
|
|
@Override
|
2014-12-23 17:19:00 -05:00
|
|
|
protected void onCreate(final Bundle savedInstanceState) {
|
2014-08-15 11:31:24 -04:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_edit_account);
|
|
|
|
this.mAccountJid = (AutoCompleteTextView) findViewById(R.id.account_jid);
|
2014-10-05 06:05:27 -04:00
|
|
|
this.mAccountJid.addTextChangedListener(this.mTextWatcher);
|
2015-08-03 16:58:17 -04:00
|
|
|
this.mAccountJidLabel = (TextView) findViewById(R.id.account_jid_label);
|
|
|
|
if (Config.DOMAIN_LOCK != null) {
|
|
|
|
this.mAccountJidLabel.setText(R.string.username);
|
|
|
|
this.mAccountJid.setHint(R.string.username_hint);
|
|
|
|
}
|
2014-08-15 11:31:24 -04:00
|
|
|
this.mPassword = (EditText) findViewById(R.id.account_password);
|
2014-10-05 06:05:27 -04:00
|
|
|
this.mPassword.addTextChangedListener(this.mTextWatcher);
|
2014-08-15 11:31:24 -04:00
|
|
|
this.mPasswordConfirm = (EditText) findViewById(R.id.account_password_confirm);
|
2014-11-04 11:38:41 -05:00
|
|
|
this.mAvatar = (ImageView) findViewById(R.id.avater);
|
|
|
|
this.mAvatar.setOnClickListener(this.mAvatarClickListener);
|
2014-08-15 11:31:24 -04:00
|
|
|
this.mRegisterNew = (CheckBox) findViewById(R.id.account_register_new);
|
2014-08-19 09:06:50 -04:00
|
|
|
this.mStats = (LinearLayout) findViewById(R.id.stats);
|
2016-01-11 05:17:45 -05:00
|
|
|
this.mBatteryOptimizations = (RelativeLayout) findViewById(R.id.battery_optimization);
|
|
|
|
this.mDisableBatterOptimizations = (Button) findViewById(R.id.batt_op_disable);
|
|
|
|
this.mDisableBatterOptimizations.setOnClickListener(new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
|
|
|
|
Uri uri = Uri.parse("package:"+getPackageName());
|
|
|
|
intent.setData(uri);
|
2016-04-29 07:58:37 -04:00
|
|
|
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-01-11 05:17:45 -05:00
|
|
|
}
|
|
|
|
});
|
2014-08-19 09:06:50 -04:00
|
|
|
this.mSessionEst = (TextView) findViewById(R.id.session_est);
|
2014-10-21 16:22:01 -04:00
|
|
|
this.mServerInfoRosterVersion = (TextView) findViewById(R.id.server_info_roster_version);
|
2014-08-23 09:56:30 -04:00
|
|
|
this.mServerInfoCarbons = (TextView) findViewById(R.id.server_info_carbons);
|
2014-10-21 16:22:01 -04:00
|
|
|
this.mServerInfoMam = (TextView) findViewById(R.id.server_info_mam);
|
|
|
|
this.mServerInfoCSI = (TextView) findViewById(R.id.server_info_csi);
|
|
|
|
this.mServerInfoBlocking = (TextView) findViewById(R.id.server_info_blocking);
|
2014-08-23 09:56:30 -04:00
|
|
|
this.mServerInfoSm = (TextView) findViewById(R.id.server_info_sm);
|
|
|
|
this.mServerInfoPep = (TextView) findViewById(R.id.server_info_pep);
|
2015-08-14 16:24:05 -04:00
|
|
|
this.mServerInfoHttpUpload = (TextView) findViewById(R.id.server_info_http_upload);
|
2016-02-12 05:39:27 -05:00
|
|
|
this.mPushRow = (TableRow) findViewById(R.id.push_row);
|
|
|
|
this.mServerInfoPush = (TextView) findViewById(R.id.server_info_push);
|
2014-08-20 05:32:49 -04:00
|
|
|
this.mOtrFingerprint = (TextView) findViewById(R.id.otr_fingerprint);
|
2014-10-13 08:36:19 -04:00
|
|
|
this.mOtrFingerprintBox = (RelativeLayout) findViewById(R.id.otr_fingerprint_box);
|
2014-10-03 09:55:06 -04:00
|
|
|
this.mOtrFingerprintToClipboardButton = (ImageButton) findViewById(R.id.action_copy_to_clipboard);
|
2015-07-07 13:36:22 -04:00
|
|
|
this.mAxolotlFingerprint = (TextView) findViewById(R.id.axolotl_fingerprint);
|
|
|
|
this.mAxolotlFingerprintBox = (RelativeLayout) findViewById(R.id.axolotl_fingerprint_box);
|
2015-07-10 00:08:44 -04:00
|
|
|
this.mAxolotlFingerprintToClipboardButton = (ImageButton) findViewById(R.id.action_copy_axolotl_to_clipboard);
|
2015-07-07 13:36:22 -04:00
|
|
|
this.mRegenerateAxolotlKeyButton = (ImageButton) findViewById(R.id.action_regenerate_axolotl_key);
|
2015-07-19 08:09:49 -04:00
|
|
|
this.keysCard = (LinearLayout) findViewById(R.id.other_device_keys_card);
|
|
|
|
this.keys = (LinearLayout) findViewById(R.id.other_device_keys);
|
2015-11-28 14:11:38 -05:00
|
|
|
this.mNamePort = (LinearLayout) findViewById(R.id.name_port);
|
|
|
|
this.mHostname = (EditText) findViewById(R.id.hostname);
|
|
|
|
this.mHostname.addTextChangedListener(mTextWatcher);
|
|
|
|
this.mPort = (EditText) findViewById(R.id.port);
|
|
|
|
this.mPort.setText("5222");
|
|
|
|
this.mPort.addTextChangedListener(mTextWatcher);
|
2014-08-15 11:31:24 -04: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 16:22:01 -04:00
|
|
|
this.mMoreTable = (TableLayout) findViewById(R.id.server_info_more);
|
2014-12-23 17:19:00 -05:00
|
|
|
final OnCheckedChangeListener OnCheckedShowConfirmPassword = new OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(final CompoundButton buttonView,
|
2015-10-11 09:48:58 -04:00
|
|
|
final boolean isChecked) {
|
2014-12-23 17:19:00 -05:00
|
|
|
if (isChecked) {
|
|
|
|
mPasswordConfirm.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
mPasswordConfirm.setVisibility(View.GONE);
|
2014-12-21 15:43:58 -05:00
|
|
|
}
|
2014-12-23 17:19:00 -05:00
|
|
|
updateSaveButton();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this.mRegisterNew.setOnCheckedChangeListener(OnCheckedShowConfirmPassword);
|
2015-08-03 16:58:17 -04:00
|
|
|
if (Config.DISALLOW_REGISTRATION_IN_UI) {
|
|
|
|
this.mRegisterNew.setVisibility(View.GONE);
|
|
|
|
}
|
2014-08-15 11:31:24 -04:00
|
|
|
}
|
|
|
|
|
2014-11-03 16:47:07 -05:00
|
|
|
@Override
|
2014-12-21 15:43:58 -05:00
|
|
|
public boolean onCreateOptionsMenu(final Menu menu) {
|
2014-11-03 16:47:07 -05:00
|
|
|
super.onCreateOptionsMenu(menu);
|
|
|
|
getMenuInflater().inflate(R.menu.editaccount, menu);
|
2014-12-21 15:43:58 -05:00
|
|
|
final MenuItem showQrCode = menu.findItem(R.id.action_show_qr_code);
|
|
|
|
final MenuItem showBlocklist = menu.findItem(R.id.action_show_block_list);
|
2014-12-23 17:12:52 -05:00
|
|
|
final MenuItem showMoreInfo = menu.findItem(R.id.action_server_info_show_more);
|
2015-01-02 18:11:02 -05:00
|
|
|
final MenuItem changePassword = menu.findItem(R.id.action_change_password_on_server);
|
2015-07-19 17:35:03 -04:00
|
|
|
final MenuItem clearDevices = menu.findItem(R.id.action_clear_devices);
|
2015-10-11 09:48:58 -04:00
|
|
|
final MenuItem renewCertificate = menu.findItem(R.id.action_renew_certificate);
|
2016-02-09 07:01:17 -05:00
|
|
|
final MenuItem mamPrefs = menu.findItem(R.id.action_mam_prefs);
|
2016-04-22 15:25:06 -04:00
|
|
|
final MenuItem changePresence = menu.findItem(R.id.action_change_presence);
|
2015-10-11 09:48:58 -04:00
|
|
|
renewCertificate.setVisible(mAccount != null && mAccount.getPrivateKeyAlias() != null);
|
|
|
|
|
2015-02-27 11:03:13 -05:00
|
|
|
if (mAccount != null && mAccount.isOnlineAndConnected()) {
|
|
|
|
if (!mAccount.getXmppConnection().getFeatures().blocking()) {
|
|
|
|
showBlocklist.setVisible(false);
|
|
|
|
}
|
|
|
|
if (!mAccount.getXmppConnection().getFeatures().register()) {
|
|
|
|
changePassword.setVisible(false);
|
|
|
|
}
|
2016-02-09 07:01:17 -05:00
|
|
|
mamPrefs.setVisible(mAccount.getXmppConnection().getFeatures().mam());
|
2015-07-19 17:35:03 -04:00
|
|
|
Set<Integer> otherDevices = mAccount.getAxolotlService().getOwnDeviceIds();
|
|
|
|
if (otherDevices == null || otherDevices.isEmpty()) {
|
|
|
|
clearDevices.setVisible(false);
|
|
|
|
}
|
2016-04-23 06:33:56 -04:00
|
|
|
changePresence.setVisible(manuallyChangePresence());
|
2015-02-27 11:03:13 -05:00
|
|
|
} else {
|
2014-11-03 16:47:07 -05:00
|
|
|
showQrCode.setVisible(false);
|
2014-12-21 15:43:58 -05:00
|
|
|
showBlocklist.setVisible(false);
|
2014-12-23 17:12:52 -05:00
|
|
|
showMoreInfo.setVisible(false);
|
2015-01-02 18:11:02 -05:00
|
|
|
changePassword.setVisible(false);
|
2015-07-20 16:19:04 -04:00
|
|
|
clearDevices.setVisible(false);
|
2016-02-09 07:01:17 -05:00
|
|
|
mamPrefs.setVisible(false);
|
2016-04-23 06:33:56 -04:00
|
|
|
changePresence.setVisible(false);
|
2014-11-03 16:47:07 -05:00
|
|
|
}
|
2016-02-27 04:25:31 -05:00
|
|
|
return super.onCreateOptionsMenu(menu);
|
2014-11-03 16:47:07 -05:00
|
|
|
}
|
|
|
|
|
2014-08-15 11:31:24 -04:00
|
|
|
@Override
|
|
|
|
protected void onStart() {
|
|
|
|
super.onStart();
|
|
|
|
if (getIntent() != null) {
|
2014-12-21 15:43:58 -05:00
|
|
|
try {
|
|
|
|
this.jidToEdit = Jid.fromString(getIntent().getStringExtra("jid"));
|
|
|
|
} catch (final InvalidJidException | NullPointerException ignored) {
|
|
|
|
this.jidToEdit = null;
|
|
|
|
}
|
2015-10-09 07:37:08 -04:00
|
|
|
this.mInitMode = getIntent().getBooleanExtra("init", false) || this.jidToEdit == null;
|
2015-07-29 14:21:37 -04:00
|
|
|
this.messageFingerprint = getIntent().getStringExtra("fingerprint");
|
2015-10-09 07:37:08 -04:00
|
|
|
if (!mInitMode) {
|
2014-08-15 11:31:24 -04:00
|
|
|
this.mRegisterNew.setVisibility(View.GONE);
|
2014-12-21 15:43:58 -05:00
|
|
|
if (getActionBar() != null) {
|
|
|
|
getActionBar().setTitle(getString(R.string.account_details));
|
|
|
|
}
|
2014-08-15 11:31:24 -04:00
|
|
|
} else {
|
2014-11-04 11:38:41 -05:00
|
|
|
this.mAvatar.setVisibility(View.GONE);
|
2014-12-21 15:43:58 -05:00
|
|
|
if (getActionBar() != null) {
|
|
|
|
getActionBar().setTitle(R.string.action_add_account);
|
|
|
|
}
|
2014-08-15 11:31:24 -04:00
|
|
|
}
|
|
|
|
}
|
2016-01-25 15:17:53 -05:00
|
|
|
SharedPreferences preferences = getPreferences();
|
|
|
|
boolean useTor = Config.FORCE_ORBOT || preferences.getBoolean("use_tor", false);
|
|
|
|
this.mShowOptions = useTor || preferences.getBoolean("show_connection_options", false);
|
|
|
|
mHostname.setHint(useTor ? R.string.hostname_or_onion : R.string.hostname_example);
|
|
|
|
this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE);
|
2014-08-15 11:31:24 -04:00
|
|
|
}
|
2014-08-23 15:31:27 -04:00
|
|
|
|
2014-08-15 11:31:24 -04:00
|
|
|
@Override
|
|
|
|
protected void onBackendConnected() {
|
|
|
|
if (this.jidToEdit != null) {
|
|
|
|
this.mAccount = xmppConnectionService.findAccountByJid(jidToEdit);
|
2015-10-09 07:37:08 -04:00
|
|
|
if (this.mAccount != null) {
|
2016-04-22 15:25:06 -04:00
|
|
|
this.mInitMode |= this.mAccount.isOptionSet(Account.OPTION_REGISTER);
|
2015-10-09 07:37:08 -04:00
|
|
|
if (this.mAccount.getPrivateKeyAlias() != null) {
|
2015-10-11 09:48:58 -04:00
|
|
|
this.mPassword.setHint(R.string.authenticate_with_certificate);
|
|
|
|
if (this.mInitMode) {
|
|
|
|
this.mPassword.requestFocus();
|
|
|
|
}
|
2015-10-09 07:37:08 -04:00
|
|
|
}
|
2015-10-11 09:48:58 -04:00
|
|
|
updateAccountInformation(true);
|
2015-10-09 07:37:08 -04:00
|
|
|
}
|
2016-04-19 12:03:24 -04:00
|
|
|
}
|
2016-04-27 04:35:08 -04:00
|
|
|
if ((Config.MAGIC_CREATE_DOMAIN == null && this.xmppConnectionService.getAccounts().size() == 0)
|
|
|
|
|| (this.mAccount != null && this.mAccount == xmppConnectionService.getPendingAccount())) {
|
2014-12-21 15:43:58 -05:00
|
|
|
if (getActionBar() != null) {
|
|
|
|
getActionBar().setDisplayHomeAsUpEnabled(false);
|
|
|
|
getActionBar().setDisplayShowHomeEnabled(false);
|
2015-02-22 07:24:29 -05:00
|
|
|
getActionBar().setHomeButtonEnabled(false);
|
2014-12-21 15:43:58 -05:00
|
|
|
}
|
2014-08-15 11:31:24 -04:00
|
|
|
this.mCancelButton.setEnabled(false);
|
2014-08-23 15:31:27 -04:00
|
|
|
this.mCancelButton.setTextColor(getSecondaryTextColor());
|
2014-08-15 11:31:24 -04:00
|
|
|
}
|
2015-08-03 16:58:17 -04:00
|
|
|
if (Config.DOMAIN_LOCK == null) {
|
|
|
|
final KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this,
|
2016-04-29 07:48:30 -04:00
|
|
|
R.layout.simple_list_item,
|
2015-08-03 16:58:17 -04:00
|
|
|
xmppConnectionService.getKnownHosts());
|
|
|
|
this.mAccountJid.setAdapter(mKnownHostsAdapter);
|
|
|
|
}
|
2014-08-15 11:31:24 -04:00
|
|
|
updateSaveButton();
|
2015-10-25 17:46:06 -04:00
|
|
|
invalidateOptionsMenu();
|
2014-08-15 11:31:24 -04:00
|
|
|
}
|
|
|
|
|
2014-12-21 15:43:58 -05:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.action_show_block_list:
|
2015-01-02 18:11:02 -05:00
|
|
|
final Intent showBlocklistIntent = new Intent(this, BlocklistActivity.class);
|
2016-01-22 14:46:24 -05:00
|
|
|
showBlocklistIntent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toString());
|
2015-01-02 18:11:02 -05:00
|
|
|
startActivity(showBlocklistIntent);
|
2014-12-21 15:43:58 -05:00
|
|
|
break;
|
2014-10-21 16:22:01 -04:00
|
|
|
case R.id.action_server_info_show_more:
|
|
|
|
mMoreTable.setVisibility(item.isChecked() ? View.GONE : View.VISIBLE);
|
|
|
|
item.setChecked(!item.isChecked());
|
2015-01-02 18:11:02 -05:00
|
|
|
break;
|
|
|
|
case R.id.action_change_password_on_server:
|
2016-04-26 17:23:48 -04:00
|
|
|
gotoChangePassword(null);
|
2015-01-02 18:11:02 -05:00
|
|
|
break;
|
2016-02-09 07:01:17 -05:00
|
|
|
case R.id.action_mam_prefs:
|
|
|
|
editMamPrefs();
|
|
|
|
break;
|
2015-07-19 17:35:03 -04:00
|
|
|
case R.id.action_clear_devices:
|
|
|
|
showWipePepDialog();
|
|
|
|
break;
|
2015-10-11 09:48:58 -04:00
|
|
|
case R.id.action_renew_certificate:
|
|
|
|
renewCertificate();
|
|
|
|
break;
|
2016-04-22 15:25:06 -04:00
|
|
|
case R.id.action_change_presence:
|
|
|
|
changePresence();
|
|
|
|
break;
|
2014-12-21 15:43:58 -05:00
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
2016-04-26 17:23:48 -04: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 09:48:58 -04:00
|
|
|
private void renewCertificate() {
|
|
|
|
KeyChain.choosePrivateKeyAlias(this, this, null, null, null, -1, null);
|
|
|
|
}
|
|
|
|
|
2016-04-22 15:25:06 -04:00
|
|
|
private void changePresence() {
|
|
|
|
Intent intent = new Intent(this, SetPresenceActivity.class);
|
|
|
|
intent.putExtra(SetPresenceActivity.EXTRA_ACCOUNT,mAccount.getJid().toBareJid().toString());
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2015-10-11 09:48:58 -04:00
|
|
|
@Override
|
|
|
|
public void alias(String alias) {
|
|
|
|
if (alias != null) {
|
|
|
|
xmppConnectionService.updateKeyInAccount(mAccount, alias);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-16 07:42:52 -04:00
|
|
|
private void updateAccountInformation(boolean init) {
|
|
|
|
if (init) {
|
2015-10-13 10:58:08 -04:00
|
|
|
this.mAccountJid.getEditableText().clear();
|
2015-08-03 16:58:17 -04:00
|
|
|
if (Config.DOMAIN_LOCK != null) {
|
2015-10-13 10:58:08 -04:00
|
|
|
this.mAccountJid.getEditableText().append(this.mAccount.getJid().getLocalpart());
|
2015-08-03 16:58:17 -04:00
|
|
|
} else {
|
2015-10-13 10:58:08 -04:00
|
|
|
this.mAccountJid.getEditableText().append(this.mAccount.getJid().toBareJid().toString());
|
2015-08-03 16:58:17 -04:00
|
|
|
}
|
2015-07-16 07:42:52 -04:00
|
|
|
this.mPassword.setText(this.mAccount.getPassword());
|
2015-11-28 14:11:38 -05: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 15:17:53 -05:00
|
|
|
this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE);
|
2015-11-28 14:11:38 -05:00
|
|
|
|
2015-07-16 07:42:52 -04:00
|
|
|
}
|
2016-02-27 04:25:31 -05:00
|
|
|
|
2015-10-09 07:37:08 -04:00
|
|
|
if (!mInitMode) {
|
2014-11-06 10:51:50 -05:00
|
|
|
this.mAvatar.setVisibility(View.VISIBLE);
|
|
|
|
this.mAvatar.setImageBitmap(avatarService().get(this.mAccount, getPixel(72)));
|
2016-04-09 18:19:20 -04:00
|
|
|
} else {
|
|
|
|
this.mAvatar.setVisibility(View.GONE);
|
2014-11-06 10:51:50 -05:00
|
|
|
}
|
2014-08-15 11:31:24 -04:00
|
|
|
if (this.mAccount.isOptionSet(Account.OPTION_REGISTER)) {
|
|
|
|
this.mRegisterNew.setVisibility(View.VISIBLE);
|
|
|
|
this.mRegisterNew.setChecked(true);
|
|
|
|
this.mPasswordConfirm.setText(this.mAccount.getPassword());
|
|
|
|
} else {
|
|
|
|
this.mRegisterNew.setVisibility(View.GONE);
|
|
|
|
this.mRegisterNew.setChecked(false);
|
|
|
|
}
|
2014-12-25 16:28:19 -05:00
|
|
|
if (this.mAccount.isOnlineAndConnected() && !this.mFetchingAvatar) {
|
2016-03-06 09:53:49 -05:00
|
|
|
Features features = this.mAccount.getXmppConnection().getFeatures();
|
2014-08-19 09:06:50 -04:00
|
|
|
this.mStats.setVisibility(View.VISIBLE);
|
2016-03-06 09:53:49 -05:00
|
|
|
boolean showOptimizingWarning = !xmppConnectionService.getPushManagementService().available(mAccount) && isOptimizingBattery();
|
|
|
|
this.mBatteryOptimizations.setVisibility(showOptimizingWarning ? View.VISIBLE : View.GONE);
|
2014-12-25 16:08:13 -05:00
|
|
|
this.mSessionEst.setText(UIHelper.readableTimeDifferenceFull(this, this.mAccount.getXmppConnection()
|
2015-10-11 09:48:58 -04:00
|
|
|
.getLastSessionEstablished()));
|
2014-10-21 16:22:01 -04:00
|
|
|
if (features.rosterVersioning()) {
|
|
|
|
this.mServerInfoRosterVersion.setText(R.string.server_info_available);
|
|
|
|
} else {
|
|
|
|
this.mServerInfoRosterVersion.setText(R.string.server_info_unavailable);
|
|
|
|
}
|
2014-08-23 09:56:30 -04:00
|
|
|
if (features.carbons()) {
|
|
|
|
this.mServerInfoCarbons.setText(R.string.server_info_available);
|
|
|
|
} else {
|
2014-08-23 15:31:27 -04:00
|
|
|
this.mServerInfoCarbons
|
2015-10-11 09:48:58 -04:00
|
|
|
.setText(R.string.server_info_unavailable);
|
2014-08-23 09:56:30 -04:00
|
|
|
}
|
2014-10-21 16:22:01 -04:00
|
|
|
if (features.mam()) {
|
|
|
|
this.mServerInfoMam.setText(R.string.server_info_available);
|
|
|
|
} else {
|
|
|
|
this.mServerInfoMam.setText(R.string.server_info_unavailable);
|
|
|
|
}
|
|
|
|
if (features.csi()) {
|
|
|
|
this.mServerInfoCSI.setText(R.string.server_info_available);
|
|
|
|
} else {
|
|
|
|
this.mServerInfoCSI.setText(R.string.server_info_unavailable);
|
|
|
|
}
|
|
|
|
if (features.blocking()) {
|
|
|
|
this.mServerInfoBlocking.setText(R.string.server_info_available);
|
|
|
|
} else {
|
|
|
|
this.mServerInfoBlocking.setText(R.string.server_info_unavailable);
|
|
|
|
}
|
2014-08-23 09:56:30 -04:00
|
|
|
if (features.sm()) {
|
|
|
|
this.mServerInfoSm.setText(R.string.server_info_available);
|
|
|
|
} else {
|
|
|
|
this.mServerInfoSm.setText(R.string.server_info_unavailable);
|
|
|
|
}
|
2015-04-25 12:24:10 -04:00
|
|
|
if (features.pep()) {
|
2015-09-06 13:40:28 -04:00
|
|
|
AxolotlService axolotlService = this.mAccount.getAxolotlService();
|
|
|
|
if (axolotlService != null && axolotlService.isPepBroken()) {
|
|
|
|
this.mServerInfoPep.setText(R.string.server_info_broken);
|
|
|
|
} else {
|
|
|
|
this.mServerInfoPep.setText(R.string.server_info_available);
|
|
|
|
}
|
2014-08-23 09:56:30 -04:00
|
|
|
} else {
|
|
|
|
this.mServerInfoPep.setText(R.string.server_info_unavailable);
|
|
|
|
}
|
2016-03-31 15:56:59 -04:00
|
|
|
if (features.httpUpload(0)) {
|
2015-08-14 16:24:05 -04:00
|
|
|
this.mServerInfoHttpUpload.setText(R.string.server_info_available);
|
|
|
|
} else {
|
|
|
|
this.mServerInfoHttpUpload.setText(R.string.server_info_unavailable);
|
|
|
|
}
|
2016-02-12 05:39:27 -05:00
|
|
|
|
2016-02-14 12:19:11 -05:00
|
|
|
this.mPushRow.setVisibility(xmppConnectionService.getPushManagementService().isStub() ? View.GONE : View.VISIBLE);
|
2016-02-12 05:39:27 -05:00
|
|
|
|
2016-02-14 12:19:11 -05:00
|
|
|
if (xmppConnectionService.getPushManagementService().available(mAccount)) {
|
2016-02-12 05:39:27 -05:00
|
|
|
this.mServerInfoPush.setText(R.string.server_info_available);
|
|
|
|
} else {
|
|
|
|
this.mServerInfoPush.setText(R.string.server_info_unavailable);
|
|
|
|
}
|
2015-07-07 13:36:22 -04:00
|
|
|
final String otrFingerprint = this.mAccount.getOtrFingerprint();
|
|
|
|
if (otrFingerprint != null) {
|
2014-10-13 08:36:19 -04:00
|
|
|
this.mOtrFingerprintBox.setVisibility(View.VISIBLE);
|
2015-07-07 13:36:22 -04:00
|
|
|
this.mOtrFingerprint.setText(CryptoHelper.prettifyFingerprint(otrFingerprint));
|
2014-10-05 06:05:27 -04:00
|
|
|
this.mOtrFingerprintToClipboardButton
|
2015-10-11 09:48:58 -04:00
|
|
|
.setVisibility(View.VISIBLE);
|
2014-10-03 09:55:06 -04:00
|
|
|
this.mOtrFingerprintToClipboardButton
|
2015-10-11 09:48:58 -04:00
|
|
|
.setOnClickListener(new View.OnClickListener() {
|
2014-10-03 09:55:06 -04:00
|
|
|
|
2015-10-11 09:48:58 -04:00
|
|
|
@Override
|
|
|
|
public void onClick(final View v) {
|
2014-10-03 09:55:06 -04:00
|
|
|
|
2015-10-11 09:48:58 -04:00
|
|
|
if (copyTextToClipboard(otrFingerprint, R.string.otr_fingerprint)) {
|
|
|
|
Toast.makeText(
|
|
|
|
EditAccountActivity.this,
|
|
|
|
R.string.toast_message_otr_fingerprint,
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
2014-10-03 09:55:06 -04:00
|
|
|
}
|
2015-10-11 09:48:58 -04:00
|
|
|
});
|
2014-08-20 05:32:49 -04:00
|
|
|
} else {
|
2014-10-13 08:36:19 -04:00
|
|
|
this.mOtrFingerprintBox.setVisibility(View.GONE);
|
2014-08-20 05:32:49 -04:00
|
|
|
}
|
2015-09-06 09:08:42 -04:00
|
|
|
final String axolotlFingerprint = this.mAccount.getAxolotlService().getOwnFingerprint();
|
2015-07-07 13:36:22 -04:00
|
|
|
if (axolotlFingerprint != null) {
|
|
|
|
this.mAxolotlFingerprintBox.setVisibility(View.VISIBLE);
|
2016-01-03 13:38:48 -05:00
|
|
|
this.mAxolotlFingerprint.setText(CryptoHelper.prettifyFingerprint(axolotlFingerprint.substring(2)));
|
2015-07-07 13:36:22 -04:00
|
|
|
this.mAxolotlFingerprintToClipboardButton
|
|
|
|
.setVisibility(View.VISIBLE);
|
|
|
|
this.mAxolotlFingerprintToClipboardButton
|
|
|
|
.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(final View v) {
|
|
|
|
|
2016-01-03 13:38:48 -05:00
|
|
|
if (copyTextToClipboard(axolotlFingerprint.substring(2), R.string.omemo_fingerprint)) {
|
2015-07-07 13:36:22 -04:00
|
|
|
Toast.makeText(
|
|
|
|
EditAccountActivity.this,
|
2015-08-08 07:29:21 -04:00
|
|
|
R.string.toast_message_omemo_fingerprint,
|
2015-07-07 13:36:22 -04:00
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-07-21 19:00:20 -04:00
|
|
|
if (Config.SHOW_REGENERATE_AXOLOTL_KEYS_BUTTON) {
|
|
|
|
this.mRegenerateAxolotlKeyButton
|
|
|
|
.setVisibility(View.VISIBLE);
|
|
|
|
this.mRegenerateAxolotlKeyButton
|
|
|
|
.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(final View v) {
|
|
|
|
showRegenerateAxolotlKeyDialog();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-07-07 13:36:22 -04:00
|
|
|
} else {
|
|
|
|
this.mAxolotlFingerprintBox.setVisibility(View.GONE);
|
|
|
|
}
|
2015-09-06 09:08:42 -04:00
|
|
|
final String ownFingerprint = mAccount.getAxolotlService().getOwnFingerprint();
|
2015-07-19 08:09:49 -04:00
|
|
|
boolean hasKeys = false;
|
|
|
|
keys.removeAllViews();
|
2015-09-06 09:08:42 -04:00
|
|
|
for (final String fingerprint : mAccount.getAxolotlService().getFingerprintsForOwnSessions()) {
|
2015-10-11 09:48:58 -04:00
|
|
|
if (ownFingerprint.equals(fingerprint)) {
|
2015-07-19 08:09:49 -04:00
|
|
|
continue;
|
|
|
|
}
|
2015-09-06 09:08:42 -04:00
|
|
|
boolean highlight = fingerprint.equals(messageFingerprint);
|
2015-12-23 13:18:53 -05:00
|
|
|
hasKeys |= addFingerprintRow(keys, mAccount, fingerprint, highlight, null);
|
2015-07-19 08:09:49 -04:00
|
|
|
}
|
|
|
|
if (hasKeys) {
|
|
|
|
keysCard.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
keysCard.setVisibility(View.GONE);
|
|
|
|
}
|
2014-08-19 09:06:50 -04:00
|
|
|
} else {
|
|
|
|
if (this.mAccount.errorStatus()) {
|
2016-01-25 15:17:53 -05:00
|
|
|
final EditText errorTextField;
|
|
|
|
if (this.mAccount.getStatus() == Account.State.UNAUTHORIZED) {
|
|
|
|
errorTextField = this.mPassword;
|
|
|
|
} else if (mShowOptions
|
|
|
|
&& this.mAccount.getStatus() == Account.State.SERVER_NOT_FOUND
|
|
|
|
&& this.mHostname.getText().length() > 0) {
|
|
|
|
errorTextField = this.mHostname;
|
|
|
|
} else {
|
|
|
|
errorTextField = this.mAccountJid;
|
|
|
|
}
|
|
|
|
errorTextField.setError(getString(this.mAccount.getStatus().getReadableId()));
|
2015-07-17 07:14:24 -04:00
|
|
|
if (init || !accountInfoEdited()) {
|
2016-01-25 15:17:53 -05:00
|
|
|
errorTextField.requestFocus();
|
2015-07-16 08:06:54 -04:00
|
|
|
}
|
2015-02-26 11:17:40 -05:00
|
|
|
} else {
|
|
|
|
this.mAccountJid.setError(null);
|
2016-01-25 15:17:53 -05:00
|
|
|
this.mPassword.setError(null);
|
|
|
|
this.mHostname.setError(null);
|
2014-08-19 09:06:50 -04:00
|
|
|
}
|
|
|
|
this.mStats.setVisibility(View.GONE);
|
|
|
|
}
|
2014-08-15 11:31:24 -04:00
|
|
|
}
|
2015-07-07 13:36:22 -04:00
|
|
|
|
|
|
|
public void showRegenerateAxolotlKeyDialog() {
|
|
|
|
Builder builder = new Builder(this);
|
|
|
|
builder.setTitle("Regenerate Key");
|
|
|
|
builder.setIconAttribute(android.R.attr.alertDialogIcon);
|
|
|
|
builder.setMessage("Are you sure you want to regenerate your Identity Key? (This will also wipe all established sessions and contact Identity Keys)");
|
|
|
|
builder.setNegativeButton(getString(R.string.cancel), null);
|
|
|
|
builder.setPositiveButton("Yes",
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2015-10-11 09:48:58 -04:00
|
|
|
mAccount.getAxolotlService().regenerateKeys(false);
|
2015-07-07 13:36:22 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.create().show();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showWipePepDialog() {
|
|
|
|
Builder builder = new Builder(this);
|
2015-07-19 17:35:03 -04:00
|
|
|
builder.setTitle(getString(R.string.clear_other_devices));
|
2015-07-07 13:36:22 -04:00
|
|
|
builder.setIconAttribute(android.R.attr.alertDialogIcon);
|
2015-07-19 17:35:03 -04:00
|
|
|
builder.setMessage(getString(R.string.clear_other_devices_desc));
|
2015-07-07 13:36:22 -04:00
|
|
|
builder.setNegativeButton(getString(R.string.cancel), null);
|
2015-07-19 17:35:03 -04:00
|
|
|
builder.setPositiveButton(getString(R.string.accept),
|
2015-07-07 13:36:22 -04:00
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
mAccount.getAxolotlService().wipeOtherPepDevices();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.create().show();
|
|
|
|
}
|
2015-07-21 08:18:16 -04:00
|
|
|
|
2016-02-09 07:01:17 -05: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 08:18:16 -04:00
|
|
|
@Override
|
2015-10-17 08:09:26 -04:00
|
|
|
public void onKeyStatusUpdated(AxolotlService.FetchStatus report) {
|
2015-07-21 08:18:16 -04:00
|
|
|
refreshUi();
|
|
|
|
}
|
2015-10-11 07:11:50 -04:00
|
|
|
|
|
|
|
@Override
|
2016-04-28 14:13:58 -04:00
|
|
|
public void onCaptchaRequested(final Account account, final String id, final Data data, final Bitmap captcha) {
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if ((mCaptchaDialog != null) && mCaptchaDialog.isShowing()) {
|
|
|
|
mCaptchaDialog.dismiss();
|
|
|
|
}
|
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(EditAccountActivity.this);
|
|
|
|
final View view = getLayoutInflater().inflate(R.layout.captcha, null);
|
|
|
|
final ImageView imageView = (ImageView) view.findViewById(R.id.captcha);
|
|
|
|
final EditText input = (EditText) view.findViewById(R.id.input);
|
|
|
|
imageView.setImageBitmap(captcha);
|
2015-10-11 07:11:50 -04:00
|
|
|
|
2016-04-28 14:13:58 -04:00
|
|
|
builder.setTitle(getString(R.string.captcha_required));
|
|
|
|
builder.setView(view);
|
2015-10-11 07:11:50 -04:00
|
|
|
|
2016-04-28 14:13:58 -04:00
|
|
|
builder.setPositiveButton(getString(R.string.ok),
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
2015-10-11 07:11:50 -04:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2016-04-28 14:13:58 -04:00
|
|
|
if (xmppConnectionService != null) {
|
|
|
|
xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null);
|
2015-10-11 07:11:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-04-28 14:13:58 -04:00
|
|
|
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
|
|
|
@Override
|
|
|
|
public void onCancel(DialogInterface dialog) {
|
|
|
|
if (xmppConnectionService != null) {
|
|
|
|
xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-10-11 07:11:50 -04:00
|
|
|
mCaptchaDialog = builder.create();
|
|
|
|
mCaptchaDialog.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-10-11 09:48:58 -04:00
|
|
|
|
|
|
|
public void onShowErrorToast(final int resId) {
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
Toast.makeText(EditAccountActivity.this, resId, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-02-09 07:01:17 -05:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPreferencesFetched(final Element prefs) {
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (mFetchingMamPrefsToast != null) {
|
|
|
|
mFetchingMamPrefsToast.cancel();
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new Builder(EditAccountActivity.this);
|
2016-02-16 06:52:31 -05:00
|
|
|
builder.setTitle(R.string.server_side_mam_prefs);
|
2016-02-09 07:01:17 -05:00
|
|
|
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(), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
choice.set(which);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(R.string.cancel, null);
|
|
|
|
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
prefs.setAttribute("default",defaults.get(choice.get()));
|
|
|
|
xmppConnectionService.pushMamPreferences(mAccount, prefs);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.create().show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPreferencesFetchFailed() {
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (mFetchingMamPrefsToast != null) {
|
|
|
|
mFetchingMamPrefsToast.cancel();
|
|
|
|
}
|
|
|
|
Toast.makeText(EditAccountActivity.this,R.string.unable_to_fetch_mam_prefs,Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-08-15 11:31:24 -04:00
|
|
|
}
|