2014-08-15 11:31:24 -04:00
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
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;
|
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
|
|
|
|
2014-08-15 11:31:24 -04:00
|
|
|
import eu.siacs.conversations.R;
|
|
|
|
import eu.siacs.conversations.entities.Account;
|
|
|
|
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;
|
2014-08-23 09:56:30 -04:00
|
|
|
import eu.siacs.conversations.xmpp.XmppConnection.Features;
|
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;
|
|
|
|
|
2014-11-11 11:39:28 -05:00
|
|
|
public class EditAccountActivity extends XmppActivity implements OnAccountUpdate {
|
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;
|
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;
|
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;
|
2014-08-19 09:06:50 -04:00
|
|
|
private TextView mSessionEst;
|
2014-08-20 05:32:49 -04:00
|
|
|
private TextView mOtrFingerprint;
|
2014-11-04 11:38:41 -05:00
|
|
|
private ImageView mAvatar;
|
2014-10-13 08:36:19 -04:00
|
|
|
private RelativeLayout mOtrFingerprintBox;
|
2014-10-03 09:55:06 -04:00
|
|
|
private ImageButton mOtrFingerprintToClipboardButton;
|
2014-08-19 09:06:50 -04:00
|
|
|
|
2014-11-06 14:33:13 -05:00
|
|
|
private Jid jidToEdit;
|
2014-08-15 11:31:24 -04:00
|
|
|
private Account mAccount;
|
|
|
|
|
|
|
|
private boolean mFetchingAvatar = false;
|
2014-08-19 09:06:50 -04:00
|
|
|
|
2014-08-15 11:31:24 -04:00
|
|
|
private OnClickListener mSaveButtonClickListener = new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
2014-12-23 13:23:13 -05:00
|
|
|
public void onClick(final View v) {
|
2014-10-05 06:05:27 -04:00
|
|
|
if (mAccount != null
|
2014-11-15 11:09:02 -05:00
|
|
|
&& mAccount.getStatus() == Account.State.DISABLED) {
|
2014-10-05 06:05:27 -04:00
|
|
|
mAccount.setOption(Account.OPTION_DISABLED, false);
|
|
|
|
xmppConnectionService.updateAccount(mAccount);
|
|
|
|
return;
|
2014-12-21 15:43:58 -05:00
|
|
|
}
|
2014-12-23 13:23:13 -05:00
|
|
|
final boolean registerNewAccount = mRegisterNew.isChecked();
|
2014-12-03 04:52:55 -05:00
|
|
|
final Jid jid;
|
|
|
|
try {
|
|
|
|
jid = Jid.fromString(mAccountJid.getText().toString());
|
|
|
|
} catch (final InvalidJidException e) {
|
|
|
|
mAccountJid.setError(getString(R.string.invalid_jid));
|
|
|
|
mAccountJid.requestFocus();
|
|
|
|
return;
|
|
|
|
}
|
2014-12-23 17:35:36 -05:00
|
|
|
if (jid.isDomainJid()) {
|
|
|
|
mAccountJid.setError(getString(R.string.invalid_jid));
|
|
|
|
mAccountJid.requestFocus();
|
|
|
|
return;
|
|
|
|
}
|
2014-12-23 13:23:13 -05:00
|
|
|
final String password = mPassword.getText().toString();
|
|
|
|
final String passwordConfirm = mPasswordConfirm.getText().toString();
|
2014-08-15 11:31:24 -04:00
|
|
|
if (registerNewAccount) {
|
|
|
|
if (!password.equals(passwordConfirm)) {
|
|
|
|
mPasswordConfirm
|
2014-12-21 15:43:58 -05:00
|
|
|
.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) {
|
|
|
|
mAccount.setPassword(password);
|
2014-12-21 15:43:58 -05:00
|
|
|
try {
|
|
|
|
mAccount.setUsername(jid.hasLocalpart() ? jid.getLocalpart() : "");
|
|
|
|
mAccount.setServer(jid.getDomainpart());
|
|
|
|
} catch (final InvalidJidException ignored) {
|
|
|
|
}
|
2014-08-23 15:31:27 -04:00
|
|
|
mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
|
2014-08-15 11:31:24 -04:00
|
|
|
xmppConnectionService.updateAccount(mAccount);
|
|
|
|
} else {
|
2014-12-21 15:43:58 -05:00
|
|
|
try {
|
|
|
|
if (xmppConnectionService.findAccountByJid(Jid.fromString(mAccountJid.getText().toString())) != null) {
|
|
|
|
mAccountJid
|
|
|
|
.setError(getString(R.string.account_already_exists));
|
|
|
|
mAccountJid.requestFocus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch (InvalidJidException e) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mAccount = new Account(jid.toBareJid(), password);
|
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);
|
|
|
|
}
|
|
|
|
if (jidToEdit != null) {
|
|
|
|
finish();
|
|
|
|
} else {
|
|
|
|
updateSaveButton();
|
|
|
|
updateAccountInformation();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
private OnClickListener mCancelButtonClickListener = new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
};
|
2014-12-21 15:43:58 -05:00
|
|
|
@Override
|
|
|
|
public void onAccountUpdate() {
|
|
|
|
runOnUiThread(new Runnable() {
|
2014-08-15 11:31:24 -04:00
|
|
|
|
2014-12-21 15:43:58 -05:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (mAccount != null
|
|
|
|
&& mAccount.getStatus() != Account.State.ONLINE
|
|
|
|
&& mFetchingAvatar) {
|
|
|
|
startActivity(new Intent(getApplicationContext(),
|
2014-08-23 15:31:27 -04:00
|
|
|
ManageAccountActivity.class));
|
2014-12-21 15:43:58 -05:00
|
|
|
finish();
|
|
|
|
} else if (jidToEdit == null && mAccount != null
|
|
|
|
&& mAccount.getStatus() == Account.State.ONLINE) {
|
|
|
|
if (!mFetchingAvatar) {
|
|
|
|
mFetchingAvatar = true;
|
|
|
|
xmppConnectionService.checkForAvatar(mAccount,
|
|
|
|
mAvatarFetchCallback);
|
2014-08-20 05:32:49 -04:00
|
|
|
}
|
2014-12-21 15:43:58 -05:00
|
|
|
} else {
|
|
|
|
updateSaveButton();
|
2014-08-15 11:31:24 -04:00
|
|
|
}
|
2014-12-21 15:43:58 -05:00
|
|
|
if (mAccount != null) {
|
|
|
|
updateAccountInformation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-08-15 11:31:24 -04:00
|
|
|
private UiCallback<Avatar> mAvatarFetchCallback = new UiCallback<Avatar>() {
|
2014-08-19 09:06:50 -04:00
|
|
|
|
2014-08-15 11:31:24 -04:00
|
|
|
@Override
|
|
|
|
public void userInputRequried(PendingIntent pi, Avatar avatar) {
|
|
|
|
finishInitialSetup(avatar);
|
|
|
|
}
|
2014-08-19 09:06:50 -04:00
|
|
|
|
2014-08-15 11:31:24 -04:00
|
|
|
@Override
|
|
|
|
public void success(Avatar avatar) {
|
|
|
|
finishInitialSetup(avatar);
|
|
|
|
}
|
2014-08-19 09:06:50 -04:00
|
|
|
|
2014-08-15 11:31:24 -04:00
|
|
|
@Override
|
|
|
|
public void error(int errorCode, Avatar avatar) {
|
|
|
|
finishInitialSetup(avatar);
|
|
|
|
}
|
|
|
|
};
|
2014-12-21 15:43:58 -05:00
|
|
|
private TextWatcher mTextWatcher = new TextWatcher() {
|
2014-10-05 06:05:27 -04:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before,
|
2014-12-21 15:43:58 -05:00
|
|
|
int count) {
|
2014-10-05 06:05:27 -04:00
|
|
|
updateSaveButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count,
|
2014-12-21 15:43:58 -05:00
|
|
|
int after) {
|
2014-10-05 06:05:27 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
2014-11-04 11:38:41 -05:00
|
|
|
private OnClickListener mAvatarClickListener = new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
if (mAccount!=null) {
|
|
|
|
Intent intent = new Intent(getApplicationContext(),
|
|
|
|
PublishProfilePictureActivity.class);
|
2014-11-09 10:57:22 -05:00
|
|
|
intent.putExtra("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-08-16 03:44:37 -04:00
|
|
|
Intent intent;
|
2014-08-19 09:06:50 -04:00
|
|
|
if (avatar != null) {
|
|
|
|
intent = new Intent(getApplicationContext(),
|
|
|
|
StartConversationActivity.class);
|
2014-08-16 03:44:37 -04:00
|
|
|
} else {
|
2014-08-19 09:06:50 -04:00
|
|
|
intent = new Intent(getApplicationContext(),
|
|
|
|
PublishProfilePictureActivity.class);
|
2014-11-09 10:57:22 -05:00
|
|
|
intent.putExtra("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
|
|
|
}
|
|
|
|
startActivity(intent);
|
|
|
|
finish();
|
2014-08-15 11:31:24 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-08-19 09:06:50 -04:00
|
|
|
|
2014-08-15 11:31:24 -04:00
|
|
|
protected void updateSaveButton() {
|
2014-08-16 03:44:37 -04:00
|
|
|
if (mAccount != null
|
2014-11-15 11:09:02 -05:00
|
|
|
&& mAccount.getStatus() == Account.State.CONNECTING) {
|
2014-08-15 11:31:24 -04:00
|
|
|
this.mSaveButton.setEnabled(false);
|
|
|
|
this.mSaveButton.setTextColor(getSecondaryTextColor());
|
|
|
|
this.mSaveButton.setText(R.string.account_status_connecting);
|
2014-10-05 06:05:27 -04:00
|
|
|
} else if (mAccount != null
|
2014-11-15 11:09:02 -05:00
|
|
|
&& mAccount.getStatus() == Account.State.DISABLED) {
|
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());
|
2014-08-19 09:06:50 -04:00
|
|
|
if (jidToEdit != null) {
|
2014-08-31 10:28:21 -04:00
|
|
|
if (mAccount != null
|
2014-11-15 11:09:02 -05:00
|
|
|
&& mAccount.getStatus() == Account.State.ONLINE) {
|
2014-08-29 04:24:25 -04:00
|
|
|
this.mSaveButton.setText(R.string.save);
|
2014-10-05 06:05:27 -04:00
|
|
|
if (!accountInfoEdited()) {
|
|
|
|
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() {
|
2014-11-09 10:57:22 -05:00
|
|
|
return (!this.mAccount.getJid().toBareJid().equals(
|
2014-12-21 15:43:58 -05:00
|
|
|
this.mAccountJid.getText().toString()))
|
|
|
|
|| (!this.mAccount.getPassword().equals(
|
|
|
|
this.mPassword.getText().toString()));
|
2014-10-05 06:05:27 -04:00
|
|
|
}
|
|
|
|
|
2014-11-04 06:15:14 -05:00
|
|
|
@Override
|
|
|
|
protected String getShareableUri() {
|
|
|
|
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
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
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);
|
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);
|
|
|
|
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);
|
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);
|
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-08-15 11:31:24 -04:00
|
|
|
this.mRegisterNew
|
2014-12-21 15:43:58 -05:00
|
|
|
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView,
|
|
|
|
boolean isChecked) {
|
|
|
|
if (isChecked) {
|
|
|
|
mPasswordConfirm.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
mPasswordConfirm.setVisibility(View.GONE);
|
2014-08-15 11:31:24 -04:00
|
|
|
}
|
2014-12-21 15:43:58 -05:00
|
|
|
updateSaveButton();
|
|
|
|
}
|
|
|
|
});
|
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);
|
2014-11-03 16:47:07 -05:00
|
|
|
if (mAccount == null) {
|
|
|
|
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);
|
2014-12-22 10:50:29 -05:00
|
|
|
} else if (mAccount.getStatus() != Account.State.ONLINE || !mAccount.getXmppConnection().getFeatures().blocking()) {
|
2014-12-21 15:43:58 -05:00
|
|
|
showBlocklist.setVisible(false);
|
2014-12-23 17:12:52 -05:00
|
|
|
showMoreInfo.setVisible(false);
|
2014-11-03 16:47:07 -05:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
if (this.jidToEdit != null) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-23 15:31:27 -04:00
|
|
|
|
2014-08-15 11:31:24 -04:00
|
|
|
@Override
|
|
|
|
protected void onBackendConnected() {
|
2014-12-21 15:43:58 -05:00
|
|
|
final KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this,
|
|
|
|
android.R.layout.simple_list_item_1,
|
|
|
|
xmppConnectionService.getKnownHosts());
|
2014-08-15 11:31:24 -04:00
|
|
|
if (this.jidToEdit != null) {
|
|
|
|
this.mAccount = xmppConnectionService.findAccountByJid(jidToEdit);
|
|
|
|
updateAccountInformation();
|
|
|
|
} else if (this.xmppConnectionService.getAccounts().size() == 0) {
|
2014-12-21 15:43:58 -05:00
|
|
|
if (getActionBar() != null) {
|
|
|
|
getActionBar().setDisplayHomeAsUpEnabled(false);
|
|
|
|
getActionBar().setDisplayShowHomeEnabled(false);
|
|
|
|
}
|
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
|
|
|
}
|
2014-11-06 14:33:13 -05:00
|
|
|
this.mAccountJid.setAdapter(mKnownHostsAdapter);
|
2014-08-15 11:31:24 -04:00
|
|
|
updateSaveButton();
|
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
final Intent intent = new Intent(this, BlocklistActivity.class);
|
|
|
|
intent.putExtra("account", mAccount.getJid().toString());
|
|
|
|
startActivity(intent);
|
|
|
|
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());
|
2014-12-21 15:43:58 -05:00
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
2014-08-15 11:31:24 -04:00
|
|
|
private void updateAccountInformation() {
|
2014-11-09 10:57:22 -05:00
|
|
|
this.mAccountJid.setText(this.mAccount.getJid().toBareJid().toString());
|
2014-08-15 11:31:24 -04:00
|
|
|
this.mPassword.setText(this.mAccount.getPassword());
|
2014-11-06 10:51:50 -05:00
|
|
|
if (this.jidToEdit != null) {
|
|
|
|
this.mAvatar.setVisibility(View.VISIBLE);
|
|
|
|
this.mAvatar.setImageBitmap(avatarService().get(this.mAccount, getPixel(72)));
|
|
|
|
}
|
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-11-15 11:09:02 -05:00
|
|
|
if (this.mAccount.getStatus() == Account.State.ONLINE
|
2014-08-23 15:31:27 -04:00
|
|
|
&& !this.mFetchingAvatar) {
|
2014-08-19 09:06:50 -04:00
|
|
|
this.mStats.setVisibility(View.VISIBLE);
|
2014-10-21 16:22:01 -04:00
|
|
|
this.mSessionEst.setText(UIHelper.readableTimeDifference(
|
2014-12-21 15:43:58 -05:00
|
|
|
getApplicationContext(), this.mAccount.getXmppConnection()
|
|
|
|
.getLastSessionEstablished()));
|
2014-10-21 16:22:01 -04:00
|
|
|
Features features = this.mAccount.getXmppConnection().getFeatures();
|
|
|
|
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
|
2014-12-21 15:43:58 -05: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);
|
|
|
|
}
|
|
|
|
if (features.pubsub()) {
|
|
|
|
this.mServerInfoPep.setText(R.string.server_info_available);
|
|
|
|
} else {
|
|
|
|
this.mServerInfoPep.setText(R.string.server_info_unavailable);
|
|
|
|
}
|
2014-11-15 18:20:20 -05:00
|
|
|
final String fingerprint = this.mAccount.getOtrFingerprint();
|
2014-08-23 15:31:27 -04:00
|
|
|
if (fingerprint != null) {
|
2014-10-13 08:36:19 -04:00
|
|
|
this.mOtrFingerprintBox.setVisibility(View.VISIBLE);
|
2014-11-15 18:20:20 -05:00
|
|
|
this.mOtrFingerprint.setText(CryptoHelper.prettifyFingerprint(fingerprint));
|
2014-10-05 06:05:27 -04:00
|
|
|
this.mOtrFingerprintToClipboardButton
|
2014-12-21 15:43:58 -05:00
|
|
|
.setVisibility(View.VISIBLE);
|
2014-10-03 09:55:06 -04:00
|
|
|
this.mOtrFingerprintToClipboardButton
|
2014-12-21 15:43:58 -05:00
|
|
|
.setOnClickListener(new View.OnClickListener() {
|
2014-10-03 09:55:06 -04:00
|
|
|
|
2014-12-21 15:43:58 -05:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2014-10-03 09:55:06 -04:00
|
|
|
|
2014-12-21 15:43:58 -05:00
|
|
|
if (copyTextToClipboard(fingerprint, 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
|
|
|
}
|
2014-12-21 15:43:58 -05: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
|
|
|
}
|
2014-08-19 09:06:50 -04:00
|
|
|
} else {
|
|
|
|
if (this.mAccount.errorStatus()) {
|
2014-11-15 11:31:15 -05:00
|
|
|
this.mAccountJid.setError(getString(this.mAccount.getStatus().getReadableId()));
|
2014-08-19 09:06:50 -04:00
|
|
|
this.mAccountJid.requestFocus();
|
|
|
|
}
|
|
|
|
this.mStats.setVisibility(View.GONE);
|
|
|
|
}
|
2014-08-15 11:31:24 -04:00
|
|
|
}
|
|
|
|
}
|