aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-10-23 21:27:41 +0200
committeriNPUTmice <daniel@gultsch.de>2014-10-23 21:27:41 +0200
commitd73a77643d7923cae0789c5ed9f6a2a4cf41385f (patch)
tree14012cf90146a8a1feacd29cbc6fa6ad959ba1c2 /src/eu/siacs
parentde3739970b32a927d8c1ec5f7a378fa50c4b4f99 (diff)
context menu for messages. allow to resend single messages
Diffstat (limited to 'src/eu/siacs')
-rw-r--r--src/eu/siacs/conversations/entities/Message.java11
-rw-r--r--src/eu/siacs/conversations/services/XmppConnectionService.java17
-rw-r--r--src/eu/siacs/conversations/ui/ConversationActivity.java1
-rw-r--r--src/eu/siacs/conversations/ui/ConversationFragment.java101
-rw-r--r--src/eu/siacs/conversations/ui/EditAccountActivity.java13
-rw-r--r--src/eu/siacs/conversations/ui/XmppActivity.java13
-rw-r--r--src/eu/siacs/conversations/ui/adapter/MessageAdapter.java28
7 files changed, 154 insertions, 30 deletions
diff --git a/src/eu/siacs/conversations/entities/Message.java b/src/eu/siacs/conversations/entities/Message.java
index a390c7ca..5fa16460 100644
--- a/src/eu/siacs/conversations/entities/Message.java
+++ b/src/eu/siacs/conversations/entities/Message.java
@@ -431,6 +431,11 @@ public class Message extends AbstractEntity {
params.size = Long.parseLong(parts[0]);
} catch (NumberFormatException e) {
params.origin = parts[0];
+ try {
+ params.url = new URL(parts[0]);
+ } catch (MalformedURLException e1) {
+ params.url = null;
+ }
}
} else if (parts.length == 3) {
try {
@@ -451,6 +456,11 @@ public class Message extends AbstractEntity {
} else if (parts.length == 4) {
params.origin = parts[0];
try {
+ params.url = new URL(parts[0]);
+ } catch (MalformedURLException e1) {
+ params.url = null;
+ }
+ try {
params.size = Long.parseLong(parts[1]);
} catch (NumberFormatException e) {
params.size = 0;
@@ -470,6 +480,7 @@ public class Message extends AbstractEntity {
}
public class ImageParams {
+ public URL url;
public long size = 0;
public int width = 0;
public int height = 0;
diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java
index 37e334eb..6d6c672e 100644
--- a/src/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/eu/siacs/conversations/services/XmppConnectionService.java
@@ -1924,4 +1924,21 @@ public class XmppConnectionService extends Service {
}
}
+
+ public void resendFailedMessages(Message message) {
+ List<Message> messages = new ArrayList<Message>();
+ Message current = message;
+ while(current.getStatus() == Message.STATUS_SEND_FAILED) {
+ messages.add(current);
+ if (current.mergable(current.next())) {
+ current = current.next();
+ } else {
+ break;
+ }
+ }
+ for(Message msg: messages) {
+ markMessage(msg, Message.STATUS_WAITING);
+ this.resendMessage(msg);
+ }
+ }
}
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java
index 91e1c81f..8a647f30 100644
--- a/src/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/eu/siacs/conversations/ui/ConversationActivity.java
@@ -191,6 +191,7 @@ public class ConversationActivity extends XmppActivity implements
xmppConnectionService.getNotificationService()
.setOpenConversation(null);
}
+ closeContextMenu();
}
@Override
diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java
index 580fa2d2..4c8d27e9 100644
--- a/src/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/eu/siacs/conversations/ui/ConversationFragment.java
@@ -11,6 +11,7 @@ import eu.siacs.conversations.crypto.PgpEngine;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
+import eu.siacs.conversations.entities.Downloadable;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.entities.Presences;
@@ -33,9 +34,12 @@ import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
import android.text.Editable;
import android.text.Selection;
+import android.view.ContextMenu;
+import android.view.ContextMenu.ContextMenuInfo;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
+import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
@@ -45,6 +49,8 @@ import android.widget.AbsListView.OnScrollListener;
import android.widget.TextView.OnEditorActionListener;
import android.widget.AbsListView;
+import android.widget.AdapterView;
+import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ListView;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
@@ -193,6 +199,7 @@ public class ConversationFragment extends Fragment {
};
private ConversationActivity activity;
+ private Message selectedMessage;
private void sendMessage() {
if (this.conversation == null) {
@@ -326,9 +333,100 @@ public class ConversationFragment extends Fragment {
});
messagesView.setAdapter(messageListAdapter);
+ registerForContextMenu(messagesView);
+
return view;
}
+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View v,
+ ContextMenuInfo menuInfo) {
+ super.onCreateContextMenu(menu, v, menuInfo);
+ AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
+ this.selectedMessage = this.messageList.get(acmi.position);
+ populateContextMenu(menu);
+ }
+
+ private void populateContextMenu(ContextMenu menu) {
+ if (this.selectedMessage.getType() != Message.TYPE_STATUS) {
+ activity.getMenuInflater().inflate(R.menu.message_context, menu);
+ menu.setHeaderTitle(R.string.message_options);
+ MenuItem copyText = menu.findItem(R.id.copy_text);
+ MenuItem shareImage = menu.findItem(R.id.share_image);
+ MenuItem sendAgain = menu.findItem(R.id.send_again);
+ MenuItem copyUrl = menu.findItem(R.id.copy_url);
+ if (this.selectedMessage.getType() != Message.TYPE_TEXT
+ || this.selectedMessage.getDownloadable() != null) {
+ copyText.setVisible(false);
+ }
+ if (this.selectedMessage.getType() != Message.TYPE_IMAGE
+ || (this.selectedMessage.getDownloadable() != null && this.selectedMessage
+ .getDownloadable().getStatus() == Downloadable.STATUS_DELETED)) {
+ shareImage.setVisible(false);
+ }
+ if (this.selectedMessage.getStatus() != Message.STATUS_SEND_FAILED) {
+ sendAgain.setVisible(false);
+ }
+ if ((this.selectedMessage.getType() != Message.TYPE_IMAGE && this.selectedMessage
+ .getDownloadable() == null)
+ || this.selectedMessage.getImageParams().url == null) {
+ copyUrl.setVisible(false);
+ }
+ }
+ }
+
+ @Override
+ public boolean onContextItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.share_image:
+ shareImage(selectedMessage);
+ return true;
+ case R.id.copy_text:
+ copyText(selectedMessage);
+ return true;
+ case R.id.send_again:
+ resendMessage(selectedMessage);
+ return true;
+ case R.id.copy_url:
+ copyUrl(selectedMessage);
+ return true;
+ default:
+ return super.onContextItemSelected(item);
+ }
+ }
+
+ private void shareImage(Message message) {
+ Intent shareIntent = new Intent();
+ shareIntent.setAction(Intent.ACTION_SEND);
+ shareIntent.putExtra(Intent.EXTRA_STREAM,
+ activity.xmppConnectionService.getFileBackend()
+ .getJingleFileUri(message));
+ shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ shareIntent.setType("image/webp");
+ activity.startActivity(Intent.createChooser(shareIntent,
+ getText(R.string.share_with)));
+ }
+
+ private void copyText(Message message) {
+ if (activity.copyTextToClipboard(message.getMergedBody(),
+ R.string.message_text)) {
+ Toast.makeText(activity, R.string.message_copied_to_clipboard,
+ Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ private void resendMessage(Message message) {
+ activity.xmppConnectionService.resendFailedMessages(message);
+ }
+
+ private void copyUrl(Message message) {
+ if (activity.copyTextToClipboard(
+ message.getImageParams().url.toString(), R.string.image_url)) {
+ Toast.makeText(activity, R.string.url_copied_to_clipboard,
+ Toast.LENGTH_SHORT).show();
+ }
+ }
+
protected void privateMessageWith(String counterpart) {
this.mEditMessage.setText("");
this.conversation.setNextPresence(counterpart);
@@ -437,7 +535,8 @@ public class ConversationFragment extends Fragment {
for (Message message : this.conversation.getMessages()) {
if (message.getEncryption() == Message.ENCRYPTION_PGP
&& (message.getStatus() == Message.STATUS_RECEIVED || message
- .getStatus() >= Message.STATUS_SEND) && message.getDownloadable() == null) {
+ .getStatus() >= Message.STATUS_SEND)
+ && message.getDownloadable() == null) {
if (!mEncryptedMessages.contains(message)) {
mEncryptedMessages.add(message);
}
diff --git a/src/eu/siacs/conversations/ui/EditAccountActivity.java b/src/eu/siacs/conversations/ui/EditAccountActivity.java
index 1543d740..89c06592 100644
--- a/src/eu/siacs/conversations/ui/EditAccountActivity.java
+++ b/src/eu/siacs/conversations/ui/EditAccountActivity.java
@@ -389,7 +389,7 @@ public class EditAccountActivity extends XmppActivity {
@Override
public void onClick(View v) {
- if (OtrFingerprintToClipBoard(fingerprint)) {
+ if (copyTextToClipboard(fingerprint,R.string.otr_fingerprint)) {
Toast.makeText(
EditAccountActivity.this,
R.string.toast_message_otr_fingerprint,
@@ -409,15 +409,4 @@ public class EditAccountActivity extends XmppActivity {
this.mStats.setVisibility(View.GONE);
}
}
-
- private boolean OtrFingerprintToClipBoard(String fingerprint) {
- ClipboardManager mClipBoardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
- String label = getResources().getString(R.string.otr_fingerprint);
- if (mClipBoardManager != null) {
- ClipData mClipData = ClipData.newPlainText(label, fingerprint);
- mClipBoardManager.setPrimaryClip(mClipData);
- return true;
- }
- return false;
- }
}
diff --git a/src/eu/siacs/conversations/ui/XmppActivity.java b/src/eu/siacs/conversations/ui/XmppActivity.java
index d26f0e31..c04a4c0b 100644
--- a/src/eu/siacs/conversations/ui/XmppActivity.java
+++ b/src/eu/siacs/conversations/ui/XmppActivity.java
@@ -21,6 +21,8 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.app.AlertDialog.Builder;
+import android.content.ClipData;
+import android.content.ClipboardManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
@@ -531,6 +533,17 @@ public abstract class XmppActivity extends Activity {
DisplayMetrics metrics = getResources().getDisplayMetrics();
return ((int) (dp * metrics.density));
}
+
+ public boolean copyTextToClipboard(String text,int labelResId) {
+ ClipboardManager mClipBoardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
+ String label = getResources().getString(labelResId);
+ if (mClipBoardManager != null) {
+ ClipData mClipData = ClipData.newPlainText(label, text);
+ mClipBoardManager.setPrimaryClip(mClipData);
+ return true;
+ }
+ return false;
+ }
public AvatarService avatarService() {
return xmppConnectionService.getAvatarService();
diff --git a/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java
index a9a55cbf..4e04e315 100644
--- a/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java
+++ b/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java
@@ -43,6 +43,15 @@ public class MessageAdapter extends ArrayAdapter<Message> {
private OnContactPictureClicked mOnContactPictureClickedListener;
private OnContactPictureLongClicked mOnContactPictureLongClickedListener;
+ private OnLongClickListener openContextMenu = new OnLongClickListener() {
+
+ @Override
+ public boolean onLongClick(View v) {
+ v.showContextMenu();
+ return true;
+ }
+ };
+
public MessageAdapter(ConversationActivity activity, List<Message> messages) {
super(activity, 0, messages);
this.activity = activity;
@@ -259,6 +268,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
startDonwloadable(message);
}
});
+ viewHolder.download_button.setOnLongClickListener(openContextMenu);
}
private void displayImageMessage(ViewHolder viewHolder,
@@ -292,23 +302,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
getContext().startActivity(intent);
}
});
- viewHolder.image.setOnLongClickListener(new OnLongClickListener() {
-
- @Override
- public boolean onLongClick(View v) {
- Intent shareIntent = new Intent();
- shareIntent.setAction(Intent.ACTION_SEND);
- shareIntent.putExtra(Intent.EXTRA_STREAM,
- activity.xmppConnectionService.getFileBackend()
- .getJingleFileUri(message));
- shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- shareIntent.setType("image/webp");
- getContext().startActivity(
- Intent.createChooser(shareIntent,
- getContext().getText(R.string.share_with)));
- return true;
- }
- });
+ viewHolder.image.setOnLongClickListener(openContextMenu);
}
@Override