switch account activity to card view. started using data binder

This commit is contained in:
Daniel Gultsch 2018-02-18 09:06:37 +01:00
parent 1c441a57e8
commit d0e58330e9
2 changed files with 840 additions and 899 deletions

View File

@ -5,6 +5,7 @@ import android.content.ActivityNotFoundException;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.databinding.DataBindingUtil;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@ -50,6 +51,7 @@ import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession; import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
import eu.siacs.conversations.databinding.ActivityEditAccountBinding;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.services.BarcodeProvider; import eu.siacs.conversations.services.BarcodeProvider;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
@ -74,7 +76,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
OnKeyStatusUpdated, OnCaptchaRequested, KeyChainAliasCallback, XmppConnectionService.OnShowErrorToast, XmppConnectionService.OnMamPreferencesFetched { OnKeyStatusUpdated, OnCaptchaRequested, KeyChainAliasCallback, XmppConnectionService.OnShowErrorToast, XmppConnectionService.OnMamPreferencesFetched {
private static final int REQUEST_DATA_SAVER = 0x37af244; private static final int REQUEST_DATA_SAVER = 0x37af244;
private AutoCompleteTextView mAccountJid;
private TextInputLayout mAccountJidLayout; private TextInputLayout mAccountJidLayout;
private EditText mPassword; private EditText mPassword;
private TextInputLayout mPasswordLayout; private TextInputLayout mPasswordLayout;
@ -82,12 +83,9 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
private Button mCancelButton; private Button mCancelButton;
private Button mSaveButton; private Button mSaveButton;
private Button mDisableOsOptimizationsButton; private Button mDisableOsOptimizationsButton;
private TextView mDisableOsOptimizationsHeadline;
private TextView getmDisableOsOptimizationsBody; private TextView getmDisableOsOptimizationsBody;
private TableLayout mMoreTable; private TableLayout mMoreTable;
private LinearLayout mStats;
private RelativeLayout mOsOptimizations;
private TextView mServerInfoSm; private TextView mServerInfoSm;
private TextView mServerInfoRosterVersion; private TextView mServerInfoRosterVersion;
private TextView mServerInfoCarbons; private TextView mServerInfoCarbons;
@ -112,7 +110,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
private ImageButton mAxolotlFingerprintToClipboardButton; private ImageButton mAxolotlFingerprintToClipboardButton;
private ImageButton mPgpDeleteFingerprintButton; private ImageButton mPgpDeleteFingerprintButton;
private LinearLayout keys; private LinearLayout keys;
private LinearLayout keysCard;
private LinearLayout mNamePort; private LinearLayout mNamePort;
private EditText mHostname; private EditText mHostname;
private TextInputLayout mHostnameLayout; private TextInputLayout mHostnameLayout;
@ -151,10 +148,10 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
return; return;
} }
final boolean registerNewAccount = mRegisterNew.isChecked() && !Config.DISALLOW_REGISTRATION_IN_UI; final boolean registerNewAccount = mRegisterNew.isChecked() && !Config.DISALLOW_REGISTRATION_IN_UI;
if (mUsernameMode && mAccountJid.getText().toString().contains("@")) { if (mUsernameMode && binding.accountJid.getText().toString().contains("@")) {
mAccountJidLayout.setError(getString(R.string.invalid_username)); mAccountJidLayout.setError(getString(R.string.invalid_username));
removeErrorsOnAllBut(mAccountJidLayout); removeErrorsOnAllBut(mAccountJidLayout);
mAccountJid.requestFocus(); binding.accountJid.requestFocus();
return; return;
} }
@ -176,9 +173,9 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
final Jid jid; final Jid jid;
try { try {
if (mUsernameMode) { if (mUsernameMode) {
jid = Jid.fromParts(mAccountJid.getText().toString(), getUserModeDomain(), null); jid = Jid.fromParts(binding.accountJid.getText().toString(), getUserModeDomain(), null);
} else { } else {
jid = Jid.fromString(mAccountJid.getText().toString()); jid = Jid.fromString(binding.accountJid.getText().toString());
} }
} catch (final InvalidJidException e) { } catch (final InvalidJidException e) {
if (mUsernameMode) { if (mUsernameMode) {
@ -186,7 +183,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
} else { } else {
mAccountJidLayout.setError(getString(R.string.invalid_jid)); mAccountJidLayout.setError(getString(R.string.invalid_jid));
} }
mAccountJid.requestFocus(); binding.accountJid.requestFocus();
removeErrorsOnAllBut(mAccountJidLayout); removeErrorsOnAllBut(mAccountJidLayout);
return; return;
} }
@ -225,7 +222,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
mAccountJidLayout.setError(getString(R.string.invalid_jid)); mAccountJidLayout.setError(getString(R.string.invalid_jid));
} }
removeErrorsOnAllBut(mAccountJidLayout); removeErrorsOnAllBut(mAccountJidLayout);
mAccountJid.requestFocus(); binding.accountJid.requestFocus();
return; return;
} }
if (mAccount != null) { if (mAccount != null) {
@ -246,7 +243,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
if (xmppConnectionService.findAccountByJid(jid) != null) { if (xmppConnectionService.findAccountByJid(jid) != null) {
mAccountJidLayout.setError(getString(R.string.account_already_exists)); mAccountJidLayout.setError(getString(R.string.account_already_exists));
removeErrorsOnAllBut(mAccountJidLayout); removeErrorsOnAllBut(mAccountJidLayout);
mAccountJid.requestFocus(); binding.accountJid.requestFocus();
return; return;
} }
mAccount = new Account(jid.toBareJid(), password); mAccount = new Account(jid.toBareJid(), password);
@ -285,6 +282,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
private Button mClearDevicesButton; private Button mClearDevicesButton;
private XmppUri pendingUri = null; private XmppUri pendingUri = null;
private boolean mUseTor; private boolean mUseTor;
private ActivityEditAccountBinding binding;
public void refreshUiReal() { public void refreshUiReal() {
invalidateOptionsMenu(); invalidateOptionsMenu();
@ -515,7 +513,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
} else { } else {
unmodified = this.mAccount.getJid().toBareJid().toString(); unmodified = this.mAccount.getJid().toBareJid().toString();
} }
return !unmodified.equals(this.mAccountJid.getText().toString()); return !unmodified.equals(this.binding.accountJid.getText().toString());
} }
protected boolean passwordChangedInMagicCreateMode() { protected boolean passwordChangedInMagicCreateMode() {
@ -542,10 +540,9 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
this.mSavedInstanceAccount = savedInstanceState.getString("account"); this.mSavedInstanceAccount = savedInstanceState.getString("account");
this.mSavedInstanceInit = savedInstanceState.getBoolean("initMode", false); this.mSavedInstanceInit = savedInstanceState.getBoolean("initMode", false);
} }
setContentView(R.layout.activity_edit_account); this.binding = DataBindingUtil.setContentView(this, R.layout.activity_edit_account);
this.mAccountJid = (AutoCompleteTextView) findViewById(R.id.account_jid); binding.accountJid.addTextChangedListener(this.mTextWatcher);
this.mAccountJid.addTextChangedListener(this.mTextWatcher); binding.accountJid.setOnFocusChangeListener(this.mEditTextFocusListener);
this.mAccountJid.setOnFocusChangeListener(this.mEditTextFocusListener);
this.mAccountJidLayout = (TextInputLayout) findViewById(R.id.account_jid_layout); this.mAccountJidLayout = (TextInputLayout) findViewById(R.id.account_jid_layout);
this.mPassword = (EditText) findViewById(R.id.account_password); this.mPassword = (EditText) findViewById(R.id.account_password);
this.mPassword.addTextChangedListener(this.mTextWatcher); this.mPassword.addTextChangedListener(this.mTextWatcher);
@ -553,10 +550,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
this.mAvatar = (ImageView) findViewById(R.id.avater); this.mAvatar = (ImageView) findViewById(R.id.avater);
this.mAvatar.setOnClickListener(this.mAvatarClickListener); this.mAvatar.setOnClickListener(this.mAvatarClickListener);
this.mRegisterNew = (CheckBox) findViewById(R.id.account_register_new); this.mRegisterNew = (CheckBox) findViewById(R.id.account_register_new);
this.mStats = (LinearLayout) findViewById(R.id.stats);
this.mOsOptimizations = (RelativeLayout) findViewById(R.id.os_optimization);
this.mDisableOsOptimizationsButton = (Button) findViewById(R.id.os_optimization_disable); this.mDisableOsOptimizationsButton = (Button) findViewById(R.id.os_optimization_disable);
this.mDisableOsOptimizationsHeadline = (TextView) findViewById(R.id.os_optimization_headline);
this.getmDisableOsOptimizationsBody = (TextView) findViewById(R.id.os_optimization_body); this.getmDisableOsOptimizationsBody = (TextView) findViewById(R.id.os_optimization_body);
this.mSessionEst = (TextView) findViewById(R.id.session_est); this.mSessionEst = (TextView) findViewById(R.id.session_est);
this.mServerInfoRosterVersion = (TextView) findViewById(R.id.server_info_roster_version); this.mServerInfoRosterVersion = (TextView) findViewById(R.id.server_info_roster_version);
@ -581,7 +575,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
this.mAxolotlFingerprintBox = (RelativeLayout) findViewById(R.id.axolotl_fingerprint_box); this.mAxolotlFingerprintBox = (RelativeLayout) findViewById(R.id.axolotl_fingerprint_box);
this.mAxolotlFingerprintToClipboardButton = (ImageButton) findViewById(R.id.action_copy_axolotl_to_clipboard); this.mAxolotlFingerprintToClipboardButton = (ImageButton) findViewById(R.id.action_copy_axolotl_to_clipboard);
this.mOwnFingerprintDesc = (TextView) findViewById(R.id.own_fingerprint_desc); this.mOwnFingerprintDesc = (TextView) findViewById(R.id.own_fingerprint_desc);
this.keysCard = (LinearLayout) findViewById(R.id.other_device_keys_card);
this.keys = (LinearLayout) findViewById(R.id.other_device_keys); this.keys = (LinearLayout) findViewById(R.id.other_device_keys);
this.mNamePort = (LinearLayout) findViewById(R.id.name_port); this.mNamePort = (LinearLayout) findViewById(R.id.name_port);
this.mHostname = (EditText) findViewById(R.id.hostname); this.mHostname = (EditText) findViewById(R.id.hostname);
@ -768,12 +761,12 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
this.mCancelButton.setTextColor(getSecondaryTextColor()); this.mCancelButton.setTextColor(getSecondaryTextColor());
} }
if (mUsernameMode) { if (mUsernameMode) {
this.mAccountJid.setHint(R.string.username_hint); this.binding.accountJid.setHint(R.string.username_hint);
} else { } else {
final KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this, final KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this,
R.layout.simple_list_item, R.layout.simple_list_item,
xmppConnectionService.getKnownHosts()); xmppConnectionService.getKnownHosts());
this.mAccountJid.setAdapter(mKnownHostsAdapter); this.binding.accountJid.setAdapter(mKnownHostsAdapter);
} }
if (pendingUri != null) { if (pendingUri != null) {
@ -869,11 +862,11 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
private void updateAccountInformation(boolean init) { private void updateAccountInformation(boolean init) {
if (init) { if (init) {
this.mAccountJid.getEditableText().clear(); this.binding.accountJid.getEditableText().clear();
if (mUsernameMode) { if (mUsernameMode) {
this.mAccountJid.getEditableText().append(this.mAccount.getJid().getLocalpart()); this.binding.accountJid.getEditableText().append(this.mAccount.getJid().getLocalpart());
} else { } else {
this.mAccountJid.getEditableText().append(this.mAccount.getJid().toBareJid().toString()); this.binding.accountJid.getEditableText().append(this.mAccount.getJid().toBareJid().toString());
} }
this.mPassword.getEditableText().clear(); this.mPassword.getEditableText().clear();
this.mPassword.getEditableText().append(this.mAccount.getPassword()); this.mPassword.getEditableText().append(this.mAccount.getPassword());
@ -886,9 +879,9 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
} }
final boolean editable = !mAccount.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY); final boolean editable = !mAccount.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY);
this.mAccountJid.setEnabled(editable); this.binding.accountJid.setEnabled(editable);
this.mAccountJid.setFocusable(editable); this.binding.accountJid.setFocusable(editable);
this.mAccountJid.setFocusableInTouchMode(editable); this.binding.accountJid.setFocusableInTouchMode(editable);
if (editable) { if (editable) {
this.mPassword.setCustomSelectionActionModeCallback(null); this.mPassword.setCustomSelectionActionModeCallback(null);
} else { } else {
@ -910,7 +903,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
} }
if (this.mAccount.isOnlineAndConnected() && !this.mFetchingAvatar) { if (this.mAccount.isOnlineAndConnected() && !this.mFetchingAvatar) {
Features features = this.mAccount.getXmppConnection().getFeatures(); Features features = this.mAccount.getXmppConnection().getFeatures();
this.mStats.setVisibility(View.VISIBLE); this.binding.stats.setVisibility(View.VISIBLE);
boolean showBatteryWarning = !xmppConnectionService.getPushManagementService().available(mAccount) && isOptimizingBattery(); boolean showBatteryWarning = !xmppConnectionService.getPushManagementService().available(mAccount) && isOptimizingBattery();
boolean showDataSaverWarning = isAffectedByDataSaver(); boolean showDataSaverWarning = isAffectedByDataSaver();
showOsOptimizationWarning(showBatteryWarning, showDataSaverWarning); showOsOptimizationWarning(showBatteryWarning, showDataSaverWarning);
@ -974,18 +967,8 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
} }
final long pgpKeyId = this.mAccount.getPgpId(); final long pgpKeyId = this.mAccount.getPgpId();
if (pgpKeyId != 0 && Config.supportOpenPgp()) { if (pgpKeyId != 0 && Config.supportOpenPgp()) {
OnClickListener openPgp = new OnClickListener() { OnClickListener openPgp = view -> launchOpenKeyChain(pgpKeyId);
@Override OnClickListener delete = view -> showDeletePgpDialog();
public void onClick(View view) {
launchOpenKeyChain(pgpKeyId);
}
};
OnClickListener delete = new OnClickListener() {
@Override
public void onClick(View view) {
showDeletePgpDialog();
}
};
this.mPgpFingerprintBox.setVisibility(View.VISIBLE); this.mPgpFingerprintBox.setVisibility(View.VISIBLE);
this.mPgpFingerprint.setText(OpenPgpUtils.convertKeyIdToHex(pgpKeyId)); this.mPgpFingerprint.setText(OpenPgpUtils.convertKeyIdToHex(pgpKeyId));
this.mPgpFingerprint.setOnClickListener(openPgp); this.mPgpFingerprint.setOnClickListener(openPgp);
@ -1004,21 +987,14 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
} }
this.mOtrFingerprintBox.setVisibility(View.VISIBLE); this.mOtrFingerprintBox.setVisibility(View.VISIBLE);
this.mOtrFingerprint.setText(CryptoHelper.prettifyFingerprint(otrFingerprint)); this.mOtrFingerprint.setText(CryptoHelper.prettifyFingerprint(otrFingerprint));
this.mOtrFingerprintToClipboardButton this.mOtrFingerprintToClipboardButton.setVisibility(View.VISIBLE);
.setVisibility(View.VISIBLE); this.mOtrFingerprintToClipboardButton.setOnClickListener(v -> {
this.mOtrFingerprintToClipboardButton
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
if (copyTextToClipboard(CryptoHelper.prettifyFingerprint(otrFingerprint), R.string.otr_fingerprint)) { if (copyTextToClipboard(CryptoHelper.prettifyFingerprint(otrFingerprint), R.string.otr_fingerprint)) {
Toast.makeText( Toast.makeText(
EditAccountActivity.this, EditAccountActivity.this,
R.string.toast_message_otr_fingerprint, R.string.toast_message_otr_fingerprint,
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} }
}
}); });
} else { } else {
this.mOtrFingerprintBox.setVisibility(View.GONE); this.mOtrFingerprintBox.setVisibility(View.GONE);
@ -1034,16 +1010,8 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
this.mOwnFingerprintDesc.setText(R.string.omemo_fingerprint); this.mOwnFingerprintDesc.setText(R.string.omemo_fingerprint);
} }
this.mAxolotlFingerprint.setText(CryptoHelper.prettifyFingerprint(ownAxolotlFingerprint.substring(2))); this.mAxolotlFingerprint.setText(CryptoHelper.prettifyFingerprint(ownAxolotlFingerprint.substring(2)));
this.mAxolotlFingerprintToClipboardButton this.mAxolotlFingerprintToClipboardButton.setVisibility(View.VISIBLE);
.setVisibility(View.VISIBLE); this.mAxolotlFingerprintToClipboardButton.setOnClickListener(v -> copyOmemoFingerprint(ownAxolotlFingerprint));
this.mAxolotlFingerprintToClipboardButton
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
copyOmemoFingerprint(ownAxolotlFingerprint);
}
});
} else { } else {
this.mAxolotlFingerprintBox.setVisibility(View.GONE); this.mAxolotlFingerprintBox.setVisibility(View.GONE);
} }
@ -1057,7 +1025,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
} }
} }
if (hasKeys && Config.supportOmemo()) { if (hasKeys && Config.supportOmemo()) {
keysCard.setVisibility(View.VISIBLE); this.binding.otherDeviceKeysCard.setVisibility(View.VISIBLE);
Set<Integer> otherDevices = mAccount.getAxolotlService().getOwnDeviceIds(); Set<Integer> otherDevices = mAccount.getAxolotlService().getOwnDeviceIds();
if (otherDevices == null || otherDevices.isEmpty()) { if (otherDevices == null || otherDevices.isEmpty()) {
mClearDevicesButton.setVisibility(View.GONE); mClearDevicesButton.setVisibility(View.GONE);
@ -1065,7 +1033,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
mClearDevicesButton.setVisibility(View.VISIBLE); mClearDevicesButton.setVisibility(View.VISIBLE);
} }
} else { } else {
keysCard.setVisibility(View.GONE); this.binding.otherDeviceKeysCard.setVisibility(View.GONE);
} }
} else { } else {
final TextInputLayout errorLayout; final TextInputLayout errorLayout;
@ -1087,7 +1055,8 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
errorLayout = null; errorLayout = null;
} }
removeErrorsOnAllBut(errorLayout); removeErrorsOnAllBut(errorLayout);
this.mStats.setVisibility(View.GONE); this.binding.stats.setVisibility(View.GONE);
this.binding.otherDeviceKeysCard.setVisibility(View.GONE);
} }
} }
@ -1115,28 +1084,23 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
builder.setTitle(R.string.unpublish_pgp); builder.setTitle(R.string.unpublish_pgp);
builder.setMessage(R.string.unpublish_pgp_message); builder.setMessage(R.string.unpublish_pgp_message);
builder.setNegativeButton(R.string.cancel, null); builder.setNegativeButton(R.string.cancel, null);
builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { builder.setPositiveButton(R.string.confirm, (dialogInterface, i) -> {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
mAccount.setPgpSignId(0); mAccount.setPgpSignId(0);
mAccount.unsetPgpSignature(); mAccount.unsetPgpSignature();
xmppConnectionService.databaseBackend.updateAccount(mAccount); xmppConnectionService.databaseBackend.updateAccount(mAccount);
xmppConnectionService.sendPresence(mAccount); xmppConnectionService.sendPresence(mAccount);
refreshUiReal(); refreshUiReal();
}
}); });
builder.create().show(); builder.create().show();
} }
private void showOsOptimizationWarning(boolean showBatteryWarning, boolean showDataSaverWarning) { private void showOsOptimizationWarning(boolean showBatteryWarning, boolean showDataSaverWarning) {
this.mOsOptimizations.setVisibility(showBatteryWarning || showDataSaverWarning ? View.VISIBLE : View.GONE); this.binding.osOptimization.setVisibility(showBatteryWarning || showDataSaverWarning ? View.VISIBLE : View.GONE);
if (showDataSaverWarning) { if (showDataSaverWarning) {
this.mDisableOsOptimizationsHeadline.setText(R.string.data_saver_enabled); this.binding.osOptimizationHeadline.setText(R.string.data_saver_enabled);
this.getmDisableOsOptimizationsBody.setText(R.string.data_saver_enabled_explained); this.getmDisableOsOptimizationsBody.setText(R.string.data_saver_enabled_explained);
this.mDisableOsOptimizationsButton.setText(R.string.allow); this.mDisableOsOptimizationsButton.setText(R.string.allow);
this.mDisableOsOptimizationsButton.setOnClickListener(new OnClickListener() { this.mDisableOsOptimizationsButton.setOnClickListener(v -> {
@Override
public void onClick(View v) {
Intent intent = new Intent(Settings.ACTION_IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS); Intent intent = new Intent(Settings.ACTION_IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS);
Uri uri = Uri.parse("package:" + getPackageName()); Uri uri = Uri.parse("package:" + getPackageName());
intent.setData(uri); intent.setData(uri);
@ -1145,15 +1109,12 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
Toast.makeText(EditAccountActivity.this, R.string.device_does_not_support_data_saver, Toast.LENGTH_SHORT).show(); Toast.makeText(EditAccountActivity.this, R.string.device_does_not_support_data_saver, Toast.LENGTH_SHORT).show();
} }
}
}); });
} else if (showBatteryWarning) { } else if (showBatteryWarning) {
this.mDisableOsOptimizationsButton.setText(R.string.disable); this.mDisableOsOptimizationsButton.setText(R.string.disable);
this.mDisableOsOptimizationsHeadline.setText(R.string.battery_optimizations_enabled); this.binding.osOptimizationHeadline.setText(R.string.battery_optimizations_enabled);
this.getmDisableOsOptimizationsBody.setText(R.string.battery_optimizations_enabled_explained); this.getmDisableOsOptimizationsBody.setText(R.string.battery_optimizations_enabled_explained);
this.mDisableOsOptimizationsButton.setOnClickListener(new OnClickListener() { this.mDisableOsOptimizationsButton.setOnClickListener(v -> {
@Override
public void onClick(View v) {
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
Uri uri = Uri.parse("package:" + getPackageName()); Uri uri = Uri.parse("package:" + getPackageName());
intent.setData(uri); intent.setData(uri);
@ -1162,7 +1123,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
Toast.makeText(EditAccountActivity.this, R.string.device_does_not_support_battery_op, Toast.LENGTH_SHORT).show(); Toast.makeText(EditAccountActivity.this, R.string.device_does_not_support_battery_op, Toast.LENGTH_SHORT).show();
} }
}
}); });
} }
} }
@ -1174,12 +1134,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
builder.setMessage(getString(R.string.clear_other_devices_desc)); builder.setMessage(getString(R.string.clear_other_devices_desc));
builder.setNegativeButton(getString(R.string.cancel), null); builder.setNegativeButton(getString(R.string.cancel), null);
builder.setPositiveButton(getString(R.string.accept), builder.setPositiveButton(getString(R.string.accept),
new DialogInterface.OnClickListener() { (dialog, which) -> mAccount.getAxolotlService().wipeOtherPepDevices());
@Override
public void onClick(DialogInterface dialog, int which) {
mAccount.getAxolotlService().wipeOtherPepDevices();
}
});
builder.create().show(); builder.create().show();
} }
@ -1196,13 +1151,11 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
@Override @Override
public void onCaptchaRequested(final Account account, final String id, final Data data, final Bitmap captcha) { public void onCaptchaRequested(final Account account, final String id, final Data data, final Bitmap captcha) {
runOnUiThread(new Runnable() { runOnUiThread(() -> {
@Override if (mCaptchaDialog != null && mCaptchaDialog.isShowing()) {
public void run() {
if ((mCaptchaDialog != null) && mCaptchaDialog.isShowing()) {
mCaptchaDialog.dismiss(); mCaptchaDialog.dismiss();
} }
final AlertDialog.Builder builder = new AlertDialog.Builder(EditAccountActivity.this); final Builder builder = new Builder(EditAccountActivity.this);
final View view = getLayoutInflater().inflate(R.layout.captcha, null); final View view = getLayoutInflater().inflate(R.layout.captcha, null);
final ImageView imageView = view.findViewById(R.id.captcha); final ImageView imageView = view.findViewById(R.id.captcha);
final EditText input = view.findViewById(R.id.input); final EditText input = view.findViewById(R.id.input);
@ -1212,9 +1165,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
builder.setView(view); builder.setView(view);
builder.setPositiveButton(getString(R.string.ok), builder.setPositiveButton(getString(R.string.ok),
new DialogInterface.OnClickListener() { (dialog, which) -> {
@Override
public void onClick(DialogInterface dialog, int which) {
String rc = input.getText().toString(); String rc = input.getText().toString();
data.put("username", account.getUsername()); data.put("username", account.getUsername());
data.put("password", account.getPassword()); data.put("password", account.getPassword());
@ -1222,86 +1173,58 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
data.submit(); data.submit();
if (xmppConnectionServiceBound) { if (xmppConnectionServiceBound) {
xmppConnectionService.sendCreateAccountWithCaptchaPacket( xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, id, data);
account, id, data);
}
} }
}); });
builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { builder.setNegativeButton(getString(R.string.cancel), (dialog, which) -> {
@Override
public void onClick(DialogInterface dialog, int which) {
if (xmppConnectionService != null) { if (xmppConnectionService != null) {
xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null); xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null);
} }
}
}); });
builder.setOnCancelListener(new DialogInterface.OnCancelListener() { builder.setOnCancelListener(dialog -> {
@Override
public void onCancel(DialogInterface dialog) {
if (xmppConnectionService != null) { if (xmppConnectionService != null) {
xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null); xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null);
} }
}
}); });
mCaptchaDialog = builder.create(); mCaptchaDialog = builder.create();
mCaptchaDialog.show(); mCaptchaDialog.show();
input.requestFocus(); input.requestFocus();
}
}); });
} }
public void onShowErrorToast(final int resId) { public void onShowErrorToast(final int resId) {
runOnUiThread(new Runnable() { runOnUiThread(() -> Toast.makeText(EditAccountActivity.this, resId, Toast.LENGTH_SHORT).show());
@Override
public void run() {
Toast.makeText(EditAccountActivity.this, resId, Toast.LENGTH_SHORT).show();
}
});
} }
@Override @Override
public void onPreferencesFetched(final Element prefs) { public void onPreferencesFetched(final Element prefs) {
runOnUiThread(new Runnable() { runOnUiThread(() -> {
@Override
public void run() {
if (mFetchingMamPrefsToast != null) { if (mFetchingMamPrefsToast != null) {
mFetchingMamPrefsToast.cancel(); mFetchingMamPrefsToast.cancel();
} }
AlertDialog.Builder builder = new Builder(EditAccountActivity.this); Builder builder = new Builder(EditAccountActivity.this);
builder.setTitle(R.string.server_side_mam_prefs); builder.setTitle(R.string.server_side_mam_prefs);
String defaultAttr = prefs.getAttribute("default"); String defaultAttr = prefs.getAttribute("default");
final List<String> defaults = Arrays.asList("never", "roster", "always"); final List<String> defaults = Arrays.asList("never", "roster", "always");
final AtomicInteger choice = new AtomicInteger(Math.max(0, defaults.indexOf(defaultAttr))); final AtomicInteger choice = new AtomicInteger(Math.max(0, defaults.indexOf(defaultAttr)));
builder.setSingleChoiceItems(R.array.mam_prefs, choice.get(), new DialogInterface.OnClickListener() { builder.setSingleChoiceItems(R.array.mam_prefs, choice.get(), (dialog, which) -> choice.set(which));
@Override
public void onClick(DialogInterface dialog, int which) {
choice.set(which);
}
});
builder.setNegativeButton(R.string.cancel, null); builder.setNegativeButton(R.string.cancel, null);
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { builder.setPositiveButton(R.string.ok, (dialog, which) -> {
@Override
public void onClick(DialogInterface dialog, int which) {
prefs.setAttribute("default", defaults.get(choice.get())); prefs.setAttribute("default", defaults.get(choice.get()));
xmppConnectionService.pushMamPreferences(mAccount, prefs); xmppConnectionService.pushMamPreferences(mAccount, prefs);
}
}); });
builder.create().show(); builder.create().show();
}
}); });
} }
@Override @Override
public void onPreferencesFetchFailed() { public void onPreferencesFetchFailed() {
runOnUiThread(new Runnable() { runOnUiThread(() -> {
@Override
public void run() {
if (mFetchingMamPrefsToast != null) { if (mFetchingMamPrefsToast != null) {
mFetchingMamPrefsToast.cancel(); mFetchingMamPrefsToast.cancel();
} }
Toast.makeText(EditAccountActivity.this, R.string.unable_to_fetch_mam_prefs, Toast.LENGTH_LONG).show(); Toast.makeText(EditAccountActivity.this, R.string.unable_to_fetch_mam_prefs, Toast.LENGTH_LONG).show();
}
}); });
} }

