use of de.pixart.messenger.xmpp.XmppConnection.Features in project Pix-Art-Messenger by kriztan.
the class EditAccountActivity method updateAccountInformation.
private void updateAccountInformation(boolean init) {
if (init) {
this.binding.accountJid.getEditableText().clear();
if (mUsernameMode) {
this.binding.accountJid.getEditableText().append(this.mAccount.getJid().getLocalpart());
} else {
this.binding.accountJid.getEditableText().append(this.mAccount.getJid().toBareJid().toString());
}
this.mPassword.getEditableText().clear();
this.mPassword.getEditableText().append(this.mAccount.getPassword());
this.mPassword.setText(this.mAccount.getPassword());
this.mHostname.setText("");
this.mHostname.getEditableText().append(this.mAccount.getHostname());
this.mPort.setText("");
this.mPort.getEditableText().append(String.valueOf(this.mAccount.getPort()));
this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE);
}
final boolean editable = !mAccount.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY);
this.binding.accountJid.setEnabled(editable);
this.binding.accountJid.setFocusable(editable);
this.binding.accountJid.setFocusableInTouchMode(editable);
if (mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE) || !mAccount.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY)) {
this.binding.accountPasswordLayout.setPasswordVisibilityToggleEnabled(true);
} else {
this.binding.accountPasswordLayout.setPasswordVisibilityToggleEnabled(false);
}
if (!mInitMode) {
this.mAvatar.setVisibility(View.VISIBLE);
this.mAvatar.setImageBitmap(avatarService().get(this.mAccount, getPixel(Config.AVATAR_SIZE)));
this.binding.accountJid.setEnabled(false);
} else {
this.mAvatar.setVisibility(View.GONE);
}
if (this.mAccount.isOptionSet(Account.OPTION_REGISTER)) {
this.mRegisterNew.setVisibility(View.VISIBLE);
this.mRegisterNew.setChecked(true);
} else {
this.mRegisterNew.setVisibility(View.GONE);
this.mRegisterNew.setChecked(false);
}
if (this.mAccount.isOnlineAndConnected() && !this.mFetchingAvatar) {
Features features = this.mAccount.getXmppConnection().getFeatures();
this.binding.stats.setVisibility(View.VISIBLE);
boolean showBatteryWarning = !xmppConnectionService.getPushManagementService().available(mAccount) && isOptimizingBattery();
boolean showDataSaverWarning = isAffectedByDataSaver();
showOsOptimizationWarning(showBatteryWarning, showDataSaverWarning);
this.mSessionEst.setText(UIHelper.readableTimeDifferenceFull(this, this.mAccount.getXmppConnection().getLastSessionEstablished()));
if (features.rosterVersioning()) {
this.mServerInfoRosterVersion.setText(R.string.server_info_available);
} else {
this.mServerInfoRosterVersion.setText(R.string.server_info_unavailable);
}
if (features.carbons()) {
this.mServerInfoCarbons.setText(R.string.server_info_available);
} else {
this.mServerInfoCarbons.setText(R.string.server_info_unavailable);
}
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);
}
if (features.sm()) {
this.mServerInfoSm.setText(R.string.server_info_available);
} else {
this.mServerInfoSm.setText(R.string.server_info_unavailable);
}
if (features.pep()) {
AxolotlService axolotlService = this.mAccount.getAxolotlService();
if (axolotlService != null && axolotlService.isPepBroken()) {
this.mServerInfoPep.setText(R.string.server_info_broken);
} else if (features.pepPublishOptions() || features.pepOmemoWhitelisted()) {
this.mServerInfoPep.setText(R.string.server_info_available);
} else {
this.mServerInfoPep.setText(R.string.server_info_partial);
}
} else {
this.mServerInfoPep.setText(R.string.server_info_unavailable);
}
if (features.httpUpload(0)) {
this.mServerInfoHttpUpload.setText(R.string.server_info_available);
} else {
this.mServerInfoHttpUpload.setText(R.string.server_info_unavailable);
}
this.mPushRow.setVisibility(xmppConnectionService.getPushManagementService().isStub() ? View.GONE : View.VISIBLE);
if (xmppConnectionService.getPushManagementService().available(mAccount)) {
this.mServerInfoPush.setText(R.string.server_info_available);
} else {
this.mServerInfoPush.setText(R.string.server_info_unavailable);
}
final long pgpKeyId = this.mAccount.getPgpId();
if (pgpKeyId != 0 && Config.supportOpenPgp()) {
OnClickListener openPgp = view -> launchOpenKeyChain(pgpKeyId);
OnClickListener delete = view -> showDeletePgpDialog();
this.mPgpFingerprintBox.setVisibility(View.VISIBLE);
this.mPgpFingerprint.setText(OpenPgpUtils.convertKeyIdToHex(pgpKeyId));
this.mPgpFingerprint.setOnClickListener(openPgp);
if ("pgp".equals(messageFingerprint)) {
this.getmPgpFingerprintDesc.setTextAppearance(this, R.style.TextAppearance_Conversations_Caption_Highlight);
}
this.getmPgpFingerprintDesc.setOnClickListener(openPgp);
this.mPgpDeleteFingerprintButton.setOnClickListener(delete);
} else {
this.mPgpFingerprintBox.setVisibility(View.GONE);
}
final String otrFingerprint = this.mAccount.getOtrFingerprint();
if (otrFingerprint != null && Config.supportOtr()) {
if ("otr".equals(messageFingerprint)) {
this.mOtrFingerprintDesc.setTextColor(ContextCompat.getColor(this, R.color.accent));
}
this.mOtrFingerprintBox.setVisibility(View.VISIBLE);
this.mOtrFingerprint.setText(CryptoHelper.prettifyFingerprint(otrFingerprint));
this.mOtrFingerprintToClipboardButton.setVisibility(View.VISIBLE);
this.mOtrFingerprintToClipboardButton.setOnClickListener(v -> {
if (copyTextToClipboard(CryptoHelper.prettifyFingerprint(otrFingerprint), R.string.otr_fingerprint)) {
Toast.makeText(EditAccountActivity.this, R.string.toast_message_otr_fingerprint, Toast.LENGTH_SHORT).show();
}
});
} else {
this.mOtrFingerprintBox.setVisibility(View.GONE);
}
final String ownAxolotlFingerprint = this.mAccount.getAxolotlService().getOwnFingerprint();
if (ownAxolotlFingerprint != null && Config.supportOmemo()) {
this.mAxolotlFingerprintBox.setVisibility(View.VISIBLE);
if (ownAxolotlFingerprint.equals(messageFingerprint)) {
this.mOwnFingerprintDesc.setTextAppearance(this, R.style.TextAppearance_Conversations_Caption_Highlight);
this.mOwnFingerprintDesc.setText(R.string.omemo_fingerprint_selected_message);
} else {
this.mOwnFingerprintDesc.setTextAppearance(this, R.style.TextAppearance_Conversations_Caption);
this.mOwnFingerprintDesc.setText(R.string.omemo_fingerprint);
}
this.mAxolotlFingerprint.setText(CryptoHelper.prettifyFingerprint(ownAxolotlFingerprint.substring(2)));
this.mAxolotlFingerprintToClipboardButton.setVisibility(View.VISIBLE);
this.mAxolotlFingerprintToClipboardButton.setOnClickListener(v -> copyOmemoFingerprint(ownAxolotlFingerprint));
} else {
this.mAxolotlFingerprintBox.setVisibility(View.GONE);
}
boolean hasKeys = false;
keys.removeAllViews();
for (XmppAxolotlSession session : mAccount.getAxolotlService().findOwnSessions()) {
if (!session.getTrust().isCompromised()) {
boolean highlight = session.getFingerprint().equals(messageFingerprint);
addFingerprintRow(keys, session, highlight);
hasKeys = true;
}
}
if (hasKeys && Config.supportOmemo()) {
this.binding.otherDeviceKeysCard.setVisibility(View.VISIBLE);
Set<Integer> otherDevices = mAccount.getAxolotlService().getOwnDeviceIds();
if (otherDevices == null || otherDevices.isEmpty()) {
mClearDevicesButton.setVisibility(View.GONE);
} else {
mClearDevicesButton.setVisibility(View.VISIBLE);
}
} else {
this.binding.otherDeviceKeysCard.setVisibility(View.GONE);
}
} else {
final TextInputLayout errorLayout;
if (this.mAccount.errorStatus()) {
if (this.mAccount.getStatus() == Account.State.UNAUTHORIZED) {
errorLayout = this.mPasswordLayout;
} else if (mShowOptions && this.mAccount.getStatus() == Account.State.SERVER_NOT_FOUND && this.mHostname.getText().length() > 0) {
errorLayout = this.mHostnameLayout;
} else {
errorLayout = this.mAccountJidLayout;
}
errorLayout.setError(getString(this.mAccount.getStatus().getReadableId()));
if (init || !accountInfoEdited()) {
errorLayout.requestFocus();
}
} else {
errorLayout = null;
}
removeErrorsOnAllBut(errorLayout);
this.binding.stats.setVisibility(View.GONE);
this.binding.otherDeviceKeysCard.setVisibility(View.GONE);
}
}
Aggregations