From cc463c27d76ac5655ff5adb2e8f79b6e1cf3a2dc Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 24 Jul 2016 10:35:53 +0200 Subject: refactored view intents --- .../siacs/conversations/entities/Conversation.java | 4 +-- .../services/NotificationService.java | 35 ++++++++++------------ .../conversations/ui/ConversationActivity.java | 17 +++++------ .../eu/siacs/conversations/ui/XmppActivity.java | 3 +- 4 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index a94d008e..56739f40 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -158,9 +158,9 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl public Message findMessageWithFileAndUuid(final String uuid) { synchronized (this.messages) { for (final Message message : this.messages) { - if ((message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) + if (message.getUuid().equals(uuid) && message.getEncryption() != Message.ENCRYPTION_PGP - && message.getUuid().equals(uuid)) { + && (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || message.treatAsDownloadable() != Message.Decision.NEVER)) { return message; } } diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index f28bab0d..41826816 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -374,8 +374,10 @@ public class NotificationService { private Message getFirstDownloadableMessage(final Iterable messages) { for (final Message message : messages) { - if ((message.getType() == Message.TYPE_FILE || message.getType() == Message.TYPE_IMAGE) && - message.getTransferable() != null) { + if (message.getTransferable() != null + && (message.getType() == Message.TYPE_FILE + || message.getType() == Message.TYPE_IMAGE + || message.treatAsDownloadable() != Message.Decision.NEVER)) { return message; } } @@ -413,28 +415,23 @@ public class NotificationService { } private PendingIntent createContentIntent(final String conversationUuid, final String downloadMessageUuid) { - final TaskStackBuilder stackBuilder = TaskStackBuilder - .create(mXmppConnectionService); - stackBuilder.addParentStack(ConversationActivity.class); - - final Intent viewConversationIntent = new Intent(mXmppConnectionService, - ConversationActivity.class); - if (downloadMessageUuid != null) { - viewConversationIntent.setAction(ConversationActivity.ACTION_DOWNLOAD); - } else { - viewConversationIntent.setAction(Intent.ACTION_VIEW); - } + final Intent viewConversationIntent = new Intent(mXmppConnectionService,ConversationActivity.class); + viewConversationIntent.setAction(ConversationActivity.ACTION_VIEW_CONVERSATION); if (conversationUuid != null) { viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, conversationUuid); - viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION); } if (downloadMessageUuid != null) { - viewConversationIntent.putExtra(ConversationActivity.MESSAGE, downloadMessageUuid); + viewConversationIntent.putExtra(ConversationActivity.EXTRA_DOWNLOAD_UUID, downloadMessageUuid); + return PendingIntent.getActivity(mXmppConnectionService, + 57, + viewConversationIntent, + PendingIntent.FLAG_UPDATE_CURRENT); + } else { + return PendingIntent.getActivity(mXmppConnectionService, + 58, + viewConversationIntent, + PendingIntent.FLAG_UPDATE_CURRENT); } - - stackBuilder.addNextIntent(viewConversationIntent); - - return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); } private PendingIntent createDownloadIntent(final Message message) { diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index f2304664..e8ef9ca5 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -69,11 +69,9 @@ import eu.siacs.conversations.xmpp.jid.Jid; public class ConversationActivity extends XmppActivity implements OnAccountUpdate, OnConversationUpdate, OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast { - public static final String ACTION_DOWNLOAD = "eu.siacs.conversations.action.DOWNLOAD"; - - public static final String VIEW_CONVERSATION = "viewConversation"; + public static final String ACTION_VIEW_CONVERSATION = "eu.siacs.conversations.action.VIEW"; public static final String CONVERSATION = "conversationUuid"; - public static final String MESSAGE = "messageUuid"; + public static final String EXTRA_DOWNLOAD_UUID = "eu.siacs.conversations.download_uuid"; public static final String TEXT = "text"; public static final String NICK = "nick"; public static final String PRIVATE_MESSAGE = "pm"; @@ -1043,10 +1041,10 @@ public class ConversationActivity extends XmppActivity Log.d(Config.LOGTAG,"onNewIntent()"); if (xmppConnectionServiceBound) { Log.d(Config.LOGTAG,"onNewIntent(): service bound"); - if (intent != null && VIEW_CONVERSATION.equals(intent.getType())) { + if (intent != null && ACTION_VIEW_CONVERSATION.equals(intent.getAction())) { handleViewConversationIntent(intent); Log.d(Config.LOGTAG,"onNewIntent() : overwriting intent"); - setIntent(new Intent(Intent.ACTION_MAIN)); + intent.setAction(Intent.ACTION_MAIN); } } else { Log.d(Config.LOGTAG,"onNewIntent(): service was not bound. saving for later"); @@ -1158,10 +1156,11 @@ public class ConversationActivity extends XmppActivity } finish(); } - } else if (intent != null && VIEW_CONVERSATION.equals(intent.getType())) { + } else if (intent != null && ACTION_VIEW_CONVERSATION.equals(intent.getAction())) { Log.d(Config.LOGTAG,"onBackendConnected() - stored intent was view_conversations"); clearPending(); handleViewConversationIntent(intent); + intent.setAction(Intent.ACTION_MAIN); } else if (selectConversationByUuid(mOpenConverstaion)) { if (mPanelOpen) { showConversationsOverview(); @@ -1208,14 +1207,12 @@ public class ConversationActivity extends XmppActivity if (!ExceptionHelper.checkForCrash(this, this.xmppConnectionService)) { openBatteryOptimizationDialogIfNeeded(); } - Log.d(Config.LOGTAG,"onBackendConnected() - overwriting intent"); - setIntent(new Intent(Intent.ACTION_MAIN)); } private void handleViewConversationIntent(final Intent intent) { Log.d(Config.LOGTAG,"handleViewConversationIntent()"); final String uuid = intent.getStringExtra(CONVERSATION); - final String downloadUuid = intent.getStringExtra(MESSAGE); + final String downloadUuid = intent.getStringExtra(EXTRA_DOWNLOAD_UUID); final String text = intent.getStringExtra(TEXT); final String nick = intent.getStringExtra(NICK); final boolean pm = intent.getBooleanExtra(PRIVATE_MESSAGE, false); diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index b745afec..df16fd64 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -471,7 +471,7 @@ public abstract class XmppActivity extends Activity { private void switchToConversation(Conversation conversation, String text, String nick, boolean pm, boolean newTask) { Intent viewConversationIntent = new Intent(this, ConversationActivity.class); - viewConversationIntent.setAction(Intent.ACTION_VIEW); + viewConversationIntent.setAction(ConversationActivity.ACTION_VIEW_CONVERSATION); viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, conversation.getUuid()); if (text != null) { @@ -481,7 +481,6 @@ public abstract class XmppActivity extends Activity { viewConversationIntent.putExtra(ConversationActivity.NICK, nick); viewConversationIntent.putExtra(ConversationActivity.PRIVATE_MESSAGE,pm); } - viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION); if (newTask) { viewConversationIntent.setFlags(viewConversationIntent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK -- cgit v1.2.3