View File

@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools">
<RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/color_background_secondary"> android:background="?attr/color_background_secondary">
@ -18,16 +20,19 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<RelativeLayout
<android.support.v7.widget.CardView
android:id="@+id/editor" android:id="@+id/editor"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_vertical_margin" android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin" android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin" android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin" android:layout_marginTop="@dimen/activity_vertical_margin">
android:background="?attr/infocard_border"
android:orientation="vertical" <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/infocard_padding"> android:padding="@dimen/infocard_padding">
<com.makeramen.roundedimageview.RoundedImageView <com.makeramen.roundedimageview.RoundedImageView
@ -98,9 +103,9 @@
android:orientation="vertical"> android:orientation="vertical">
<android.support.design.widget.TextInputLayout <android.support.design.widget.TextInputLayout
android:id="@+id/hostname_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/hostname_layout"
android:hint="@string/account_settings_hostname"> android:hint="@string/account_settings_hostname">
<EditText <EditText
@ -121,9 +126,9 @@
android:orientation="vertical"> android:orientation="vertical">
<android.support.design.widget.TextInputLayout <android.support.design.widget.TextInputLayout
android:id="@+id/port_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/port_layout"
android:hint="@string/account_settings_port"> android:hint="@string/account_settings_port">
<EditText <EditText
@ -149,8 +154,9 @@
android:textSize="?attr/TextSizeBody"/> android:textSize="?attr/TextSizeBody"/>
</LinearLayout> </LinearLayout>
</RelativeLayout> </RelativeLayout>
</android.support.v7.widget.CardView>
<RelativeLayout <android.support.v7.widget.CardView
android:id="@+id/os_optimization" android:id="@+id/os_optimization"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -158,11 +164,13 @@
android:layout_marginLeft="@dimen/activity_horizontal_margin" android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin" android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin" android:layout_marginTop="@dimen/activity_vertical_margin"
android:background="?attr/infocard_border"
android:orientation="vertical"
android:padding="@dimen/infocard_padding"
android:visibility="gone"> android:visibility="gone">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/infocard_padding">
<TextView <TextView
android:id="@+id/os_optimization_headline" android:id="@+id/os_optimization_headline"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -196,9 +204,10 @@
android:text="@string/disable" android:text="@string/disable"
android:textColor="@color/accent"/> android:textColor="@color/accent"/>
</RelativeLayout> </RelativeLayout>
</android.support.v7.widget.CardView>
<LinearLayout <android.support.v7.widget.CardView
android:id="@+id/stats" android:id="@+id/stats"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
@ -206,11 +215,14 @@
android:layout_marginLeft="@dimen/activity_horizontal_margin" android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin" android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin" android:layout_marginTop="@dimen/activity_vertical_margin"
android:background="?attr/infocard_border"
android:orientation="vertical"
android:padding="@dimen/infocard_padding"
android:visibility="gone"> android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/infocard_padding">
<TableLayout <TableLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -624,8 +636,9 @@
</LinearLayout> </LinearLayout>
</RelativeLayout> </RelativeLayout>
</LinearLayout> </LinearLayout>
</android.support.v7.widget.CardView>
<LinearLayout <android.support.v7.widget.CardView
android:id="@+id/other_device_keys_card" android:id="@+id/other_device_keys_card"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -633,11 +646,14 @@
android:layout_marginLeft="@dimen/activity_horizontal_margin" android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin" android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin" android:layout_marginTop="@dimen/activity_vertical_margin"
android:background="?attr/infocard_border"
android:orientation="vertical"
android:padding="@dimen/infocard_padding"
android:visibility="gone"> android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/infocard_padding">
<TextView <TextView
android:id="@+id/other_device_keys_title" android:id="@+id/other_device_keys_title"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -664,6 +680,7 @@
android:text="@string/clear_other_devices" android:text="@string/clear_other_devices"
android:textColor="@color/accent"/> android:textColor="@color/accent"/>
</LinearLayout> </LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
@ -705,3 +722,4 @@
</LinearLayout> </LinearLayout>
</RelativeLayout> </RelativeLayout>
</layout>