diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-08-19 15:06:50 +0200 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-08-19 15:06:50 +0200 |
commit | 3b79cc2f23617903dda1876f80fd295d45e9ba3b (patch) | |
tree | ae346f109c9a0b96890d8769be0bccca5dbfc2af /src/eu/siacs/conversations/ui | |
parent | d74692e0a582edc7d9701f58d19ca812a39096bc (diff) |
better error display and additional infos (stats) for the edit account activity
Diffstat (limited to 'src/eu/siacs/conversations/ui')
3 files changed, 65 insertions, 126 deletions
diff --git a/src/eu/siacs/conversations/ui/EditAccountActivity.java b/src/eu/siacs/conversations/ui/EditAccountActivity.java index e5920cdfe..5f1835e91 100644 --- a/src/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/eu/siacs/conversations/ui/EditAccountActivity.java @@ -12,11 +12,15 @@ import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TableLayout; import android.widget.CompoundButton.OnCheckedChangeListener; +import android.widget.TextView; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate; import eu.siacs.conversations.ui.adapter.KnownHostsAdapter; +import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.Validator; import eu.siacs.conversations.xmpp.pep.Avatar; @@ -29,18 +33,20 @@ public class EditAccountActivity extends XmppActivity { private Button mCancelButton; private Button mSaveButton; + private LinearLayout mStats; + private TextView mServerCompat; + private TextView mSessionEst; + private String jidToEdit; private Account mAccount; - private boolean mUserInputIsValid = false; private boolean mFetchingAvatar = false; - + private OnClickListener mSaveButtonClickListener = new OnClickListener() { @Override public void onClick(View v) { - if (mAccount != null && mAccount.errorStatus() - && !mUserInputIsValid) { + if (mAccount != null && mAccount.errorStatus()) { xmppConnectionService.reconnectAccount(mAccount, true); return; } @@ -66,11 +72,14 @@ public class EditAccountActivity extends XmppActivity { mAccount.setPassword(password); mAccount.setUsername(username); mAccount.setServer(server); - mAccount.setOption(Account.OPTION_REGISTER, mRegisterNew.isChecked()); + mAccount.setOption(Account.OPTION_REGISTER, + mRegisterNew.isChecked()); xmppConnectionService.updateAccount(mAccount); } else { - if (xmppConnectionService.findAccountByJid(mAccountJid.getText().toString())!=null) { - mAccountJid.setError(getString(R.string.account_already_exists)); + if (xmppConnectionService.findAccountByJid(mAccountJid + .getText().toString()) != null) { + mAccountJid + .setError(getString(R.string.account_already_exists)); return; } mAccount = new Account(username, server, password); @@ -84,7 +93,6 @@ public class EditAccountActivity extends XmppActivity { if (jidToEdit != null) { finish(); } else { - mUserInputIsValid = false; updateSaveButton(); updateAccountInformation(); } @@ -98,24 +106,6 @@ public class EditAccountActivity extends XmppActivity { finish(); } }; - private TextWatcher mTextWatcher = new TextWatcher() { - - @Override - public void onTextChanged(CharSequence s, int start, int before, - int count) { - mUserInputIsValid = inputDataDiffersFromAccount() && Validator.isValidJid(mAccountJid.getText().toString()); - updateSaveButton(); - } - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, - int after) { - } - - @Override - public void afterTextChanged(Editable s) { - } - }; private OnAccountUpdate mOnAccountUpdateListener = new OnAccountUpdate() { @Override @@ -124,10 +114,15 @@ public class EditAccountActivity extends XmppActivity { @Override public void run() { - if (jidToEdit==null && mAccount!=null && mAccount.getStatus() == Account.STATUS_ONLINE) { + if (mAccount != null) { + updateAccountInformation(); + } + if (jidToEdit == null && mAccount != null + && mAccount.getStatus() == Account.STATUS_ONLINE) { if (!mFetchingAvatar) { mFetchingAvatar = true; - xmppConnectionService.checkForAvatar(mAccount, mAvatarFetchCallback); + xmppConnectionService.checkForAvatar(mAccount, + mAvatarFetchCallback); } } else { updateSaveButton(); @@ -137,33 +132,36 @@ public class EditAccountActivity extends XmppActivity { } }; private UiCallback<Avatar> mAvatarFetchCallback = new UiCallback<Avatar>() { - + @Override public void userInputRequried(PendingIntent pi, Avatar avatar) { finishInitialSetup(avatar); } - + @Override public void success(Avatar avatar) { finishInitialSetup(avatar); } - + @Override public void error(int errorCode, Avatar avatar) { finishInitialSetup(avatar); } }; + private KnownHostsAdapter mKnownHostsAdapter; protected void finishInitialSetup(final Avatar avatar) { runOnUiThread(new Runnable() { - + @Override public void run() { Intent intent; - if (avatar!=null) { - intent = new Intent(getApplicationContext(), StartConversationActivity.class); + if (avatar != null) { + intent = new Intent(getApplicationContext(), + StartConversationActivity.class); } else { - intent = new Intent(getApplicationContext(), PublishProfilePictureActivity.class); + intent = new Intent(getApplicationContext(), + PublishProfilePictureActivity.class); intent.putExtra("account", mAccount.getJid()); } startActivity(intent); @@ -171,7 +169,7 @@ public class EditAccountActivity extends XmppActivity { } }); } - + protected boolean inputDataDiffersFromAccount() { if (mAccount == null) { return true; @@ -186,29 +184,15 @@ public class EditAccountActivity extends XmppActivity { protected void updateSaveButton() { if (mAccount != null - && mAccount.getStatus() == Account.STATUS_CONNECTING - && !mUserInputIsValid) { + && mAccount.getStatus() == Account.STATUS_CONNECTING) { this.mSaveButton.setEnabled(false); this.mSaveButton.setTextColor(getSecondaryTextColor()); this.mSaveButton.setText(R.string.account_status_connecting); - } else if (mAccount != null && mAccount.errorStatus() - && !mUserInputIsValid) { - this.mSaveButton.setEnabled(true); - this.mSaveButton.setTextColor(getPrimaryTextColor()); - this.mSaveButton.setText(R.string.connect); - } else if (mUserInputIsValid) { + } else { this.mSaveButton.setEnabled(true); this.mSaveButton.setTextColor(getPrimaryTextColor()); - if (jidToEdit!=null) { - this.mSaveButton.setText(R.string.save); - } else { - this.mSaveButton.setText(R.string.next); - } - } else { - this.mSaveButton.setEnabled(false); - this.mSaveButton.setTextColor(getSecondaryTextColor()); - if (jidToEdit!=null) { - this.mSaveButton.setText(R.string.save); + if (jidToEdit != null) { + this.mSaveButton.setText(R.string.connect); } else { this.mSaveButton.setText(R.string.next); } @@ -223,6 +207,9 @@ public class EditAccountActivity extends XmppActivity { this.mPassword = (EditText) findViewById(R.id.account_password); this.mPasswordConfirm = (EditText) findViewById(R.id.account_password_confirm); 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.mServerCompat = (TextView) findViewById(R.id.server_compat); this.mSaveButton = (Button) findViewById(R.id.save_button); this.mCancelButton = (Button) findViewById(R.id.cancel_button); this.mSaveButton.setOnClickListener(this.mSaveButtonClickListener); @@ -238,12 +225,9 @@ public class EditAccountActivity extends XmppActivity { } else { mPasswordConfirm.setVisibility(View.GONE); } - mUserInputIsValid = inputDataDiffersFromAccount() && Validator.isValidJid(mAccountJid.getText().toString()); updateSaveButton(); } }); - this.mAccountJid.addTextChangedListener(this.mTextWatcher); - this.mPassword.addTextChangedListener(this.mTextWatcher); } @Override @@ -262,6 +246,9 @@ public class EditAccountActivity extends XmppActivity { @Override protected void onBackendConnected() { + this.mKnownHostsAdapter = new KnownHostsAdapter(this, + android.R.layout.simple_list_item_1, + xmppConnectionService.getKnownHosts()); this.xmppConnectionService .setOnAccountListChangedListener(this.mOnAccountUpdateListener); this.mAccountJid.setAdapter(null); @@ -273,9 +260,7 @@ public class EditAccountActivity extends XmppActivity { getActionBar().setDisplayShowHomeEnabled(false); this.mCancelButton.setEnabled(false); } - this.mAccountJid.setAdapter(new KnownHostsAdapter(this, - android.R.layout.simple_list_item_1, xmppConnectionService - .getKnownHosts())); + this.mAccountJid.setAdapter(this.mKnownHostsAdapter); updateSaveButton(); } @@ -290,5 +275,21 @@ public class EditAccountActivity extends XmppActivity { this.mRegisterNew.setVisibility(View.GONE); this.mRegisterNew.setChecked(false); } + if (this.mAccount.getStatus() == Account.STATUS_ONLINE) { + this.mStats.setVisibility(View.VISIBLE); + this.mSessionEst.setText(UIHelper.readableTimeDifference( + getApplicationContext(), this.mAccount.getXmppConnection() + .getLastSessionEstablished())); + this.mServerCompat.setText(this.mAccount.getXmppConnection() + .getFeatures().getCompatibility() + + "%"); + } else { + if (this.mAccount.errorStatus()) { + this.mAccountJid.setError(getString(this.mAccount + .getReadableStatusId())); + this.mAccountJid.requestFocus(); + } + this.mStats.setVisibility(View.GONE); + } } } diff --git a/src/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/eu/siacs/conversations/ui/ManageAccountActivity.java index 803917b97..457dded3f 100644 --- a/src/eu/siacs/conversations/ui/ManageAccountActivity.java +++ b/src/eu/siacs/conversations/ui/ManageAccountActivity.java @@ -146,71 +146,6 @@ public class ManageAccountActivity extends XmppActivity { builder.setView(view); builder.setPositiveButton(getString(R.string.done), null); builder.create().show(); - } else if (item.getItemId() == R.id.mgmt_account_info) { - AlertDialog.Builder builder = new AlertDialog.Builder(activity); - builder.setTitle(getString(R.string.account_info)); - if (selectedAccountForActionMode.getStatus() == Account.STATUS_ONLINE) { - XmppConnection xmpp = selectedAccountForActionMode - .getXmppConnection(); - long connectionAge = (SystemClock.elapsedRealtime() - xmpp.lastConnect) / 60000; - long sessionAge = (SystemClock.elapsedRealtime() - xmpp.lastSessionStarted) / 60000; - long connectionAgeHours = connectionAge / 60; - long sessionAgeHours = sessionAge / 60; - View view = (View) getLayoutInflater().inflate( - R.layout.server_info, null); - TextView connection = (TextView) view - .findViewById(R.id.connection); - TextView session = (TextView) view - .findViewById(R.id.session); - TextView pcks_sent = (TextView) view - .findViewById(R.id.pcks_sent); - TextView pcks_received = (TextView) view - .findViewById(R.id.pcks_received); - TextView carbon = (TextView) view.findViewById(R.id.carbon); - TextView stream = (TextView) view.findViewById(R.id.stream); - TextView roster = (TextView) view.findViewById(R.id.roster); - TextView presences = (TextView) view - .findViewById(R.id.number_presences); - presences.setText(selectedAccountForActionMode - .countPresences() + ""); - pcks_received.setText("" + xmpp.getReceivedStanzas()); - pcks_sent.setText("" + xmpp.getSentStanzas()); - if (connectionAgeHours >= 2) { - connection.setText(connectionAgeHours + " " - + getString(R.string.hours)); - } else { - connection.setText(connectionAge + " " - + getString(R.string.mins)); - } - if (xmpp.getFeatures().sm()) { - if (sessionAgeHours >= 2) { - session.setText(sessionAgeHours + " " - + getString(R.string.hours)); - } else { - session.setText(sessionAge + " " - + getString(R.string.mins)); - } - stream.setText(getString(R.string.yes)); - } else { - stream.setText(getString(R.string.no)); - session.setText(connection.getText()); - } - if (xmpp.getFeatures().carbons()) { - carbon.setText(getString(R.string.yes)); - } else { - carbon.setText(getString(R.string.no)); - } - if (xmpp.getFeatures().rosterVersioning()) { - roster.setText(getString(R.string.yes)); - } else { - roster.setText(getString(R.string.no)); - } - builder.setView(view); - } else { - builder.setMessage(getString(R.string.mgmt_account_account_offline)); - } - builder.setPositiveButton(getString(R.string.hide), null); - builder.create().show(); } return true; } diff --git a/src/eu/siacs/conversations/ui/adapter/KnownHostsAdapter.java b/src/eu/siacs/conversations/ui/adapter/KnownHostsAdapter.java index 040e62667..d286052cb 100644 --- a/src/eu/siacs/conversations/ui/adapter/KnownHostsAdapter.java +++ b/src/eu/siacs/conversations/ui/adapter/KnownHostsAdapter.java @@ -23,7 +23,10 @@ public class KnownHostsAdapter extends ArrayAdapter<String> { } } else if (split.length == 2) { for (String domain : domains) { - if (domain.contains(split[1])) { + if (domain.contentEquals(split[1])) { + suggestions.clear(); + break; + } else if (domain.contains(split[1])) { suggestions.add(split[0].toLowerCase(Locale.getDefault()) + "@" + domain); } } |