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