Commit c0f6e151 authored by Grigory Fedorov's avatar Grigory Fedorov

Merge branch 'feature/options_menu' into develop

parents 155af8df 06010393
...@@ -14,15 +14,11 @@ ...@@ -14,15 +14,11 @@
*/ */
package com.xabber.android.ui; package com.xabber.android.ui;
import java.util.Collection;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import com.xabber.android.data.ActivityManager; import com.xabber.android.data.ActivityManager;
...@@ -43,6 +39,8 @@ import com.xabber.android.ui.widget.PageSwitcher; ...@@ -43,6 +39,8 @@ import com.xabber.android.ui.widget.PageSwitcher;
import com.xabber.android.ui.widget.PageSwitcher.OnSelectListener; import com.xabber.android.ui.widget.PageSwitcher.OnSelectListener;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
import java.util.Collection;
/** /**
* Chat activity. * Chat activity.
* *
...@@ -53,357 +51,347 @@ import com.xabber.androiddev.R; ...@@ -53,357 +51,347 @@ import com.xabber.androiddev.R;
* *
*/ */
public class ChatViewer extends ManagedActivity implements OnSelectListener, public class ChatViewer extends ManagedActivity implements OnSelectListener,
OnChatChangedListener, OnContactChangedListener, OnChatChangedListener, OnContactChangedListener,
OnAccountChangedListener { OnAccountChangedListener {
/** /**
* Attention request. * Attention request.
*/ */
private static final String ACTION_ATTENTION = "com.xabber.android.data.ATTENTION"; private static final String ACTION_ATTENTION = "com.xabber.android.data.ATTENTION";
private static final String SAVED_ACCOUNT = "com.xabber.android.ui.ChatViewer.SAVED_ACCOUNT"; private static final String SAVED_ACCOUNT = "com.xabber.android.ui.ChatViewer.SAVED_ACCOUNT";
private static final String SAVED_USER = "com.xabber.android.ui.ChatViewer.SAVED_USER"; private static final String SAVED_USER = "com.xabber.android.ui.ChatViewer.SAVED_USER";
private static final String SAVED_EXIT_ON_SEND = "com.xabber.android.ui.ChatViewer.EXIT_ON_SEND"; private static final String SAVED_EXIT_ON_SEND = "com.xabber.android.ui.ChatViewer.EXIT_ON_SEND";
private ChatViewerAdapter chatViewerAdapter; private ChatViewerAdapter chatViewerAdapter;
private PageSwitcher pageSwitcher; private PageSwitcher pageSwitcher;
private String actionWithAccount; private String actionWithAccount;
private String actionWithUser; private String actionWithUser;
private View actionWithView; private View actionWithView;
private boolean exitOnSend; private boolean exitOnSend;
private boolean isVisible; private boolean isVisible;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (isFinishing()) if (isFinishing())
return; return;
Intent intent = getIntent(); Intent intent = getIntent();
String account = getAccount(intent); String account = getAccount(intent);
String user = getUser(intent); String user = getUser(intent);
if (PageSwitcher.LOG) if (PageSwitcher.LOG)
LogManager.i(this, "Intent: " + account + ":" + user); LogManager.i(this, "Intent: " + account + ":" + user);
if (account == null || user == null) { if (account == null || user == null) {
Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND); Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
finish(); finish();
return; return;
} }
if (hasAttention(intent)) if (hasAttention(intent))
AttentionManager.getInstance().removeAccountNotifications(account, AttentionManager.getInstance().removeAccountNotifications(account,
user); user);
actionWithAccount = null; actionWithAccount = null;
actionWithUser = null; actionWithUser = null;
actionWithView = null; actionWithView = null;
setContentView(R.layout.chat_viewer); setContentView(R.layout.chat_viewer);
chatViewerAdapter = new ChatViewerAdapter(this, account, user); chatViewerAdapter = new ChatViewerAdapter(this, account, user);
pageSwitcher = (PageSwitcher) findViewById(R.id.switcher);
pageSwitcher.setAdapter(chatViewerAdapter); pageSwitcher = (PageSwitcher) findViewById(R.id.switcher);
pageSwitcher.setOnSelectListener(this); pageSwitcher.setAdapter(chatViewerAdapter);
pageSwitcher.setOnSelectListener(this);
if (savedInstanceState != null) {
actionWithAccount = savedInstanceState.getString(SAVED_ACCOUNT); if (savedInstanceState != null) {
actionWithUser = savedInstanceState.getString(SAVED_USER); actionWithAccount = savedInstanceState.getString(SAVED_ACCOUNT);
exitOnSend = savedInstanceState.getBoolean(SAVED_EXIT_ON_SEND); actionWithUser = savedInstanceState.getString(SAVED_USER);
} exitOnSend = savedInstanceState.getBoolean(SAVED_EXIT_ON_SEND);
if (actionWithAccount == null) }
actionWithAccount = account; if (actionWithAccount == null)
if (actionWithUser == null) actionWithAccount = account;
actionWithUser = user; if (actionWithUser == null)
actionWithUser = user;
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
selectChat(actionWithAccount, actionWithUser); selectChat(actionWithAccount, actionWithUser);
} }
@Override
protected void onResume() {
super.onResume();
Application.getInstance().addUIListener(OnChatChangedListener.class,
this);
Application.getInstance().addUIListener(OnContactChangedListener.class,
this);
Application.getInstance().addUIListener(OnAccountChangedListener.class,
this);
chatViewerAdapter.onChange();
if (actionWithView != null)
chatViewerAdapter.onChatChange(actionWithView, false);
Intent intent = getIntent();
if (Intent.ACTION_SEND.equals(intent.getAction())) {
String additional = intent.getStringExtra(Intent.EXTRA_TEXT);
if (additional != null) {
intent.removeExtra(Intent.EXTRA_TEXT);
exitOnSend = true;
if (actionWithView != null)
chatViewerAdapter.insertText(actionWithView, additional);
}
}
isVisible = true;
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (PageSwitcher.LOG)
LogManager.i(this, "onSave: " + actionWithAccount + ":"
+ actionWithUser);
outState.putString(SAVED_ACCOUNT, actionWithAccount);
outState.putString(SAVED_USER, actionWithUser);
outState.putBoolean(SAVED_EXIT_ON_SEND, exitOnSend);
}
@Override
protected void onPause() {
super.onPause();
Application.getInstance().removeUIListener(OnChatChangedListener.class,
this);
Application.getInstance().removeUIListener(
OnContactChangedListener.class, this);
Application.getInstance().removeUIListener(
OnAccountChangedListener.class, this);
MessageManager.getInstance().removeVisibleChat();
pageSwitcher.saveState();
isVisible = false;
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (isFinishing())
return;
String account = getAccount(intent);
String user = getUser(intent);
if (account == null || user == null) {
return;
}
if (hasAttention(intent))
AttentionManager.getInstance().removeAccountNotifications(account,
user);
chatViewerAdapter.onChange();
if (!selectChat(account, user))
Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
menu.clear();
chatViewerAdapter.onPrepareOptionsMenu(actionWithView, menu);
return true;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
close();
return false;
}
return super.onKeyDown(keyCode, event);
}
void close() {
finish();
if (!Intent.ACTION_SEND.equals(getIntent().getAction())) {
ActivityManager.getInstance().clearStack(false);
if (!ActivityManager.getInstance().hasContactList(this))
startActivity(ContactList.createIntent(this));
}
}
void onSent() {
if (exitOnSend)
close();
}
@Override
public void onSelect() {
BaseEntity contactItem = (BaseEntity) pageSwitcher.getSelectedItem();
actionWithAccount = contactItem.getAccount();
actionWithUser = contactItem.getUser();
if (PageSwitcher.LOG)
LogManager.i(this, "onSelect: " + actionWithAccount + ":"
+ actionWithUser);
actionWithView = pageSwitcher.getSelectedView();
if (isVisible)
MessageManager.getInstance().setVisibleChat(actionWithAccount,
actionWithUser);
MessageArchiveManager.getInstance().requestHistory(
actionWithAccount,
actionWithUser,
0,
MessageManager.getInstance()
.getChat(actionWithAccount, actionWithUser)
.getRequiredMessageCount());
NotificationManager.getInstance().removeMessageNotification(
actionWithAccount, actionWithUser);
}
@Override
public void onUnselect() {
actionWithAccount = null;
actionWithUser = null;
actionWithView = null;
if (PageSwitcher.LOG)
LogManager.i(this, "onUnselect");
}
@Override
public void onChatChanged(final String account, final String user,
final boolean incoming) {
BaseEntity baseEntity;
baseEntity = (BaseEntity) pageSwitcher.getSelectedItem();
if (baseEntity != null && baseEntity.equals(account, user)) {
chatViewerAdapter.onChatChange(pageSwitcher.getSelectedView(),
incoming);
return;
}
baseEntity = (BaseEntity) pageSwitcher.getVisibleItem();
if (baseEntity != null && baseEntity.equals(account, user)) {
chatViewerAdapter.onChatChange(pageSwitcher.getVisibleView(),
incoming);
return;
}
// Search for chat in adapter.
final int count = chatViewerAdapter.getCount();
for (int index = 0; index < count; index++)
if (((BaseEntity) chatViewerAdapter.getItem(index)).equals(account,
user))
return;
// New chat.
chatViewerAdapter.onChange();
}
@Override
public void onContactsChanged(Collection<BaseEntity> entities) {
BaseEntity baseEntity;
baseEntity = (BaseEntity) pageSwitcher.getSelectedItem();
if (baseEntity != null && entities.contains(baseEntity)) {
chatViewerAdapter.onChange();
return;
}
baseEntity = (BaseEntity) pageSwitcher.getVisibleItem();
if (baseEntity != null && entities.contains(baseEntity)) {
chatViewerAdapter.onChange();
return;
}
}
@Override
public void onAccountsChanged(Collection<String> accounts) {
BaseEntity baseEntity;
baseEntity = (BaseEntity) pageSwitcher.getSelectedItem();
if (baseEntity != null && accounts.contains(baseEntity.getAccount())) {
chatViewerAdapter.onChange();
return;
}
baseEntity = (BaseEntity) pageSwitcher.getVisibleItem();
if (baseEntity != null && accounts.contains(baseEntity.getAccount())) {
chatViewerAdapter.onChange();
return;
}
}
private boolean selectChat(String account, String user) {
for (int position = 0; position < chatViewerAdapter.getCount(); position++)
if (((BaseEntity) chatViewerAdapter.getItem(position)).equals(
account, user)) {
if (PageSwitcher.LOG)
LogManager.i(this, "setSelection: " + position + ", "
+ account + ":" + user);
pageSwitcher.setSelection(position);
return true;
}
if (PageSwitcher.LOG)
LogManager.i(this, "setSelection: not found, " + account + ":"
+ user);
return false;
}
public int getChatCount() {
return chatViewerAdapter.getCount();
}
public int getChatPosition(String account, String user) {
return chatViewerAdapter.getPosition(account, user);
}
public static Intent createIntent(Context context, String account,
String user) {
return new EntityIntentBuilder(context, ChatViewer.class)
.setAccount(account).setUser(user).build();
}
public static Intent createClearTopIntent(Context context, String account,
String user) {
Intent intent = createIntent(context, account, user);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
return intent;
}
/**
* Create intent to send message.
*
* Contact list will not be shown on when chat will be closed.
*
* @param context
* @param account
* @param user
* @param text
* if <code>null</code> then user will be able to send a number
* of messages. Else only one message can be send.
* @return
*/
public static Intent createSendIntent(Context context, String account,
String user, String text) {
Intent intent = ChatViewer.createIntent(context, account, user);
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, text);
return intent;
}
public static Intent createAttentionRequestIntent(Context context,
String account, String user) {
Intent intent = ChatViewer.createClearTopIntent(context, account, user);
intent.setAction(ACTION_ATTENTION);
return intent;
}
private static String getAccount(Intent intent) {
String value = EntityIntentBuilder.getAccount(intent);
if (value != null)
return value;
// Backward compatibility.
return intent.getStringExtra("com.xabber.android.data.account");
}
private static String getUser(Intent intent) {
String value = EntityIntentBuilder.getUser(intent);
if (value != null)
return value;
// Backward compatibility.
return intent.getStringExtra("com.xabber.android.data.user");
}
private static boolean hasAttention(Intent intent) {
return ACTION_ATTENTION.equals(intent.getAction());
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { protected void onResume() {
switch (item.getItemId()) { super.onResume();
// Respond to the action bar's Up/Home button Application.getInstance().addUIListener(OnChatChangedListener.class,
case android.R.id.home: this);
NavUtils.navigateUpFromSameTask(this); Application.getInstance().addUIListener(OnContactChangedListener.class,
return true; this);
Application.getInstance().addUIListener(OnAccountChangedListener.class,
this);
chatViewerAdapter.onChange();
if (actionWithView != null)
chatViewerAdapter.onChatChange(actionWithView, false);
Intent intent = getIntent();
if (Intent.ACTION_SEND.equals(intent.getAction())) {
String additional = intent.getStringExtra(Intent.EXTRA_TEXT);
if (additional != null) {
intent.removeExtra(Intent.EXTRA_TEXT);
exitOnSend = true;
if (actionWithView != null)
chatViewerAdapter.insertText(actionWithView, additional);
}
} }
return super.onOptionsItemSelected(item); isVisible = true;
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (PageSwitcher.LOG)
LogManager.i(this, "onSave: " + actionWithAccount + ":"
+ actionWithUser);
outState.putString(SAVED_ACCOUNT, actionWithAccount);
outState.putString(SAVED_USER, actionWithUser);
outState.putBoolean(SAVED_EXIT_ON_SEND, exitOnSend);
}
@Override
protected void onPause() {
super.onPause();
Application.getInstance().removeUIListener(OnChatChangedListener.class,
this);
Application.getInstance().removeUIListener(
OnContactChangedListener.class, this);
Application.getInstance().removeUIListener(
OnAccountChangedListener.class, this);
MessageManager.getInstance().removeVisibleChat();
pageSwitcher.saveState();
isVisible = false;
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (isFinishing())
return;
String account = getAccount(intent);
String user = getUser(intent);
if (account == null || user == null) {
return;
}
if (hasAttention(intent))
AttentionManager.getInstance().removeAccountNotifications(account,
user);
chatViewerAdapter.onChange();
if (!selectChat(account, user))
Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
menu.clear();
chatViewerAdapter.onPrepareOptionsMenu(actionWithView, menu);
return true;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
close();
return false;
}
return super.onKeyDown(keyCode, event);
}
void close() {
finish();
if (!Intent.ACTION_SEND.equals(getIntent().getAction())) {
ActivityManager.getInstance().clearStack(false);
if (!ActivityManager.getInstance().hasContactList(this))
startActivity(ContactList.createIntent(this));
}
}
void onSent() {
if (exitOnSend)
close();
}
@Override
public void onSelect() {
BaseEntity contactItem = (BaseEntity) pageSwitcher.getSelectedItem();
actionWithAccount = contactItem.getAccount();
actionWithUser = contactItem.getUser();
if (PageSwitcher.LOG)
LogManager.i(this, "onSelect: " + actionWithAccount + ":"
+ actionWithUser);
actionWithView = pageSwitcher.getSelectedView();
if (isVisible)
MessageManager.getInstance().setVisibleChat(actionWithAccount,
actionWithUser);
MessageArchiveManager.getInstance().requestHistory(
actionWithAccount,
actionWithUser,
0,
MessageManager.getInstance()
.getChat(actionWithAccount, actionWithUser)
.getRequiredMessageCount());
NotificationManager.getInstance().removeMessageNotification(
actionWithAccount, actionWithUser);
}
@Override
public void onUnselect() {
actionWithAccount = null;
actionWithUser = null;
actionWithView = null;
if (PageSwitcher.LOG)
LogManager.i(this, "onUnselect");
}
@Override
public void onChatChanged(final String account, final String user,
final boolean incoming) {
BaseEntity baseEntity;
baseEntity = (BaseEntity) pageSwitcher.getSelectedItem();
if (baseEntity != null && baseEntity.equals(account, user)) {
chatViewerAdapter.onChatChange(pageSwitcher.getSelectedView(),
incoming);
return;
}
baseEntity = (BaseEntity) pageSwitcher.getVisibleItem();
if (baseEntity != null && baseEntity.equals(account, user)) {
chatViewerAdapter.onChatChange(pageSwitcher.getVisibleView(),
incoming);
return;
}
// Search for chat in adapter.
final int count = chatViewerAdapter.getCount();
for (int index = 0; index < count; index++)
if (((BaseEntity) chatViewerAdapter.getItem(index)).equals(account,
user))
return;
// New chat.
chatViewerAdapter.onChange();
}
@Override
public void onContactsChanged(Collection<BaseEntity> entities) {
BaseEntity baseEntity;
baseEntity = (BaseEntity) pageSwitcher.getSelectedItem();
if (baseEntity != null && entities.contains(baseEntity)) {
chatViewerAdapter.onChange();
return;
}
baseEntity = (BaseEntity) pageSwitcher.getVisibleItem();
if (baseEntity != null && entities.contains(baseEntity)) {
chatViewerAdapter.onChange();
return;
}
}
@Override
public void onAccountsChanged(Collection<String> accounts) {
BaseEntity baseEntity;
baseEntity = (BaseEntity) pageSwitcher.getSelectedItem();
if (baseEntity != null && accounts.contains(baseEntity.getAccount())) {
chatViewerAdapter.onChange();
return;
}
baseEntity = (BaseEntity) pageSwitcher.getVisibleItem();
if (baseEntity != null && accounts.contains(baseEntity.getAccount())) {
chatViewerAdapter.onChange();
return;
}
}
private boolean selectChat(String account, String user) {
for (int position = 0; position < chatViewerAdapter.getCount(); position++)
if (((BaseEntity) chatViewerAdapter.getItem(position)).equals(
account, user)) {
if (PageSwitcher.LOG)
LogManager.i(this, "setSelection: " + position + ", "
+ account + ":" + user);
pageSwitcher.setSelection(position);
return true;
}
if (PageSwitcher.LOG)
LogManager.i(this, "setSelection: not found, " + account + ":"
+ user);
return false;
}
public int getChatCount() {
return chatViewerAdapter.getCount();
}
public int getChatPosition(String account, String user) {
return chatViewerAdapter.getPosition(account, user);
}
public static Intent createIntent(Context context, String account,
String user) {
return new EntityIntentBuilder(context, ChatViewer.class)
.setAccount(account).setUser(user).build();
}
public static Intent createClearTopIntent(Context context, String account,
String user) {
Intent intent = createIntent(context, account, user);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
return intent;
}
/**
* Create intent to send message.
*
* Contact list will not be shown on when chat will be closed.
*
* @param context
* @param account
* @param user
* @param text
* if <code>null</code> then user will be able to send a number
* of messages. Else only one message can be send.
* @return
*/
public static Intent createSendIntent(Context context, String account,
String user, String text) {
Intent intent = ChatViewer.createIntent(context, account, user);
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, text);
return intent;
}
public static Intent createAttentionRequestIntent(Context context,
String account, String user) {
Intent intent = ChatViewer.createClearTopIntent(context, account, user);
intent.setAction(ACTION_ATTENTION);
return intent;
}
private static String getAccount(Intent intent) {
String value = EntityIntentBuilder.getAccount(intent);
if (value != null)
return value;
// Backward compatibility.
return intent.getStringExtra("com.xabber.android.data.account");
}
private static String getUser(Intent intent) {
String value = EntityIntentBuilder.getUser(intent);
if (value != null)
return value;
// Backward compatibility.
return intent.getStringExtra("com.xabber.android.data.user");
}
private static boolean hasAttention(Intent intent) {
return ACTION_ATTENTION.equals(intent.getAction());
} }
} }
...@@ -249,245 +249,206 @@ public class ChatViewerFragment implements OnCreateContextMenuListener { ...@@ -249,245 +249,206 @@ public class ChatViewerFragment implements OnCreateContextMenuListener {
return view; return view;
} }
public boolean onPrepareOptionsMenu(Menu menu) { public boolean onPrepareOptionsMenu(Menu menu) {
final String account = chatMessageAdapter.getAccount(); final String account = chatMessageAdapter.getAccount();
final String user = chatMessageAdapter.getUser(); final String user = chatMessageAdapter.getUser();
AbstractChat abstractChat = MessageManager.getInstance().getChat( AbstractChat abstractChat = MessageManager.getInstance().getChat(account, user);
account, user);
if (abstractChat != null && abstractChat instanceof RoomChat) { getActivity().getMenuInflater().inflate(R.menu.chat, menu);
if (((RoomChat) abstractChat).getState() == RoomState.unavailable)
menu.add(R.string.muc_join) if (abstractChat != null && abstractChat instanceof RoomChat) {
.setIcon(android.R.drawable.ic_menu_add) if (((RoomChat) abstractChat).getState() == RoomState.unavailable) {
.setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() { MenuItem item = menu.findItem(R.id.action_join_conference);
item.setVisible(true);
@Override item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) { @Override
MUCManager.getInstance().joinRoom( public boolean onMenuItemClick(MenuItem item) {
account, user, true); MUCManager.getInstance().joinRoom(account, user, true);
return true; return true;
} }});
} else {
}); menu.findItem(R.id.action_invite_to_chat).setVisible(true)
else .setIntent(ContactList.createRoomInviteIntent(getActivity(), account, user));
menu.add(R.string.muc_invite) }
.setIcon(android.R.drawable.ic_menu_add) } else {
.setIntent( menu.findItem(R.id.action_edit_contact).setVisible(true)
ContactList.createRoomInviteIntent( .setIntent(ContactEditor.createIntent(getActivity(), account, user));
getActivity(), account, user)); }
} else { menu.findItem(R.id.action_chat_list).setIntent(ChatList.createIntent(getActivity()));
menu.add(R.string.contact_editor)
.setIcon(android.R.drawable.ic_menu_edit) menu.findItem(R.id.action_chat_settings)
.setIntent( .setIntent(ChatEditor.createIntent(getActivity(), account, user));
ContactEditor.createIntent(getActivity(), account,
user)); menu.findItem(R.id.action_show_history).setOnMenuItemClickListener(
} new MenuItem.OnMenuItemClickListener() {
menu.add(R.string.chat_list).setIcon(R.drawable.ic_menu_friendslist) @Override
.setIntent(ChatList.createIntent(getActivity())); public boolean onMenuItemClick(MenuItem item) {
menu.add(R.string.chat_settings) MessageManager.getInstance().requestToLoadLocalHistory(account, user);
.setIcon(android.R.drawable.ic_menu_preferences) MessageArchiveManager.getInstance()
.setIntent( .requestHistory(account, user, MINIMUM_MESSAGES_TO_LOAD, 0);
ChatEditor.createIntent(getActivity(), account, user)); onChatChange(false);
menu.add(R.string.show_history) return true;
.setIcon(R.drawable.ic_menu_archive) }
.setOnMenuItemClickListener( });
new MenuItem.OnMenuItemClickListener() {
if (abstractChat != null && abstractChat instanceof RoomChat
@Override && ((RoomChat) abstractChat).getState() != RoomState.unavailable) {
public boolean onMenuItemClick(MenuItem item) { if (((RoomChat) abstractChat).getState() == RoomState.error) {
MessageManager.getInstance() menu.findItem(R.id.action_authorization_settings).setVisible(true)
.requestToLoadLocalHistory(account, .setIntent(MUCEditor.createIntent(getActivity(), account, user));
user); } else {
MessageArchiveManager.getInstance() menu.findItem(R.id.action_leave_conference).setVisible(true).setOnMenuItemClickListener(
.requestHistory(account, user, new MenuItem.OnMenuItemClickListener() {
MINIMUM_MESSAGES_TO_LOAD, 0); @Override
onChatChange(false); public boolean onMenuItemClick(MenuItem item) {
return true; MUCManager.getInstance().leaveRoom(account, user);
} MessageManager.getInstance().closeChat(account, user);
NotificationManager.getInstance()
}); .removeMessageNotification(account, user);
if (abstractChat != null ((ChatViewer) getActivity()).close();
&& abstractChat instanceof RoomChat return true;
&& ((RoomChat) abstractChat).getState() != RoomState.unavailable) { }
if (((RoomChat) abstractChat).getState() == RoomState.error) });
menu.add(R.string.muc_edit) }
.setIcon(android.R.drawable.ic_menu_edit) } else {
.setIntent( menu.findItem(R.id.action_close_chat).setVisible(true)
MUCEditor.createIntent(getActivity(), account, .setOnMenuItemClickListener(
user)); new MenuItem.OnMenuItemClickListener() {
else @Override
menu.add(R.string.muc_leave) public boolean onMenuItemClick(MenuItem item) {
.setIcon(android.R.drawable.ic_menu_close_clear_cancel) MessageManager.getInstance().closeChat(account, user);
.setOnMenuItemClickListener( NotificationManager.getInstance()
new MenuItem.OnMenuItemClickListener() { .removeMessageNotification(account, user);
((ChatViewer) getActivity()).close();
@Override return true;
public boolean onMenuItemClick(MenuItem item) { }
MUCManager.getInstance().leaveRoom( });
account, user); }
MessageManager.getInstance().closeChat(
account, user); menu.findItem(R.id.action_clear_text).setOnMenuItemClickListener(
NotificationManager.getInstance() new MenuItem.OnMenuItemClickListener() {
.removeMessageNotification( @Override
account, user); public boolean onMenuItemClick(MenuItem item) {
((ChatViewer) getActivity()).close(); inputView.setText("");
return true; return true;
} }
});
});
} else { menu.findItem(R.id.action_clear_history).setOnMenuItemClickListener(
menu.add(R.string.close_chat) new MenuItem.OnMenuItemClickListener() {
.setIcon(android.R.drawable.ic_menu_close_clear_cancel) @Override
.setOnMenuItemClickListener( public boolean onMenuItemClick(MenuItem item) {
new MenuItem.OnMenuItemClickListener() { MessageManager.getInstance()
.clearHistory(account, user);
@Override onChatChange(false);
public boolean onMenuItemClick(MenuItem item) { return false;
MessageManager.getInstance().closeChat( }
account, user); });
NotificationManager.getInstance()
.removeMessageNotification(account, menu.findItem(R.id.action_export_chat).setOnMenuItemClickListener(
user); new MenuItem.OnMenuItemClickListener() {
((ChatViewer) getActivity()).close();
return true; @Override
} public boolean onMenuItemClick(MenuItem item) {
ChatExportDialogFragment
}); .newInstance(account, user)
} .show(getActivity().getSupportFragmentManager(),
menu.add(R.string.clear_message) "CHAT_EXPORT");
.setIcon(R.drawable.ic_menu_stop) return true;
.setOnMenuItemClickListener( }
new MenuItem.OnMenuItemClickListener() {
});
@Override if (abstractChat != null && abstractChat instanceof RegularChat) {
public boolean onMenuItemClick(MenuItem item) { menu.findItem(R.id.action_call_attention).setOnMenuItemClickListener(
inputView.setText(""); new MenuItem.OnMenuItemClickListener() {
return true; @Override
} public boolean onMenuItemClick(MenuItem item) {
try {
}); AttentionManager.getInstance().sendAttention(
menu.add(R.string.clear_history).setOnMenuItemClickListener( account, user);
new MenuItem.OnMenuItemClickListener() { } catch (NetworkException e) {
Application.getInstance().onError(e);
@Override }
public boolean onMenuItemClick(MenuItem item) { return true;
MessageManager.getInstance() }
.clearHistory(account, user); });
onChatChange(false); SecurityLevel securityLevel = OTRManager.getInstance()
return false; .getSecurityLevel(abstractChat.getAccount(),
} abstractChat.getUser());
if (securityLevel == SecurityLevel.plain) {
}); menu.findItem(R.id.action_start_encryption).setVisible(true)
menu.add(R.string.export_chat).setOnMenuItemClickListener( .setEnabled(SettingsManager.securityOtrMode() != SecurityOtrMode.disabled)
new MenuItem.OnMenuItemClickListener() { .setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
try {
OTRManager.getInstance().startSession(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
return true;
}
});
} else {
menu.findItem(R.id.action_restart_encryption).setVisible(true)
.setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
try {
OTRManager.getInstance().refreshSession(
account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
return true;
}
});
}
menu.findItem(R.id.action_stop_encryption)
.setEnabled(securityLevel != SecurityLevel.plain)
.setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
try {
OTRManager.getInstance().endSession(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
return true;
}
});
menu.findItem(R.id.action_verify_with_fingerprint)
.setEnabled(securityLevel != SecurityLevel.plain)
.setIntent(FingerprintViewer.createIntent(getActivity(), account, user));
menu.findItem(R.id.action_verify_with_question)
.setEnabled(securityLevel != SecurityLevel.plain)
.setIntent(QuestionViewer
.createIntent(getActivity(), account, user, true, false, null));
menu.findItem(R.id.action_verify_with_shared_secret)
.setEnabled(securityLevel != SecurityLevel.plain)
.setIntent(QuestionViewer
.createIntent(getActivity(), account, user, false, false, null));
}
if (abstractChat != null && abstractChat instanceof RoomChat
&& ((RoomChat) abstractChat).getState() == RoomState.available)
menu.findItem(R.id.action_list_of_occupants).setVisible(true).setIntent(
OccupantList.createIntent(getActivity(), account, user));
return true;
}
@Override
public boolean onMenuItemClick(MenuItem item) {
ChatExportDialogFragment
.newInstance(account, user)
.show(getActivity().getSupportFragmentManager(),
"CHAT_EXPORT");
return true;
}
});
if (abstractChat != null && abstractChat instanceof RegularChat) {
menu.add(R.string.call_attention).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
try {
AttentionManager.getInstance().sendAttention(
account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
return true;
}
});
SecurityLevel securityLevel = OTRManager.getInstance()
.getSecurityLevel(abstractChat.getAccount(),
abstractChat.getUser());
SubMenu otrMenu = menu.addSubMenu(R.string.otr_encryption);
otrMenu.setHeaderTitle(R.string.otr_encryption);
if (securityLevel == SecurityLevel.plain)
otrMenu.add(R.string.otr_start)
.setEnabled(
SettingsManager.securityOtrMode() != SecurityOtrMode.disabled)
.setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
try {
OTRManager
.getInstance()
.startSession(account, user);
} catch (NetworkException e) {
Application.getInstance()
.onError(e);
}
return true;
}
});
else
otrMenu.add(R.string.otr_refresh).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
try {
OTRManager.getInstance().refreshSession(
account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
return true;
}
});
otrMenu.add(R.string.otr_end)
.setEnabled(securityLevel != SecurityLevel.plain)
.setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
try {
OTRManager.getInstance().endSession(
account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
return true;
}
});
otrMenu.add(R.string.otr_verify_fingerprint)
.setEnabled(securityLevel != SecurityLevel.plain)
.setIntent(
FingerprintViewer.createIntent(getActivity(),
account, user));
otrMenu.add(R.string.otr_verify_question)
.setEnabled(securityLevel != SecurityLevel.plain)
.setIntent(
QuestionViewer.createIntent(getActivity(), account,
user, true, false, null));
otrMenu.add(R.string.otr_verify_secret)
.setEnabled(securityLevel != SecurityLevel.plain)
.setIntent(
QuestionViewer.createIntent(getActivity(), account,
user, false, false, null));
}
if (abstractChat != null && abstractChat instanceof RoomChat
&& ((RoomChat) abstractChat).getState() == RoomState.available)
menu.add(R.string.occupant_list).setIntent(
OccupantList.createIntent(getActivity(), account, user));
return true;
}
@Override @Override
public void onCreateContextMenu(ContextMenu menu, View view, public void onCreateContextMenu(ContextMenu menu, View view,
......
...@@ -80,15 +80,6 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O ...@@ -80,15 +80,6 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O
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_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_STATUS_EDITOR_ID = 0x04;
private static final int OPTION_MENU_PREFERENCE_EDITOR_ID = 0x05;
private static final int OPTION_MENU_CHAT_LIST_ID = 0x06;
private static final int OPTION_MENU_JOIN_ROOM_ID = 0x07;
private static final int OPTION_MENU_EXIT_ID = 0x08;
private static final int OPTION_MENU_SEARCH_ID = 0x0A;
private static final int OPTION_MENU_CLOSE_CHATS_ID = 0x0B;
private static final int DIALOG_CLOSE_APPLICATION_ID = 0x57; private static final int DIALOG_CLOSE_APPLICATION_ID = 0x57;
private static final String CONTACT_LIST_TAG = "CONTACT_LIST"; private static final String CONTACT_LIST_TAG = "CONTACT_LIST";
...@@ -270,80 +261,70 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O ...@@ -270,80 +261,70 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O
super.onPause(); super.onPause();
} }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);
menu.add(0, OPTION_MENU_ADD_CONTACT_ID, 0, getMenuInflater().inflate(R.menu.contact_list, menu);
getText(R.string.contact_add)).setIcon( return true;
R.drawable.ic_menu_invite); }
menu.add(0, OPTION_MENU_CLOSE_CHATS_ID, 0,
getText(R.string.close_chats)).setIcon( @Override
R.drawable.ic_menu_end_conversation); public boolean onOptionsItemSelected(MenuItem item) {
menu.add(0, OPTION_MENU_PREFERENCE_EDITOR_ID, 0, switch (item.getItemId()) {
getResources().getText(R.string.preference_editor)).setIcon( case R.id.action_search:
android.R.drawable.ic_menu_preferences); search();
menu.add(0, OPTION_MENU_STATUS_EDITOR_ID, 0, return true;
getText(R.string.status_editor)).setIcon( case R.id.action_change_status:
R.drawable.ic_menu_notifications); startActivity(StatusEditor.createIntent(this));
menu.add(0, OPTION_MENU_EXIT_ID, 0, getText(R.string.exit)).setIcon( return true;
android.R.drawable.ic_menu_close_clear_cancel); case R.id.action_add_contact:
menu.add(0, OPTION_MENU_JOIN_ROOM_ID, 0, getText(R.string.muc_add)); startActivity(ContactAdd.createIntent(this));
menu.add(0, OPTION_MENU_SEARCH_ID, 0, return true;
getText(android.R.string.search_go)); case R.id.action_close_chats:
menu.add(0, OPTION_MENU_CHAT_LIST_ID, 0, getText(R.string.chat_list)) closeAllChats();
.setIcon(R.drawable.ic_menu_friendslist); return true;
return true; case R.id.action_join_conference:
} startActivity(MUCEditor.createIntent(this));
return true;
@Override case R.id.action_chat_list:
public boolean onOptionsItemSelected(MenuItem item) { startActivity(ChatList.createIntent(this));
super.onOptionsItemSelected(item); return true;
switch (item.getItemId()) { case R.id.action_settings:
case OPTION_MENU_ADD_CONTACT_ID: startActivity(PreferenceEditor.createIntent(this));
startActivity(ContactAdd.createIntent(this)); return true;
return true; case R.id.action_exit:
case OPTION_MENU_STATUS_EDITOR_ID: exit();
startActivity(StatusEditor.createIntent(this)); return true;
return true; default:
case OPTION_MENU_PREFERENCE_EDITOR_ID: return super.onOptionsItemSelected(item);
startActivity(PreferenceEditor.createIntent(this)); }
return true; }
case OPTION_MENU_CHAT_LIST_ID:
startActivity(ChatList.createIntent(this)); private void exit() {
return true; Application.getInstance().requestToClose();
case OPTION_MENU_JOIN_ROOM_ID: showDialog(DIALOG_CLOSE_APPLICATION_ID);
startActivity(MUCEditor.createIntent(this)); getContactListFragment().unregisterListeners();
return true; new Handler().postDelayed(new Runnable() {
case OPTION_MENU_EXIT_ID: @Override
Application.getInstance().requestToClose(); public void run() {
showDialog(DIALOG_CLOSE_APPLICATION_ID); // Close activity if application was not killed yet.
getContactListFragment().unregisterListeners(); finish();
new Handler().postDelayed(new Runnable() { }
@Override }, CLOSE_ACTIVITY_AFTER_DELAY);
public void run() { }
// Close activity if application was not killed yet.
finish(); private void closeAllChats() {
} for (AbstractChat chat : MessageManager.getInstance()
}, CLOSE_ACTIVITY_AFTER_DELAY); .getActiveChats()) {
return true; MessageManager.getInstance().closeChat(chat.getAccount(),
case OPTION_MENU_SEARCH_ID: chat.getUser());
search(); NotificationManager.getInstance().removeMessageNotification(
return true; chat.getAccount(), chat.getUser());
case OPTION_MENU_CLOSE_CHATS_ID: }
for (AbstractChat chat : MessageManager.getInstance() getContactListFragment().getAdapter().onChange();
.getActiveChats()) { }
MessageManager.getInstance().closeChat(chat.getAccount(),
chat.getUser());
NotificationManager.getInstance().removeMessageNotification(
chat.getAccount(), chat.getUser());
}
getContactListFragment().getAdapter().onChange();
return true;
}
return false;
}
private ContactListFragment getContactListFragment() { private ContactListFragment getContactListFragment() {
return (ContactListFragment) getSupportFragmentManager() return (ContactListFragment) getSupportFragmentManager()
.findFragmentByTag(CONTACT_LIST_TAG); .findFragmentByTag(CONTACT_LIST_TAG);
} }
......
...@@ -46,9 +46,7 @@ public abstract class GroupListActivity extends ManagedListActivity implements ...@@ -46,9 +46,7 @@ public abstract class GroupListActivity extends ManagedListActivity implements
private static final String SAVED_GROUPS = "com.xabber.android.ui.ContactList.SAVED_GROUPS"; private static final String SAVED_GROUPS = "com.xabber.android.ui.ContactList.SAVED_GROUPS";
private static final String SAVED_SELECTED = "com.xabber.android.ui.ContactList.SAVED_SELECTED"; private static final String SAVED_SELECTED = "com.xabber.android.ui.ContactList.SAVED_SELECTED";
static final int OPTION_MENU_ADD_GROUP_ID = 1; private ArrayAdapter<String> arrayAdapter;
private ArrayAdapter<String> arrayAdapter;
private ListView listView; private ListView listView;
...@@ -73,7 +71,7 @@ public abstract class GroupListActivity extends ManagedListActivity implements ...@@ -73,7 +71,7 @@ public abstract class GroupListActivity extends ManagedListActivity implements
listView = getListView(); listView = getListView();
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setOnItemClickListener(this); listView.setOnItemClickListener(this);
arrayAdapter = new ArrayAdapter<String>(this, arrayAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_multiple_choice, android.R.layout.simple_list_item_multiple_choice,
new ArrayList<String>()); new ArrayList<String>());
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
...@@ -113,7 +111,7 @@ public abstract class GroupListActivity extends ManagedListActivity implements ...@@ -113,7 +111,7 @@ public abstract class GroupListActivity extends ManagedListActivity implements
* @return Actual groups from adapter. * @return Actual groups from adapter.
*/ */
private ArrayList<String> getGroups() { private ArrayList<String> getGroups() {
ArrayList<String> groups = new ArrayList<String>(); ArrayList<String> groups = new ArrayList<>();
for (int position = 0; position < arrayAdapter.getCount(); position++) for (int position = 0; position < arrayAdapter.getCount(); position++)
groups.add(arrayAdapter.getItem(position)); groups.add(arrayAdapter.getItem(position));
return groups; return groups;
...@@ -123,7 +121,7 @@ public abstract class GroupListActivity extends ManagedListActivity implements ...@@ -123,7 +121,7 @@ public abstract class GroupListActivity extends ManagedListActivity implements
* @return Actual selected groups from adapter. * @return Actual selected groups from adapter.
*/ */
public ArrayList<String> getSelected() { public ArrayList<String> getSelected() {
ArrayList<String> groups = new ArrayList<String>(); ArrayList<String> groups = new ArrayList<>();
for (int position = 0; position < arrayAdapter.getCount(); position++) for (int position = 0; position < arrayAdapter.getCount(); position++)
if (listView.isItemChecked(position if (listView.isItemChecked(position
+ listView.getHeaderViewsCount())) { + listView.getHeaderViewsCount())) {
...@@ -132,23 +130,21 @@ public abstract class GroupListActivity extends ManagedListActivity implements ...@@ -132,23 +130,21 @@ public abstract class GroupListActivity extends ManagedListActivity implements
return groups; return groups;
} }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, OPTION_MENU_ADD_GROUP_ID, 0, getMenuInflater().inflate(R.menu.create_new_group, menu);
getResources().getText(R.string.group_add)).setIcon( return true;
android.R.drawable.ic_menu_add); }
return true;
} @Override
public boolean onOptionsItemSelected(MenuItem item) {
@Override switch (item.getItemId()) {
public boolean onOptionsItemSelected(MenuItem item) { case R.id.action_create_new_group:
switch (item.getItemId()) { showGroupAddDialog();
case OPTION_MENU_ADD_GROUP_ID: return true;
showGroupAddDialog(); }
return true; return false;
} }
return false;
}
private void showGroupAddDialog() { private void showGroupAddDialog() {
GroupAddDialogFragment.newInstance(getGroups()).show( GroupAddDialogFragment.newInstance(getGroups()).show(
...@@ -169,7 +165,7 @@ public abstract class GroupListActivity extends ManagedListActivity implements ...@@ -169,7 +165,7 @@ public abstract class GroupListActivity extends ManagedListActivity implements
* @param selected * @param selected
*/ */
void setGroups(Collection<String> groups, Collection<String> selected) { void setGroups(Collection<String> groups, Collection<String> selected) {
ArrayList<String> list = new ArrayList<String>(groups); ArrayList<String> list = new ArrayList<>(groups);
Collections.sort(list); Collections.sort(list);
arrayAdapter.clear(); arrayAdapter.clear();
for (int position = 0; position < list.size(); position++) { for (int position = 0; position < list.size(); position++) {
......
...@@ -26,7 +26,6 @@ import android.view.View; ...@@ -26,7 +26,6 @@ import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Spinner; import android.widget.Spinner;
...@@ -49,9 +48,7 @@ public class StatusEditor extends ManagedListActivity implements ...@@ -49,9 +48,7 @@ public class StatusEditor extends ManagedListActivity implements
private static final String SAVED_TEXT = "com.xabber.android.ui.StatusEditor.SAVED_TEXT"; private static final String SAVED_TEXT = "com.xabber.android.ui.StatusEditor.SAVED_TEXT";
private static final String SAVED_MODE = "com.xabber.android.ui.StatusEditor.SAVED_MODE"; private static final String SAVED_MODE = "com.xabber.android.ui.StatusEditor.SAVED_MODE";
static final public int OPTION_MENU_CLEAR_STATUSES_ID = 1; static final public int CONTEXT_MENU_SELECT_STATUS_ID = 10;
static final public int CONTEXT_MENU_SELECT_STATUS_ID = 10;
static final public int CONTEXT_MENU_EDIT_STATUS_ID = 11; static final public int CONTEXT_MENU_EDIT_STATUS_ID = 11;
static final public int CONTEXT_MENU_REMOVE_STATUS_ID = 12; static final public int CONTEXT_MENU_REMOVE_STATUS_ID = 12;
...@@ -95,7 +92,7 @@ public class StatusEditor extends ManagedListActivity implements ...@@ -95,7 +92,7 @@ public class StatusEditor extends ManagedListActivity implements
statusTextView = (EditText) header.findViewById(R.id.status_text); statusTextView = (EditText) header.findViewById(R.id.status_text);
statusModeView = (Spinner) header.findViewById(R.id.status_mode); statusModeView = (Spinner) header.findViewById(R.id.status_mode);
statusModeView.setAdapter(new StatusModeAdapter(this)); statusModeView.setAdapter(new StatusModeAdapter(this));
((Button) findViewById(R.id.ok)).setOnClickListener(this); findViewById(R.id.ok).setOnClickListener(this);
StatusMode statusMode; StatusMode statusMode;
String statusText; String statusText;
...@@ -152,26 +149,26 @@ public class StatusEditor extends ManagedListActivity implements ...@@ -152,26 +149,26 @@ public class StatusEditor extends ManagedListActivity implements
adapter.onChange(); adapter.onChange();
} }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);
menu.add(0, OPTION_MENU_CLEAR_STATUSES_ID, 0, getMenuInflater().inflate(R.menu.delete_status_message, menu);
getResources().getText(R.string.clear_statuses)).setIcon(
android.R.drawable.ic_menu_close_clear_cancel);
return true; return true;
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item); super.onOptionsItemSelected(item);
switch (item.getItemId()) { switch (item.getItemId()) {
case OPTION_MENU_CLEAR_STATUSES_ID: case R.id.action_delete_status_message:
AccountManager.getInstance().clearSavedStatuses(); AccountManager.getInstance().clearSavedStatuses();
adapter.onChange(); adapter.onChange();
return true; return true;
} }
return false; return false;
} }
@Override @Override
public void onCreateContextMenu(ContextMenu menu, View v, public void onCreateContextMenu(ContextMenu menu, View v,
......
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_join_conference"
android:title="@string/muc_join"
app:showAsAction="ifRoom"
android:orderInCategory="80"
android:visible="false"
android:icon="@drawable/ic_group_white_24dp"
/>
<item android:id="@+id/action_invite_to_chat"
android:title="@string/muc_invite"
app:showAsAction="never"
android:orderInCategory="90"
android:visible="false"
/>
<item android:id="@+id/action_edit_contact"
android:title="@string/contact_editor"
app:showAsAction="ifRoom"
android:orderInCategory="100"
android:visible="false"
android:icon="@drawable/ic_create_white_24dp"
/>
<item android:id="@+id/action_chat_list"
android:title="@string/chat_list"
app:showAsAction="never"
android:orderInCategory="110"
/>
<item android:id="@+id/action_chat_settings"
android:title="@string/chat_settings"
app:showAsAction="never"
android:orderInCategory="120"
/>
<item android:id="@+id/action_show_history"
android:title="@string/show_history"
app:showAsAction="never"
android:orderInCategory="130"
/>
<item android:id="@+id/action_authorization_settings"
android:title="@string/muc_edit"
app:showAsAction="never"
android:orderInCategory="133"
android:visible="false"
/>
<item android:id="@+id/action_leave_conference"
android:title="@string/muc_leave"
app:showAsAction="never"
android:orderInCategory="136"
android:visible="false"
/>
<item android:id="@+id/action_close_chat"
android:title="@string/close_chat"
app:showAsAction="ifRoom"
android:orderInCategory="140"
android:visible="false"
android:icon="@drawable/ic_clear_white_24dp"
/>
<item android:id="@+id/action_clear_text"
android:title="@string/clear_message"
app:showAsAction="never"
android:orderInCategory="150"
/>
<item android:id="@+id/action_clear_history"
android:title="@string/clear_history"
app:showAsAction="never"
android:orderInCategory="160"
/>
<item android:id="@+id/action_export_chat"
android:title="@string/export_chat"
app:showAsAction="never"
android:orderInCategory="170"
/>
<item android:id="@+id/action_call_attention"
android:title="@string/call_attention"
app:showAsAction="never"
android:orderInCategory="180"
/>
<item android:id="@+id/action_otr_encryption"
android:title="@string/otr_encryption"
app:showAsAction="never"
android:orderInCategory="190">
<menu>
<item android:id="@+id/action_start_encryption"
android:title="@string/otr_start"
app:showAsAction="never"
android:orderInCategory="100"
android:visible="false"
/>
<item android:id="@+id/action_restart_encryption"
android:title="@string/otr_refresh"
app:showAsAction="never"
android:orderInCategory="105"
android:visible="false"
/>
<item android:id="@+id/action_stop_encryption"
android:title="@string/otr_end"
app:showAsAction="never"
android:orderInCategory="110"
/>
<item android:id="@+id/action_verify_with_fingerprint"
android:title="@string/otr_verify_fingerprint"
app:showAsAction="never"
android:orderInCategory="120"
/>
<item android:id="@+id/action_verify_with_question"
android:title="@string/otr_verify_question"
app:showAsAction="never"
android:orderInCategory="130"
/>
<item android:id="@+id/action_verify_with_shared_secret"
android:title="@string/otr_verify_secret"
app:showAsAction="never"
android:orderInCategory="140"
/>
</menu>
</item>
<item android:id="@+id/action_list_of_occupants"
android:title="@string/occupant_list"
app:showAsAction="never"
android:orderInCategory="200"
android:visible="false"
/>
</menu>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_search"
android:title="@android:string/search_go"
app:showAsAction="always"
android:orderInCategory="100"
android:icon="@drawable/ic_search_white_24dp"
/>
<item android:id="@+id/action_add_contact"
android:title="@string/contact_add"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_person_add_white_24dp"
android:orderInCategory="110"
/>
<item android:id="@+id/action_join_conference"
android:title="@string/muc_add"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_group_white_24dp"
android:orderInCategory="120"
/>
<item android:id="@+id/action_change_status"
android:title="@string/status_editor"
app:showAsAction="never"
android:orderInCategory="130"
/>
<item android:id="@+id/action_chat_list"
android:title="@string/chat_list"
app:showAsAction="never"
android:orderInCategory="140"
/>
<item android:id="@+id/action_close_chats"
android:title="@string/close_chats"
app:showAsAction="never"
android:orderInCategory="150"
/>
<item android:id="@+id/action_settings"
android:title="@string/preference_editor"
app:showAsAction="never"
android:orderInCategory="160"
android:icon="@drawable/ic_settings_white_24dp"
/>
<item android:id="@+id/action_exit"
android:title="@string/exit"
app:showAsAction="never"
android:orderInCategory="200"
/>
</menu>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_create_new_group"
android:title="@string/group_add"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_group_add_white_24dp"
android:orderInCategory="100"
/>
</menu>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_delete_status_message"
android:title="@string/clear_statuses"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_delete_white_24dp"
android:orderInCategory="100"
/>
</menu>
\ No newline at end of file
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