diff options
author | Christian Schneppe <christian@pix-art.de> | 2016-08-30 22:39:20 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2016-08-30 22:39:20 +0200 |
commit | 87049340caf3c000de6ed46589e13cf9948127f6 (patch) | |
tree | 0ec4fd045bf7ef35c0eb1586e709a9fc8ef7a6f5 /src/main/java | |
parent | 0b4f6dff57409c121d2db105902b42e830c56b56 (diff) |
show dialog while compressing video
Diffstat (limited to 'src/main/java')
3 files changed, 51 insertions, 8 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java index 5b22bd0de..a8f07848b 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java @@ -1756,9 +1756,16 @@ public class ConversationActivity extends XmppActivity } final Toast prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_video), Toast.LENGTH_LONG); prepareFileToast.show(); + runOnUiThread(new Runnable() { + @Override + public void run() { + showProgress(); + } + }); xmppConnectionService.attachVideoToConversation(conversation, uri, new UiCallback<Message>() { @Override public void success(Message message) { + closeProgress(); hidePrepareFileToast(prepareFileToast); xmppConnectionService.sendMessage(message); } diff --git a/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java b/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java index d0a840af8..34cf0b1ca 100644 --- a/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java @@ -1,6 +1,7 @@ package de.pixart.messenger.ui; import android.app.PendingIntent; +import android.app.ProgressDialog; import android.content.Intent; import android.net.Uri; import android.os.Bundle; @@ -43,6 +44,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer private class Share { public List<Uri> uris = new ArrayList<>(); public boolean image; + public boolean video; public String account; public String contact; public String text; @@ -79,6 +81,8 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer resId = R.string.shared_images_with_x; } else if (share.image) { resId = R.string.shared_image_with_x; + } else if (share.video) { + resId = R.string.shared_video_with_x; } else { resId = R.string.shared_file_with_x; } @@ -86,6 +90,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer if (mReturnToPrevious) { finish(); } else { + closeProgress(); switchToConversation(message.getConversation()); } } @@ -196,6 +201,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer this.share.uris.clear(); this.share.uris.add(uri); this.share.image = type.startsWith("image/") || isImage(uri); + this.share.video = type.startsWith("video/") || isVideo(uri); } else { this.share.text = text; } @@ -225,6 +231,15 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer } } + protected boolean isVideo(Uri uri) { + try { + String guess = URLConnection.guessContentTypeFromName(uri.toString()); + return (guess != null && guess.startsWith("video/")); + } catch (final StringIndexOutOfBoundsException ignored) { + return false; + } + } + @Override void onBackendConnected() { if (xmppConnectionServiceBound && share != null @@ -283,13 +298,19 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer public void onPresenceSelected() { attachmentCounter.set(share.uris.size()); if (share.image) { - share.multiple = share.uris.size() > 1; - replaceToast(getString(share.multiple ? R.string.preparing_images : R.string.preparing_image)); - for (Iterator<Uri> i = share.uris.iterator(); i.hasNext(); i.remove()) { - ShareWithActivity.this.xmppConnectionService - .attachImageToConversation(conversation, i.next(), - attachFileCallback); - } + share.multiple = share.uris.size() > 1; + replaceToast(getString(share.multiple ? R.string.preparing_images : R.string.preparing_image)); + for (Iterator<Uri> i = share.uris.iterator(); i.hasNext(); i.remove()) { + ShareWithActivity.this.xmppConnectionService + .attachImageToConversation(conversation, i.next(), + attachFileCallback); + } + } else if (share.video) { + showProgress(); + replaceToast(getString(R.string.preparing_video)); + ShareWithActivity.this.xmppConnectionService + .attachVideoToConversation(conversation, share.uris.get(0), + attachFileCallback); } else { replaceToast(getString(R.string.preparing_file)); ShareWithActivity.this.xmppConnectionService diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java index 2497d9ded..3c8a561c1 100644 --- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java +++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java @@ -8,6 +8,7 @@ import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.app.PendingIntent; +import android.app.ProgressDialog; import android.content.ActivityNotFoundException; import android.content.ClipData; import android.content.ClipboardManager; @@ -127,8 +128,9 @@ public abstract class XmppActivity extends Activity { protected boolean mUsingEnterKey = false; protected Toast mToast; + protected ProgressDialog mProgress; - protected void hideToast() { + protected void hideToast() { if (mToast != null) { mToast.cancel(); } @@ -144,6 +146,19 @@ public abstract class XmppActivity extends Activity { mToast.show(); } + protected void showProgress() { + mProgress = new ProgressDialog(this); + mProgress.setMessage(getString(R.string.compressing_video)); + mProgress.setCancelable(false); + mProgress.show(); + } + + protected void closeProgress() { + if (mProgress.isShowing()) { + mProgress.dismiss(); + } + } + protected Runnable onOpenPGPKeyPublished = new Runnable() { @Override public void run() { |