Commit 4ba3b54a authored by Grigory Fedorov's avatar Grigory Fedorov

Chat context menu fixed and rewritten using xml resource.

parent 31ee1e6b
package com.xabber.android.ui;
import android.app.Fragment;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
......@@ -201,7 +202,6 @@ public class ChatViewerFragment extends Fragment implements ChatViewer.CurrentUp
}
});
registerForContextMenu(listView);
setHasOptionsMenu(true);
......@@ -218,6 +218,8 @@ public class ChatViewerFragment extends Fragment implements ChatViewer.CurrentUp
super.onResume();
((ChatViewer)getActivity()).registerChat(this);
registerForContextMenu(listView);
}
@Override
......@@ -225,6 +227,8 @@ public class ChatViewerFragment extends Fragment implements ChatViewer.CurrentUp
super.onPause();
((ChatViewer)getActivity()).unregisterChat(this);
unregisterForContextMenu(listView);
}
private void sendMessage() {
......@@ -506,54 +510,41 @@ public class ChatViewerFragment extends Fragment implements ChatViewer.CurrentUp
final MessageItem message = (MessageItem) listView.getAdapter().getItem(info.position);
if (message == null || message.getAction() == null) {
return;
}
if (message.isError()) {
menu.add(R.string.message_repeat).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
MenuInflater inflater = getActivity().getMenuInflater();
inflater.inflate(R.menu.chat_context_menu, menu);
@Override
public boolean onMenuItemClick(MenuItem item) {
sendMessage(message.getText());
return true;
if (message.isError()) {
menu.findItem(R.id.action_message_repeat).setVisible(true);
}
});
}
menu.add(R.string.message_quote).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
insertText("> " + message.getText() + "\n");
return true;
}
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
final MessageItem message = (MessageItem) listView.getAdapter().getItem(info.position);
});
menu.add(R.string.message_copy).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
switch (item.getItemId()) {
case R.id.action_message_repeat:
sendMessage(message.getText());
return true;
@Override
public boolean onMenuItemClick(MenuItem item) {
((ClipboardManager) getActivity().getSystemService(
Context.CLIPBOARD_SERVICE)).setText(message
.getSpannable());
case R.id.action_message_copy:
((ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE))
.setPrimaryClip(ClipData.newPlainText(message.getSpannable(), message.getSpannable()));
return true;
}
});
menu.add(R.string.message_remove).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
case R.id.action_message_quote:
insertText("> " + message.getText() + "\n");
return true;
@Override
public boolean onMenuItemClick(MenuItem item) {
case R.id.action_message_remove:
MessageManager.getInstance().removeMessage(message);
updateChat(false);
return true;
}
});
default:
return super.onContextItemSelected(item);
}
}
/**
......
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/action_message_repeat"
android:visible="false"
android:title="@string/message_repeat" />
<item android:id="@+id/action_message_quote"
android:title="@string/message_quote" />
<item android:id="@+id/action_message_copy"
android:title="@string/message_copy" />
<item android:id="@+id/action_message_remove"
android:title="@string/message_remove" />
</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