Commit 47e05268 authored by Grigory Fedorov's avatar Grigory Fedorov

Chat options menu rewritten using xml resource. One icon added.

parent 2e99802f
...@@ -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.
* *
...@@ -101,6 +99,7 @@ public class ChatViewer extends ManagedActivity implements OnSelectListener, ...@@ -101,6 +99,7 @@ public class ChatViewer extends ManagedActivity implements OnSelectListener,
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 = (PageSwitcher) findViewById(R.id.switcher);
pageSwitcher.setAdapter(chatViewerAdapter); pageSwitcher.setAdapter(chatViewerAdapter);
pageSwitcher.setOnSelectListener(this); pageSwitcher.setOnSelectListener(this);
...@@ -395,15 +394,4 @@ public class ChatViewer extends ManagedActivity implements OnSelectListener, ...@@ -395,15 +394,4 @@ public class ChatViewer extends ManagedActivity implements OnSelectListener,
return ACTION_ATTENTION.equals(intent.getAction()); return ACTION_ATTENTION.equals(intent.getAction());
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
} }
...@@ -252,123 +252,91 @@ public class ChatViewerFragment implements OnCreateContextMenuListener { ...@@ -252,123 +252,91 @@ public class ChatViewerFragment implements OnCreateContextMenuListener {
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);
getActivity().getMenuInflater().inflate(R.menu.chat, menu);
if (abstractChat != null && abstractChat instanceof RoomChat) { if (abstractChat != null && abstractChat instanceof RoomChat) {
if (((RoomChat) abstractChat).getState() == RoomState.unavailable) if (((RoomChat) abstractChat).getState() == RoomState.unavailable) {
menu.add(R.string.muc_join)
.setIcon(android.R.drawable.ic_menu_add)
.setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
MenuItem item = menu.findItem(R.id.action_join_conference);
item.setVisible(true);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
MUCManager.getInstance().joinRoom( MUCManager.getInstance().joinRoom(account, user, true);
account, user, true);
return true; return true;
}});
} else {
menu.findItem(R.id.action_invite_to_chat).setVisible(true)
.setIntent(ContactList.createRoomInviteIntent(getActivity(), account, user));
} }
});
else
menu.add(R.string.muc_invite)
.setIcon(android.R.drawable.ic_menu_add)
.setIntent(
ContactList.createRoomInviteIntent(
getActivity(), account, user));
} else { } else {
menu.add(R.string.contact_editor) menu.findItem(R.id.action_edit_contact).setVisible(true)
.setIcon(android.R.drawable.ic_menu_edit) .setIntent(ContactEditor.createIntent(getActivity(), account, user));
.setIntent( }
ContactEditor.createIntent(getActivity(), account, menu.findItem(R.id.action_chat_list).setIntent(ChatList.createIntent(getActivity()));
user));
} menu.findItem(R.id.action_chat_settings)
menu.add(R.string.chat_list).setIcon(R.drawable.ic_menu_friendslist) .setIntent(ChatEditor.createIntent(getActivity(), account, user));
.setIntent(ChatList.createIntent(getActivity()));
menu.add(R.string.chat_settings)
.setIcon(android.R.drawable.ic_menu_preferences)
.setIntent(
ChatEditor.createIntent(getActivity(), account, user));
menu.add(R.string.show_history)
.setIcon(R.drawable.ic_menu_archive)
.setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
menu.findItem(R.id.action_show_history).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
MessageManager.getInstance() MessageManager.getInstance().requestToLoadLocalHistory(account, user);
.requestToLoadLocalHistory(account,
user);
MessageArchiveManager.getInstance() MessageArchiveManager.getInstance()
.requestHistory(account, user, .requestHistory(account, user, MINIMUM_MESSAGES_TO_LOAD, 0);
MINIMUM_MESSAGES_TO_LOAD, 0);
onChatChange(false); onChatChange(false);
return true; return true;
} }
}); });
if (abstractChat != null
&& abstractChat instanceof RoomChat if (abstractChat != null && abstractChat instanceof RoomChat
&& ((RoomChat) abstractChat).getState() != RoomState.unavailable) { && ((RoomChat) abstractChat).getState() != RoomState.unavailable) {
if (((RoomChat) abstractChat).getState() == RoomState.error) if (((RoomChat) abstractChat).getState() == RoomState.error) {
menu.add(R.string.muc_edit) menu.findItem(R.id.action_authorization_settings).setVisible(true)
.setIcon(android.R.drawable.ic_menu_edit) .setIntent(MUCEditor.createIntent(getActivity(), account, user));
.setIntent( } else {
MUCEditor.createIntent(getActivity(), account, menu.findItem(R.id.action_leave_conference).setVisible(true).setOnMenuItemClickListener(
user));
else
menu.add(R.string.muc_leave)
.setIcon(android.R.drawable.ic_menu_close_clear_cancel)
.setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() { new MenuItem.OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
MUCManager.getInstance().leaveRoom( MUCManager.getInstance().leaveRoom(account, user);
account, user); MessageManager.getInstance().closeChat(account, user);
MessageManager.getInstance().closeChat(
account, user);
NotificationManager.getInstance() NotificationManager.getInstance()
.removeMessageNotification( .removeMessageNotification(account, user);
account, user);
((ChatViewer) getActivity()).close(); ((ChatViewer) getActivity()).close();
return true; return true;
} }
}); });
}
} else { } else {
menu.add(R.string.close_chat) menu.findItem(R.id.action_close_chat).setVisible(true)
.setIcon(android.R.drawable.ic_menu_close_clear_cancel)
.setOnMenuItemClickListener( .setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() { new MenuItem.OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
MessageManager.getInstance().closeChat( MessageManager.getInstance().closeChat(account, user);
account, user);
NotificationManager.getInstance() NotificationManager.getInstance()
.removeMessageNotification(account, .removeMessageNotification(account, user);
user);
((ChatViewer) getActivity()).close(); ((ChatViewer) getActivity()).close();
return true; return true;
} }
}); });
} }
menu.add(R.string.clear_message)
.setIcon(R.drawable.ic_menu_stop)
.setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
menu.findItem(R.id.action_clear_text).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
inputView.setText(""); inputView.setText("");
return true; return true;
} }
}); });
menu.add(R.string.clear_history).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
menu.findItem(R.id.action_clear_history).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
MessageManager.getInstance() MessageManager.getInstance()
...@@ -376,9 +344,9 @@ public class ChatViewerFragment implements OnCreateContextMenuListener { ...@@ -376,9 +344,9 @@ public class ChatViewerFragment implements OnCreateContextMenuListener {
onChatChange(false); onChatChange(false);
return false; return false;
} }
}); });
menu.add(R.string.export_chat).setOnMenuItemClickListener(
menu.findItem(R.id.action_export_chat).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() { new MenuItem.OnMenuItemClickListener() {
@Override @Override
...@@ -392,9 +360,8 @@ public class ChatViewerFragment implements OnCreateContextMenuListener { ...@@ -392,9 +360,8 @@ public class ChatViewerFragment implements OnCreateContextMenuListener {
}); });
if (abstractChat != null && abstractChat instanceof RegularChat) { if (abstractChat != null && abstractChat instanceof RegularChat) {
menu.add(R.string.call_attention).setOnMenuItemClickListener( menu.findItem(R.id.action_call_attention).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() { new MenuItem.OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
try { try {
...@@ -405,36 +372,29 @@ public class ChatViewerFragment implements OnCreateContextMenuListener { ...@@ -405,36 +372,29 @@ public class ChatViewerFragment implements OnCreateContextMenuListener {
} }
return true; return true;
} }
}); });
SecurityLevel securityLevel = OTRManager.getInstance() SecurityLevel securityLevel = OTRManager.getInstance()
.getSecurityLevel(abstractChat.getAccount(), .getSecurityLevel(abstractChat.getAccount(),
abstractChat.getUser()); abstractChat.getUser());
SubMenu otrMenu = menu.addSubMenu(R.string.otr_encryption); if (securityLevel == SecurityLevel.plain) {
otrMenu.setHeaderTitle(R.string.otr_encryption); menu.findItem(R.id.action_start_encryption).setVisible(true)
if (securityLevel == SecurityLevel.plain) .setEnabled(SettingsManager.securityOtrMode() != SecurityOtrMode.disabled)
otrMenu.add(R.string.otr_start)
.setEnabled(
SettingsManager.securityOtrMode() != SecurityOtrMode.disabled)
.setOnMenuItemClickListener( .setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() { new MenuItem.OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
try { try {
OTRManager OTRManager.getInstance().startSession(account, user);
.getInstance()
.startSession(account, user);
} catch (NetworkException e) { } catch (NetworkException e) {
Application.getInstance() Application.getInstance().onError(e);
.onError(e);
} }
return true; return true;
} }
}); });
else } else {
otrMenu.add(R.string.otr_refresh).setOnMenuItemClickListener( menu.findItem(R.id.action_restart_encryption).setVisible(true)
.setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() { new MenuItem.OnMenuItemClickListener() {
@Override @Override
...@@ -449,7 +409,8 @@ public class ChatViewerFragment implements OnCreateContextMenuListener { ...@@ -449,7 +409,8 @@ public class ChatViewerFragment implements OnCreateContextMenuListener {
} }
}); });
otrMenu.add(R.string.otr_end) }
menu.findItem(R.id.action_stop_encryption)
.setEnabled(securityLevel != SecurityLevel.plain) .setEnabled(securityLevel != SecurityLevel.plain)
.setOnMenuItemClickListener( .setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() { new MenuItem.OnMenuItemClickListener() {
...@@ -457,8 +418,7 @@ public class ChatViewerFragment implements OnCreateContextMenuListener { ...@@ -457,8 +418,7 @@ public class ChatViewerFragment implements OnCreateContextMenuListener {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
try { try {
OTRManager.getInstance().endSession( OTRManager.getInstance().endSession(account, user);
account, user);
} catch (NetworkException e) { } catch (NetworkException e) {
Application.getInstance().onError(e); Application.getInstance().onError(e);
} }
...@@ -466,29 +426,30 @@ public class ChatViewerFragment implements OnCreateContextMenuListener { ...@@ -466,29 +426,30 @@ public class ChatViewerFragment implements OnCreateContextMenuListener {
} }
}); });
otrMenu.add(R.string.otr_verify_fingerprint)
menu.findItem(R.id.action_verify_with_fingerprint)
.setEnabled(securityLevel != SecurityLevel.plain) .setEnabled(securityLevel != SecurityLevel.plain)
.setIntent( .setIntent(FingerprintViewer.createIntent(getActivity(), account, user));
FingerprintViewer.createIntent(getActivity(),
account, user)); menu.findItem(R.id.action_verify_with_question)
otrMenu.add(R.string.otr_verify_question)
.setEnabled(securityLevel != SecurityLevel.plain) .setEnabled(securityLevel != SecurityLevel.plain)
.setIntent( .setIntent(QuestionViewer
QuestionViewer.createIntent(getActivity(), account, .createIntent(getActivity(), account, user, true, false, null));
user, true, false, null));
otrMenu.add(R.string.otr_verify_secret) menu.findItem(R.id.action_verify_with_shared_secret)
.setEnabled(securityLevel != SecurityLevel.plain) .setEnabled(securityLevel != SecurityLevel.plain)
.setIntent( .setIntent(QuestionViewer
QuestionViewer.createIntent(getActivity(), account, .createIntent(getActivity(), account, user, false, false, null));
user, false, false, null));
} }
if (abstractChat != null && abstractChat instanceof RoomChat if (abstractChat != null && abstractChat instanceof RoomChat
&& ((RoomChat) abstractChat).getState() == RoomState.available) && ((RoomChat) abstractChat).getState() == RoomState.available)
menu.add(R.string.occupant_list).setIntent( menu.findItem(R.id.action_list_of_occupants).setVisible(true).setIntent(
OccupantList.createIntent(getActivity(), account, user)); OccupantList.createIntent(getActivity(), account, user));
return true; return true;
} }
@Override @Override
public void onCreateContextMenu(ContextMenu menu, View view, public void onCreateContextMenu(ContextMenu menu, View view,
ContextMenuInfo menuInfo) { ContextMenuInfo menuInfo) {
......
<?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
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