diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-08-20 11:32:49 +0200 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-08-20 11:32:49 +0200 |
commit | 06da080371de8a8bc05d614ea4d4aaf208933700 (patch) | |
tree | 71b931917ba50821786b9ffb48459bd72dff9983 /src/eu | |
parent | 63452173285cc991fe9c512023e91067e560394e (diff) |
revised manage account activity. removed contexual action mode
Diffstat (limited to 'src/eu')
-rw-r--r-- | src/eu/siacs/conversations/ui/EditAccountActivity.java | 38 | ||||
-rw-r--r-- | src/eu/siacs/conversations/ui/ManageAccountActivity.java | 243 |
2 files changed, 109 insertions, 172 deletions
diff --git a/src/eu/siacs/conversations/ui/EditAccountActivity.java b/src/eu/siacs/conversations/ui/EditAccountActivity.java index 9058179ed..774219d86 100644 --- a/src/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/eu/siacs/conversations/ui/EditAccountActivity.java @@ -3,8 +3,6 @@ package eu.siacs.conversations.ui; import android.app.PendingIntent; import android.content.Intent; import android.os.Bundle; -import android.text.Editable; -import android.text.TextWatcher; import android.view.View; import android.view.View.OnClickListener; import android.widget.AutoCompleteTextView; @@ -13,7 +11,6 @@ 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; @@ -36,6 +33,8 @@ public class EditAccountActivity extends XmppActivity { private LinearLayout mStats; private TextView mServerCompat; private TextView mSessionEst; + private TextView mOtrFingerprint; + private TextView mOtrFingerprintHeadline; private String jidToEdit; private Account mAccount; @@ -46,8 +45,9 @@ public class EditAccountActivity extends XmppActivity { @Override public void onClick(View v) { - if (mAccount != null && mAccount.errorStatus()) { - xmppConnectionService.reconnectAccount(mAccount, true); + if (!Validator.isValidJid(mAccountJid.getText().toString())) { + mAccountJid.setError(getString(R.string.invalid_jid)); + mAccountJid.requestFocus(); return; } boolean registerNewAccount = mRegisterNew.isChecked(); @@ -65,6 +65,7 @@ public class EditAccountActivity extends XmppActivity { if (!password.equals(passwordConfirm)) { mPasswordConfirm .setError(getString(R.string.passwords_do_not_match)); + mPasswordConfirm.requestFocus(); return; } } @@ -72,22 +73,20 @@ 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,registerNewAccount); xmppConnectionService.updateAccount(mAccount); } else { if (xmppConnectionService.findAccountByJid(mAccountJid .getText().toString()) != null) { mAccountJid .setError(getString(R.string.account_already_exists)); + mAccountJid.requestFocus(); return; } mAccount = new Account(username, server, password); mAccount.setOption(Account.OPTION_USETLS, true); mAccount.setOption(Account.OPTION_USECOMPRESSION, true); - if (registerNewAccount) { - mAccount.setOption(Account.OPTION_REGISTER, true); - } + mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount); xmppConnectionService.createAccount(mAccount); } if (jidToEdit != null) { @@ -114,9 +113,6 @@ public class EditAccountActivity extends XmppActivity { @Override public void run() { - if (mAccount != null) { - updateAccountInformation(); - } if (jidToEdit == null && mAccount != null && mAccount.getStatus() == Account.STATUS_ONLINE) { if (!mFetchingAvatar) { @@ -127,6 +123,9 @@ public class EditAccountActivity extends XmppActivity { } else { updateSaveButton(); } + if (mAccount != null) { + updateAccountInformation(); + } } }); } @@ -210,6 +209,8 @@ public class EditAccountActivity extends XmppActivity { this.mStats = (LinearLayout) findViewById(R.id.stats); this.mSessionEst = (TextView) findViewById(R.id.session_est); this.mServerCompat = (TextView) findViewById(R.id.server_compat); + this.mOtrFingerprint = (TextView) findViewById(R.id.otr_fingerprint); + this.mOtrFingerprintHeadline = (TextView) findViewById(R.id.otr_fingerprint_headline); this.mSaveButton = (Button) findViewById(R.id.save_button); this.mCancelButton = (Button) findViewById(R.id.cancel_button); this.mSaveButton.setOnClickListener(this.mSaveButtonClickListener); @@ -274,7 +275,7 @@ public class EditAccountActivity extends XmppActivity { this.mRegisterNew.setVisibility(View.GONE); this.mRegisterNew.setChecked(false); } - if (this.mAccount.getStatus() == Account.STATUS_ONLINE) { + if (this.mAccount.getStatus() == Account.STATUS_ONLINE && !this.mFetchingAvatar) { this.mStats.setVisibility(View.VISIBLE); this.mSessionEst.setText(UIHelper.readableTimeDifference( getApplicationContext(), this.mAccount.getXmppConnection() @@ -282,6 +283,15 @@ public class EditAccountActivity extends XmppActivity { this.mServerCompat.setText(this.mAccount.getXmppConnection() .getFeatures().getCompatibility() + "%"); + String fingerprint = this.mAccount.getOtrFingerprint(getApplicationContext()); + if (fingerprint!=null) { + this.mOtrFingerprintHeadline.setVisibility(View.VISIBLE); + this.mOtrFingerprint.setVisibility(View.VISIBLE); + this.mOtrFingerprint.setText(fingerprint); + } else { + this.mOtrFingerprint.setVisibility(View.GONE); + this.mOtrFingerprintHeadline.setVisibility(View.GONE); + } } else { if (this.mAccount.errorStatus()) { this.mAccountJid.setError(getString(this.mAccount diff --git a/src/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/eu/siacs/conversations/ui/ManageAccountActivity.java index 457dded3f..c57121da7 100644 --- a/src/eu/siacs/conversations/ui/ManageAccountActivity.java +++ b/src/eu/siacs/conversations/ui/ManageAccountActivity.java @@ -7,32 +7,26 @@ import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate; import eu.siacs.conversations.ui.adapter.AccountAdapter; -import eu.siacs.conversations.xmpp.XmppConnection; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.os.Bundle; -import android.os.SystemClock; -import android.view.ActionMode; +import android.view.ContextMenu; import android.view.Menu; -import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.view.ContextMenu.ContextMenuInfo; import android.widget.AdapterView; +import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; -import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ListView; -import android.widget.TextView; public class ManageAccountActivity extends XmppActivity { - protected boolean isActionMode = false; - protected ActionMode actionMode; - protected Account selectedAccountForActionMode = null; protected ManageAccountActivity activity = this; - protected boolean firstrun = true; + protected Account selectedAccount = null; protected List<Account> accountList = new ArrayList<Account>(); protected ListView accountListView; @@ -53,105 +47,6 @@ public class ManageAccountActivity extends XmppActivity { } }; - protected ActionMode.Callback mActionModeCallback = new ActionMode.Callback() { - - @Override - public boolean onPrepareActionMode(ActionMode mode, Menu menu) { - if (selectedAccountForActionMode - .isOptionSet(Account.OPTION_DISABLED)) { - menu.findItem(R.id.mgmt_account_enable).setVisible(true); - menu.findItem(R.id.mgmt_account_disable).setVisible(false); - } else { - menu.findItem(R.id.mgmt_account_disable).setVisible(true); - menu.findItem(R.id.mgmt_account_enable).setVisible(false); - } - return true; - } - - @Override - public void onDestroyActionMode(ActionMode mode) { - // TODO Auto-generated method stub - - } - - @Override - public boolean onCreateActionMode(ActionMode mode, Menu menu) { - MenuInflater inflater = mode.getMenuInflater(); - inflater.inflate(R.menu.manageaccounts_context, menu); - return true; - } - - @Override - public boolean onActionItemClicked(final ActionMode mode, MenuItem item) { - if (item.getItemId() == R.id.mgmt_account_edit) { - editAccount(selectedAccountForActionMode); - } else if (item.getItemId() == R.id.mgmt_account_disable) { - selectedAccountForActionMode.setOption(Account.OPTION_DISABLED, - true); - xmppConnectionService - .updateAccount(selectedAccountForActionMode); - mode.finish(); - } else if (item.getItemId() == R.id.mgmt_account_enable) { - selectedAccountForActionMode.setOption(Account.OPTION_DISABLED, - false); - xmppConnectionService - .updateAccount(selectedAccountForActionMode); - mode.finish(); - } else if (item.getItemId() == R.id.mgmt_account_publish_avatar) { - Intent intent = new Intent(getApplicationContext(), PublishProfilePictureActivity.class); - intent.putExtra("account", selectedAccountForActionMode.getJid()); - startActivity(intent); - } else if (item.getItemId() == R.id.mgmt_account_delete) { - AlertDialog.Builder builder = new AlertDialog.Builder(activity); - builder.setTitle(getString(R.string.mgmt_account_are_you_sure)); - builder.setIconAttribute(android.R.attr.alertDialogIcon); - builder.setMessage(getString(R.string.mgmt_account_delete_confirm_text)); - builder.setPositiveButton(getString(R.string.delete), - new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, - int which) { - xmppConnectionService - .deleteAccount(selectedAccountForActionMode); - selectedAccountForActionMode = null; - mode.finish(); - } - }); - builder.setNegativeButton(getString(R.string.cancel), null); - builder.create().show(); - } else if (item.getItemId() == R.id.mgmt_account_announce_pgp) { - if (activity.hasPgp()) { - mode.finish(); - announcePgp(selectedAccountForActionMode, null); - } else { - activity.showInstallPgpDialog(); - } - } else if (item.getItemId() == R.id.mgmt_otr_key) { - AlertDialog.Builder builder = new AlertDialog.Builder(activity); - builder.setTitle("OTR Fingerprint"); - String fingerprintTxt = selectedAccountForActionMode - .getOtrFingerprint(getApplicationContext()); - View view = (View) getLayoutInflater().inflate( - R.layout.otr_fingerprint, null); - if (fingerprintTxt != null) { - TextView fingerprint = (TextView) view - .findViewById(R.id.otr_fingerprint); - TextView noFingerprintView = (TextView) view - .findViewById(R.id.otr_no_fingerprint); - fingerprint.setText(fingerprintTxt); - fingerprint.setVisibility(View.VISIBLE); - noFingerprintView.setVisibility(View.GONE); - } - builder.setView(view); - builder.setPositiveButton(getString(R.string.done), null); - builder.create().show(); - } - return true; - } - - }; - @Override protected void onCreate(Bundle savedInstanceState) { @@ -160,7 +55,6 @@ public class ManageAccountActivity extends XmppActivity { setContentView(R.layout.manage_accounts); accountListView = (ListView) findViewById(R.id.account_list); - final XmppActivity activity = this; this.mAccountAdapter = new AccountAdapter(this, accountList); accountListView.setAdapter(this.mAccountAdapter); accountListView.setOnItemClickListener(new OnItemClickListener() { @@ -168,34 +62,27 @@ public class ManageAccountActivity extends XmppActivity { @Override public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) { - if (!isActionMode) { - editAccount(accountList.get(position)); - } else { - selectedAccountForActionMode = accountList.get(position); - actionMode.invalidate(); - } + editAccount(accountList.get(position)); } }); - accountListView - .setOnItemLongClickListener(new OnItemLongClickListener() { + registerForContextMenu(accountListView); + } - @Override - public boolean onItemLongClick(AdapterView<?> arg0, - View view, int position, long arg3) { - if (!isActionMode) { - accountListView - .setChoiceMode(ListView.CHOICE_MODE_SINGLE); - accountListView.setItemChecked(position, true); - selectedAccountForActionMode = accountList - .get(position); - actionMode = activity - .startActionMode(mActionModeCallback); - return true; - } else { - return false; - } - } - }); + @Override + public void onCreateContextMenu(ContextMenu menu, View v, + ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, v, menuInfo); + activity.getMenuInflater().inflate(R.menu.manageaccounts_context, menu); + AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo; + this.selectedAccount = accountList.get(acmi.position); + if (this.selectedAccount.isOptionSet(Account.OPTION_DISABLED)) { + menu.findItem(R.id.mgmt_account_disable).setVisible(false); + menu.findItem(R.id.mgmt_account_announce_pgp).setVisible(false); + menu.findItem(R.id.mgmt_account_publish_avatar).setVisible(false); + } else { + menu.findItem(R.id.mgmt_account_enable).setVisible(false); + } + menu.setHeaderTitle(this.selectedAccount.getJid()); } @Override @@ -212,11 +99,6 @@ public class ManageAccountActivity extends XmppActivity { this.accountList.clear(); this.accountList.addAll(xmppConnectionService.getAccounts()); mAccountAdapter.notifyDataSetChanged(); - if ((this.accountList.size() == 0) && (this.firstrun)) { - getActionBar().setDisplayHomeAsUpEnabled(false); - getActionBar().setHomeButtonEnabled(false); - this.firstrun = false; - } } @Override @@ -226,10 +108,33 @@ public class ManageAccountActivity extends XmppActivity { } @Override + public boolean onContextItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.mgmt_account_publish_avatar: + publishAvatar(selectedAccount); + return true; + case R.id.mgmt_account_disable: + disableAccount(selectedAccount); + return true; + case R.id.mgmt_account_enable: + enableAccount(selectedAccount); + return true; + case R.id.mgmt_account_delete: + deleteAccount(selectedAccount); + return true; + case R.id.mgmt_account_announce_pgp: + publishOpenPGPPublicKey(selectedAccount); + default: + return super.onContextItemSelected(item); + } + } + + @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_add_account: - startActivity(new Intent(getApplicationContext(), EditAccountActivity.class)); + startActivity(new Intent(getApplicationContext(), + EditAccountActivity.class)); break; default: break; @@ -264,24 +169,46 @@ public class ManageAccountActivity extends XmppActivity { startActivity(intent); } - @Override - public void onActionModeStarted(ActionMode mode) { - super.onActionModeStarted(mode); - this.isActionMode = true; + private void publishAvatar(Account account) { + Intent intent = new Intent(getApplicationContext(), + PublishProfilePictureActivity.class); + intent.putExtra("account", account.getJid()); + startActivity(intent); } - @Override - public void onActionModeFinished(ActionMode mode) { - super.onActionModeFinished(mode); - this.isActionMode = false; - accountListView.clearChoices(); - accountListView.requestLayout(); - accountListView.post(new Runnable() { - @Override - public void run() { - accountListView.setChoiceMode(ListView.CHOICE_MODE_NONE); - } - }); + private void disableAccount(Account account) { + account.setOption(Account.OPTION_DISABLED, true); + xmppConnectionService.updateAccount(account); + } + + private void enableAccount(Account account) { + account.setOption(Account.OPTION_DISABLED, false); + xmppConnectionService.updateAccount(account); + } + + private void publishOpenPGPPublicKey(Account account) { + if (activity.hasPgp()) { + announcePgp(account, null); + } else { + this.showInstallPgpDialog(); + } + } + + private void deleteAccount(final Account account) { + AlertDialog.Builder builder = new AlertDialog.Builder(activity); + builder.setTitle(getString(R.string.mgmt_account_are_you_sure)); + builder.setIconAttribute(android.R.attr.alertDialogIcon); + builder.setMessage(getString(R.string.mgmt_account_delete_confirm_text)); + builder.setPositiveButton(getString(R.string.delete), + new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + xmppConnectionService.deleteAccount(account); + selectedAccount = null; + } + }); + builder.setNegativeButton(getString(R.string.cancel), null); + builder.create().show(); } @Override @@ -289,7 +216,7 @@ public class ManageAccountActivity extends XmppActivity { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { if (requestCode == REQUEST_ANNOUNCE_PGP) { - announcePgp(selectedAccountForActionMode, null); + announcePgp(selectedAccount, null); } } } |