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 {
try {
return MimeUtils.guessExtensionFromMimeType(extractRelevantExtension(new URL(body.trim())));
return MimeUtils.guessMimeTypeFromExtension(extractRelevantExtension(new URL(body.trim())));
} catch (MalformedURLException e) {
return null;
}

View File

@ -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);
}

View File

@ -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);
}
}

View File

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

View File

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