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