aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
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
parenta2525346f461183125c5840498228c347a86d4aa (diff)
refactored message context menu
Diffstat (limited to '')
-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
-rw-r--r--src/main/res/menu/message_context.xml20
-rw-r--r--src/main/res/values/strings.xml5
5 files changed, 53 insertions, 43 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);
}
}
diff --git a/src/main/res/menu/message_context.xml b/src/main/res/menu/message_context.xml
index 21659266..4e1316d3 100644
--- a/src/main/res/menu/message_context.xml
+++ b/src/main/res/menu/message_context.xml
@@ -3,21 +3,27 @@
<item
android:id="@+id/copy_text"
- android:title="@string/copy_text"/>
+ android:title="@string/copy_text"
+ android:visible="false"/>
<item
android:id="@+id/share_with"
- android:title="@string/share_with"/>
+ android:title="@string/share_with"
+ android:visible="false"/>
<item
android:id="@+id/copy_url"
- android:title="@string/copy_original_url"/>
+ android:title="@string/copy_original_url"
+ android:visible="false"/>
<item
android:id="@+id/send_again"
- android:title="@string/send_again"/>
+ android:title="@string/send_again"
+ android:visible="false"/>
<item
- android:id="@+id/download_image"
- android:title="@string/download_image"/>
+ android:id="@+id/download_file"
+ android:title="@string/download_x_file"
+ android:visible="false"/>
<item
android:id="@+id/cancel_transmission"
- android:title="@string/cancel_transmission" />
+ android:title="@string/cancel_transmission"
+ android:visible="false"/>
</menu> \ No newline at end of file
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 4631bd60..444d9ecf 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -82,7 +82,6 @@
<string name="send_otr_message">Send OTR encrypted message</string>
<string name="send_pgp_message">Send OpenPGP encrypted message</string>
<string name="your_nick_has_been_changed">Your nickname has been changed</string>
- <string name="download_image">Download Image</string>
<string name="send_unencrypted">Send unencrypted</string>
<string name="decryption_failed">Decryption failed. Maybe you don’t have the proper private key.</string>
<string name="openkeychain_required">OpenKeychain</string>
@@ -320,12 +319,12 @@
<string name="checking_image">Checking image on HTTP host</string>
<string name="image_file_deleted">The image file has been deleted</string>
<string name="not_connected_try_again">You are not connected. Try again later</string>
- <string name="check_image_filesize">Check image file size</string>
+ <string name="check_x_filesize">Check %s size</string>
<string name="message_options">Message options</string>
<string name="copy_text">Copy text</string>
<string name="copy_original_url">Copy original URL</string>
<string name="send_again">Send again</string>
- <string name="image_url">Image URL</string>
+ <string name="file_url">File URL</string>
<string name="message_text">Message text</string>
<string name="url_copied_to_clipboard">URL copied to clipboard</string>
<string name="message_copied_to_clipboard">Message copied to clipboard</string>