Search in sources :

Example 1 with AvatarPlaceholderDrawable

use of im.actor.sdk.view.avatar.AvatarPlaceholderDrawable in project actor-platform by actorapp.

the class ContactHolder method bindData.

@Override
protected void bindData(final Message message, long readDate, long receiveDate, boolean isUpdated, PreprocessedData preprocessedData) {
    ContactContent contact = (ContactContent) message.getContent();
    // Update state
    if (message.getSenderId() == myUid()) {
        stateIcon.setVisibility(View.VISIBLE);
        switch(message.getMessageState()) {
            case ERROR:
                stateIcon.setResource(R.drawable.msg_error);
                stateIcon.setTint(errorColor);
                break;
            default:
            case PENDING:
                stateIcon.setResource(R.drawable.msg_clock);
                stateIcon.setTint(waitColor);
                break;
            case SENT:
                if (message.getSortDate() <= readDate) {
                    stateIcon.setResource(R.drawable.msg_check_2);
                    stateIcon.setTint(readColor);
                } else if (message.getSortDate() <= receiveDate) {
                    stateIcon.setResource(R.drawable.msg_check_2);
                    stateIcon.setTint(deliveredColor);
                } else {
                    stateIcon.setResource(R.drawable.msg_check_1);
                    stateIcon.setTint(sentColor);
                }
                break;
        }
    } else {
        stateIcon.setVisibility(View.GONE);
    }
    // Update time
    setTimeAndReactions(time);
    if (message.getSenderId() == myUid()) {
        messageBubble.setBackgroundResource(R.drawable.conv_bubble_media_out);
    } else {
        messageBubble.setBackgroundResource(R.drawable.conv_bubble_media_in);
    }
    Drawable avatar;
    Bitmap b = convertPhoto(contact);
    if (b != null) {
        avatar = getRoundedBitmapDrawable(itemView.getContext(), b);
    } else {
        avatar = new AvatarPlaceholderDrawable(contact.getName(), message.getSenderId(), 18, itemView.getContext());
    }
    contactAvatar.setBackgroundDrawable(avatar);
    text.setText(((PreprocessedTextData) preprocessedData).getSpannableString());
}
Also used : Bitmap(android.graphics.Bitmap) AvatarPlaceholderDrawable(im.actor.sdk.view.avatar.AvatarPlaceholderDrawable) Drawable(android.graphics.drawable.Drawable) RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable) AvatarPlaceholderDrawable(im.actor.sdk.view.avatar.AvatarPlaceholderDrawable) ContactContent(im.actor.core.entity.content.ContactContent)

Example 2 with AvatarPlaceholderDrawable

use of im.actor.sdk.view.avatar.AvatarPlaceholderDrawable 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

Drawable (android.graphics.drawable.Drawable)2 RoundedBitmapDrawable (android.support.v4.graphics.drawable.RoundedBitmapDrawable)2 AvatarPlaceholderDrawable (im.actor.sdk.view.avatar.AvatarPlaceholderDrawable)2 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 Avatar (im.actor.core.entity.Avatar)1 Notification (im.actor.core.entity.Notification)1 ContactContent (im.actor.core.entity.content.ContactContent)1 FileVMCallback (im.actor.core.viewmodel.FileVMCallback)1 FileSystemReference (im.actor.runtime.files.FileSystemReference)1