aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2015-07-02 23:13:00 +0200
committerDaniel Gultsch <daniel@gultsch.de>2015-07-02 23:13:00 +0200
commitf5ba9d4223ca8e5dc9ce00024f69a8374d170a31 (patch)
treec4f5f5cbecee7b70641c71d70f35350aca2cad47 /src/main/java/eu
parenta2525346f461183125c5840498228c347a86d4aa (diff)
refactored message context menu
Diffstat (limited to 'src/main/java/eu')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Message.java2
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationFragment.java57
-rw-r--r--src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java12
3 files changed, 38 insertions, 33 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java
index 0b938639..d15f3bbd 100644
--- a/src/main/java/eu/siacs/conversations/entities/Message.java
+++ b/src/main/java/eu/siacs/conversations/entities/Message.java
@@ -468,7 +468,7 @@ public class Message extends AbstractEntity {
}
} else {
try {
- return MimeUtils.guessExtensionFromMimeType(extractRelevantExtension(new URL(body.trim())));
+ return MimeUtils.guessMimeTypeFromExtension(extractRelevantExtension(new URL(body.trim())));
} catch (MalformedURLException e) {
return null;
}
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
index a0403335..20c6681b 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
@@ -34,7 +34,6 @@ 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;
@@ -437,33 +436,36 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
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);
+ MenuItem downloadFile = menu.findItem(R.id.download_file);
MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission);
- if ((m.getType() != Message.TYPE_TEXT && m.getType() != Message.TYPE_PRIVATE)
- || m.getDownloadable() != null || GeoHelper.isGeoUri(m.getBody())) {
- copyText.setVisible(false);
+ if ((m.getType() == Message.TYPE_TEXT || m.getType() == Message.TYPE_PRIVATE)
+ && m.getDownloadable() == null
+ && !GeoHelper.isGeoUri(m.getBody())
+ && m.treatAsDownloadable() != Message.Decision.MUST) {
+ copyText.setVisible(true);
}
- if ((m.getType() == Message.TYPE_TEXT
- || m.getType() == Message.TYPE_PRIVATE
- || m.getDownloadable() != null)
- && (!GeoHelper.isGeoUri(m.getBody()))) {
- shareWith.setVisible(false);
+ if ((m.getType() != Message.TYPE_TEXT
+ && m.getType() != Message.TYPE_PRIVATE
+ && m.getDownloadable() == null)
+ || (GeoHelper.isGeoUri(m.getBody()))) {
+ shareWith.setVisible(true);
}
- if (m.getStatus() != Message.STATUS_SEND_FAILED) {
- sendAgain.setVisible(false);
+ if (m.getStatus() == Message.STATUS_SEND_FAILED) {
+ sendAgain.setVisible(true);
}
- if (!m.hasFileOnRemoteHost() && !GeoHelper.isGeoUri(m.getBody())) {
- copyUrl.setVisible(false);
+ if (m.hasFileOnRemoteHost()
+ || GeoHelper.isGeoUri(m.getBody())
+ || m.treatAsDownloadable() == Message.Decision.MUST) {
+ copyUrl.setVisible(true);
}
- if (m.getType() != Message.TYPE_TEXT
- || m.getDownloadable() != null
- || m.treatAsDownloadable() == Message.Decision.NEVER) {
- downloadImage.setVisible(false);
+ if (m.getType() == Message.TYPE_TEXT && m.getDownloadable() == null && m.treatAsDownloadable() != Message.Decision.NEVER) {
+ downloadFile.setVisible(true);
+ downloadFile.setTitle(activity.getString(R.string.download_x_file,UIHelper.getFileDescriptionString(activity, m)));
}
- if (!((m.getDownloadable() != null && !(m.getDownloadable() instanceof DownloadablePlaceholder))
+ if ((m.getDownloadable() != null && !(m.getDownloadable() instanceof DownloadablePlaceholder))
|| (m.isFileOrImage() && (m.getStatus() == Message.STATUS_WAITING
- || m.getStatus() == Message.STATUS_OFFERED)))) {
- cancelTransmission.setVisible(false);
+ || m.getStatus() == Message.STATUS_OFFERED))) {
+ cancelTransmission.setVisible(true);
}
}
}
@@ -483,8 +485,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
case R.id.copy_url:
copyUrl(selectedMessage);
return true;
- case R.id.download_image:
- downloadImage(selectedMessage);
+ case R.id.download_file:
+ downloadFile(selectedMessage);
return true;
case R.id.cancel_transmission:
cancelTransmission(selectedMessage);
@@ -540,9 +542,12 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (GeoHelper.isGeoUri(message.getBody())) {
resId = R.string.location;
url = message.getBody();
- } else {
- resId = R.string.image_url;
+ } else if (message.hasFileOnRemoteHost()) {
+ resId = R.string.file_url;
url = message.getFileParams().url.toString();
+ } else {
+ url = message.getBody().trim();
+ resId = R.string.file_url;
}
if (activity.copyTextToClipboard(url, resId)) {
Toast.makeText(activity, R.string.url_copied_to_clipboard,
@@ -550,7 +555,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
}
- private void downloadImage(Message message) {
+ private void downloadFile(Message message) {
activity.xmppConnectionService.getHttpConnectionManager()
.createNewConnection(message);
}
diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
index 8648f048..dedac77e 100644
--- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
+++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
@@ -487,7 +487,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
if (downloadable.getStatus() == Downloadable.STATUS_OFFER) {
displayDownloadableMessage(viewHolder,message,activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, message)));
} else if (downloadable.getStatus() == Downloadable.STATUS_OFFER_CHECK_FILESIZE) {
- displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_image_filesize));
+ displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize, UIHelper.getFileDescriptionString(activity, message)));
} else {
displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first);
}
@@ -521,12 +521,12 @@ public class MessageAdapter extends ArrayAdapter<Message> {
} else {
if (GeoHelper.isGeoUri(message.getBody())) {
displayLocationMessage(viewHolder,message);
+ } else if (message.bodyIsHeart()) {
+ displayHeartMessage(viewHolder, message.getBody().trim());
+ } else if (message.treatAsDownloadable() == Message.Decision.MUST) {
+ displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize, UIHelper.getFileDescriptionString(activity, message)));
} else {
- if (message.bodyIsHeart()) {
- displayHeartMessage(viewHolder, message.getBody().trim());
- } else {
- displayTextMessage(viewHolder, message);
- }
+ displayTextMessage(viewHolder, message);
}
}