Merge branch 'SamWhited-download-button-notification' into development

This commit is contained in:
iNPUTmice 2015-01-16 16:10:27 +01:00
commit be169215ca
8 changed files with 71 additions and 29 deletions

View File

@ -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) { 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) if ((message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE)
&& message.getEncryption() != Message.ENCRYPTION_PGP) { && message.getEncryption() != Message.ENCRYPTION_PGP) {
onMessageFound.onMessageFound(message); 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) { synchronized (this.messages) {
for (Message message : this.messages) { for (final Message message : this.messages) {
if (message.getType() == Message.TYPE_IMAGE if ((message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE)
&& message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_PGP
&& message.getUuid().equals(uuid)) { && message.getUuid().equals(uuid)) {
return message; return message;
} }
} }
} }
return null; return null;

View File

@ -44,7 +44,7 @@ import eu.siacs.conversations.utils.UIHelper;
public class NotificationService { public class NotificationService {
private XmppConnectionService mXmppConnectionService; private final XmppConnectionService mXmppConnectionService;
private final LinkedHashMap<String, ArrayList<Message>> notifications = new LinkedHashMap<>(); private final LinkedHashMap<String, ArrayList<Message>> notifications = new LinkedHashMap<>();
@ -56,7 +56,7 @@ public class NotificationService {
private boolean mIsInForeground; private boolean mIsInForeground;
private long mLastNotification; private long mLastNotification;
public NotificationService(XmppConnectionService service) { public NotificationService(final XmppConnectionService service) {
this.mXmppConnectionService = service; this.mXmppConnectionService = service;
} }
@ -214,17 +214,17 @@ public class NotificationService {
private Builder buildMultipleConversation() { private Builder buildMultipleConversation() {
final Builder mBuilder = new NotificationCompat.Builder( final Builder mBuilder = new NotificationCompat.Builder(
mXmppConnectionService); mXmppConnectionService);
NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
style.setBigContentTitle(notifications.size() style.setBigContentTitle(notifications.size()
+ " " + " "
+ mXmppConnectionService + mXmppConnectionService
.getString(R.string.unread_conversations)); .getString(R.string.unread_conversations));
final StringBuilder names = new StringBuilder(); final StringBuilder names = new StringBuilder();
Conversation conversation = null; Conversation conversation = null;
for (ArrayList<Message> messages : notifications.values()) { for (final ArrayList<Message> messages : notifications.values()) {
if (messages.size() > 0) { if (messages.size() > 0) {
conversation = messages.get(0).getConversation(); conversation = messages.get(0).getConversation();
String name = conversation.getName(); final String name = conversation.getName();
style.addLine(Html.fromHtml("<b>" + name + "</b> " style.addLine(Html.fromHtml("<b>" + name + "</b> "
+ UIHelper.getMessagePreview(mXmppConnectionService,messages.get(0)).first)); + UIHelper.getMessagePreview(mXmppConnectionService,messages.get(0)).first));
names.append(name); names.append(name);
@ -241,8 +241,7 @@ public class NotificationService {
mBuilder.setContentText(names.toString()); mBuilder.setContentText(names.toString());
mBuilder.setStyle(style); mBuilder.setStyle(style);
if (conversation != null) { if (conversation != null) {
mBuilder.setContentIntent(createContentIntent(conversation mBuilder.setContentIntent(createContentIntent(conversation));
.getUuid()));
} }
return mBuilder; return mBuilder;
} }
@ -256,14 +255,24 @@ public class NotificationService {
mBuilder.setLargeIcon(mXmppConnectionService.getAvatarService() mBuilder.setLargeIcon(mXmppConnectionService.getAvatarService()
.get(conversation, getPixel(64))); .get(conversation, getPixel(64)));
mBuilder.setContentTitle(conversation.getName()); mBuilder.setContentTitle(conversation.getName());
final Message message; Message message;
if ((message = getImage(messages)) != null) { if ((message = getImage(messages)) != null) {
modifyForImage(mBuilder, message, messages, notify); modifyForImage(mBuilder, message, messages, notify);
} else { } else {
modifyForTextOnly(mBuilder, messages, notify); modifyForTextOnly(mBuilder, messages, notify);
} }
mBuilder.setContentIntent(createContentIntent(conversation if ((message = getFirstDownloadableMessage(messages)) != null) {
.getUuid())); 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; 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) { for (final Message message : messages) {
if (message.getType() == Message.TYPE_IMAGE if (message.getType() == Message.TYPE_IMAGE
&& message.getDownloadable() == null && message.getDownloadable() == null
@ -314,7 +323,17 @@ public class NotificationService {
return null; 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(); final StringBuilder text = new StringBuilder();
for (int i = 0; i < messages.size(); ++i) { for (int i = 0; i < messages.size(); ++i) {
text.append(UIHelper.getMessagePreview(mXmppConnectionService,messages.get(i)).first); text.append(UIHelper.getMessagePreview(mXmppConnectionService,messages.get(i)).first);
@ -325,25 +344,39 @@ public class NotificationService {
return text.toString(); return text.toString();
} }
private PendingIntent createContentIntent(final String conversationUuid) { private PendingIntent createContentIntent(final String conversationUuid, final String downloadMessageUuid) {
final TaskStackBuilder stackBuilder = TaskStackBuilder final TaskStackBuilder stackBuilder = TaskStackBuilder
.create(mXmppConnectionService); .create(mXmppConnectionService);
stackBuilder.addParentStack(ConversationActivity.class); stackBuilder.addParentStack(ConversationActivity.class);
final Intent viewConversationIntent = new Intent(mXmppConnectionService, final Intent viewConversationIntent = new Intent(mXmppConnectionService,
ConversationActivity.class); ConversationActivity.class);
viewConversationIntent.setAction(Intent.ACTION_VIEW); if (downloadMessageUuid != null) {
viewConversationIntent.setAction(ConversationActivity.ACTION_DOWNLOAD);
} else {
viewConversationIntent.setAction(Intent.ACTION_VIEW);
}
if (conversationUuid != null) { if (conversationUuid != null) {
viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, conversationUuid);
conversationUuid);
viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION); viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
} }
if (downloadMessageUuid != null) {
viewConversationIntent.putExtra(ConversationActivity.MESSAGE, downloadMessageUuid);
}
stackBuilder.addNextIntent(viewConversationIntent); stackBuilder.addNextIntent(viewConversationIntent);
return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); 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() { private PendingIntent createDeleteIntent() {
final Intent intent = new Intent(mXmppConnectionService, final Intent intent = new Intent(mXmppConnectionService,
XmppConnectionService.class); XmppConnectionService.class);
@ -445,7 +478,7 @@ public class NotificationService {
mBuilder.setOngoing(true); mBuilder.setOngoing(true);
//mBuilder.setLights(0xffffffff, 2000, 4000); //mBuilder.setLights(0xffffffff, 2000, 4000);
mBuilder.setSmallIcon(R.drawable.ic_stat_alert_warning); mBuilder.setSmallIcon(R.drawable.ic_stat_alert_warning);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(mXmppConnectionService); final TaskStackBuilder stackBuilder = TaskStackBuilder.create(mXmppConnectionService);
stackBuilder.addParentStack(ConversationActivity.class); stackBuilder.addParentStack(ConversationActivity.class);
final Intent manageAccountsIntent = new Intent(mXmppConnectionService,ManageAccountActivity.class); final Intent manageAccountsIntent = new Intent(mXmppConnectionService,ManageAccountActivity.class);

View File

@ -15,7 +15,6 @@ import android.os.SystemClock;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.support.v4.widget.SlidingPaneLayout; import android.support.v4.widget.SlidingPaneLayout;
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener; import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -33,7 +32,6 @@ import net.java.otr4j.session.SessionStatus;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Blockable; import eu.siacs.conversations.entities.Blockable;
@ -50,8 +48,11 @@ import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
public class ConversationActivity extends XmppActivity public class ConversationActivity extends XmppActivity
implements OnAccountUpdate, OnConversationUpdate, OnRosterUpdate, OnUpdateBlocklist { 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 VIEW_CONVERSATION = "viewConversation";
public static final String CONVERSATION = "conversationUuid"; public static final String CONVERSATION = "conversationUuid";
public static final String MESSAGE = "messageUuid";
public static final String TEXT = "text"; public static final String TEXT = "text";
public static final String NICK = "nick"; public static final String NICK = "nick";
@ -823,10 +824,11 @@ public class ConversationActivity extends XmppActivity
setIntent(new Intent()); setIntent(new Intent());
} }
private void handleViewConversationIntent(Intent intent) { private void handleViewConversationIntent(final Intent intent) {
String uuid = (String) intent.getExtras().get(CONVERSATION); final String uuid = (String) intent.getExtras().get(CONVERSATION);
String text = intent.getExtras().getString(TEXT, ""); final String downloadUuid = (String) intent.getExtras().get(MESSAGE);
String nick = intent.getExtras().getString(NICK,null); final String text = intent.getExtras().getString(TEXT, "");
final String nick = intent.getExtras().getString(NICK, null);
if (selectConversationByUuid(uuid)) { if (selectConversationByUuid(uuid)) {
this.mConversationFragment.reInit(getSelectedConversation()); this.mConversationFragment.reInit(getSelectedConversation());
if (nick != null) { if (nick != null) {
@ -839,6 +841,12 @@ public class ConversationActivity extends XmppActivity
if (mContentView instanceof SlidingPaneLayout) { if (mContentView instanceof SlidingPaneLayout) {
updateActionBarTitle(true); //fixes bug where slp isn't properly closed yet 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);
}
}
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 313 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 470 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 574 B

View File

@ -85,6 +85,7 @@
<string name="send_pgp_message">Send OpenPGP 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="your_nick_has_been_changed">Your nickname has been changed</string>
<string name="download_image">Download Image</string> <string name="download_image">Download Image</string>
<string name="download_file">Download File</string>
<string name="image_offered_for_download"><i>Image file offered for download</i></string> <string name="image_offered_for_download"><i>Image file offered for download</i></string>
<string name="send_unencrypted">Send unencrypted</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="decryption_failed">Decryption failed. Maybe you dont have the proper private key.</string>