Commit 5d3e3182 authored by Alexander Ivanov's avatar Alexander Ivanov

Set contact menu actions while ContextMenu creation.

parent ca3cfdc1
...@@ -112,9 +112,6 @@ public class ContactList extends ManagedListActivity implements ...@@ -112,9 +112,6 @@ public class ContactList extends ManagedListActivity implements
private static final long CLOSE_ACTIVITY_AFTER_DELAY = 300; private static final long CLOSE_ACTIVITY_AFTER_DELAY = 300;
private static final String SAVED_ACTION = "com.xabber.android.ui.ContactList.SAVED_ACTION"; private static final String SAVED_ACTION = "com.xabber.android.ui.ContactList.SAVED_ACTION";
private static final String SAVED_ACTION_WITH_ACCOUNT = "com.xabber.android.ui.ContactList.SAVED_ACTION_WITH_ACCOUNT";
private static final String SAVED_ACTION_WITH_GROUP = "com.xabber.android.ui.ContactList.SAVED_ACTION_WITH_GROUP";
private static final String SAVED_ACTION_WITH_USER = "com.xabber.android.ui.ContactList.SAVED_ACTION_WITH_USER";
private static final String SAVED_SEND_TEXT = "com.xabber.android.ui.ContactList.SAVED_SEND_TEXT"; private static final String SAVED_SEND_TEXT = "com.xabber.android.ui.ContactList.SAVED_SEND_TEXT";
private static final int OPTION_MENU_ADD_CONTACT_ID = 0x02; private static final int OPTION_MENU_ADD_CONTACT_ID = 0x02;
...@@ -126,18 +123,6 @@ public class ContactList extends ManagedListActivity implements ...@@ -126,18 +123,6 @@ public class ContactList extends ManagedListActivity implements
private static final int OPTION_MENU_SEARCH_ID = 0x0A; private static final int OPTION_MENU_SEARCH_ID = 0x0A;
private static final int OPTION_MENU_CLOSE_CHATS_ID = 0x0B; private static final int OPTION_MENU_CLOSE_CHATS_ID = 0x0B;
private static final int CONTEXT_MENU_VIEW_CHAT_ID = 0x12;
private static final int CONTEXT_MENU_EDIT_CONTACT_ID = 0x13;
private static final int CONTEXT_MENU_DELETE_CONTACT_ID = 0x14;
private static final int CONTEXT_MENU_CLOSE_CHAT_ID = 0x15;
private static final int CONTEXT_MENU_REQUEST_SUBSCRIPTION_ID = 0x16;
private static final int CONTEXT_MENU_ACCEPT_SUBSCRIPTION_ID = 0x17;
private static final int CONTEXT_MENU_DISCARD_SUBSCRIPTION_ID = 0x18;
private static final int CONTEXT_MENU_LEAVE_ROOM_ID = 0x19;
private static final int CONTEXT_MENU_JOIN_ROOM_ID = 0x1A;
private static final int CONTEXT_MENU_EDIT_ROOM_ID = 0x1B;
private static final int CONTEXT_MENU_VIEW_CONTACT_ID = 0x1C;
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 DIALOG_CLOSE_APPLICATION_ID = 0x57; private static final int DIALOG_CLOSE_APPLICATION_ID = 0x57;
...@@ -160,9 +145,6 @@ public class ContactList extends ManagedListActivity implements ...@@ -160,9 +145,6 @@ public class ContactList extends ManagedListActivity implements
/** /**
* Dialog related values. * Dialog related values.
*/ */
private String actionWithAccount;
private String actionWithGroup;
private String actionWithUser;
private String sendText; private String sendText;
/** /**
...@@ -217,18 +199,9 @@ public class ContactList extends ManagedListActivity implements ...@@ -217,18 +199,9 @@ public class ContactList extends ManagedListActivity implements
findViewById(R.id.back_button).setOnClickListener(this); findViewById(R.id.back_button).setOnClickListener(this);
if (savedInstanceState != null) { if (savedInstanceState != null) {
actionWithAccount = savedInstanceState
.getString(SAVED_ACTION_WITH_ACCOUNT);
actionWithGroup = savedInstanceState
.getString(SAVED_ACTION_WITH_GROUP);
actionWithUser = savedInstanceState
.getString(SAVED_ACTION_WITH_USER);
sendText = savedInstanceState.getString(SAVED_SEND_TEXT); sendText = savedInstanceState.getString(SAVED_SEND_TEXT);
action = savedInstanceState.getString(SAVED_ACTION); action = savedInstanceState.getString(SAVED_ACTION);
} else { } else {
actionWithAccount = null;
actionWithGroup = null;
actionWithUser = null;
sendText = null; sendText = null;
action = getIntent().getAction(); action = getIntent().getAction();
} }
...@@ -247,9 +220,6 @@ public class ContactList extends ManagedListActivity implements ...@@ -247,9 +220,6 @@ public class ContactList extends ManagedListActivity implements
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
outState.putString(SAVED_ACTION, action); outState.putString(SAVED_ACTION, action);
outState.putString(SAVED_ACTION_WITH_ACCOUNT, actionWithAccount);
outState.putString(SAVED_ACTION_WITH_GROUP, actionWithGroup);
outState.putString(SAVED_ACTION_WITH_USER, actionWithUser);
outState.putString(SAVED_SEND_TEXT, sendText); outState.putString(SAVED_SEND_TEXT, sendText);
} }
...@@ -492,57 +462,161 @@ public class ContactList extends ManagedListActivity implements ...@@ -492,57 +462,161 @@ public class ContactList extends ManagedListActivity implements
private void createContactContextMenu(AbstractContact abstractContact, private void createContactContextMenu(AbstractContact abstractContact,
ContextMenu menu) { ContextMenu menu) {
actionWithAccount = abstractContact.getAccount(); final String account = abstractContact.getAccount();
actionWithGroup = null; final String user = abstractContact.getUser();
actionWithUser = abstractContact.getUser();
menu.setHeaderTitle(abstractContact.getName()); menu.setHeaderTitle(abstractContact.getName());
menu.add(0, CONTEXT_MENU_VIEW_CHAT_ID, 0, getResources() menu.add(R.string.chat_viewer).setOnMenuItemClickListener(
.getText(R.string.chat_viewer)); new MenuItem.OnMenuItemClickListener() {
if (MUCManager.getInstance().hasRoom(actionWithAccount,
actionWithUser)) { @Override
if (!MUCManager.getInstance().inUse(actionWithAccount, public boolean onMenuItemClick(MenuItem item) {
actionWithUser)) MessageManager.getInstance().openChat(account, user);
menu.add(0, CONTEXT_MENU_EDIT_ROOM_ID, 0, startActivity(ChatViewer.createIntent(ContactList.this,
getResources().getText(R.string.muc_edit)); account, user));
menu.add(0, CONTEXT_MENU_DELETE_CONTACT_ID, 0, return true;
getResources().getText(R.string.muc_delete)); }
if (MUCManager.getInstance().isDisabled(actionWithAccount, });
actionWithUser)) if (MUCManager.getInstance().hasRoom(account, user)) {
menu.add(0, CONTEXT_MENU_JOIN_ROOM_ID, 0, if (!MUCManager.getInstance().inUse(account, user))
getResources().getText(R.string.muc_join)); menu.add(R.string.muc_edit).setIntent(
MUCEditor.createIntent(this, account, user));
menu.add(R.string.muc_delete).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
ContactDeleteDialogFragment.newInstance(
account == GroupManager.NO_ACCOUNT ? null
: account, user).show(
getSupportFragmentManager(),
"CONTACT_DELETE");
return true;
}
});
if (MUCManager.getInstance().isDisabled(account, user))
menu.add(R.string.muc_join).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
MUCManager.getInstance().joinRoom(account,
user, true);
return true;
}
});
else else
menu.add(0, CONTEXT_MENU_LEAVE_ROOM_ID, 0, menu.add(R.string.muc_leave).setOnMenuItemClickListener(
getResources().getText(R.string.muc_leave)); new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
MUCManager.getInstance().leaveRoom(account,
user);
MessageManager.getInstance().closeChat(account,
user);
NotificationManager.getInstance()
.removeMessageNotification(account,
user);
contactListAdapter.onChange();
return true;
}
});
} else { } else {
menu.add(0, CONTEXT_MENU_VIEW_CONTACT_ID, 0, getResources() menu.add(R.string.contact_viewer).setIntent(
.getText(R.string.contact_viewer)); ContactViewer.createIntent(this, account, user));
menu.add(0, CONTEXT_MENU_EDIT_CONTACT_ID, 0, getResources() menu.add(R.string.contact_editor).setIntent(
.getText(R.string.contact_editor)); ContactEditor.createIntent(this, account, user));
menu.add(0, CONTEXT_MENU_DELETE_CONTACT_ID, 0, menu.add(R.string.contact_delete).setOnMenuItemClickListener(
getResources().getText(R.string.contact_delete)); new MenuItem.OnMenuItemClickListener() {
if (MessageManager.getInstance().hasActiveChat(
actionWithAccount, actionWithUser)) @Override
menu.add(0, CONTEXT_MENU_CLOSE_CHAT_ID, 0, public boolean onMenuItemClick(MenuItem item) {
getResources().getText(R.string.close_chat)); ContactDeleteDialogFragment.newInstance(
account == GroupManager.NO_ACCOUNT ? null
: account, user).show(
getSupportFragmentManager(),
"CONTACT_DELETE");
return true;
}
});
if (MessageManager.getInstance().hasActiveChat(account, user))
menu.add(R.string.close_chat).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
MessageManager.getInstance().closeChat(account,
user);
NotificationManager.getInstance()
.removeMessageNotification(account,
user);
contactListAdapter.onChange();
return true;
}
});
if (abstractContact.getStatusMode() == StatusMode.unsubscribed) if (abstractContact.getStatusMode() == StatusMode.unsubscribed)
menu.add(0, CONTEXT_MENU_REQUEST_SUBSCRIPTION_ID, 0, menu.add(R.string.request_subscription)
getText(R.string.request_subscription)); .setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
try {
PresenceManager.getInstance()
.requestSubscription(
account, user);
} catch (NetworkException e) {
Application.getInstance()
.onError(e);
} }
if (PresenceManager.getInstance().hasSubscriptionRequest( return true;
actionWithAccount, actionWithUser)) { }
menu.add(0, CONTEXT_MENU_ACCEPT_SUBSCRIPTION_ID, 0,
getResources() });
.getText(R.string.accept_subscription)); }
menu.add(0, CONTEXT_MENU_DISCARD_SUBSCRIPTION_ID, 0, if (PresenceManager.getInstance().hasSubscriptionRequest(account, user)) {
getText(R.string.discard_subscription)); menu.add(R.string.accept_subscription).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
try {
PresenceManager.getInstance()
.acceptSubscription(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
startActivity(ContactEditor.createIntent(
ContactList.this, account, user));
return true;
}
});
menu.add(R.string.discard_subscription).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
try {
PresenceManager.getInstance()
.discardSubscription(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
return true;
}
});
} }
} }
private void createGroupContextMenu(final String account, private void createGroupContextMenu(final String account,
final String group, ContextMenu menu) { final String group, ContextMenu menu) {
actionWithAccount = account;
actionWithGroup = group;
actionWithUser = null;
menu.setHeaderTitle(GroupManager.getInstance().getGroupName(account, menu.setHeaderTitle(GroupManager.getInstance().getGroupName(account,
group)); group));
if (group != GroupManager.ACTIVE_CHATS && group != GroupManager.IS_ROOM) { if (group != GroupManager.ACTIVE_CHATS && group != GroupManager.IS_ROOM) {
...@@ -581,9 +655,6 @@ public class ContactList extends ManagedListActivity implements ...@@ -581,9 +655,6 @@ public class ContactList extends ManagedListActivity implements
} }
private void createAccountContextMenu(final String account, ContextMenu menu) { private void createAccountContextMenu(final String account, ContextMenu menu) {
actionWithAccount = account;
actionWithGroup = null;
actionWithUser = null;
menu.setHeaderTitle(AccountManager.getInstance() menu.setHeaderTitle(AccountManager.getInstance()
.getVerboseName(account)); .getVerboseName(account));
AccountItem accountItem = AccountManager.getInstance().getAccount( AccountItem accountItem = AccountManager.getInstance().getAccount(
...@@ -668,85 +739,6 @@ public class ContactList extends ManagedListActivity implements ...@@ -668,85 +739,6 @@ public class ContactList extends ManagedListActivity implements
throw new IllegalStateException(); throw new IllegalStateException();
} }
@Override
public boolean onContextItemSelected(MenuItem item) {
super.onContextItemSelected(item);
switch (item.getItemId()) {
// Contact
case CONTEXT_MENU_VIEW_CHAT_ID:
MessageManager.getInstance().openChat(actionWithAccount,
actionWithUser);
startActivity(ChatViewer.createIntent(this, actionWithAccount,
actionWithUser));
return true;
case CONTEXT_MENU_VIEW_CONTACT_ID:
startActivity(ContactViewer.createIntent(this, actionWithAccount,
actionWithUser));
return true;
case CONTEXT_MENU_EDIT_CONTACT_ID:
startActivity(ContactEditor.createIntent(this, actionWithAccount,
actionWithUser));
return true;
case CONTEXT_MENU_DELETE_CONTACT_ID:
ContactDeleteDialogFragment.newInstance(
actionWithAccount == GroupManager.NO_ACCOUNT ? null
: actionWithAccount, actionWithUser).show(
getSupportFragmentManager(), "CONTACT_DELETE");
return true;
case CONTEXT_MENU_EDIT_ROOM_ID:
startActivity(MUCEditor.createIntent(this, actionWithAccount,
actionWithUser));
return true;
case CONTEXT_MENU_JOIN_ROOM_ID:
MUCManager.getInstance().joinRoom(actionWithAccount,
actionWithUser, true);
return true;
case CONTEXT_MENU_LEAVE_ROOM_ID:
MUCManager.getInstance().leaveRoom(actionWithAccount,
actionWithUser);
MessageManager.getInstance().closeChat(actionWithAccount,
actionWithUser);
NotificationManager.getInstance().removeMessageNotification(
actionWithAccount, actionWithUser);
contactListAdapter.onChange();
return true;
case CONTEXT_MENU_CLOSE_CHAT_ID:
MessageManager.getInstance().closeChat(actionWithAccount,
actionWithUser);
NotificationManager.getInstance().removeMessageNotification(
actionWithAccount, actionWithUser);
contactListAdapter.onChange();
return true;
case CONTEXT_MENU_REQUEST_SUBSCRIPTION_ID:
try {
PresenceManager.getInstance().requestSubscription(
actionWithAccount, actionWithUser);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
return true;
case CONTEXT_MENU_ACCEPT_SUBSCRIPTION_ID:
try {
PresenceManager.getInstance().acceptSubscription(
actionWithAccount, actionWithUser);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
startActivity(ContactEditor.createIntent(this, actionWithAccount,
actionWithUser));
return true;
case CONTEXT_MENU_DISCARD_SUBSCRIPTION_ID:
try {
PresenceManager.getInstance().discardSubscription(
actionWithAccount, actionWithUser);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
return true;
}
return false;
}
@Override @Override
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
super.onCreateDialog(id); super.onCreateDialog(id);
......
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