1package eu.siacs.conversations.ui;
2
3import android.app.AlertDialog.Builder;
4import android.app.PendingIntent;
5import android.content.DialogInterface;
6import android.content.Intent;
7import android.os.Bundle;
8import android.text.Editable;
9import android.text.TextWatcher;
10import android.view.Menu;
11import android.view.MenuItem;
12import android.view.View;
13import android.view.View.OnClickListener;
14import android.widget.AutoCompleteTextView;
15import android.widget.Button;
16import android.widget.CheckBox;
17import android.widget.CompoundButton;
18import android.widget.CompoundButton.OnCheckedChangeListener;
19import android.widget.EditText;
20import android.widget.ImageButton;
21import android.widget.ImageView;
22import android.widget.LinearLayout;
23import android.widget.RelativeLayout;
24import android.widget.TableLayout;
25import android.widget.TextView;
26import android.widget.Toast;
27
28import org.whispersystems.libaxolotl.IdentityKey;
29
30import java.util.Set;
31
32import eu.siacs.conversations.Config;
33import eu.siacs.conversations.R;
34import eu.siacs.conversations.entities.Account;
35import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
36import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
37import eu.siacs.conversations.utils.CryptoHelper;
38import eu.siacs.conversations.utils.UIHelper;
39import eu.siacs.conversations.xmpp.OnKeyStatusUpdated;
40import eu.siacs.conversations.xmpp.XmppConnection.Features;
41import eu.siacs.conversations.xmpp.jid.InvalidJidException;
42import eu.siacs.conversations.xmpp.jid.Jid;
43import eu.siacs.conversations.xmpp.pep.Avatar;
44
45public class EditAccountActivity extends XmppActivity implements OnAccountUpdate, OnKeyStatusUpdated {
46
47 private AutoCompleteTextView mAccountJid;
48 private EditText mPassword;
49 private EditText mPasswordConfirm;
50 private CheckBox mRegisterNew;
51 private Button mCancelButton;
52 private Button mSaveButton;
53 private TableLayout mMoreTable;
54
55 private LinearLayout mStats;
56 private TextView mServerInfoSm;
57 private TextView mServerInfoRosterVersion;
58 private TextView mServerInfoCarbons;
59 private TextView mServerInfoMam;
60 private TextView mServerInfoCSI;
61 private TextView mServerInfoBlocking;
62 private TextView mServerInfoPep;
63 private TextView mServerInfoHttpUpload;
64 private TextView mSessionEst;
65 private TextView mOtrFingerprint;
66 private TextView mAxolotlFingerprint;
67 private TextView mAccountJidLabel;
68 private ImageView mAvatar;
69 private RelativeLayout mOtrFingerprintBox;
70 private RelativeLayout mAxolotlFingerprintBox;
71 private ImageButton mOtrFingerprintToClipboardButton;
72 private ImageButton mAxolotlFingerprintToClipboardButton;
73 private ImageButton mRegenerateAxolotlKeyButton;
74 private LinearLayout keys;
75 private LinearLayout keysCard;
76
77 private Jid jidToEdit;
78 private Account mAccount;
79 private String messageFingerprint;
80
81 private boolean mFetchingAvatar = false;
82
83 private final OnClickListener mSaveButtonClickListener = new OnClickListener() {
84
85 @Override
86 public void onClick(final View v) {
87 if (mAccount != null && mAccount.getStatus() == Account.State.DISABLED && !accountInfoEdited()) {
88 mAccount.setOption(Account.OPTION_DISABLED, false);
89 xmppConnectionService.updateAccount(mAccount);
90 return;
91 }
92 final boolean registerNewAccount = mRegisterNew.isChecked() && !Config.DISALLOW_REGISTRATION_IN_UI;
93 if (Config.DOMAIN_LOCK != null && mAccountJid.getText().toString().contains("@")) {
94 mAccountJid.setError(getString(R.string.invalid_username));
95 mAccountJid.requestFocus();
96 return;
97 }
98 final Jid jid;
99 try {
100 if (Config.DOMAIN_LOCK != null) {
101 jid = Jid.fromParts(mAccountJid.getText().toString(),Config.DOMAIN_LOCK,null);
102 } else {
103 jid = Jid.fromString(mAccountJid.getText().toString());
104 }
105 } catch (final InvalidJidException e) {
106 if (Config.DOMAIN_LOCK != null) {
107 mAccountJid.setError(getString(R.string.invalid_username));
108 } else {
109 mAccountJid.setError(getString(R.string.invalid_jid));
110 }
111 mAccountJid.requestFocus();
112 return;
113 }
114 if (jid.isDomainJid()) {
115 if (Config.DOMAIN_LOCK != null) {
116 mAccountJid.setError(getString(R.string.invalid_username));
117 } else {
118 mAccountJid.setError(getString(R.string.invalid_jid));
119 }
120 mAccountJid.requestFocus();
121 return;
122 }
123 final String password = mPassword.getText().toString();
124 final String passwordConfirm = mPasswordConfirm.getText().toString();
125 if (registerNewAccount) {
126 if (!password.equals(passwordConfirm)) {
127 mPasswordConfirm.setError(getString(R.string.passwords_do_not_match));
128 mPasswordConfirm.requestFocus();
129 return;
130 }
131 }
132 if (mAccount != null) {
133 try {
134 mAccount.setUsername(jid.hasLocalpart() ? jid.getLocalpart() : "");
135 mAccount.setServer(jid.getDomainpart());
136 } catch (final InvalidJidException ignored) {
137 return;
138 }
139 mAccountJid.setError(null);
140 mPasswordConfirm.setError(null);
141 mAccount.setPassword(password);
142 mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
143 xmppConnectionService.updateAccount(mAccount);
144 } else {
145 if (xmppConnectionService.findAccountByJid(jid) != null) {
146 mAccountJid.setError(getString(R.string.account_already_exists));
147 mAccountJid.requestFocus();
148 return;
149 }
150 mAccount = new Account(jid.toBareJid(), password);
151 mAccount.setOption(Account.OPTION_USETLS, true);
152 mAccount.setOption(Account.OPTION_USECOMPRESSION, true);
153 mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
154 xmppConnectionService.createAccount(mAccount);
155 }
156 if (jidToEdit != null && !mAccount.isOptionSet(Account.OPTION_DISABLED)) {
157 finish();
158 } else {
159 updateSaveButton();
160 updateAccountInformation(true);
161 }
162
163 }
164 };
165 private final OnClickListener mCancelButtonClickListener = new OnClickListener() {
166
167 @Override
168 public void onClick(final View v) {
169 finish();
170 }
171 };
172
173 public void refreshUiReal() {
174 invalidateOptionsMenu();
175 if (mAccount != null
176 && mAccount.getStatus() != Account.State.ONLINE
177 && mFetchingAvatar) {
178 startActivity(new Intent(getApplicationContext(),
179 ManageAccountActivity.class));
180 finish();
181 } else if (jidToEdit == null && mAccount != null
182 && mAccount.getStatus() == Account.State.ONLINE) {
183 if (!mFetchingAvatar) {
184 mFetchingAvatar = true;
185 xmppConnectionService.checkForAvatar(mAccount,
186 mAvatarFetchCallback);
187 }
188 } else {
189 updateSaveButton();
190 }
191 if (mAccount != null) {
192 updateAccountInformation(false);
193 }
194 }
195
196 @Override
197 public void onAccountUpdate() {
198 refreshUi();
199 }
200 private final UiCallback<Avatar> mAvatarFetchCallback = new UiCallback<Avatar>() {
201
202 @Override
203 public void userInputRequried(final PendingIntent pi, final Avatar avatar) {
204 finishInitialSetup(avatar);
205 }
206
207 @Override
208 public void success(final Avatar avatar) {
209 finishInitialSetup(avatar);
210 }
211
212 @Override
213 public void error(final int errorCode, final Avatar avatar) {
214 finishInitialSetup(avatar);
215 }
216 };
217 private final TextWatcher mTextWatcher = new TextWatcher() {
218
219 @Override
220 public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
221 updateSaveButton();
222 }
223
224 @Override
225 public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) {
226 }
227
228 @Override
229 public void afterTextChanged(final Editable s) {
230
231 }
232 };
233
234 private final OnClickListener mAvatarClickListener = new OnClickListener() {
235 @Override
236 public void onClick(final View view) {
237 if (mAccount != null) {
238 final Intent intent = new Intent(getApplicationContext(),
239 PublishProfilePictureActivity.class);
240 intent.putExtra("account", mAccount.getJid().toBareJid().toString());
241 startActivity(intent);
242 }
243 }
244 };
245
246 protected void finishInitialSetup(final Avatar avatar) {
247 runOnUiThread(new Runnable() {
248
249 @Override
250 public void run() {
251 final Intent intent;
252 if (avatar != null) {
253 intent = new Intent(getApplicationContext(),
254 StartConversationActivity.class);
255 if (xmppConnectionService != null && xmppConnectionService.getAccounts().size() == 1) {
256 intent.putExtra("init", true);
257 }
258 } else {
259 intent = new Intent(getApplicationContext(),
260 PublishProfilePictureActivity.class);
261 intent.putExtra("account", mAccount.getJid().toBareJid().toString());
262 intent.putExtra("setup", true);
263 }
264 startActivity(intent);
265 finish();
266 }
267 });
268 }
269
270 protected void updateSaveButton() {
271 if (accountInfoEdited() && jidToEdit != null) {
272 this.mSaveButton.setText(R.string.save);
273 this.mSaveButton.setEnabled(true);
274 this.mSaveButton.setTextColor(getPrimaryTextColor());
275 } else if (mAccount != null && (mAccount.getStatus() == Account.State.CONNECTING || mFetchingAvatar)) {
276 this.mSaveButton.setEnabled(false);
277 this.mSaveButton.setTextColor(getSecondaryTextColor());
278 this.mSaveButton.setText(R.string.account_status_connecting);
279 } else if (mAccount != null && mAccount.getStatus() == Account.State.DISABLED) {
280 this.mSaveButton.setEnabled(true);
281 this.mSaveButton.setTextColor(getPrimaryTextColor());
282 this.mSaveButton.setText(R.string.enable);
283 } else {
284 this.mSaveButton.setEnabled(true);
285 this.mSaveButton.setTextColor(getPrimaryTextColor());
286 if (jidToEdit != null) {
287 if (mAccount != null && mAccount.isOnlineAndConnected()) {
288 this.mSaveButton.setText(R.string.save);
289 if (!accountInfoEdited()) {
290 this.mSaveButton.setEnabled(false);
291 this.mSaveButton.setTextColor(getSecondaryTextColor());
292 }
293 } else {
294 this.mSaveButton.setText(R.string.connect);
295 }
296 } else {
297 this.mSaveButton.setText(R.string.next);
298 }
299 }
300 }
301
302 protected boolean accountInfoEdited() {
303 if (this.mAccount == null) {
304 return false;
305 }
306 final String unmodified;
307 if (Config.DOMAIN_LOCK != null) {
308 unmodified = this.mAccount.getJid().getLocalpart();
309 } else {
310 unmodified = this.mAccount.getJid().toBareJid().toString();
311 }
312 return !unmodified.equals(this.mAccountJid.getText().toString()) ||
313 !this.mAccount.getPassword().equals(this.mPassword.getText().toString());
314 }
315
316 @Override
317 protected String getShareableUri() {
318 if (mAccount!=null) {
319 return mAccount.getShareableUri();
320 } else {
321 return "";
322 }
323 }
324
325 @Override
326 protected void onCreate(final Bundle savedInstanceState) {
327 super.onCreate(savedInstanceState);
328 setContentView(R.layout.activity_edit_account);
329 this.mAccountJid = (AutoCompleteTextView) findViewById(R.id.account_jid);
330 this.mAccountJid.addTextChangedListener(this.mTextWatcher);
331 this.mAccountJidLabel = (TextView) findViewById(R.id.account_jid_label);
332 if (Config.DOMAIN_LOCK != null) {
333 this.mAccountJidLabel.setText(R.string.username);
334 this.mAccountJid.setHint(R.string.username_hint);
335 }
336 this.mPassword = (EditText) findViewById(R.id.account_password);
337 this.mPassword.addTextChangedListener(this.mTextWatcher);
338 this.mPasswordConfirm = (EditText) findViewById(R.id.account_password_confirm);
339 this.mAvatar = (ImageView) findViewById(R.id.avater);
340 this.mAvatar.setOnClickListener(this.mAvatarClickListener);
341 this.mRegisterNew = (CheckBox) findViewById(R.id.account_register_new);
342 this.mStats = (LinearLayout) findViewById(R.id.stats);
343 this.mSessionEst = (TextView) findViewById(R.id.session_est);
344 this.mServerInfoRosterVersion = (TextView) findViewById(R.id.server_info_roster_version);
345 this.mServerInfoCarbons = (TextView) findViewById(R.id.server_info_carbons);
346 this.mServerInfoMam = (TextView) findViewById(R.id.server_info_mam);
347 this.mServerInfoCSI = (TextView) findViewById(R.id.server_info_csi);
348 this.mServerInfoBlocking = (TextView) findViewById(R.id.server_info_blocking);
349 this.mServerInfoSm = (TextView) findViewById(R.id.server_info_sm);
350 this.mServerInfoPep = (TextView) findViewById(R.id.server_info_pep);
351 this.mServerInfoHttpUpload = (TextView) findViewById(R.id.server_info_http_upload);
352 this.mOtrFingerprint = (TextView) findViewById(R.id.otr_fingerprint);
353 this.mOtrFingerprintBox = (RelativeLayout) findViewById(R.id.otr_fingerprint_box);
354 this.mOtrFingerprintToClipboardButton = (ImageButton) findViewById(R.id.action_copy_to_clipboard);
355 this.mAxolotlFingerprint = (TextView) findViewById(R.id.axolotl_fingerprint);
356 this.mAxolotlFingerprintBox = (RelativeLayout) findViewById(R.id.axolotl_fingerprint_box);
357 this.mAxolotlFingerprintToClipboardButton = (ImageButton) findViewById(R.id.action_copy_axolotl_to_clipboard);
358 this.mRegenerateAxolotlKeyButton = (ImageButton) findViewById(R.id.action_regenerate_axolotl_key);
359 this.keysCard = (LinearLayout) findViewById(R.id.other_device_keys_card);
360 this.keys = (LinearLayout) findViewById(R.id.other_device_keys);
361 this.mSaveButton = (Button) findViewById(R.id.save_button);
362 this.mCancelButton = (Button) findViewById(R.id.cancel_button);
363 this.mSaveButton.setOnClickListener(this.mSaveButtonClickListener);
364 this.mCancelButton.setOnClickListener(this.mCancelButtonClickListener);
365 this.mMoreTable = (TableLayout) findViewById(R.id.server_info_more);
366 final OnCheckedChangeListener OnCheckedShowConfirmPassword = new OnCheckedChangeListener() {
367 @Override
368 public void onCheckedChanged(final CompoundButton buttonView,
369 final boolean isChecked) {
370 if (isChecked) {
371 mPasswordConfirm.setVisibility(View.VISIBLE);
372 } else {
373 mPasswordConfirm.setVisibility(View.GONE);
374 }
375 updateSaveButton();
376 }
377 };
378 this.mRegisterNew.setOnCheckedChangeListener(OnCheckedShowConfirmPassword);
379 if (Config.DISALLOW_REGISTRATION_IN_UI) {
380 this.mRegisterNew.setVisibility(View.GONE);
381 }
382 }
383
384 @Override
385 public boolean onCreateOptionsMenu(final Menu menu) {
386 super.onCreateOptionsMenu(menu);
387 getMenuInflater().inflate(R.menu.editaccount, menu);
388 final MenuItem showQrCode = menu.findItem(R.id.action_show_qr_code);
389 final MenuItem showBlocklist = menu.findItem(R.id.action_show_block_list);
390 final MenuItem showMoreInfo = menu.findItem(R.id.action_server_info_show_more);
391 final MenuItem changePassword = menu.findItem(R.id.action_change_password_on_server);
392 final MenuItem clearDevices = menu.findItem(R.id.action_clear_devices);
393 if (mAccount != null && mAccount.isOnlineAndConnected()) {
394 if (!mAccount.getXmppConnection().getFeatures().blocking()) {
395 showBlocklist.setVisible(false);
396 }
397 if (!mAccount.getXmppConnection().getFeatures().register()) {
398 changePassword.setVisible(false);
399 }
400 Set<Integer> otherDevices = mAccount.getAxolotlService().getOwnDeviceIds();
401 if (otherDevices == null || otherDevices.isEmpty()) {
402 clearDevices.setVisible(false);
403 }
404 } else {
405 showQrCode.setVisible(false);
406 showBlocklist.setVisible(false);
407 showMoreInfo.setVisible(false);
408 changePassword.setVisible(false);
409 clearDevices.setVisible(false);
410 }
411 return true;
412 }
413
414 @Override
415 protected void onStart() {
416 super.onStart();
417 if (getIntent() != null) {
418 try {
419 this.jidToEdit = Jid.fromString(getIntent().getStringExtra("jid"));
420 } catch (final InvalidJidException | NullPointerException ignored) {
421 this.jidToEdit = null;
422 }
423 this.messageFingerprint = getIntent().getStringExtra("fingerprint");
424 if (this.jidToEdit != null) {
425 this.mRegisterNew.setVisibility(View.GONE);
426 if (getActionBar() != null) {
427 getActionBar().setTitle(getString(R.string.account_details));
428 }
429 } else {
430 this.mAvatar.setVisibility(View.GONE);
431 if (getActionBar() != null) {
432 getActionBar().setTitle(R.string.action_add_account);
433 }
434 }
435 }
436 }
437
438 @Override
439 protected void onBackendConnected() {
440 if (this.jidToEdit != null) {
441 this.mAccount = xmppConnectionService.findAccountByJid(jidToEdit);
442 updateAccountInformation(true);
443 } else if (this.xmppConnectionService.getAccounts().size() == 0) {
444 if (getActionBar() != null) {
445 getActionBar().setDisplayHomeAsUpEnabled(false);
446 getActionBar().setDisplayShowHomeEnabled(false);
447 getActionBar().setHomeButtonEnabled(false);
448 }
449 this.mCancelButton.setEnabled(false);
450 this.mCancelButton.setTextColor(getSecondaryTextColor());
451 }
452 if (Config.DOMAIN_LOCK == null) {
453 final KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this,
454 android.R.layout.simple_list_item_1,
455 xmppConnectionService.getKnownHosts());
456 this.mAccountJid.setAdapter(mKnownHostsAdapter);
457 }
458 updateSaveButton();
459 }
460
461 @Override
462 public boolean onOptionsItemSelected(final MenuItem item) {
463 switch (item.getItemId()) {
464 case R.id.action_show_block_list:
465 final Intent showBlocklistIntent = new Intent(this, BlocklistActivity.class);
466 showBlocklistIntent.putExtra("account", mAccount.getJid().toString());
467 startActivity(showBlocklistIntent);
468 break;
469 case R.id.action_server_info_show_more:
470 mMoreTable.setVisibility(item.isChecked() ? View.GONE : View.VISIBLE);
471 item.setChecked(!item.isChecked());
472 break;
473 case R.id.action_change_password_on_server:
474 final Intent changePasswordIntent = new Intent(this, ChangePasswordActivity.class);
475 changePasswordIntent.putExtra("account", mAccount.getJid().toString());
476 startActivity(changePasswordIntent);
477 break;
478 case R.id.action_clear_devices:
479 showWipePepDialog();
480 break;
481 }
482 return super.onOptionsItemSelected(item);
483 }
484
485 private void updateAccountInformation(boolean init) {
486 if (init) {
487 if (Config.DOMAIN_LOCK != null) {
488 this.mAccountJid.setText(this.mAccount.getJid().getLocalpart());
489 } else {
490 this.mAccountJid.setText(this.mAccount.getJid().toBareJid().toString());
491 }
492 this.mPassword.setText(this.mAccount.getPassword());
493 }
494 if (this.jidToEdit != null) {
495 this.mAvatar.setVisibility(View.VISIBLE);
496 this.mAvatar.setImageBitmap(avatarService().get(this.mAccount, getPixel(72)));
497 }
498 if (this.mAccount.isOptionSet(Account.OPTION_REGISTER)) {
499 this.mRegisterNew.setVisibility(View.VISIBLE);
500 this.mRegisterNew.setChecked(true);
501 this.mPasswordConfirm.setText(this.mAccount.getPassword());
502 } else {
503 this.mRegisterNew.setVisibility(View.GONE);
504 this.mRegisterNew.setChecked(false);
505 }
506 if (this.mAccount.isOnlineAndConnected() && !this.mFetchingAvatar) {
507 this.mStats.setVisibility(View.VISIBLE);
508 this.mSessionEst.setText(UIHelper.readableTimeDifferenceFull(this, this.mAccount.getXmppConnection()
509 .getLastSessionEstablished()));
510 Features features = this.mAccount.getXmppConnection().getFeatures();
511 if (features.rosterVersioning()) {
512 this.mServerInfoRosterVersion.setText(R.string.server_info_available);
513 } else {
514 this.mServerInfoRosterVersion.setText(R.string.server_info_unavailable);
515 }
516 if (features.carbons()) {
517 this.mServerInfoCarbons.setText(R.string.server_info_available);
518 } else {
519 this.mServerInfoCarbons
520 .setText(R.string.server_info_unavailable);
521 }
522 if (features.mam()) {
523 this.mServerInfoMam.setText(R.string.server_info_available);
524 } else {
525 this.mServerInfoMam.setText(R.string.server_info_unavailable);
526 }
527 if (features.csi()) {
528 this.mServerInfoCSI.setText(R.string.server_info_available);
529 } else {
530 this.mServerInfoCSI.setText(R.string.server_info_unavailable);
531 }
532 if (features.blocking()) {
533 this.mServerInfoBlocking.setText(R.string.server_info_available);
534 } else {
535 this.mServerInfoBlocking.setText(R.string.server_info_unavailable);
536 }
537 if (features.sm()) {
538 this.mServerInfoSm.setText(R.string.server_info_available);
539 } else {
540 this.mServerInfoSm.setText(R.string.server_info_unavailable);
541 }
542 if (features.pep()) {
543 this.mServerInfoPep.setText(R.string.server_info_available);
544 } else {
545 this.mServerInfoPep.setText(R.string.server_info_unavailable);
546 }
547 if (features.httpUpload()) {
548 this.mServerInfoHttpUpload.setText(R.string.server_info_available);
549 } else {
550 this.mServerInfoHttpUpload.setText(R.string.server_info_unavailable);
551 }
552 final String otrFingerprint = this.mAccount.getOtrFingerprint();
553 if (otrFingerprint != null) {
554 this.mOtrFingerprintBox.setVisibility(View.VISIBLE);
555 this.mOtrFingerprint.setText(CryptoHelper.prettifyFingerprint(otrFingerprint));
556 this.mOtrFingerprintToClipboardButton
557 .setVisibility(View.VISIBLE);
558 this.mOtrFingerprintToClipboardButton
559 .setOnClickListener(new View.OnClickListener() {
560
561 @Override
562 public void onClick(final View v) {
563
564 if (copyTextToClipboard(otrFingerprint, R.string.otr_fingerprint)) {
565 Toast.makeText(
566 EditAccountActivity.this,
567 R.string.toast_message_otr_fingerprint,
568 Toast.LENGTH_SHORT).show();
569 }
570 }
571 });
572 } else {
573 this.mOtrFingerprintBox.setVisibility(View.GONE);
574 }
575 final String axolotlFingerprint = this.mAccount.getAxolotlService().getOwnPublicKey().getFingerprint();
576 if (axolotlFingerprint != null) {
577 this.mAxolotlFingerprintBox.setVisibility(View.VISIBLE);
578 this.mAxolotlFingerprint.setText(CryptoHelper.prettifyFingerprint(axolotlFingerprint));
579 this.mAxolotlFingerprintToClipboardButton
580 .setVisibility(View.VISIBLE);
581 this.mAxolotlFingerprintToClipboardButton
582 .setOnClickListener(new View.OnClickListener() {
583
584 @Override
585 public void onClick(final View v) {
586
587 if (copyTextToClipboard(axolotlFingerprint, R.string.omemo_fingerprint)) {
588 Toast.makeText(
589 EditAccountActivity.this,
590 R.string.toast_message_omemo_fingerprint,
591 Toast.LENGTH_SHORT).show();
592 }
593 }
594 });
595 if (Config.SHOW_REGENERATE_AXOLOTL_KEYS_BUTTON) {
596 this.mRegenerateAxolotlKeyButton
597 .setVisibility(View.VISIBLE);
598 this.mRegenerateAxolotlKeyButton
599 .setOnClickListener(new View.OnClickListener() {
600
601 @Override
602 public void onClick(final View v) {
603 showRegenerateAxolotlKeyDialog();
604 }
605 });
606 }
607 } else {
608 this.mAxolotlFingerprintBox.setVisibility(View.GONE);
609 }
610 final IdentityKey ownKey = mAccount.getAxolotlService().getOwnPublicKey();
611 boolean hasKeys = false;
612 keys.removeAllViews();
613 for(final IdentityKey identityKey : xmppConnectionService.databaseBackend.loadIdentityKeys(
614 mAccount, mAccount.getJid().toBareJid().toString())) {
615 if(ownKey.equals(identityKey)) {
616 continue;
617 }
618 boolean highlight = identityKey.getFingerprint().replaceAll("\\s", "").equals(messageFingerprint);
619 hasKeys |= addFingerprintRow(keys, mAccount, identityKey, highlight);
620 }
621 if (hasKeys) {
622 keysCard.setVisibility(View.VISIBLE);
623 } else {
624 keysCard.setVisibility(View.GONE);
625 }
626 } else {
627 if (this.mAccount.errorStatus()) {
628 this.mAccountJid.setError(getString(this.mAccount.getStatus().getReadableId()));
629 if (init || !accountInfoEdited()) {
630 this.mAccountJid.requestFocus();
631 }
632 } else {
633 this.mAccountJid.setError(null);
634 }
635 this.mStats.setVisibility(View.GONE);
636 }
637 }
638
639 public void showRegenerateAxolotlKeyDialog() {
640 Builder builder = new Builder(this);
641 builder.setTitle("Regenerate Key");
642 builder.setIconAttribute(android.R.attr.alertDialogIcon);
643 builder.setMessage("Are you sure you want to regenerate your Identity Key? (This will also wipe all established sessions and contact Identity Keys)");
644 builder.setNegativeButton(getString(R.string.cancel), null);
645 builder.setPositiveButton("Yes",
646 new DialogInterface.OnClickListener() {
647 @Override
648 public void onClick(DialogInterface dialog, int which) {
649 mAccount.getAxolotlService().regenerateKeys();
650 }
651 });
652 builder.create().show();
653 }
654
655 public void showWipePepDialog() {
656 Builder builder = new Builder(this);
657 builder.setTitle(getString(R.string.clear_other_devices));
658 builder.setIconAttribute(android.R.attr.alertDialogIcon);
659 builder.setMessage(getString(R.string.clear_other_devices_desc));
660 builder.setNegativeButton(getString(R.string.cancel), null);
661 builder.setPositiveButton(getString(R.string.accept),
662 new DialogInterface.OnClickListener() {
663 @Override
664 public void onClick(DialogInterface dialog, int which) {
665 mAccount.getAxolotlService().wipeOtherPepDevices();
666 }
667 });
668 builder.create().show();
669 }
670
671 @Override
672 public void onKeyStatusUpdated() {
673 refreshUi();
674 }
675}