diff options
author | lookshe <github@lookshe.org> | 2015-01-03 23:19:05 +0100 |
---|---|---|
committer | lookshe <github@lookshe.org> | 2015-01-03 23:19:05 +0100 |
commit | 95e2a539517c27b3235acd582f17968c8e301e81 (patch) | |
tree | 213bbeed798751e949376d85f4d7d0bd30c5fbfa /src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java | |
parent | 48717dd7d37c066ab626fc626a2ced626ef21d42 (diff) | |
parent | 4f4eff2353f4e359b5582c8e808a4e88631c3e74 (diff) |
Merge branch 'master' of ssh://git.fucktheforce.de/conversations
Conflicts:
src/main/java/eu/siacs/conversations/Config.java
src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
src/main/java/eu/siacs/conversations/utils/UIHelper.java
Diffstat (limited to '')
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java | 324 |
1 files changed, 192 insertions, 132 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index 8fad66cf..ea45b75e 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -19,6 +19,7 @@ import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; +import android.widget.TableLayout; import android.widget.TextView; import android.widget.Toast; @@ -28,13 +29,12 @@ import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate; import eu.siacs.conversations.ui.adapter.KnownHostsAdapter; import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.UIHelper; -import eu.siacs.conversations.utils.Validator; import eu.siacs.conversations.xmpp.XmppConnection.Features; import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.pep.Avatar; -public class EditAccountActivity extends XmppActivity implements OnAccountUpdate { +public class EditAccountActivity extends XmppActivity implements OnAccountUpdate{ private AutoCompleteTextView mAccountJid; private EditText mPassword; @@ -42,10 +42,15 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate private CheckBox mRegisterNew; private Button mCancelButton; private Button mSaveButton; + private TableLayout mMoreTable; private LinearLayout mStats; private TextView mServerInfoSm; + private TextView mServerInfoRosterVersion; private TextView mServerInfoCarbons; + private TextView mServerInfoMam; + private TextView mServerInfoCSI; + private TextView mServerInfoBlocking; private TextView mServerInfoPep; private TextView mSessionEst; private TextView mOtrFingerprint; @@ -58,22 +63,16 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate private boolean mFetchingAvatar = false; - private OnClickListener mSaveButtonClickListener = new OnClickListener() { + private final OnClickListener mSaveButtonClickListener = new OnClickListener() { @Override - public void onClick(View v) { - if (mAccount != null - && mAccount.getStatus() == Account.State.DISABLED) { + public void onClick(final View v) { + if (mAccount != null && mAccount.getStatus() == Account.State.DISABLED) { mAccount.setOption(Account.OPTION_DISABLED, false); xmppConnectionService.updateAccount(mAccount); return; } - if (!Validator.isValidJid(mAccountJid.getText().toString())) { - mAccountJid.setError(getString(R.string.invalid_jid)); - mAccountJid.requestFocus(); - return; - } - boolean registerNewAccount = mRegisterNew.isChecked(); + final boolean registerNewAccount = mRegisterNew.isChecked(); final Jid jid; try { jid = Jid.fromString(mAccountJid.getText().toString()); @@ -82,37 +81,41 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate mAccountJid.requestFocus(); return; } - String password = mPassword.getText().toString(); - String passwordConfirm = mPasswordConfirm.getText().toString(); + if (jid.isDomainJid()) { + mAccountJid.setError(getString(R.string.invalid_jid)); + mAccountJid.requestFocus(); + return; + } + final String password = mPassword.getText().toString(); + final String passwordConfirm = mPasswordConfirm.getText().toString(); if (registerNewAccount) { if (!password.equals(passwordConfirm)) { - mPasswordConfirm - .setError(getString(R.string.passwords_do_not_match)); + mPasswordConfirm.setError(getString(R.string.passwords_do_not_match)); mPasswordConfirm.requestFocus(); return; } } if (mAccount != null) { + try { + mAccount.setUsername(jid.hasLocalpart() ? jid.getLocalpart() : ""); + mAccount.setServer(jid.getDomainpart()); + } catch (final InvalidJidException ignored) { + return; + } mAccount.setPassword(password); - try { - mAccount.setUsername(jid.hasLocalpart() ? jid.getLocalpart() : ""); - mAccount.setServer(jid.getDomainpart()); - } catch (final InvalidJidException ignored) { - } mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount); xmppConnectionService.updateAccount(mAccount); } else { - try { - if (xmppConnectionService.findAccountByJid(Jid.fromString(mAccountJid.getText().toString())) != null) { - mAccountJid - .setError(getString(R.string.account_already_exists)); - mAccountJid.requestFocus(); - return; - } - } catch (InvalidJidException e) { - return; - } - mAccount = new Account(jid.toBareJid(), password); + try { + if (xmppConnectionService.findAccountByJid(Jid.fromString(mAccountJid.getText().toString())) != null) { + mAccountJid.setError(getString(R.string.account_already_exists)); + mAccountJid.requestFocus(); + return; + } + } catch (final InvalidJidException e) { + return; + } + mAccount = new Account(jid.toBareJid(), password); mAccount.setOption(Account.OPTION_USETLS, true); mAccount.setOption(Account.OPTION_USECOMPRESSION, true); mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount); @@ -127,82 +130,81 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate } }; - private OnClickListener mCancelButtonClickListener = new OnClickListener() { + private final OnClickListener mCancelButtonClickListener = new OnClickListener() { @Override - public void onClick(View v) { + public void onClick(final View v) { finish(); } }; - @Override - public void onAccountUpdate() { - runOnUiThread(new Runnable() { - - @Override - public void run() { - if (mAccount != null - && mAccount.getStatus() != Account.State.ONLINE - && mFetchingAvatar) { - startActivity(new Intent(getApplicationContext(), + @Override + public void onAccountUpdate() { + runOnUiThread(new Runnable() { + + @Override + public void run() { + invalidateOptionsMenu(); + if (mAccount != null + && mAccount.getStatus() != Account.State.ONLINE + && mFetchingAvatar) { + startActivity(new Intent(getApplicationContext(), ManageAccountActivity.class)); - finish(); - } else if (jidToEdit == null && mAccount != null - && mAccount.getStatus() == Account.State.ONLINE) { - if (!mFetchingAvatar) { - mFetchingAvatar = true; - xmppConnectionService.checkForAvatar(mAccount, - mAvatarFetchCallback); - } - } else { - updateSaveButton(); - } - if (mAccount != null) { - updateAccountInformation(); + finish(); + } else if (jidToEdit == null && mAccount != null + && mAccount.getStatus() == Account.State.ONLINE) { + if (!mFetchingAvatar) { + mFetchingAvatar = true; + xmppConnectionService.checkForAvatar(mAccount, + mAvatarFetchCallback); } + } else { + updateSaveButton(); } - }); - } - private UiCallback<Avatar> mAvatarFetchCallback = new UiCallback<Avatar>() { + if (mAccount != null) { + updateAccountInformation(); + } + } + }); + } + private final UiCallback<Avatar> mAvatarFetchCallback = new UiCallback<Avatar>() { @Override - public void userInputRequried(PendingIntent pi, Avatar avatar) { + public void userInputRequried(final PendingIntent pi, final Avatar avatar) { finishInitialSetup(avatar); } @Override - public void success(Avatar avatar) { + public void success(final Avatar avatar) { finishInitialSetup(avatar); } @Override - public void error(int errorCode, Avatar avatar) { + public void error(final int errorCode, final Avatar avatar) { finishInitialSetup(avatar); } }; - private TextWatcher mTextWatcher = new TextWatcher() { + private final TextWatcher mTextWatcher = new TextWatcher() { @Override - public void onTextChanged(CharSequence s, int start, int before, - int count) { + public void onTextChanged(final CharSequence s, final int start, final int before, final int count) { updateSaveButton(); } @Override - public void beforeTextChanged(CharSequence s, int start, int count, - int after) { - + public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) { } @Override - public void afterTextChanged(Editable s) { + public void afterTextChanged(final Editable s) { } }; - private OnClickListener mAvatarClickListener = new OnClickListener() { + + private final OnClickListener mAvatarClickListener = new OnClickListener() { @Override - public void onClick(View view) { - if (mAccount!=null) { - Intent intent = new Intent(getApplicationContext(), + public void onClick(final View view) { + if (mAccount != null) { + final Intent intent = new Intent(getApplicationContext(), PublishProfilePictureActivity.class); intent.putExtra("account", mAccount.getJid().toBareJid().toString()); startActivity(intent); @@ -215,7 +217,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate @Override public void run() { - Intent intent; + final Intent intent; if (avatar != null) { intent = new Intent(getApplicationContext(), StartConversationActivity.class); @@ -232,13 +234,11 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate } protected void updateSaveButton() { - if (mAccount != null - && mAccount.getStatus() == Account.State.CONNECTING) { + if (mAccount != null && mAccount.getStatus() == Account.State.CONNECTING) { this.mSaveButton.setEnabled(false); this.mSaveButton.setTextColor(getSecondaryTextColor()); this.mSaveButton.setText(R.string.account_status_connecting); - } else if (mAccount != null - && mAccount.getStatus() == Account.State.DISABLED) { + } else if (mAccount != null && mAccount.getStatus() == Account.State.DISABLED) { this.mSaveButton.setEnabled(true); this.mSaveButton.setTextColor(getPrimaryTextColor()); this.mSaveButton.setText(R.string.enable); @@ -246,8 +246,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate this.mSaveButton.setEnabled(true); this.mSaveButton.setTextColor(getPrimaryTextColor()); if (jidToEdit != null) { - if (mAccount != null - && mAccount.getStatus() == Account.State.ONLINE) { + if (mAccount != null && mAccount.isOnlineAndConnected()) { this.mSaveButton.setText(R.string.save); if (!accountInfoEdited()) { this.mSaveButton.setEnabled(false); @@ -263,10 +262,10 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate } protected boolean accountInfoEdited() { - return (!this.mAccount.getJid().toBareJid().equals( - this.mAccountJid.getText().toString())) - || (!this.mAccount.getPassword().equals( - this.mPassword.getText().toString())); + return (!this.mAccount.getJid().toBareJid().toString().equals( + this.mAccountJid.getText().toString())) + || (!this.mAccount.getPassword().equals( + this.mPassword.getText().toString())); } @Override @@ -279,7 +278,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate } @Override - protected void onCreate(Bundle savedInstanceState) { + protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_edit_account); this.mAccountJid = (AutoCompleteTextView) findViewById(R.id.account_jid); @@ -292,7 +291,11 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate this.mRegisterNew = (CheckBox) findViewById(R.id.account_register_new); this.mStats = (LinearLayout) findViewById(R.id.stats); this.mSessionEst = (TextView) findViewById(R.id.session_est); + this.mServerInfoRosterVersion = (TextView) findViewById(R.id.server_info_roster_version); this.mServerInfoCarbons = (TextView) findViewById(R.id.server_info_carbons); + this.mServerInfoMam = (TextView) findViewById(R.id.server_info_mam); + this.mServerInfoCSI = (TextView) findViewById(R.id.server_info_csi); + this.mServerInfoBlocking = (TextView) findViewById(R.id.server_info_blocking); this.mServerInfoSm = (TextView) findViewById(R.id.server_info_sm); this.mServerInfoPep = (TextView) findViewById(R.id.server_info_pep); this.mOtrFingerprint = (TextView) findViewById(R.id.otr_fingerprint); @@ -302,29 +305,41 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate this.mCancelButton = (Button) findViewById(R.id.cancel_button); this.mSaveButton.setOnClickListener(this.mSaveButtonClickListener); this.mCancelButton.setOnClickListener(this.mCancelButtonClickListener); - this.mRegisterNew - .setOnCheckedChangeListener(new OnCheckedChangeListener() { - - @Override - public void onCheckedChanged(CompoundButton buttonView, - boolean isChecked) { - if (isChecked) { - mPasswordConfirm.setVisibility(View.VISIBLE); - } else { - mPasswordConfirm.setVisibility(View.GONE); - } - updateSaveButton(); - } - }); + this.mMoreTable = (TableLayout) findViewById(R.id.server_info_more); + final OnCheckedChangeListener OnCheckedShowConfirmPassword = new OnCheckedChangeListener() { + @Override + public void onCheckedChanged(final CompoundButton buttonView, + final boolean isChecked) { + if (isChecked) { + mPasswordConfirm.setVisibility(View.VISIBLE); + } else { + mPasswordConfirm.setVisibility(View.GONE); + } + updateSaveButton(); + } + }; + this.mRegisterNew.setOnCheckedChangeListener(OnCheckedShowConfirmPassword); } @Override - public boolean onCreateOptionsMenu(Menu menu) { + public boolean onCreateOptionsMenu(final Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.editaccount, menu); - MenuItem showQrCode = menu.findItem(R.id.action_show_qr_code); + final MenuItem showQrCode = menu.findItem(R.id.action_show_qr_code); + final MenuItem showBlocklist = menu.findItem(R.id.action_show_block_list); + final MenuItem showMoreInfo = menu.findItem(R.id.action_server_info_show_more); + final MenuItem changePassword = menu.findItem(R.id.action_change_password_on_server); if (mAccount == null) { showQrCode.setVisible(false); + showBlocklist.setVisible(false); + showMoreInfo.setVisible(false); + changePassword.setVisible(false); + } else if (mAccount.getStatus() != Account.State.ONLINE) { + showBlocklist.setVisible(false); + showMoreInfo.setVisible(false); + changePassword.setVisible(false); + } else if (!mAccount.getXmppConnection().getFeatures().blocking()) { + showBlocklist.setVisible(false); } return true; } @@ -333,32 +348,38 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate protected void onStart() { super.onStart(); if (getIntent() != null) { - try { - this.jidToEdit = Jid.fromString(getIntent().getStringExtra("jid")); - } catch (final InvalidJidException | NullPointerException ignored) { - this.jidToEdit = null; - } - if (this.jidToEdit != null) { + try { + this.jidToEdit = Jid.fromString(getIntent().getStringExtra("jid")); + } catch (final InvalidJidException | NullPointerException ignored) { + this.jidToEdit = null; + } + if (this.jidToEdit != null) { this.mRegisterNew.setVisibility(View.GONE); - getActionBar().setTitle(getString(R.string.account_details)); + if (getActionBar() != null) { + getActionBar().setTitle(getString(R.string.account_details)); + } } else { this.mAvatar.setVisibility(View.GONE); - getActionBar().setTitle(R.string.action_add_account); + if (getActionBar() != null) { + getActionBar().setTitle(R.string.action_add_account); + } } } } @Override protected void onBackendConnected() { - KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this, - android.R.layout.simple_list_item_1, - xmppConnectionService.getKnownHosts()); + final KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this, + android.R.layout.simple_list_item_1, + xmppConnectionService.getKnownHosts()); if (this.jidToEdit != null) { this.mAccount = xmppConnectionService.findAccountByJid(jidToEdit); updateAccountInformation(); } else if (this.xmppConnectionService.getAccounts().size() == 0) { - getActionBar().setDisplayHomeAsUpEnabled(false); - getActionBar().setDisplayShowHomeEnabled(false); + if (getActionBar() != null) { + getActionBar().setDisplayHomeAsUpEnabled(false); + getActionBar().setDisplayShowHomeEnabled(false); + } this.mCancelButton.setEnabled(false); this.mCancelButton.setTextColor(getSecondaryTextColor()); } @@ -366,6 +387,27 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate updateSaveButton(); } + @Override + public boolean onOptionsItemSelected(final MenuItem item) { + switch (item.getItemId()) { + case R.id.action_show_block_list: + final Intent showBlocklistIntent = new Intent(this, BlocklistActivity.class); + showBlocklistIntent.putExtra("account", mAccount.getJid().toString()); + startActivity(showBlocklistIntent); + break; + case R.id.action_server_info_show_more: + mMoreTable.setVisibility(item.isChecked() ? View.GONE : View.VISIBLE); + item.setChecked(!item.isChecked()); + break; + case R.id.action_change_password_on_server: + final Intent changePasswordIntent = new Intent(this, ChangePasswordActivity.class); + changePasswordIntent.putExtra("account", mAccount.getJid().toString()); + startActivity(changePasswordIntent); + break; + } + return super.onOptionsItemSelected(item); + } + private void updateAccountInformation() { this.mAccountJid.setText(this.mAccount.getJid().toBareJid().toString()); this.mPassword.setText(this.mAccount.getPassword()); @@ -381,18 +423,36 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate this.mRegisterNew.setVisibility(View.GONE); this.mRegisterNew.setChecked(false); } - if (this.mAccount.getStatus() == Account.State.ONLINE - && !this.mFetchingAvatar) { + if (this.mAccount.isOnlineAndConnected() && !this.mFetchingAvatar) { this.mStats.setVisibility(View.VISIBLE); - this.mSessionEst.setText(UIHelper.readableTimeDifferenceFull( - getApplicationContext(), this.mAccount.getXmppConnection() - .getLastSessionEstablished())); + this.mSessionEst.setText(UIHelper.readableTimeDifferenceFull(this, this.mAccount.getXmppConnection() + .getLastSessionEstablished())); Features features = this.mAccount.getXmppConnection().getFeatures(); + if (features.rosterVersioning()) { + this.mServerInfoRosterVersion.setText(R.string.server_info_available); + } else { + this.mServerInfoRosterVersion.setText(R.string.server_info_unavailable); + } if (features.carbons()) { this.mServerInfoCarbons.setText(R.string.server_info_available); } else { this.mServerInfoCarbons - .setText(R.string.server_info_unavailable); + .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); @@ -409,21 +469,21 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate this.mOtrFingerprintBox.setVisibility(View.VISIBLE); this.mOtrFingerprint.setText(CryptoHelper.prettifyFingerprint(fingerprint)); this.mOtrFingerprintToClipboardButton - .setVisibility(View.VISIBLE); + .setVisibility(View.VISIBLE); this.mOtrFingerprintToClipboardButton - .setOnClickListener(new View.OnClickListener() { + .setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { + @Override + public void onClick(final View v) { - if (copyTextToClipboard(fingerprint, R.string.otr_fingerprint)) { - Toast.makeText( - EditAccountActivity.this, - R.string.toast_message_otr_fingerprint, - Toast.LENGTH_SHORT).show(); - } + if (copyTextToClipboard(fingerprint, R.string.otr_fingerprint)) { + Toast.makeText( + EditAccountActivity.this, + R.string.toast_message_otr_fingerprint, + Toast.LENGTH_SHORT).show(); } - }); + } + }); } else { this.mOtrFingerprintBox.setVisibility(View.GONE); } |