Commit 362aa208 authored by Alexander Ivanov's avatar Alexander Ivanov

Set account context menu actions while ContextMenu creation.

parent 7e258b6e
...@@ -141,12 +141,6 @@ public class ContactList extends ManagedListActivity implements ...@@ -141,12 +141,6 @@ public class ContactList extends ManagedListActivity implements
private static final int CONTEXT_MENU_GROUP_RENAME_ID = 0x31; private static final int CONTEXT_MENU_GROUP_RENAME_ID = 0x31;
private static final int CONTEXT_MENU_GROUP_DELETE_ID = 0x32; private static final int CONTEXT_MENU_GROUP_DELETE_ID = 0x32;
private static final int CONTEXT_MENU_ACCOUNT_EDITOR_ID = 0x33;
private static final int CONTEXT_MENU_ACCOUNT_STATUS_ID = 0x34;
private static final int CONTEXT_MENU_ACCOUNT_ADD_CONTACT_ID = 0x35;
private static final int CONTEXT_MENU_ACCOUNT_RECONNECT_ID = 0x39;
private static final int CONTEXT_MENU_ACCOUNT_VCARD_ID = 0x3A;
private static final int CONTEXT_MENU_SHOW_OFFLINE_GROUP_ID = 0x40; private static final int CONTEXT_MENU_SHOW_OFFLINE_GROUP_ID = 0x40;
private static final int CONTEXT_MENU_SHOW_OFFLINE_ALWAYS_ID = 0x41; private static final int CONTEXT_MENU_SHOW_OFFLINE_ALWAYS_ID = 0x41;
private static final int CONTEXT_MENU_SHOW_OFFLINE_NORMAL_ID = 0x42; private static final int CONTEXT_MENU_SHOW_OFFLINE_NORMAL_ID = 0x42;
...@@ -497,8 +491,8 @@ public class ContactList extends ManagedListActivity implements ...@@ -497,8 +491,8 @@ public class ContactList extends ManagedListActivity implements
} }
} else { } else {
// Account panel // Account panel
createAccountContextMenu( createAccountContextMenu(accountToggleAdapter.getItemForView(view),
(String) accountToggleAdapter.getItemForView(view), menu); menu);
} }
} }
...@@ -568,29 +562,56 @@ public class ContactList extends ManagedListActivity implements ...@@ -568,29 +562,56 @@ public class ContactList extends ManagedListActivity implements
createOfflineModeContextMenu(menu); createOfflineModeContextMenu(menu);
} }
private void createAccountContextMenu(String account, ContextMenu menu) { private void createAccountContextMenu(final String account, ContextMenu menu) {
actionWithAccount = account; actionWithAccount = account;
actionWithGroup = null; actionWithGroup = null;
actionWithUser = null; actionWithUser = null;
menu.setHeaderTitle(AccountManager.getInstance().getVerboseName( menu.setHeaderTitle(AccountManager.getInstance()
actionWithAccount)); .getVerboseName(account));
AccountItem accountItem = AccountManager.getInstance().getAccount( AccountItem accountItem = AccountManager.getInstance().getAccount(
actionWithAccount); account);
ConnectionState state = accountItem.getState(); ConnectionState state = accountItem.getState();
if (state == ConnectionState.waiting) if (state == ConnectionState.waiting)
menu.add(0, CONTEXT_MENU_ACCOUNT_RECONNECT_ID, 0, menu.add(R.string.account_reconnect).setOnMenuItemClickListener(
getText(R.string.account_reconnect)); new MenuItem.OnMenuItemClickListener() {
menu.add(0, CONTEXT_MENU_ACCOUNT_STATUS_ID, 0,
getText(R.string.status_editor)); @Override
menu.add(0, CONTEXT_MENU_ACCOUNT_EDITOR_ID, 0, public boolean onMenuItemClick(MenuItem item) {
getText(R.string.account_editor)); if (AccountManager.getInstance()
if (state.isConnected()) { .getAccount(account).updateConnection(true))
menu.add(0, CONTEXT_MENU_ACCOUNT_VCARD_ID, 0, AccountManager.getInstance().onAccountChanged(
getText(R.string.contact_viewer)); account);
menu.add(0, CONTEXT_MENU_ACCOUNT_ADD_CONTACT_ID, 0, return true;
getText(R.string.contact_add)); }
}
createOfflineModeContextMenu(menu); });
menu.add(R.string.status_editor).setIntent(
StatusEditor.createIntent(this, account));
menu.add(R.string.account_editor).setIntent(
AccountEditor.createIntent(this, account));
if (state.isConnected()) {
menu.add(R.string.contact_viewer).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
String user = AccountManager.getInstance()
.getAccount(account).getRealJid();
if (user == null)
Application.getInstance().onError(
R.string.NOT_CONNECTED);
else {
startActivity(ContactViewer.createIntent(
ContactList.this, account, user));
}
return true;
}
});
menu.add(R.string.contact_add).setIntent(
ContactAdd.createIntent(this, account));
}
createOfflineModeContextMenu(menu);
} }
private void createOfflineModeContextMenu(ContextMenu menu) { private void createOfflineModeContextMenu(ContextMenu menu) {
...@@ -717,33 +738,6 @@ public class ContactList extends ManagedListActivity implements ...@@ -717,33 +738,6 @@ public class ContactList extends ManagedListActivity implements
getSupportFragmentManager(), "GROUP_DELETE"); getSupportFragmentManager(), "GROUP_DELETE");
return true; return true;
// Account
case CONTEXT_MENU_ACCOUNT_RECONNECT_ID:
if (AccountManager.getInstance().getAccount(actionWithAccount)
.updateConnection(true))
AccountManager.getInstance()
.onAccountChanged(actionWithAccount);
return true;
case CONTEXT_MENU_ACCOUNT_VCARD_ID:
String user = AccountManager.getInstance()
.getAccount(actionWithAccount).getRealJid();
if (user == null)
Application.getInstance().onError(R.string.NOT_CONNECTED);
else {
startActivity(ContactViewer.createIntent(this,
actionWithAccount, user));
}
return true;
case CONTEXT_MENU_ACCOUNT_EDITOR_ID:
startActivity(AccountEditor.createIntent(this, actionWithAccount));
return true;
case CONTEXT_MENU_ACCOUNT_STATUS_ID:
startActivity(StatusEditor.createIntent(this, actionWithAccount));
return true;
case CONTEXT_MENU_ACCOUNT_ADD_CONTACT_ID:
startActivity(ContactAdd.createIntent(this, actionWithAccount));
return true;
// Groups or account // Groups or account
case CONTEXT_MENU_SHOW_OFFLINE_ALWAYS_ID: case CONTEXT_MENU_SHOW_OFFLINE_ALWAYS_ID:
GroupManager.getInstance().setShowOfflineMode( GroupManager.getInstance().setShowOfflineMode(
...@@ -840,7 +834,7 @@ public class ContactList extends ManagedListActivity implements ...@@ -840,7 +834,7 @@ public class ContactList extends ManagedListActivity implements
scrollUp(); scrollUp();
break; break;
default: default:
String account = (String) accountToggleAdapter.getItemForView(view); String account = accountToggleAdapter.getItemForView(view);
if (account == null) // Check for tap on account in the title if (account == null) // Check for tap on account in the title
break; break;
ListView listView = getListView(); ListView listView = getListView();
......
...@@ -138,7 +138,7 @@ public class AccountToggleAdapter implements UpdatableAdapter { ...@@ -138,7 +138,7 @@ public class AccountToggleAdapter implements UpdatableAdapter {
* child. * child.
* @return The data for the specified view. * @return The data for the specified view.
*/ */
public Object getItemForView(View view) { public String getItemForView(View view) {
if (view.getId() == R.id.status_mode) if (view.getId() == R.id.status_mode)
view = (View) view.getParent(); view = (View) view.getParent();
for (int index = 0; index < linearLayout.getChildCount(); index++) for (int index = 0; index < linearLayout.getChildCount(); index++)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment