refactored message context menu

This commit is contained in:
Daniel Gultsch 2015-07-02 23:13:00 +02:00
parent a2525346f4
commit f5ba9d4223
5 changed files with 53 additions and 43 deletions

View file

@ -468,7 +468,7 @@ public class Message extends AbstractEntity {
} }
} else { } else {
try { try {
return MimeUtils.guessExtensionFromMimeType(extractRelevantExtension(new URL(body.trim()))); return MimeUtils.guessMimeTypeFromExtension(extractRelevantExtension(new URL(body.trim())));
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
return null; return null;
} }

View file

@ -34,7 +34,6 @@ import android.widget.Toast;
import net.java.otr4j.session.SessionStatus; import net.java.otr4j.session.SessionStatus;
import java.net.URLConnection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException; 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 shareWith = menu.findItem(R.id.share_with);
MenuItem sendAgain = menu.findItem(R.id.send_again); MenuItem sendAgain = menu.findItem(R.id.send_again);
MenuItem copyUrl = menu.findItem(R.id.copy_url); 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); MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission);
if ((m.getType() != Message.TYPE_TEXT && m.getType() != Message.TYPE_PRIVATE) if ((m.getType() == Message.TYPE_TEXT || m.getType() == Message.TYPE_PRIVATE)
|| m.getDownloadable() != null || GeoHelper.isGeoUri(m.getBody())) { && m.getDownloadable() == null
copyText.setVisible(false); && !GeoHelper.isGeoUri(m.getBody())
&& m.treatAsDownloadable() != Message.Decision.MUST) {
copyText.setVisible(true);
} }
if ((m.getType() == Message.TYPE_TEXT if ((m.getType() != Message.TYPE_TEXT
|| m.getType() == Message.TYPE_PRIVATE && m.getType() != Message.TYPE_PRIVATE
|| m.getDownloadable() != null) && m.getDownloadable() == null)
&& (!GeoHelper.isGeoUri(m.getBody()))) { || (GeoHelper.isGeoUri(m.getBody()))) {
shareWith.setVisible(false); shareWith.setVisible(true);
} }
if (m.getStatus() != Message.STATUS_SEND_FAILED) { if (m.getStatus() == Message.STATUS_SEND_FAILED) {
sendAgain.setVisible(false); sendAgain.setVisible(true);
} }
if (!m.hasFileOnRemoteHost() && !GeoHelper.isGeoUri(m.getBody())) { if (m.hasFileOnRemoteHost()
copyUrl.setVisible(false); || GeoHelper.isGeoUri(m.getBody())
|| m.treatAsDownloadable() == Message.Decision.MUST) {
copyUrl.setVisible(true);
} }
if (m.getType() != Message.TYPE_TEXT if (m.getType() == Message.TYPE_TEXT && m.getDownloadable() == null && m.treatAsDownloadable() != Message.Decision.NEVER) {
|| m.getDownloadable() != null downloadFile.setVisible(true);
|| m.treatAsDownloadable() == Message.Decision.NEVER) { downloadFile.setTitle(activity.getString(R.string.download_x_file,UIHelper.getFileDescriptionString(activity, m)));
downloadImage.setVisible(false);
} }
if (!((m.getDownloadable() != null && !(m.getDownloadable() instanceof DownloadablePlaceholder)) 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)))) { || m.getStatus() == Message.STATUS_OFFERED))) {
cancelTransmission.setVisible(false); cancelTransmission.setVisible(true);
} }
} }
} }
@ -483,8 +485,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
case R.id.copy_url: case R.id.copy_url:
copyUrl(selectedMessage); copyUrl(selectedMessage);
return true; return true;
case R.id.download_image: case R.id.download_file:
downloadImage(selectedMessage); downloadFile(selectedMessage);
return true; return true;
case R.id.cancel_transmission: case R.id.cancel_transmission:
cancelTransmission(selectedMessage); cancelTransmission(selectedMessage);
@ -540,9 +542,12 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (GeoHelper.isGeoUri(message.getBody())) { if (GeoHelper.isGeoUri(message.getBody())) {
resId = R.string.location; resId = R.string.location;
url = message.getBody(); url = message.getBody();
} else { } else if (message.hasFileOnRemoteHost()) {
resId = R.string.image_url; resId = R.string.file_url;
url = message.getFileParams().url.toString(); url = message.getFileParams().url.toString();
} else {
url = message.getBody().trim();
resId = R.string.file_url;
} }
if (activity.copyTextToClipboard(url, resId)) { if (activity.copyTextToClipboard(url, resId)) {
Toast.makeText(activity, R.string.url_copied_to_clipboard, 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() activity.xmppConnectionService.getHttpConnectionManager()
.createNewConnection(message); .createNewConnection(message);
} }

View file

@ -487,7 +487,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
if (downloadable.getStatus() == Downloadable.STATUS_OFFER) { if (downloadable.getStatus() == Downloadable.STATUS_OFFER) {
displayDownloadableMessage(viewHolder,message,activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, message))); displayDownloadableMessage(viewHolder,message,activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, message)));
} else if (downloadable.getStatus() == Downloadable.STATUS_OFFER_CHECK_FILESIZE) { } 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 { } else {
displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first); displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first);
} }
@ -521,12 +521,12 @@ public class MessageAdapter extends ArrayAdapter<Message> {
} else { } else {
if (GeoHelper.isGeoUri(message.getBody())) { if (GeoHelper.isGeoUri(message.getBody())) {
displayLocationMessage(viewHolder,message); 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 { } else {
if (message.bodyIsHeart()) { displayTextMessage(viewHolder, message);
displayHeartMessage(viewHolder, message.getBody().trim());
} else {
displayTextMessage(viewHolder, message);
}
} }
} }

