diff options
author | Daniel Gultsch <inputmice@siacs.eu> | 2015-01-12 16:42:20 +0100 |
---|---|---|
committer | Daniel Gultsch <inputmice@siacs.eu> | 2015-01-12 16:42:20 +0100 |
commit | 8d3323e384746acfad563d9389529b0802787261 (patch) | |
tree | 3433856f6c4eb6e0be2ab65ef472ced35ebaebe4 /src/main/java/eu/siacs/conversations | |
parent | 77e4e1c2acfffcb64d0538c00b087462d15a4bbf (diff) |
context menu for files and offered files. fixed #848 fixed #849
Diffstat (limited to 'src/main/java/eu/siacs/conversations')
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/ConversationFragment.java | 34 |
1 files changed, 21 insertions, 13 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) { |