Search in sources :

Example 1 with Avatar

use of im.actor.core.entity.Avatar in project actor-platform by actorapp.

the class JsGroup method fromGroupVM.

public static JsGroup fromGroupVM(GroupVM groupVM, JsMessenger messenger) {
    int online = groupVM.getPresence().get();
    String presence = messenger.getFormatter().formatGroupMembers(groupVM.getMembersCount().get());
    if (online > 0) {
        presence += ", " + messenger.getFormatter().formatGroupOnline(online);
    }
    String fileUrl = null;
    String bigFileUrl = null;
    Avatar avatar = groupVM.getAvatar().get();
    if (avatar != null) {
        if (avatar.getSmallImage() != null) {
            fileUrl = messenger.getFileUrl(avatar.getSmallImage().getFileReference());
        }
        if (avatar.getLargeImage() != null) {
            bigFileUrl = messenger.getFileUrl(avatar.getLargeImage().getFileReference());
        }
    }
    ArrayList<JsGroupMember> convertedMembers = new ArrayList<JsGroupMember>();
    HashSet<GroupMember> groupMembers = groupVM.getMembers().get();
    GroupMember[] members = groupMembers.toArray(new GroupMember[groupMembers.size()]);
    for (GroupMember g : members) {
        JsPeerInfo peerInfo = messenger.buildPeerInfo(Peer.user(g.getUid()));
        // Log.d("JsGroup", "PeerInfo: " + peerInfo);
        convertedMembers.add(JsGroupMember.create(peerInfo, g.isAdministrator(), g.getInviterUid() == messenger.myUid()));
    }
    Collections.sort(convertedMembers, new Comparator<JsGroupMember>() {

        @Override
        public int compare(JsGroupMember o1, JsGroupMember o2) {
            return o1.getPeerInfo().getTitle().compareToIgnoreCase(o2.getPeerInfo().getTitle());
        }
    });
    JsArray<JsGroupMember> jsMembers = JsArray.createArray().cast();
    for (JsGroupMember member : convertedMembers) {
        jsMembers.push(member);
    }
    return create(groupVM.getId(), groupVM.getName().get(), groupVM.getAbout().get(), fileUrl, bigFileUrl, Placeholders.getPlaceholder(groupVM.getId()), presence, jsMembers);
}
Also used : GroupMember(im.actor.core.entity.GroupMember) ArrayList(java.util.ArrayList) Avatar(im.actor.core.entity.Avatar)

Example 2 with Avatar

use of im.actor.core.entity.Avatar in project actor-platform by actorapp.

the class JsNotificationsProvider method onNotification.

