New email notification fixes
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package i2p.bote.android.service;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
@@ -22,8 +23,10 @@ import net.i2p.router.RouterLaunch;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import javax.mail.Address;
|
||||
import javax.mail.MessagingException;
|
||||
|
||||
import i2p.bote.I2PBote;
|
||||
@@ -221,9 +224,10 @@ public class BoteService extends Service implements NetworkStatusListener, NewEm
|
||||
NotificationManager nm = (NotificationManager) getSystemService(
|
||||
Context.NOTIFICATION_SERVICE);
|
||||
|
||||
NotificationCompat.Builder b =
|
||||
new NotificationCompat.Builder(this)
|
||||
.setAutoCancel(true);
|
||||
NotificationCompat.Builder b = new NotificationCompat.Builder(this)
|
||||
.setAutoCancel(true)
|
||||
.setSmallIcon(R.drawable.ic_notif)
|
||||
.setDefaults(Notification.DEFAULT_ALL);
|
||||
|
||||
try {
|
||||
EmailFolder inbox = I2PBote.getInstance().getInbox();
|
||||
@@ -246,9 +250,11 @@ public class BoteService extends Service implements NetworkStatusListener, NewEm
|
||||
Bitmap picture = BoteHelper.getPictureForAddress(fromAddress);
|
||||
if (picture != null)
|
||||
b.setLargeIcon(picture);
|
||||
else if (!email.isAnonymous())
|
||||
b.setLargeIcon(BoteHelper.getIdenticonForAddress(fromAddress, 56, 56)); // TODO fix size
|
||||
else
|
||||
else if (!email.isAnonymous()) {
|
||||
int width = getResources().getDimensionPixelSize(R.dimen.notification_large_icon_width);
|
||||
int height = getResources().getDimensionPixelSize(R.dimen.notification_large_icon_height);
|
||||
b.setLargeIcon(BoteHelper.getIdenticonForAddress(fromAddress, width, height));
|
||||
} else
|
||||
b.setSmallIcon(R.drawable.ic_contact_picture);
|
||||
|
||||
b.setContentTitle(BoteHelper.getNameAndShortDestination(
|
||||
@@ -264,16 +270,18 @@ public class BoteService extends Service implements NetworkStatusListener, NewEm
|
||||
break;
|
||||
|
||||
default:
|
||||
b.setSmallIcon(R.drawable.ic_notif);
|
||||
b.setContentTitle(getResources().getQuantityString(
|
||||
R.plurals.n_new_emails, numNew, numNew));
|
||||
|
||||
HashSet<Address> recipients = new HashSet<Address>();
|
||||
String bigText = "";
|
||||
for (Email ne : newEmails) {
|
||||
recipients.add(BoteHelper.getOneLocalRecipient(ne));
|
||||
bigText += BoteHelper.getNameAndShortDestination(
|
||||
ne.getOneFromAddress());
|
||||
bigText += ": " + ne.getSubject() + "\n";
|
||||
}
|
||||
b.setContentText(BoteHelper.joinAddressNames(recipients));
|
||||
b.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText));
|
||||
|
||||
Intent eli = new Intent(this, EmailListActivity.class);
|
||||
|
||||
@@ -23,11 +23,11 @@ import com.lambdaworks.codec.Base64;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.mail.Address;
|
||||
import javax.mail.Flags.Flag;
|
||||
import javax.mail.MessagingException;
|
||||
|
||||
import i2p.bote.android.R;
|
||||
@@ -401,4 +401,18 @@ public class BoteHelper extends GeneralHelper {
|
||||
mListener.onPasswordVerified();
|
||||
}
|
||||
}
|
||||
|
||||
public static String joinAddressNames(Collection<Address> s) throws PasswordException, GeneralSecurityException, IOException {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Iterator<Address> iter = s.iterator();
|
||||
while (iter.hasNext()) {
|
||||
String name = getName(iter.next().toString());
|
||||
builder.append(name);
|
||||
if (!iter.hasNext()) {
|
||||
break;
|
||||
}
|
||||
builder.append(", ");
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user