Commit 4a374d5f authored by Alexander Ivanov's avatar Alexander Ivanov

Set offline mode menu actions while ContextMenu creation.

parent 362aa208
...@@ -142,9 +142,6 @@ public class ContactList extends ManagedListActivity implements ...@@ -142,9 +142,6 @@ public class ContactList extends ManagedListActivity implements
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_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_NORMAL_ID = 0x42;
private static final int CONTEXT_MENU_SHOW_OFFLINE_NEVER_ID = 0x43;
private static final int DIALOG_CLOSE_APPLICATION_ID = 0x57; private static final int DIALOG_CLOSE_APPLICATION_ID = 0x57;
...@@ -559,7 +556,7 @@ public class ContactList extends ManagedListActivity implements ...@@ -559,7 +556,7 @@ public class ContactList extends ManagedListActivity implements
menu.add(0, CONTEXT_MENU_GROUP_DELETE_ID, 0, menu.add(0, CONTEXT_MENU_GROUP_DELETE_ID, 0,
getText(R.string.group_remove)); getText(R.string.group_remove));
} }
createOfflineModeContextMenu(menu); createOfflineModeContextMenu(account, group, menu);
} }
private void createAccountContextMenu(final String account, ContextMenu menu) { private void createAccountContextMenu(final String account, ContextMenu menu) {
...@@ -611,30 +608,35 @@ public class ContactList extends ManagedListActivity implements ...@@ -611,30 +608,35 @@ public class ContactList extends ManagedListActivity implements
menu.add(R.string.contact_add).setIntent( menu.add(R.string.contact_add).setIntent(
ContactAdd.createIntent(this, account)); ContactAdd.createIntent(this, account));
} }
createOfflineModeContextMenu(menu); if (SettingsManager.contactsShowAccounts())
createOfflineModeContextMenu(account, null, menu);
} }
private void createOfflineModeContextMenu(ContextMenu menu) { private void createOfflineModeContextMenu(String account, String group,
if (actionWithGroup != null || SettingsManager.contactsShowAccounts()) { ContextMenu menu) {
SubMenu mapMode = menu.addSubMenu(getResources().getText( SubMenu mapMode = menu.addSubMenu(getResources().getText(
R.string.show_offline_settings)); R.string.show_offline_settings));
mapMode.setHeaderTitle(R.string.show_offline_settings); mapMode.setHeaderTitle(R.string.show_offline_settings);
MenuItem always = mapMode.add(CONTEXT_MENU_SHOW_OFFLINE_GROUP_ID, MenuItem always = mapMode.add(CONTEXT_MENU_SHOW_OFFLINE_GROUP_ID, 0, 0,
CONTEXT_MENU_SHOW_OFFLINE_ALWAYS_ID, 0, getResources() getText(R.string.show_offline_always))
.getText(R.string.show_offline_always)); .setOnMenuItemClickListener(
MenuItem normal = mapMode.add(CONTEXT_MENU_SHOW_OFFLINE_GROUP_ID, new OfflineModeClickListener(account, group,
CONTEXT_MENU_SHOW_OFFLINE_NORMAL_ID, 0, getResources() ShowOfflineMode.always));
.getText(R.string.show_offline_normal)); MenuItem normal = mapMode.add(CONTEXT_MENU_SHOW_OFFLINE_GROUP_ID, 0, 0,
MenuItem never = mapMode.add(CONTEXT_MENU_SHOW_OFFLINE_GROUP_ID, getText(R.string.show_offline_normal))
CONTEXT_MENU_SHOW_OFFLINE_NEVER_ID, 0, getResources() .setOnMenuItemClickListener(
.getText(R.string.show_offline_never)); new OfflineModeClickListener(account, group,
ShowOfflineMode.normal));
MenuItem never = mapMode.add(CONTEXT_MENU_SHOW_OFFLINE_GROUP_ID, 0, 0,
getText(R.string.show_offline_never))
.setOnMenuItemClickListener(
new OfflineModeClickListener(account, group,
ShowOfflineMode.never));
mapMode.setGroupCheckable(CONTEXT_MENU_SHOW_OFFLINE_GROUP_ID, true, mapMode.setGroupCheckable(CONTEXT_MENU_SHOW_OFFLINE_GROUP_ID, true,
true); true);
ShowOfflineMode showOfflineMode = GroupManager.getInstance() ShowOfflineMode showOfflineMode = GroupManager.getInstance()
.getShowOfflineMode( .getShowOfflineMode(account,
actionWithAccount, group == null ? GroupManager.IS_ACCOUNT : group);
actionWithGroup == null ? GroupManager.IS_ACCOUNT
: actionWithGroup);
if (showOfflineMode == ShowOfflineMode.always) if (showOfflineMode == ShowOfflineMode.always)
always.setChecked(true); always.setChecked(true);
else if (showOfflineMode == ShowOfflineMode.normal) else if (showOfflineMode == ShowOfflineMode.normal)
...@@ -644,7 +646,6 @@ public class ContactList extends ManagedListActivity implements ...@@ -644,7 +646,6 @@ public class ContactList extends ManagedListActivity implements
else else
throw new IllegalStateException(); throw new IllegalStateException();
} }
}
@Override @Override
public boolean onContextItemSelected(MenuItem item) { public boolean onContextItemSelected(MenuItem item) {
...@@ -737,29 +738,6 @@ public class ContactList extends ManagedListActivity implements ...@@ -737,29 +738,6 @@ public class ContactList extends ManagedListActivity implements
: actionWithAccount, actionWithGroup).show( : actionWithAccount, actionWithGroup).show(
getSupportFragmentManager(), "GROUP_DELETE"); getSupportFragmentManager(), "GROUP_DELETE");
return true; return true;
// Groups or account
case CONTEXT_MENU_SHOW_OFFLINE_ALWAYS_ID:
GroupManager.getInstance().setShowOfflineMode(
actionWithAccount,
actionWithGroup == null ? GroupManager.IS_ACCOUNT
: actionWithGroup, ShowOfflineMode.always);
contactListAdapter.onChange();
return true;
case CONTEXT_MENU_SHOW_OFFLINE_NORMAL_ID:
GroupManager.getInstance().setShowOfflineMode(
actionWithAccount,
actionWithGroup == null ? GroupManager.IS_ACCOUNT
: actionWithGroup, ShowOfflineMode.normal);
contactListAdapter.onChange();
return true;
case CONTEXT_MENU_SHOW_OFFLINE_NEVER_ID:
GroupManager.getInstance().setShowOfflineMode(
actionWithAccount,
actionWithGroup == null ? GroupManager.IS_ACCOUNT
: actionWithGroup, ShowOfflineMode.never);
contactListAdapter.onChange();
return true;
} }
return false; return false;
} }
...@@ -1025,6 +1003,31 @@ public class ContactList extends ManagedListActivity implements ...@@ -1025,6 +1003,31 @@ public class ContactList extends ManagedListActivity implements
0); 0);
} }
private class OfflineModeClickListener implements
MenuItem.OnMenuItemClickListener {
private final String account;
private final String group;
private final ShowOfflineMode mode;
public OfflineModeClickListener(String account, String group,
ShowOfflineMode mode) {
super();
this.account = account;
this.group = group;
this.mode = mode;
}
@Override
public boolean onMenuItemClick(MenuItem item) {
GroupManager.getInstance().setShowOfflineMode(account,
group == null ? GroupManager.IS_ACCOUNT : group, mode);
contactListAdapter.onChange();
return true;
}
}
public static Intent createPersistentIntent(Context context) { public static Intent createPersistentIntent(Context context) {
Intent intent = new Intent(context, ContactList.class); Intent intent = new Intent(context, ContactList.class);
intent.setAction("android.intent.action.MAIN"); intent.setAction("android.intent.action.MAIN");
......
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