@Override
public void onNotification(Messenger messenger, List<Notification> topNotifications, int messagesCount, int conversationsCount) {
    String peerTitle;
    String peerKey = null;
    String peerAvatarUrl = null;
    String contentMessage = "";
    Notification notification = topNotifications.get(0);
    // Peer info
    Peer peer = notification.getPeer();
    if (conversationsCount == 1) {
        Avatar peerAvatar;
        JsPeer jsPeer = JsPeer.create(peer);
        if (peer.getPeerType() == PeerType.PRIVATE) {
            UserVM userVM = messenger.getUser(peer.getPeerId());
            peerTitle = userVM.getName().get();
            peerAvatar = userVM.getAvatar().get();
        } else {
            GroupVM groupVM = messenger.getGroup(peer.getPeerId());
            peerTitle = groupVM.getName().get();
            peerAvatar = groupVM.getAvatar().get();
        }
        if (peerAvatar != null && peerAvatar.getSmallImage() != null) {
            peerAvatarUrl = ((JsMessenger) messenger).getFileUrl(peerAvatar.getSmallImage().getFileReference());
        }
        peerKey = jsPeer.getPeerKey();
    } else {
        peerTitle = "New messages";
        peerAvatarUrl = "assets/img/notification_icon_512.png";
    }
    // Notification body
    int nCount = Math.min(topNotifications.size(), 5);
    boolean showCounters = false;
    if (topNotifications.size() > 5) {
        nCount--;
        showCounters = true;
    }
    boolean isChannel = peer.getPeerType() == PeerType.GROUP && messenger.getGroups().get(peer.getPeerId()).getGroupType() == GroupType.CHANNEL;
    if (conversationsCount == 1) {
        for (int i = 0; i < nCount; i++) {
            Notification n = topNotifications.get(i);
            if (contentMessage.length() > 0) {
                contentMessage += "\n";
            }
            if (peer.getPeerType() == PeerType.GROUP) {
                contentMessage += messenger.getUser(notification.getSender()).getName().get() + ": ";
            }
            contentMessage += messenger.getFormatter().formatContentText(n.getSender(), n.getContentDescription().getContentType(), n.getContentDescription().getText(), n.getContentDescription().getRelatedUser(), isChannel);
        }
        if (showCounters) {
            contentMessage += "\n+" + (messagesCount - 4) + " new messages";
        }
    } else {
        for (int i = 0; i < nCount; i++) {
            Notification n = topNotifications.get(i);
            if (contentMessage.length() > 0) {
                contentMessage += "\n";
            }
            String senderName = messenger.getUser(n.getSender()).getName().get();
            if (n.getPeer().getPeerType() == PeerType.GROUP) {
                String groupName = messenger.getGroup(n.getPeer().getPeerId()).getName().get();
                contentMessage += "[" + groupName + "] " + senderName + ": ";
            } else {
                contentMessage += senderName + ": ";
            }
            contentMessage += messenger.getFormatter().formatContentText(n.getSender(), n.getContentDescription().getContentType(), n.getContentDescription().getText(), n.getContentDescription().getRelatedUser(), isChannel);
        }
        if (showCounters) {
            contentMessage += "\n+" + (messagesCount - 4) + " new messages in " + conversationsCount + " conversations";
        }
    }
    if (!JsElectronApp.isElectron()) {
        playSound();
    }
    if (!JsNotification.isSupported()) {
        return;
    }
    if (!JsNotification.isGranted()) {
        return;
    }
    JsManagedNotification.show(peerKey, peerTitle, contentMessage, peerAvatarUrl);
}
Also used : UserVM(im.actor.core.viewmodel.UserVM) GroupVM(im.actor.core.viewmodel.GroupVM) Peer(im.actor.core.entity.Peer) JsPeer(im.actor.core.js.entity.JsPeer) JsPeer(im.actor.core.js.entity.JsPeer) JsNotification(im.actor.core.js.providers.notification.JsNotification) Notification(im.actor.core.entity.Notification) JsManagedNotification(im.actor.core.js.providers.notification.JsManagedNotification) Avatar(im.actor.core.entity.Avatar)

Example 3 with Avatar

use of im.actor.core.entity.Avatar in project actor-platform by actorapp.

the class RouterActor method notifyActiveDialogsVM.

private void notifyActiveDialogsVM() {
    int counter = 0;
    ArrayList<DialogGroup> groups = new ArrayList<>();
    for (ActiveDialogGroup i : activeDialogStorage.getGroups()) {
        ArrayListDialogSmall dialogSmalls = new ArrayListDialogSmall();
        for (Peer p : i.getPeers()) {
            String title;
            Avatar avatar;
            if (p.getPeerType() == PeerType.GROUP) {
                Group group = getGroup(p.getPeerId());
                title = group.getTitle();
                avatar = group.getAvatar();
            } else if (p.getPeerType() == PeerType.PRIVATE) {
                User user = getUser(p.getPeerId());
                title = user.getName();
                avatar = user.getAvatar();
            } else {
                continue;
            }
            int unreadCount = conversationStates.getValue(p.getUnuqueId()).getUnreadCount();
            counter += unreadCount;
            dialogSmalls.add(new DialogSmall(p, title, avatar, unreadCount));
        }
        groups.add(new DialogGroup(i.getTitle(), i.getKey(), dialogSmalls));
    }
    context().getMessagesModule().getDialogGroupsVM().getGroupsValueModel().change(groups);
    context().getConductor().getGlobalStateVM().onGlobalCounterChanged(counter);
}
Also used : ApiDialogGroup(im.actor.core.api.ApiDialogGroup) Group(im.actor.core.entity.Group) DialogGroup(im.actor.core.viewmodel.DialogGroup) ActiveDialogGroup(im.actor.core.modules.messaging.router.entity.ActiveDialogGroup) ArrayListDialogSmall(im.actor.core.viewmodel.generics.ArrayListDialogSmall) User(im.actor.core.entity.User) ApiDialogGroup(im.actor.core.api.ApiDialogGroup) DialogGroup(im.actor.core.viewmodel.DialogGroup) ActiveDialogGroup(im.actor.core.modules.messaging.router.entity.ActiveDialogGroup) Peer(im.actor.core.entity.Peer) ArrayList(java.util.ArrayList) ActiveDialogGroup(im.actor.core.modules.messaging.router.entity.ActiveDialogGroup) DialogSmall(im.actor.core.viewmodel.DialogSmall) ArrayListDialogSmall(im.actor.core.viewmodel.generics.ArrayListDialogSmall) Avatar(im.actor.core.entity.Avatar)

