first step towards nicer notifications
This commit is contained in:
parent
fbd25c8129
commit
02883a7ac4
|
@ -164,7 +164,7 @@ public class XmppConnectionService extends Service {
|
||||||
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
mNotificationManager.notify(2342, UIHelper
|
mNotificationManager.notify(2342, UIHelper
|
||||||
.getUnreadMessageNotification(
|
.getUnreadMessageNotification(
|
||||||
getApplicationContext(), conversation));
|
getApplicationContext(),getConversations()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package eu.siacs.conversations.utils;
|
package eu.siacs.conversations.utils;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -29,7 +30,10 @@ import android.net.Uri;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.provider.ContactsContract.Contacts;
|
import android.provider.ContactsContract.Contacts;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
|
import android.support.v4.app.NotificationCompat.InboxStyle;
|
||||||
import android.support.v4.app.TaskStackBuilder;
|
import android.support.v4.app.TaskStackBuilder;
|
||||||
|
import android.text.Html;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
@ -104,7 +108,15 @@ public class UIHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Notification getUnreadMessageNotification(Context context,
|
public static Notification getUnreadMessageNotification(Context context,
|
||||||
Conversation conversation) {
|
List<Conversation> conversations) {
|
||||||
|
|
||||||
|
String targetUuid = "";
|
||||||
|
List<Conversation> unread = new ArrayList<Conversation>();
|
||||||
|
for(Conversation conversation : conversations) {
|
||||||
|
if (!conversation.isRead()) {
|
||||||
|
unread.add(conversation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SharedPreferences sharedPref = PreferenceManager
|
SharedPreferences sharedPref = PreferenceManager
|
||||||
.getDefaultSharedPreferences(context);
|
.getDefaultSharedPreferences(context);
|
||||||
|
@ -113,6 +125,9 @@ public class UIHelper {
|
||||||
Resources res = context.getResources();
|
Resources res = context.getResources();
|
||||||
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
|
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
|
||||||
context);
|
context);
|
||||||
|
if (unread.size() == 1) {
|
||||||
|
Conversation conversation = unread.get(0);
|
||||||
|
targetUuid = conversation.getUuid();
|
||||||
mBuilder.setLargeIcon(UIHelper.getUnknownContactPicture(conversation
|
mBuilder.setLargeIcon(UIHelper.getUnknownContactPicture(conversation
|
||||||
.getName(), (int) res
|
.getName(), (int) res
|
||||||
.getDimension(android.R.dimen.notification_large_icon_width)));
|
.getDimension(android.R.dimen.notification_large_icon_width)));
|
||||||
|
@ -136,6 +151,23 @@ public class UIHelper {
|
||||||
}
|
}
|
||||||
mBuilder.setContentText(firstLine);
|
mBuilder.setContentText(firstLine);
|
||||||
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText.toString()));
|
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText.toString()));
|
||||||
|
} else {
|
||||||
|
NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
|
||||||
|
style.setBigContentTitle(unread.size()+" unread Conversations");
|
||||||
|
StringBuilder names = new StringBuilder();
|
||||||
|
for(int i = 0; i < unread.size(); ++i) {
|
||||||
|
targetUuid = conversations.get(0).getUuid();
|
||||||
|
if (i< unread.size()-1) {
|
||||||
|
names.append(unread.get(i).getName()+", ");
|
||||||
|
} else {
|
||||||
|
names.append(unread.get(i).getName());
|
||||||
|
}
|
||||||
|
style.addLine(Html.fromHtml("<b>"+unread.get(i).getName()+"</b> "+unread.get(i).getLatestMessage().getBody()));
|
||||||
|
}
|
||||||
|
mBuilder.setContentTitle(unread.size()+" unread Conversations");
|
||||||
|
mBuilder.setContentText(names.toString());
|
||||||
|
mBuilder.setStyle(style);
|
||||||
|
}
|
||||||
mBuilder.setSmallIcon(R.drawable.notification);
|
mBuilder.setSmallIcon(R.drawable.notification);
|
||||||
mBuilder.setLights(0xffffffff, 2000, 4000);
|
mBuilder.setLights(0xffffffff, 2000, 4000);
|
||||||
if (ringtone != null) {
|
if (ringtone != null) {
|
||||||
|
@ -149,7 +181,7 @@ public class UIHelper {
|
||||||
ConversationActivity.class);
|
ConversationActivity.class);
|
||||||
viewConversationIntent.setAction(Intent.ACTION_VIEW);
|
viewConversationIntent.setAction(Intent.ACTION_VIEW);
|
||||||
viewConversationIntent.putExtra(ConversationActivity.CONVERSATION,
|
viewConversationIntent.putExtra(ConversationActivity.CONVERSATION,
|
||||||
conversation.getUuid());
|
targetUuid);
|
||||||
viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
|
viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
|
||||||
|
|
||||||
stackBuilder.addNextIntent(viewConversationIntent);
|
stackBuilder.addNextIntent(viewConversationIntent);
|
||||||
|
|
Loading…
Reference in a new issue