diff options
author | Christian Schneppe <christian@pix-art.de> | 2016-10-16 11:54:53 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2016-10-16 11:54:53 +0200 |
commit | 0af5c054c386dcafeedded2c467b22b53afc1d0f (patch) | |
tree | f6fccab5d1d610d03d7bb6014d45ec25f784ac11 /src/main/java/de | |
parent | faa8f2d117e0db56748330ff9baa907f3a93d4fe (diff) |
little notification improvements for video compression
Diffstat (limited to 'src/main/java/de')
4 files changed, 19 insertions, 17 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index bd5b30b59..59ef4c299 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -3,6 +3,7 @@ package de.pixart.messenger.services; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.AlarmManager; +import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; import android.content.Context; @@ -28,6 +29,7 @@ import android.os.Vibrator; import android.preference.PreferenceManager; import android.provider.ContactsContract; import android.security.KeyChain; +import android.support.v4.app.NotificationCompat; import android.support.v4.app.RemoteInput; import android.util.DisplayMetrics; import android.util.Log; @@ -99,6 +101,7 @@ import de.pixart.messenger.parser.PresenceParser; import de.pixart.messenger.persistance.DatabaseBackend; import de.pixart.messenger.persistance.FileBackend; import de.pixart.messenger.ui.UiCallback; +import de.pixart.messenger.ui.XmppActivity; import de.pixart.messenger.utils.ConversationsFileObserver; import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.utils.ExceptionHelper; @@ -135,6 +138,8 @@ import de.pixart.messenger.xmpp.stanzas.MessagePacket; import de.pixart.messenger.xmpp.stanzas.PresencePacket; import me.leolin.shortcutbadger.ShortcutBadger; +import static de.pixart.messenger.services.NotificationService.NOTIFICATION_ID; + public class XmppConnectionService extends Service { public static final String ACTION_REPLY_TO_CONVERSATION = "reply_to_conversations"; @@ -156,6 +161,7 @@ public class XmppConnectionService extends Service { private WakeLock wakeLock; private long mLastActivity = 0; public static VideoCompressor CompressVideo; + private NotificationManager mNotifyManager; public DatabaseBackend databaseBackend; private ContentObserver contactObserver = new ContentObserver(null) { @@ -529,6 +535,14 @@ public class XmppConnectionService extends Service { } public void attachVideoToConversation(final Conversation conversation, final Uri uri, final UiCallback<Message> callback) { + final Integer NOTIFICATION_ID = (int) (new Date().getTime()/1000); + mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getBaseContext()); + mBuilder.setContentTitle(getString(R.string.app_name)) + .setContentText(getString(R.string.compressing_video)) + .setSmallIcon(R.drawable.ic_play_box_outline_white_24dp) + .setProgress(0, 0, true); + mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build()); if (FileBackend.weOwnFile(this, uri)) { Log.d(Config.LOGTAG,"trying to attach video that belonged to us"); callback.error(R.string.security_error_invalid_file_access, null); @@ -546,6 +560,7 @@ public class XmppConnectionService extends Service { final Uri compressed_uri = Uri.fromFile(compressed_file); if (filesize > 0 && filesize <= Config.VIDEO_MAX_SIZE) { Log.d(Config.LOGTAG,conversation.getAccount().getJid().toBareJid()+ ": not compressing video. sending as file"); + mNotifyManager.cancel(NOTIFICATION_ID); attachFileToConversation(conversation, uri, callback); } else { CompressVideo = new VideoCompressor(path, compressed_path, new Interface() { @@ -553,6 +568,7 @@ public class XmppConnectionService extends Service { public void videocompressed(boolean result) { if (result) { Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": sending compressed video."); + mNotifyManager.cancel(NOTIFICATION_ID); attachFileToConversation(conversation, compressed_uri, callback); } } diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java index ffff13c5c..baf962392 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java @@ -1852,18 +1852,15 @@ public class ConversationActivity extends XmppActivity } final Toast prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_video), Toast.LENGTH_LONG); prepareFileToast.show(); - showProgress(); xmppConnectionService.attachVideoToConversation(conversation, uri, new UiCallback<Message>() { @Override public void success(Message message) { - closeProgress(); hidePrepareFileToast(prepareFileToast); xmppConnectionService.sendMessage(message); } @Override public void error(final int errorCode, Message message) { - closeProgress(); hidePrepareFileToast(prepareFileToast); runOnUiThread(new Runnable() { @Override @@ -1876,7 +1873,6 @@ public class ConversationActivity extends XmppActivity @Override public void userInputRequried(PendingIntent pi, Message message) { - closeProgress(); hidePrepareFileToast(prepareFileToast); } }); diff --git a/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java b/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java index 8dfea2179..e2280bdf2 100644 --- a/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java @@ -83,7 +83,6 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer } else if (share.image) { resId = R.string.shared_image_with_x; } else if (share.video) { - closeProgress(); resId = R.string.shared_video_with_x; } else { resId = R.string.shared_file_with_x; @@ -313,7 +312,6 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer } } else if (share.video) { replaceToast(getString(R.string.preparing_video)); - showProgress(); ShareWithActivity.this.xmppConnectionService .attachVideoToConversation(conversation, share.uris.get(0), attachFileCallback); diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java index b32438871..051b660bd 100644 --- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java +++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java @@ -107,8 +107,6 @@ public abstract class XmppActivity extends Activity { protected static final int REQUEST_INVITE_TO_CONVERSATION = 0x0102; protected static final int REQUEST_CHOOSE_PGP_ID = 0x0103; protected static final int REQUEST_BATTERY_OP = 0x13849ff; - private static final int NOTIFICATION_ID = 1230; - private NotificationManager mNotifyManager; public static final String EXTRA_ACCOUNT = "account"; @@ -150,18 +148,12 @@ public abstract class XmppActivity extends Activity { mToast.show(); } - protected void showProgress() { - mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getBaseContext()); - mBuilder.setContentTitle(getString(R.string.app_name)) - .setContentText(getString(R.string.compressing_video)) - .setSmallIcon(R.drawable.ic_play_box_outline_white_24dp) - .setProgress(0, 0, true); - mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build()); + public void showProgress() { + } public void closeProgress() { - mNotifyManager.cancel(NOTIFICATION_ID); + } protected Runnable onOpenPGPKeyPublished = new Runnable() { |