Example 4 with Avatar

use of im.actor.core.entity.Avatar in project actor-platform by actorapp.

the class DialogSmall method parse.

@Override
public void parse(BserValues values) throws IOException {
    peer = Peer.fromBytes(values.getBytes(1));
    title = values.getString(2);
    avatar = new Avatar(values.getBytes(3));
    counter = values.getInt(4);
}
Also used : Avatar(im.actor.core.entity.Avatar)

Example 5 with Avatar

use of im.actor.core.entity.Avatar in project actor-platform by actorapp.

the class AndroidNotifications method onNotification.

@Override
public void onNotification(Messenger messenger, List<Notification> topNotifications, int messagesCount, int conversationsCount) {
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setAutoCancel(true);
    builder.setSmallIcon(R.drawable.ic_app_notify);
    builder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
    builder.setCategory(NotificationCompat.CATEGORY_MESSAGE);
    int defaults = NotificationCompat.DEFAULT_LIGHTS;
    if (messenger.isNotificationVibrationEnabled()) {
        defaults |= NotificationCompat.DEFAULT_VIBRATE;
    }
    //        if (silentUpdate) {
    //            defaults = 0;
    //        }
    builder.setDefaults(defaults);
    // Wearable
    //        builder.extend(new NotificationCompat.WearableExtender()
    //                .setBackground(((BitmapDrawable) AppContext.getContext().getResources().getDrawable(R.drawable.wear_bg)).getBitmap())
    //                .setHintHideIcon(true));
    final Notification topNotification = topNotifications.get(topNotifications.size() - 1);
    //        if (!silentUpdate) {
    //            builder.setTicker(getNotificationTextFull(topNotification, messenger));
    //        }
    android.app.Notification result;
    if (messagesCount == 1) {
        // Single message notification
        final String sender = getNotificationSender(topNotification);
        //            final CharSequence text = bypass.markdownToSpannable(messenger().getFormatter().formatNotificationText(topNotification), true).toString();
        final CharSequence text = messenger.getFormatter().formatNotificationText(topNotification);
        visiblePeer = topNotification.getPeer();
        Avatar avatar = null;
        int id = 0;
        String avatarTitle = "";
        switch(visiblePeer.getPeerType()) {
            case PRIVATE:
                avatar = messenger().getUsers().get(visiblePeer.getPeerId()).getAvatar().get();
                id = messenger().getUsers().get(visiblePeer.getPeerId()).getId();
                avatarTitle = messenger().getUsers().get(visiblePeer.getPeerId()).getName().get();
                break;
            case GROUP:
                avatar = messenger().getGroups().get(visiblePeer.getPeerId()).getAvatar().get();
                id = messenger().getGroups().get(visiblePeer.getPeerId()).getId();
                avatarTitle = messenger().getGroups().get(visiblePeer.getPeerId()).getName().get();
                break;
        }
        Drawable avatarDrawable = new AvatarPlaceholderDrawable(avatarTitle, id, 18, context);
        result = buildSingleMessageNotification(avatarDrawable, builder, sender, text, topNotification);
        final NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(NOTIFICATION_ID, result);
        if (avatar != null && avatar.getSmallImage() != null && avatar.getSmallImage().getFileReference() != null) {
            messenger.bindFile(avatar.getSmallImage().getFileReference(), true, new FileVMCallback() {

                @Override
                public void onNotDownloaded() {
                }

                @Override
                public void onDownloading(float progress) {
                }

                @Override
                public void onDownloaded(FileSystemReference reference) {
                    RoundedBitmapDrawable d = getRoundedBitmapDrawable(reference);
                    android.app.Notification result = buildSingleMessageNotification(d, builder, sender, text, topNotification);
                    //NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                    manager.notify(NOTIFICATION_ID, result);
                }
            });
        } else {
            manager.notify(NOTIFICATION_ID, result);
        }
    } else if (conversationsCount == 1) {
        // Single conversation notification
        String sender = getNotificationSender(topNotification);
        builder.setContentTitle(sender);
        builder.setContentText(messagesCount + context.getString(R.string.notifications_single_conversation_аfter_messages_count));
        visiblePeer = topNotification.getPeer();
        final NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        for (Notification n : topNotifications) {
            if (topNotification.getPeer().getPeerType() == PeerType.GROUP) {
                inboxStyle.addLine(getNotificationTextFull(n, messenger));
            } else {
                inboxStyle.addLine(messenger.getFormatter().formatNotificationText(n));
            }
        }
        inboxStyle.setSummaryText(messagesCount + context.getString(R.string.notifications_single_conversation_аfter_messages_count));
        Avatar avatar = null;
        int id = 0;
        String avatarTitle = "";
        switch(visiblePeer.getPeerType()) {
            case PRIVATE:
                avatar = messenger().getUsers().get(visiblePeer.getPeerId()).getAvatar().get();
                id = messenger().getUsers().get(visiblePeer.getPeerId()).getId();
                avatarTitle = messenger().getUsers().get(visiblePeer.getPeerId()).getName().get();
                break;
            case GROUP:
                avatar = messenger().getGroups().get(visiblePeer.getPeerId()).getAvatar().get();
                id = messenger().getGroups().get(visiblePeer.getPeerId()).getId();
                avatarTitle = messenger().getGroups().get(visiblePeer.getPeerId()).getName().get();
                break;
        }
        Drawable avatarDrawable = new AvatarPlaceholderDrawable(avatarTitle, id, 18, context);
        result = buildSingleConversationNotification(builder, inboxStyle, avatarDrawable, topNotification);
        final NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(NOTIFICATION_ID, result);
        if (avatar != null && avatar.getSmallImage() != null && avatar.getSmallImage().getFileReference() != null) {
            messenger.bindFile(avatar.getSmallImage().getFileReference(), true, new FileVMCallback() {

                @Override
                public void onNotDownloaded() {
                }

                @Override
                public void onDownloading(float progress) {
                }

                @Override
                public void onDownloaded(FileSystemReference reference) {
                    RoundedBitmapDrawable d = getRoundedBitmapDrawable(reference);
                    android.app.Notification result = buildSingleConversationNotification(builder, inboxStyle, d, topNotification);
                    manager.notify(NOTIFICATION_ID, result);
                }
            });
        } else {
            manager.notify(NOTIFICATION_ID, result);
        }
    } else {
        // Multiple conversations notification
        builder.setContentTitle(ActorSDK.sharedActor().getAppName());
        builder.setContentText(messagesCount + context.getString(R.string.notification_multiple_canversations_after_msg_count) + conversationsCount + context.getString(R.string.notifications_multiple_canversations_after_coversations_count));
        visiblePeer = null;
        intent = new Intent(context, RootActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        builder.setContentIntent(PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        for (Notification n : topNotifications) {
            inboxStyle.addLine(getNotificationTextFull(n, messenger));
        }
        inboxStyle.setSummaryText(messagesCount + context.getString(R.string.notification_multiple_canversations_after_msg_count) + conversationsCount + context.getString(R.string.notifications_multiple_canversations_after_coversations_count));
        result = builder.setStyle(inboxStyle).build();
        addCustomLedAndSound(topNotification, result);
        NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(NOTIFICATION_ID, result);
    }
}
Also used : RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable) FileSystemReference(im.actor.runtime.files.FileSystemReference) NotificationManager(android.app.NotificationManager) SpannableStringBuilder(android.text.SpannableStringBuilder) AvatarPlaceholderDrawable(im.actor.sdk.view.avatar.AvatarPlaceholderDrawable) Drawable(android.graphics.drawable.Drawable) RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(im.actor.core.entity.Notification) Avatar(im.actor.core.entity.Avatar) NotificationCompat(android.support.v4.app.NotificationCompat) AvatarPlaceholderDrawable(im.actor.sdk.view.avatar.AvatarPlaceholderDrawable) FileVMCallback(im.actor.core.viewmodel.FileVMCallback)

Aggregations

Avatar (im.actor.core.entity.Avatar)7 Peer (im.actor.core.entity.Peer)3 ArrayList (java.util.ArrayList)3 Notification (im.actor.core.entity.Notification)2 GroupVM (im.actor.core.viewmodel.GroupVM)2 UserVM (im.actor.core.viewmodel.UserVM)2 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Drawable (android.graphics.drawable.Drawable)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 RoundedBitmapDrawable (android.support.v4.graphics.drawable.RoundedBitmapDrawable)1 MenuItemCompat (android.support.v4.view.MenuItemCompat)1 SearchView (android.support.v7.widget.SearchView)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 MenuItem (android.view.MenuItem)1 ApiDialogGroup (im.actor.core.api.ApiDialogGroup)1 Group (im.actor.core.entity.Group)1 GroupMember (im.actor.core.entity.GroupMember)1 PeerSearchEntity (im.actor.core.entity.PeerSearchEntity)1