Commit 93f11def authored by Grigory Fedorov's avatar Grigory Fedorov

New class MessageNotificationCreator. NotificationManager refactored....

New class MessageNotificationCreator. NotificationManager refactored. Notification builder used for all notifications.
New icons for notifications. Old removed.
parent ec790d5e
......@@ -14,18 +14,6 @@
*/
package com.xabber.android.data.account;
import java.security.KeyPair;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.jivesoftware.smack.util.StringUtils;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.os.Build;
......@@ -46,6 +34,18 @@ import com.xabber.android.data.roster.RosterManager;
import com.xabber.androiddev.R;
import com.xabber.xmpp.address.Jid;
import org.jivesoftware.smack.util.StringUtils;
import java.security.KeyPair;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
/**
* This class manage all operations with accounts.
* <p/>
......@@ -117,9 +117,9 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
enabledAccounts = new HashSet<String>();
savedStatuses = new ArrayList<SavedStatus>();
authorizationErrorProvider = new BaseAccountNotificationProvider<AccountAuthorizationError>(
R.drawable.ic_stat_auth_failed);
R.drawable.ic_stat_error);
passwordRequestProvider = new BaseAccountNotificationProvider<PasswordRequest>(
R.drawable.ic_stat_request);
R.drawable.ic_stat_ic_add_circle);
TypedArray accountAvatars = application.getResources()
.obtainTypedArray(R.array.account_avatars);
......
......@@ -14,6 +14,19 @@
*/
package com.xabber.android.data.connection;
import android.content.res.AssetManager;
import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager;
import com.xabber.android.data.OnClearListener;
import com.xabber.android.data.OnLoadListener;
import com.xabber.android.data.notification.BaseNotificationProvider;
import com.xabber.android.data.notification.NotificationManager;
import com.xabber.androiddev.R;
import org.jivesoftware.smack.CertificateListener;
import org.jivesoftware.smack.util.StringUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
......@@ -34,19 +47,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.jivesoftware.smack.CertificateListener;
import org.jivesoftware.smack.util.StringUtils;
import android.content.res.AssetManager;
import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager;
import com.xabber.android.data.OnClearListener;
import com.xabber.android.data.OnLoadListener;
import com.xabber.android.data.notification.BaseNotificationProvider;
import com.xabber.android.data.notification.NotificationManager;
import com.xabber.androiddev.R;
/**
* Manage certificate exceptions.
* <p/>
......@@ -94,7 +94,7 @@ public class CertificateManager implements OnLoadListener, OnClearListener {
private final Map<CertificateInvalidReason, KeyStore> defaultStores;
private final BaseNotificationProvider<PendingCertificate> pendingCertificateProvider = new BaseNotificationProvider<PendingCertificate>(
R.drawable.ic_stat_auth_failed) {
R.drawable.ic_stat_error) {
@Override
public void clearNotifications() {
......
......@@ -14,16 +14,6 @@
*/
package com.xabber.android.data.extension.archive;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.packet.Packet;
import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager;
import com.xabber.android.data.NetworkException;
......@@ -68,6 +58,16 @@ import com.xabber.xmpp.archive.Session;
import com.xabber.xmpp.archive.SessionRemove;
import com.xabber.xmpp.rsm.Set;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.packet.Packet;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
/**
* Manage server side archive. Replicate it with memory storage.
* <p/>
......@@ -164,7 +164,7 @@ public class MessageArchiveManager implements OnPacketListener,
modificationRequests = new NestedMap<Boolean>();
chatStorages = new NestedNestedMaps<String, ChatStorage>();
availableArchiveRequestProvider = new BaseAccountNotificationProvider<AvailableArchiveRequest>(
R.drawable.ic_stat_request);
R.drawable.ic_stat_ic_help_black);
}
@Override
......
......@@ -14,16 +14,6 @@
*/
package com.xabber.android.data.extension.attention;
import java.util.Iterator;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smackx.ServiceDiscoveryManager;
import android.media.AudioManager;
import android.net.Uri;
......@@ -51,6 +41,16 @@ import com.xabber.androiddev.R;
import com.xabber.xmpp.address.Jid;
import com.xabber.xmpp.attention.Attention;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smackx.ServiceDiscoveryManager;
import java.util.Iterator;
/**
* XEP-0224: Attention.
*
......@@ -86,7 +86,7 @@ public class AttentionManager implements OnPacketListener, OnLoadListener {
}
private final EntityNotificationProvider<AttentionRequest> attentionRequestProvider = new EntityNotificationProvider<AttentionRequest>(
R.drawable.ic_stat_attention) {
R.drawable.ic_stat_error) {
@Override
public Uri getSound() {
......
......@@ -14,17 +14,6 @@
*/
package com.xabber.android.data.extension.muc;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smackx.muc.MultiUserChat;
import org.jivesoftware.smackx.packet.MUCUser;
import android.database.Cursor;
import com.xabber.android.data.Application;
......@@ -46,6 +35,17 @@ import com.xabber.android.data.roster.RosterManager;
import com.xabber.androiddev.R;
import com.xabber.xmpp.muc.MUC;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smackx.muc.MultiUserChat;
import org.jivesoftware.smackx.packet.MUCUser;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
/**
* Manage multi user chats.
* <p/>
......@@ -72,9 +72,9 @@ public class MUCManager implements OnLoadListener, OnPacketListener {
private MUCManager() {
inviteProvider = new EntityNotificationProvider<RoomInvite>(
R.drawable.ic_stat_subscribe);
R.drawable.ic_stat_ic_add_circle);
authorizationErrorProvider = new EntityNotificationProvider<RoomAuthorizationError>(
R.drawable.ic_stat_auth_failed);
R.drawable.ic_stat_error);
}
@Override
......
......@@ -14,29 +14,6 @@
*/
package com.xabber.android.data.extension.otr;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import net.java.otr4j.OtrEngineHost;
import net.java.otr4j.OtrEngineListener;
import net.java.otr4j.OtrException;
import net.java.otr4j.OtrPolicy;
import net.java.otr4j.OtrPolicyImpl;
import net.java.otr4j.crypto.OtrCryptoEngineImpl;
import net.java.otr4j.crypto.OtrCryptoException;
import net.java.otr4j.io.SerializationUtils;
import net.java.otr4j.session.Session;
import net.java.otr4j.session.SessionID;
import net.java.otr4j.session.SessionImpl;
import net.java.otr4j.session.SessionStatus;
import android.database.Cursor;
import com.xabber.android.data.Application;
......@@ -66,6 +43,29 @@ import com.xabber.androiddev.R;
import com.xabber.xmpp.archive.OtrMode;
import com.xabber.xmpp.archive.SaveMode;
import net.java.otr4j.OtrEngineHost;
import net.java.otr4j.OtrEngineListener;
import net.java.otr4j.OtrException;
import net.java.otr4j.OtrPolicy;
import net.java.otr4j.OtrPolicyImpl;
import net.java.otr4j.crypto.OtrCryptoEngineImpl;
import net.java.otr4j.crypto.OtrCryptoException;
import net.java.otr4j.io.SerializationUtils;
import net.java.otr4j.session.Session;
import net.java.otr4j.session.SessionID;
import net.java.otr4j.session.SessionImpl;
import net.java.otr4j.session.SessionStatus;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
/**
* Manage off-the-record encryption.
* <p/>
......@@ -134,9 +134,9 @@ public class OTRManager implements OtrEngineHost, OtrEngineListener,
private OTRManager() {
smRequestProvider = new EntityNotificationProvider<SMRequest>(
R.drawable.ic_stat_request);
R.drawable.ic_stat_ic_help_black);
smProgressProvider = new EntityNotificationProvider<SMProgress>(
R.drawable.ic_stat_play);
R.drawable.ic_stat_ic_play_circle_fill);
smProgressProvider.setCanClearNotifications(false);
fingerprints = new NestedNestedMaps<String, Boolean>();
actives = new NestedMap<String>();
......
package com.xabber.android.data.notification;
import android.app.PendingIntent;
import android.content.Intent;
import android.media.AudioManager;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import com.xabber.android.data.Application;
import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.extension.avatar.AvatarManager;
import com.xabber.android.data.extension.muc.MUCManager;
import com.xabber.android.data.message.MessageItem;
import com.xabber.android.data.message.chat.ChatManager;
import com.xabber.android.data.message.phrase.PhraseManager;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.ChatViewer;
import com.xabber.android.utils.StringUtils;
import com.xabber.androiddev.R;
import java.util.List;
public class MessageNotificationCreator {
private final Application application;
private List<MessageNotification> messageNotifications;
private NotificationCompat.Builder notificationBuilder;
public MessageNotificationCreator() {
application = Application.getInstance();
}
public android.app.Notification notifyMessageNotification(List<MessageNotification> messageNotifications,
MessageItem messageItem) {
this.messageNotifications = messageNotifications;
if (messageNotifications.isEmpty()) {
return null;
}
int messageCount = 0;
for (MessageNotification messageNotification : messageNotifications) {
messageCount += messageNotification.getCount();
}
MessageNotification message = messageNotifications.get(messageNotifications.size() - 1);
boolean showText = ChatManager.getInstance().isShowText(message.getAccount(), message.getUser());
notificationBuilder = new NotificationCompat.Builder(application);
notificationBuilder.setContentTitle(getTitle(message, messageCount));
notificationBuilder.setContentText(getText(message, showText));
if (showText) {
notificationBuilder.setTicker(message.getText());
}
notificationBuilder.setSmallIcon(getSmallIcon());
notificationBuilder.setLargeIcon(getLargeIcon(message));
notificationBuilder.setWhen(message.getTimestamp().getTime());
notificationBuilder.setColor(NotificationManager.COLOR_MATERIAL_RED_500);
notificationBuilder.setStyle(getStyle(message, messageCount));
notificationBuilder.setContentIntent(getIntent(message));
addEffects(messageItem);
return notificationBuilder.build();
}
private CharSequence getTitle(MessageNotification message, int messageCount) {
if (isFromOneContact()) {
return RosterManager.getInstance().getName(message.getAccount(), message.getUser());
} else {
String messageText = StringUtils.getQuantityString(
application.getResources(), R.array.chat_message_quantity, 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 CharSequence getText(MessageNotification message, boolean showText) {
if (showText && isFromOneContact()) {
return message.getText();
} else {
return "";
}
}
private int getSmallIcon() {
return R.drawable.ic_stat_chat;
}
private android.graphics.Bitmap getLargeIcon(MessageNotification message) {
if (isFromOneContact()) {
if (MUCManager.getInstance().hasRoom(message.getAccount(), message.getUser())) {
return AvatarManager.getInstance().getRoomBitmap(message.getUser());
} else {
return AvatarManager.getInstance().getUserBitmap(message.getUser());
}
}
return null;
}
private boolean isFromOneContact() {
return messageNotifications.size() == 1;
}
private NotificationCompat.BigTextStyle getStyle(MessageNotification message, int messageCount) {
if (messageCount == 1) {
String title = RosterManager.getInstance().getName(message.getAccount(), message.getUser());
String text = message.getText();
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
bigTextStyle.setBigContentTitle(title);
bigTextStyle.bigText(text);
return bigTextStyle;
}
return null;
}
private PendingIntent getIntent(MessageNotification message) {
Intent chatIntent
= ChatViewer.createClearTopIntent(application, message.getAccount(), message.getUser());
return PendingIntent.getActivity(application, 0, chatIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}
private void addEffects(MessageItem messageItem) {
if (messageItem == null) {
return;
}
if (messageItem.getChat().getFirstNotification() || !SettingsManager.eventsFirstOnly()) {
Uri sound = PhraseManager.getInstance().getSound(messageItem.getChat().getAccount(),
messageItem.getChat().getUser(), messageItem.getText());
boolean makeVibration = ChatManager.getInstance().isMakeVibro(messageItem.getChat().getAccount(),
messageItem.getChat().getUser());
NotificationManager.getInstance().setNotificationDefaults(notificationBuilder,
makeVibration, sound, AudioManager.STREAM_NOTIFICATION);
}
}
}
......@@ -14,20 +14,6 @@
*/
package com.xabber.android.data.roster;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Type;
import org.jivesoftware.smack.packet.RosterPacket;
import org.jivesoftware.smack.packet.RosterPacket.ItemType;
import org.jivesoftware.smack.util.StringUtils;
import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException;
import com.xabber.android.data.OnLoadListener;
......@@ -46,6 +32,20 @@ import com.xabber.android.data.notification.NotificationManager;
import com.xabber.androiddev.R;
import com.xabber.xmpp.address.Jid;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Type;
import org.jivesoftware.smack.packet.RosterPacket;
import org.jivesoftware.smack.packet.RosterPacket.ItemType;
import org.jivesoftware.smack.util.StringUtils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
/**
* Process contact's presence information.
*
......@@ -86,7 +86,7 @@ public class PresenceManager implements OnArchiveModificationsReceivedListener,
private PresenceManager() {
subscriptionRequestProvider = new EntityNotificationProvider<SubscriptionRequest>(
R.drawable.ic_stat_subscribe);
R.drawable.ic_stat_ic_add_circle);
requestedSubscriptions = new HashMap<String, HashSet<String>>();
presenceContainers = new NestedMap<ResourceContainer>();
readyAccounts = new ArrayList<String>();
......
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