Search in sources :

Example 11 with FileSystemReference

use of im.actor.runtime.files.FileSystemReference in project actor-platform by actorapp.

the class ViewAvatarActivity method performBind.

private void performBind(Avatar avatar, AvatarUploadState uploadState) {
    unbind();
    if (uploadState != null && uploadState.isUploading()) {
        if (uploadState.getDescriptor() != null) {
            photoView.setImageURI(Uri.fromFile(new File(uploadState.getDescriptor())));
        } else {
            photoView.setImageURI(null);
        }
        showView(progress);
        goneView(noPhoto);
        return;
    }
    if (avatar == null || avatar.getFullImage() == null) {
        photoView.setImageBitmap(null);
        showView(noPhoto);
        goneView(progress);
    } else {
        goneView(noPhoto);
        // Large image
        String file = messenger().findDownloadedDescriptor(avatar.getFullImage().getFileReference().getFileId());
        if (file != null) {
            try {
                Bitmap bitmap = ImageLoading.loadBitmapOptimized(file);
                photoView.setImageBitmap(bitmap);
                photoView.setZoomable(true);
                goneView(progress);
                return;
            } catch (ImageLoadException e) {
                e.printStackTrace();
            }
        }
        // Full image not available: showing progress
        showView(progress);
        // Trying to show preview first
        boolean isAppliedPreview = false;
        String largeFile = messenger().findDownloadedDescriptor(avatar.getLargeImage().getFileReference().getFileId());
        if (largeFile != null) {
            try {
                Bitmap bitmap = ImageLoading.loadBitmapOptimized(largeFile);
                photoView.setImageBitmap(bitmap);
                photoView.setZoomable(false);
                isAppliedPreview = true;
            } catch (ImageLoadException e) {
                e.printStackTrace();
            }
        }
        if (!isAppliedPreview) {
            String smallFile = messenger().findDownloadedDescriptor(avatar.getSmallImage().getFileReference().getFileId());
            if (smallFile != null) {
                try {
                    Bitmap bitmap = ImageLoading.loadBitmapOptimized(smallFile);
                    photoView.setImageBitmap(bitmap);
                    photoView.setZoomable(false);
                } catch (ImageLoadException e) {
                    e.printStackTrace();
                }
            }
        }
        bindedDownloadFile = messenger().bindFile(avatar.getFullImage().getFileReference(), true, new FileVMCallback() {

            @Override
            public void onNotDownloaded() {
            }

            @Override
            public void onDownloading(float progressV) {
            }

            @Override
            public void onDownloaded(FileSystemReference reference) {
                try {
                    Bitmap bitmap = ImageLoading.loadBitmapOptimized(reference.getDescriptor());
                    photoView.setImageBitmap(bitmap);
                    photoView.setZoomable(true);
                    showView(photoView);
                    goneView(progress);
                } catch (ImageLoadException e) {
                    e.printStackTrace();
                }
            }
        });
    // receiver.request(new FullAvatarTask(avatar));
    }
}
Also used : Bitmap(android.graphics.Bitmap) FileSystemReference(im.actor.runtime.files.FileSystemReference) File(java.io.File) ImageLoadException(im.actor.sdk.util.images.common.ImageLoadException) FileVMCallback(im.actor.core.viewmodel.FileVMCallback)

Example 12 with FileSystemReference

use of im.actor.runtime.files.FileSystemReference 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)

Example 13 with FileSystemReference

use of im.actor.runtime.files.FileSystemReference in project actor-platform by actorapp.

the class CoverAvatarView method bind.

public void bind(final Avatar avatar) {
    // Same avatar
    if (avatar != null && avatar.getSmallImage() != null && avatar.getSmallImage().getFileReference().getFileId() == currentId) {
        return;
    }
    if (fileVM != null) {
        fileVM.detach();
        fileVM = null;
    }
    if (fullFileVM != null) {
        fullFileVM.detach();
        fullFileVM = null;
    }
    isLoaded = false;
    smallDescriptor = null;
    if (tryToSetFast(avatar)) {
        return;
    }
    if (avatar != null && avatar.getSmallImage() != null) {
        currentId = avatar.getSmallImage().getFileReference().getFileId();
        fileVM = messenger().bindFile(avatar.getSmallImage().getFileReference(), true, new FileVMCallback() {

            @Override
            public void onNotDownloaded() {
            }

            @Override
            public void onDownloading(float progress) {
            }

            @Override
            public void onDownloaded(FileSystemReference reference) {
                if (!isLoaded) {
                    smallDescriptor = reference.getDescriptor();
                    setImageURI(Uri.fromFile(new File(smallDescriptor)));
                }
            }
        });
        if (avatar.getFullImage() != null) {
            fullFileVM = messenger().bindFile(avatar.getFullImage().getFileReference(), true, new FileVMCallback() {

                @Override
                public void onNotDownloaded() {
                }

                @Override
                public void onDownloading(float progress) {
                }

                @Override
                public void onDownloaded(FileSystemReference reference) {
                    isLoaded = true;
                    PipelineDraweeControllerBuilder dController = Fresco.newDraweeControllerBuilder();
                    if (smallDescriptor != null) {
                        dController.setLowResImageRequest(ImageRequest.fromUri(Uri.fromFile(new File(smallDescriptor))));
                    }
                    dController.setOldController(getController());
                    dController.setImageRequest(ImageRequest.fromUri(Uri.fromFile(new File(reference.getDescriptor()))));
                    setController(dController.build());
                }
            });
        }
    }
}
Also used : FileSystemReference(im.actor.runtime.files.FileSystemReference) File(java.io.File) FileVMCallback(im.actor.core.viewmodel.FileVMCallback) PipelineDraweeControllerBuilder(com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder)