View file

@ -3,21 +3,27 @@
<item <item
android:id="@+id/copy_text" android:id="@+id/copy_text"
android:title="@string/copy_text"/> android:title="@string/copy_text"
android:visible="false"/>
<item <item
android:id="@+id/share_with" android:id="@+id/share_with"
android:title="@string/share_with"/> android:title="@string/share_with"
android:visible="false"/>
<item <item
android:id="@+id/copy_url" android:id="@+id/copy_url"
android:title="@string/copy_original_url"/> android:title="@string/copy_original_url"
android:visible="false"/>
<item <item
android:id="@+id/send_again" android:id="@+id/send_again"
android:title="@string/send_again"/> android:title="@string/send_again"
android:visible="false"/>
<item <item
android:id="@+id/download_image" android:id="@+id/download_file"
android:title="@string/download_image"/> android:title="@string/download_x_file"
android:visible="false"/>
<item <item
android:id="@+id/cancel_transmission" android:id="@+id/cancel_transmission"
android:title="@string/cancel_transmission" /> android:title="@string/cancel_transmission"
android:visible="false"/>
</menu> </menu>

View file

@ -82,7 +82,6 @@
<string name="send_otr_message">Send OTR encrypted message</string> <string name="send_otr_message">Send OTR encrypted message</string>
<string name="send_pgp_message">Send OpenPGP 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="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="send_unencrypted">Send unencrypted</string>
<string name="decryption_failed">Decryption failed. Maybe you dont have the proper private key.</string> <string name="decryption_failed">Decryption failed. Maybe you dont have the proper private key.</string>
<string name="openkeychain_required">OpenKeychain</string> <string name="openkeychain_required">OpenKeychain</string>
@ -320,12 +319,12 @@
<string name="checking_image">Checking image on HTTP host</string> <string name="checking_image">Checking image on HTTP host</string>
<string name="image_file_deleted">The image file has been deleted</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="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="message_options">Message options</string>
<string name="copy_text">Copy text</string> <string name="copy_text">Copy text</string>
<string name="copy_original_url">Copy original URL</string> <string name="copy_original_url">Copy original URL</string>
<string name="send_again">Send again</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="message_text">Message text</string>
<string name="url_copied_to_clipboard">URL copied to clipboard</string> <string name="url_copied_to_clipboard">URL copied to clipboard</string>
<string name="message_copied_to_clipboard">Message copied to clipboard</string> <string name="message_copied_to_clipboard">Message copied to clipboard</string>