aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Gultsch <inputmice@siacs.eu>2015-01-12 16:42:20 +0100
committerDaniel Gultsch <inputmice@siacs.eu>2015-01-12 16:42:20 +0100
commit8d3323e384746acfad563d9389529b0802787261 (patch)
tree3433856f6c4eb6e0be2ab65ef472ced35ebaebe4
parent77e4e1c2acfffcb64d0538c00b087462d15a4bbf (diff)
context menu for files and offered files. fixed #848 fixed #849
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationFragment.java34
-rw-r--r--src/main/res/menu/message_context.xml4
-rw-r--r--src/main/res/values/strings.xml3
3 files changed, 24 insertions, 17 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
index bd6fda98..4d4ee483 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
@@ -33,6 +33,7 @@ import android.widget.Toast;
import net.java.otr4j.session.SessionStatus;
+import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
@@ -408,7 +409,7 @@ public class ConversationFragment extends Fragment {
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 shareWith = menu.findItem(R.id.share_with);
MenuItem sendAgain = menu.findItem(R.id.send_again);
MenuItem copyUrl = menu.findItem(R.id.copy_url);
MenuItem downloadImage = menu.findItem(R.id.download_image);
@@ -416,8 +417,10 @@ public class ConversationFragment extends Fragment {
if (m.getType() != Message.TYPE_TEXT || m.getDownloadable() != null) {
copyText.setVisible(false);
}
- if (m.getType() != Message.TYPE_IMAGE || m.getDownloadable() != null) {
- shareImage.setVisible(false);
+ if (m.getType() == Message.TYPE_TEXT
+ || m.getType() == Message.TYPE_PRIVATE
+ || m.getDownloadable() != null) {
+ shareWith.setVisible(false);
}
if (m.getStatus() != Message.STATUS_SEND_FAILED) {
sendAgain.setVisible(false);
@@ -425,24 +428,25 @@ public class ConversationFragment extends Fragment {
if ((m.getType() != Message.TYPE_IMAGE && m.getDownloadable() == null)
|| m.getImageParams().url == null) {
copyUrl.setVisible(false);
- }
+ }
if (m.getType() != Message.TYPE_TEXT
|| m.getDownloadable() != null
|| !m.bodyContainsDownloadable()) {
downloadImage.setVisible(false);
- }
+ }
if (!((m.getDownloadable() != null && !(m.getDownloadable() instanceof DownloadablePlaceholder))
- || (m.isFileOrImage() && m.getStatus() == Message.STATUS_WAITING))) {
+ || (m.isFileOrImage() && (m.getStatus() == Message.STATUS_WAITING
+ || m.getStatus() == Message.STATUS_OFFERED)))) {
cancelTransmission.setVisible(false);
- }
+ }
}
}
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
- case R.id.share_image:
- shareImage(selectedMessage);
+ case R.id.share_with:
+ shareWith(selectedMessage);
return true;
case R.id.copy_text:
copyText(selectedMessage);
@@ -464,16 +468,20 @@ public class ConversationFragment extends Fragment {
}
}
- private void shareImage(Message message) {
+ private void shareWith(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)));
+ String path = message.getRelativeFilePath();
+ String mime = path == null ? null :URLConnection.guessContentTypeFromName(path);
+ if (mime == null) {
+ mime = "image/webp";
+ }
+ shareIntent.setType(mime);
+ activity.startActivity(Intent.createChooser(shareIntent,getText(R.string.share_with)));
}
private void copyText(Message message) {
diff --git a/src/main/res/menu/message_context.xml b/src/main/res/menu/message_context.xml
index 3be52442..21659266 100644
--- a/src/main/res/menu/message_context.xml
+++ b/src/main/res/menu/message_context.xml
@@ -5,8 +5,8 @@
android:id="@+id/copy_text"
android:title="@string/copy_text"/>
<item
- android:id="@+id/share_image"
- android:title="@string/share_image"/>
+ android:id="@+id/share_with"
+ android:title="@string/share_with"/>
<item
android:id="@+id/copy_url"
android:title="@string/copy_original_url"/>
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index cdf5d438..7db008ea 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -47,7 +47,7 @@
<string name="remove_bookmark_text">Would you like to remove %s as a bookmark? The conversation associated with this bookmark will not be removed.</string>
<string name="register_account">Register new account on server</string>
<string name="change_password_on_server">Change password on server</string>
- <string name="share_with">Share with</string>
+ <string name="share_with">Share with…</string>
<string name="start_conversation">Start Conversation</string>
<string name="invite_contact">Invite Contact</string>
<string name="contacts">Contacts</string>
@@ -328,7 +328,6 @@
<string name="check_image_filesize">Check image file size</string>
<string name="message_options">Message options</string>
<string name="copy_text">Copy text</string>
- <string name="share_image">Share image</string>
<string name="copy_original_url">Copy original URL</string>
<string name="send_again">Send again</string>
<string name="image_url">Image URL</string>