aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Conversation.java12
-rw-r--r--src/main/java/eu/siacs/conversations/services/NotificationService.java67
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationActivity.java20
3 files changed, 70 insertions, 29 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java
index 470bd290..036acf63 100644
--- a/src/main/java/eu/siacs/conversations/entities/Conversation.java
+++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java
@@ -108,9 +108,9 @@ public class Conversation extends AbstractEntity implements Blockable {
}
}
- public void findMessagesWithFiles(OnMessageFound onMessageFound) {
+ public void findMessagesWithFiles(final OnMessageFound onMessageFound) {
synchronized (this.messages) {
- for (Message message : this.messages) {
+ for (final Message message : this.messages) {
if ((message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE)
&& message.getEncryption() != Message.ENCRYPTION_PGP) {
onMessageFound.onMessageFound(message);
@@ -119,14 +119,14 @@ public class Conversation extends AbstractEntity implements Blockable {
}
}
- public Message findMessageWithFileAndUuid(String uuid) {
+ public Message findMessageWithFileAndUuid(final String uuid) {
synchronized (this.messages) {
- for (Message message : this.messages) {
- if (message.getType() == Message.TYPE_IMAGE
+ for (final Message message : this.messages) {
+ if ((message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE)
&& message.getEncryption() != Message.ENCRYPTION_PGP
&& message.getUuid().equals(uuid)) {
return message;
- }
+ }
}
}
return null;
diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java
index a32bb279..efdd2b60 100644
--- a/src/main/java/eu/siacs/conversations/services/NotificationService.java
+++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java
@@ -44,7 +44,7 @@ import eu.siacs.conversations.utils.UIHelper;
public class NotificationService {
- private XmppConnectionService mXmppConnectionService;
+ private final XmppConnectionService mXmppConnectionService;
private final LinkedHashMap<String, ArrayList<Message>> notifications = new LinkedHashMap<>();
@@ -56,7 +56,7 @@ public class NotificationService {
private boolean mIsInForeground;
private long mLastNotification;
- public NotificationService(XmppConnectionService service) {
+ public NotificationService(final XmppConnectionService service) {
this.mXmppConnectionService = service;
}
@@ -214,17 +214,17 @@ public class NotificationService {
private Builder buildMultipleConversation() {
final Builder mBuilder = new NotificationCompat.Builder(
mXmppConnectionService);
- NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
+ final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
style.setBigContentTitle(notifications.size()
+ " "
+ mXmppConnectionService
.getString(R.string.unread_conversations));
final StringBuilder names = new StringBuilder();
Conversation conversation = null;
- for (ArrayList<Message> messages : notifications.values()) {
+ for (final ArrayList<Message> messages : notifications.values()) {
if (messages.size() > 0) {
conversation = messages.get(0).getConversation();
- String name = conversation.getName();
+ final String name = conversation.getName();
style.addLine(Html.fromHtml("<b>" + name + "</b> "
+ UIHelper.getMessagePreview(mXmppConnectionService,messages.get(0)).first));
names.append(name);
@@ -241,8 +241,7 @@ public class NotificationService {
mBuilder.setContentText(names.toString());
mBuilder.setStyle(style);
if (conversation != null) {
- mBuilder.setContentIntent(createContentIntent(conversation
- .getUuid()));
+ mBuilder.setContentIntent(createContentIntent(conversation));
}
return mBuilder;
}
@@ -256,14 +255,24 @@ public class NotificationService {
mBuilder.setLargeIcon(mXmppConnectionService.getAvatarService()
.get(conversation, getPixel(64)));
mBuilder.setContentTitle(conversation.getName());
- final Message message;
+ Message message;
if ((message = getImage(messages)) != null) {
modifyForImage(mBuilder, message, messages, notify);
} else {
modifyForTextOnly(mBuilder, messages, notify);
}
- mBuilder.setContentIntent(createContentIntent(conversation
- .getUuid()));
+ if ((message = getFirstDownloadableMessage(messages)) != null) {
+ mBuilder.addAction(
+ R.drawable.ic_action_download,
+ mXmppConnectionService.getResources().getString(
+ message.getType() == Message.TYPE_IMAGE ?
+ R.string.download_image :
+ R.string.download_file
+ ),
+ createDownloadIntent(message)
+ );
+ }
+ mBuilder.setContentIntent(createContentIntent(conversation));
}
return mBuilder;
}
@@ -303,7 +312,7 @@ public class NotificationService {
}
}
- private Message getImage(final ArrayList<Message> messages) {
+ private Message getImage(final Iterable<Message> messages) {
for (final Message message : messages) {
if (message.getType() == Message.TYPE_IMAGE
&& message.getDownloadable() == null
@@ -314,7 +323,17 @@ public class NotificationService {
return null;
}
- private String getMergedBodies(final ArrayList<Message> messages) {
+ private Message getFirstDownloadableMessage(final Iterable<Message> messages) {
+ for (final Message message : messages) {
+ if ((message.getType() == Message.TYPE_FILE || message.getType() == Message.TYPE_IMAGE) &&
+ message.getDownloadable() != null) {
+ return message;
+ }
+ }
+ return null;
+ }
+
+ private CharSequence getMergedBodies(final ArrayList<Message> messages) {
final StringBuilder text = new StringBuilder();
for (int i = 0; i < messages.size(); ++i) {
text.append(UIHelper.getMessagePreview(mXmppConnectionService,messages.get(i)).first);
@@ -325,25 +344,39 @@ public class NotificationService {
return text.toString();
}
- private PendingIntent createContentIntent(final String conversationUuid) {
+ 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);
- viewConversationIntent.setAction(Intent.ACTION_VIEW);
+ if (downloadMessageUuid != null) {
+ viewConversationIntent.setAction(ConversationActivity.ACTION_DOWNLOAD);
+ } else {
+ viewConversationIntent.setAction(Intent.ACTION_VIEW);
+ }
if (conversationUuid != null) {
- viewConversationIntent.putExtra(ConversationActivity.CONVERSATION,
- conversationUuid);
+ viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, conversationUuid);
viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
}
+ if (downloadMessageUuid != null) {
+ viewConversationIntent.putExtra(ConversationActivity.MESSAGE, downloadMessageUuid);
+ }
stackBuilder.addNextIntent(viewConversationIntent);
return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}
+ private PendingIntent createDownloadIntent(final Message message) {
+ return createContentIntent(message.getConversationUuid(), message.getUuid());
+ }
+
+ private PendingIntent createContentIntent(final Conversation conversation) {
+ return createContentIntent(conversation.getUuid(), null);
+ }
+
private PendingIntent createDeleteIntent() {
final Intent intent = new Intent(mXmppConnectionService,
XmppConnectionService.class);
@@ -445,7 +478,7 @@ public class NotificationService {
mBuilder.setOngoing(true);
//mBuilder.setLights(0xffffffff, 2000, 4000);
mBuilder.setSmallIcon(R.drawable.ic_stat_alert_warning);
- TaskStackBuilder stackBuilder = TaskStackBuilder.create(mXmppConnectionService);
+ final TaskStackBuilder stackBuilder = TaskStackBuilder.create(mXmppConnectionService);
stackBuilder.addParentStack(ConversationActivity.class);
final Intent manageAccountsIntent = new Intent(mXmppConnectionService,ManageAccountActivity.class);
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
index 4ba6c773..1356e616 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
@@ -15,7 +15,6 @@ import android.os.SystemClock;
import android.provider.MediaStore;
import android.support.v4.widget.SlidingPaneLayout;
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
-import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -33,7 +32,6 @@ import net.java.otr4j.session.SessionStatus;
import java.util.ArrayList;
import java.util.List;
-import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Blockable;
@@ -50,8 +48,11 @@ import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
public class ConversationActivity extends XmppActivity
implements OnAccountUpdate, OnConversationUpdate, OnRosterUpdate, OnUpdateBlocklist {
+ public static final String ACTION_DOWNLOAD = "eu.siacs.conversations.action.DOWNLOAD";
+
public static final String VIEW_CONVERSATION = "viewConversation";
public static final String CONVERSATION = "conversationUuid";
+ public static final String MESSAGE = "messageUuid";
public static final String TEXT = "text";
public static final String NICK = "nick";
@@ -823,10 +824,11 @@ public class ConversationActivity extends XmppActivity
setIntent(new Intent());
}
- private void handleViewConversationIntent(Intent intent) {
- String uuid = (String) intent.getExtras().get(CONVERSATION);
- String text = intent.getExtras().getString(TEXT, "");
- String nick = intent.getExtras().getString(NICK,null);
+ private void handleViewConversationIntent(final Intent intent) {
+ final String uuid = (String) intent.getExtras().get(CONVERSATION);
+ final String downloadUuid = (String) intent.getExtras().get(MESSAGE);
+ final String text = intent.getExtras().getString(TEXT, "");
+ final String nick = intent.getExtras().getString(NICK, null);
if (selectConversationByUuid(uuid)) {
this.mConversationFragment.reInit(getSelectedConversation());
if (nick != null) {
@@ -839,6 +841,12 @@ public class ConversationActivity extends XmppActivity
if (mContentView instanceof SlidingPaneLayout) {
updateActionBarTitle(true); //fixes bug where slp isn't properly closed yet
}
+ if (downloadUuid != null) {
+ final Message message = mSelectedConversation.findMessageWithFileAndUuid(downloadUuid);
+ if (message != null) {
+ mConversationFragment.messageListAdapter.startDownloadable(message);
+ }
+ }
}
}