Commit 81afb227 authored by Grigory Fedorov's avatar Grigory Fedorov

Message notifications made more complicated and informing. Head up notifications added.

parent c48d5522
......@@ -5,6 +5,9 @@ import android.content.Intent;
import android.media.AudioManager;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.StyleSpan;
import com.xabber.android.data.Application;
import com.xabber.android.data.SettingsManager;
......@@ -54,6 +57,8 @@ public class MessageNotificationCreator {
notificationBuilder = new NotificationCompat.Builder(application);
notificationBuilder.setContentTitle(getTitle(message, messageCount));
notificationBuilder.setContentText(getText(message, showText));
notificationBuilder.setSubText(message.getAccount());
if (showText) {
notificationBuilder.setTicker(message.getText());
}
......@@ -66,6 +71,9 @@ public class MessageNotificationCreator {
notificationBuilder.setContentIntent(getIntent(message));
notificationBuilder.setCategory(NotificationCompat.CATEGORY_MESSAGE);
notificationBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
addEffects(messageItem);
return notificationBuilder.build();
......@@ -73,22 +81,47 @@ public class MessageNotificationCreator {
private CharSequence getTitle(MessageNotification message, int messageCount) {
if (isFromOneContact()) {
return RosterManager.getInstance().getName(message.getAccount(), message.getUser());
return getSingleContactTitle(message, messageCount);
} else {
String messageText = StringUtils.getQuantityString(
application.getResources(), R.array.chat_message_quantity, messageCount);
return getMultiContactTitle(messageCount);
}
}
private CharSequence getSingleContactTitle(MessageNotification message, int messageCount) {
if (messageCount > 1) {
return application.getString(R.string.chat_messages_from_contact,
messageCount, getTextForMessages(messageCount), getContactName(message));
} else {
return getContactName(message);
}
}
private String getContactName(MessageNotification message) {
return RosterManager.getInstance().getName(message.getAccount(), message.getUser());
}
private CharSequence getMultiContactTitle(int messageCount) {
String messageText = getTextForMessages(messageCount);
String contactText = StringUtils.getQuantityString(application.getResources(),
R.array.chat_contact_quantity, messageNotifications.size());
return application.getString(R.string.chat_status,
messageCount, messageText, messageNotifications.size(), contactText);
}
private String getTextForMessages(int messageCount) {
return StringUtils.getQuantityString(
application.getResources(), R.array.chat_message_quantity, messageCount);
}
private CharSequence getText(MessageNotification message, boolean showText) {
if (showText && isFromOneContact()) {
if (!showText) {
return message.getAccount();
}
if (isFromOneContact()) {
return message.getText();
} else {
return "";
return getContactNameAndMessage(message);
}
}
......@@ -111,18 +144,40 @@ public class MessageNotificationCreator {
return messageNotifications.size() == 1;
}
private NotificationCompat.BigTextStyle getStyle(MessageNotification message, int messageCount) {
if (messageCount == 1) {
String title = RosterManager.getInstance().getName(message.getAccount(), message.getUser());
private NotificationCompat.Style getStyle(MessageNotification message, int messageCount) {
if (isFromOneContact()) {
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
String text = message.getText();
bigTextStyle.setBigContentTitle(getSingleContactTitle(message, messageCount));
bigTextStyle.bigText(message.getText());
bigTextStyle.setSummaryText(message.getAccount());
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
bigTextStyle.setBigContentTitle(title);
bigTextStyle.bigText(text);
return bigTextStyle;
} else {
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
inboxStyle.setBigContentTitle(getMultiContactTitle(messageCount));
for (int i = 1; i <= messageNotifications.size(); i++) {
MessageNotification messageNotification = messageNotifications.get(messageNotifications.size() - i);
inboxStyle.addLine(getContactNameAndMessage(messageNotification));
}
return null;
inboxStyle.setSummaryText(message.getAccount());
return inboxStyle;
}
}
private Spannable getContactNameAndMessage(MessageNotification messageNotification) {
String userName = getContactName(messageNotification);
String contactAndMessage = application.getString(
R.string.chat_contact_and_message, userName, messageNotification.getText());
Spannable spannableString = new SpannableString(contactAndMessage);
spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, userName.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannableString;
}
private PendingIntent getIntent(MessageNotification message) {
......
......@@ -157,8 +157,10 @@ public class NotificationManager implements OnInitializedListener, OnAccountChan
persistentNotificationBuilder.setContentTitle(application.getString(R.string.application_name));
persistentNotificationBuilder.setDeleteIntent(clearNotifications);
persistentNotificationBuilder.setOngoing(true);
persistentNotificationBuilder.setColor(COLOR_MATERIAL_RED_500);
persistentNotificationBuilder.setWhen(System.currentTimeMillis());
persistentNotificationBuilder.setCategory(NotificationCompat.CATEGORY_SERVICE);
persistentNotificationBuilder.setPriority(NotificationCompat.PRIORITY_LOW);
}
@Override
......@@ -357,8 +359,14 @@ public class NotificationManager implements OnInitializedListener, OnAccountChan
persistentIntent = ContactList.createPersistentIntent(application);
}
persistentNotificationBuilder.setSmallIcon(connected > 0 ? R.drawable.ic_stat_light_bulb_big
: R.drawable.ic_stat_light_bulb_big_off);
if (connected > 0) {
persistentNotificationBuilder.setColor(COLOR_MATERIAL_RED_500);
persistentNotificationBuilder.setSmallIcon(R.drawable.ic_stat_light_bulb_big);
} else {
persistentNotificationBuilder.setColor(NotificationCompat.COLOR_DEFAULT);
persistentNotificationBuilder.setSmallIcon(R.drawable.ic_stat_light_bulb_big_off);
}
persistentNotificationBuilder.setContentText(getConnectionState(waiting, connecting, connected, accountList.size()));
persistentNotificationBuilder.setContentIntent(PendingIntent.getActivity(application, 0, persistentIntent,
PendingIntent.FLAG_UPDATE_CURRENT));
......
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/notification_bar_connected.png -->
<string name="account_quantity_1">учетной записи</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/notification_bar_connected.png -->
......@@ -28,6 +28,10 @@
<string name="chat_message_quantity_5">сообщений</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/notification_bar_message.png -->
<string name="chat_status">%1$d %2$s от %3$d %4$s</string>
<string name="chat_messages_from_contact">%1$d %2$s от %3$s</string>
<string name="chat_contact_and_message">%1$s: %2$s</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/notification_bar_connected.png -->
<string name="connection_state_connected_1">%1$d из %2$d %3$s подключена </string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/notification_bar_connected.png -->
......
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/notification_bar_connected.png -->
<string name="account_quantity_1">account</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/notification_bar_connected.png -->
......@@ -28,6 +28,10 @@
<string name="chat_message_quantity_5">-</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/notification_bar_message.png -->
<string name="chat_status">%1$d %2$s from %3$d %4$s</string>
<string name="chat_messages_from_contact">%1$d %2$s from %3$s</string>
<string name="chat_contact_and_message">%1$s: %2$s</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/notification_bar_connected.png -->
<string name="connection_state_connected_1">%1$d of %2$d %3$s online</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/notification_bar_connected.png -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment