context menu for files and offered files. fixed #848 fixed #849

This commit is contained in:
Daniel Gultsch 2015-01-12 16:42:20 +01:00
parent 77e4e1c2ac
commit 8d3323e384
3 changed files with 24 additions and 17 deletions

View file

@ -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);
@ -432,7 +435,8 @@ public class ConversationFragment extends Fragment {
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);
}
}
@ -441,8 +445,8 @@ public class ConversationFragment extends Fragment {
@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) {

View file

@ -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"/>

View file

@ -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>