Example 14 with FileSystemReference

use of im.actor.runtime.files.FileSystemReference in project actor-platform by actorapp.

the class CallBackgroundAvatarView method bind.

public void bind(Avatar avatar) {
    // Same avatar
    if (avatar != null && getImage(avatar) != null && getImage(avatar).getFileReference().getFileId() == currentId) {
        return;
    }
    fastThumbLoader = new FastThumbLoader(this);
    fastThumbLoader.setBlur(10);
    if (bindedFile != null) {
        bindedFile.detach();
        bindedFile = null;
    }
    setImageURI(null);
    if (avatar == null || getImage(avatar) == null) {
        currentId = 0;
        return;
    }
    currentId = getImage(avatar).getFileReference().getFileId();
    bindedFile = messenger().bindFile(getImage(avatar).getFileReference(), true, new FileVMCallback() {

        @Override
        public void onNotDownloaded() {
        }

        @Override
        public void onDownloading(float progress) {
        }

        @Override
        public void onDownloaded(FileSystemReference reference) {
            blurActor.send(new BlurActor.RequestBlur(reference.getDescriptor(), 10, new BlurActor.BluredListener() {

                @Override
                public void onBlured(final File f) {
                    ((BaseActivity) getContext()).runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(f)).setResizeOptions(new ResizeOptions(Screen.getWidth(), Screen.getHeight())).build();
                            PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder().setOldController(getController()).setImageRequest(request).build();
                            setController(controller);
                        }
                    });
                }
            }));
        }
    });
}
Also used : FileSystemReference(im.actor.runtime.files.FileSystemReference) FastThumbLoader(im.actor.sdk.controllers.conversation.view.FastThumbLoader) PipelineDraweeController(com.facebook.drawee.backends.pipeline.PipelineDraweeController) ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) BaseActivity(im.actor.sdk.controllers.activity.BaseActivity) File(java.io.File) FileVMCallback(im.actor.core.viewmodel.FileVMCallback)

Example 15 with FileSystemReference

use of im.actor.runtime.files.FileSystemReference in project actor-platform by actorapp.

the class MessagesModule method sendVideo.

public void sendVideo(Peer peer, String fileName, int w, int h, int duration, FastThumb fastThumb, String descriptor) {
    FileSystemReference reference = Storage.fileFromDescriptor(descriptor);
    sendMessageActor.send(new SenderActor.SendVideo(peer, fileName, w, h, duration, fastThumb, descriptor, reference.getSize()));
}
Also used : FileSystemReference(im.actor.runtime.files.FileSystemReference) SenderActor(im.actor.core.modules.messaging.actions.SenderActor)

Aggregations

FileSystemReference (im.actor.runtime.files.FileSystemReference)18 FileVMCallback (im.actor.core.viewmodel.FileVMCallback)6 File (java.io.File)6 SenderActor (im.actor.core.modules.messaging.actions.SenderActor)5 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)4 PipelineDraweeController (com.facebook.drawee.backends.pipeline.PipelineDraweeController)3 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)3 FileReference (im.actor.core.entity.FileReference)3 FileCallback (im.actor.core.viewmodel.FileCallback)3 SpannableStringBuilder (android.text.SpannableStringBuilder)2 FileLocalSource (im.actor.core.entity.content.FileLocalSource)2 FileRemoteSource (im.actor.core.entity.content.FileRemoteSource)2 PhotoContent (im.actor.core.entity.content.PhotoContent)2 Downloaded (im.actor.core.modules.file.entity.Downloaded)2 UploadFileCallback (im.actor.core.viewmodel.UploadFileCallback)2 ImageLoadException (im.actor.sdk.util.images.common.ImageLoadException)2 Activity (android.app.Activity)1 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1