Search in sources :

Example 6 with FileSystemReference

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

the class DocHolder method onClick.

@Override
public void onClick(final Message currentMessage) {
    if (document.getSource() instanceof FileRemoteSource) {
        FileRemoteSource remoteSource = (FileRemoteSource) document.getSource();
        final FileReference location = remoteSource.getFileReference();
        messenger().requestState(location.getFileId(), new FileCallback() {

            @Override
            public void onNotDownloaded() {
                messenger().startDownloading(location);
            }

            @Override
            public void onDownloading(float progress) {
                messenger().cancelDownloading(location.getFileId());
            }

            @Override
            public void onDownloaded(final FileSystemReference reference) {
                im.actor.runtime.Runtime.postToMainThread(new Runnable() {

                    @Override
                    public void run() {
                        if (document instanceof PhotoContent) {
                            Intents.openMedia(getAdapter().getMessagesFragment().getActivity(), fileIcon, reference.getDescriptor(), currentMessage.getSenderId());
                        } else {
                            try {
                                Activity activity = getAdapter().getMessagesFragment().getActivity();
                                activity.startActivity(Intents.openDoc(document.getName(), reference.getDescriptor()));
                            } catch (Exception e) {
                                Toast.makeText(getAdapter().getMessagesFragment().getActivity(), R.string.toast_unable_open, Toast.LENGTH_LONG).show();
                                e.printStackTrace();
                            }
                        }
                    }
                });
            }
        });
    } else if (document.getSource() instanceof FileLocalSource) {
        messenger().requestUploadState(currentMessage.getRid(), new UploadFileCallback() {

            @Override
            public void onNotUploading() {
                messenger().resumeUpload(currentMessage.getRid());
            }

            @Override
            public void onUploading(float progress) {
                messenger().pauseUpload(currentMessage.getRid());
            }

            @Override
            public void onUploaded() {
            // Nothing to do
            }
        });
    }
}
Also used : FileSystemReference(im.actor.runtime.files.FileSystemReference) UploadFileCallback(im.actor.core.viewmodel.UploadFileCallback) FileCallback(im.actor.core.viewmodel.FileCallback) FileRemoteSource(im.actor.core.entity.content.FileRemoteSource) Activity(android.app.Activity) FileLocalSource(im.actor.core.entity.content.FileLocalSource) UploadFileCallback(im.actor.core.viewmodel.UploadFileCallback) FileReference(im.actor.core.entity.FileReference) ImageLoadException(im.actor.sdk.util.images.common.ImageLoadException) PhotoContent(im.actor.core.entity.content.PhotoContent)

Example 7 with FileSystemReference

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

the class PhotoHolder method onClick.

@Override
public void onClick(final Message currentMessage) {
    final DocumentContent document = (DocumentContent) currentMessage.getContent();
    if (document.getSource() instanceof FileRemoteSource) {
        FileRemoteSource remoteSource = (FileRemoteSource) document.getSource();
        final FileReference location = remoteSource.getFileReference();
        messenger().requestState(location.getFileId(), new FileCallback() {

            @Override
            public void onNotDownloaded() {
                messenger().startDownloading(location);
                playRequested = true;
            }

            @Override
            public void onDownloading(float progress) {
                messenger().cancelDownloading(location.getFileId());
            }

            @Override
            public void onDownloaded(final FileSystemReference reference) {
                im.actor.runtime.Runtime.postToMainThread(new Runnable() {

                    @Override
                    public void run() {
                        if (document instanceof PhotoContent) {
                            Intents.openMedia(getAdapter().getMessagesFragment().getActivity(), previewView, reference.getDescriptor(), currentMessage.getSenderId());
                        } else if (document instanceof VideoContent) {
                            playVideo(document, reference);
                        } else if (document instanceof AnimationContent) {
                            toggleAnimation();
                        }
                    }
                });
            }
        });
    } else if (document.getSource() instanceof FileLocalSource) {
        messenger().requestUploadState(currentMessage.getRid(), new UploadFileCallback() {

            @Override
            public void onNotUploading() {
                messenger().resumeUpload(currentMessage.getRid());
            }

            @Override
            public void onUploading(float progress) {
                messenger().pauseUpload(currentMessage.getRid());
            }

            @Override
            public void onUploaded() {
            // Nothing to do
            }
        });
    }
}
Also used : FileSystemReference(im.actor.runtime.files.FileSystemReference) VideoContent(im.actor.core.entity.content.VideoContent) AnimationContent(im.actor.core.entity.content.AnimationContent) UploadFileCallback(im.actor.core.viewmodel.UploadFileCallback) FileCallback(im.actor.core.viewmodel.FileCallback) FileRemoteSource(im.actor.core.entity.content.FileRemoteSource) DocumentContent(im.actor.core.entity.content.DocumentContent) FileLocalSource(im.actor.core.entity.content.FileLocalSource) UploadFileCallback(im.actor.core.viewmodel.UploadFileCallback) FileReference(im.actor.core.entity.FileReference) PhotoContent(im.actor.core.entity.content.PhotoContent)

Example 8 with FileSystemReference

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

the class StickerView method bind.

public void bind(FileReference fileReference, int size) {
    if (this.fileReference != null && this.fileReference.equals(fileReference)) {
        return;
    }
    if (bindedFile != null) {
        bindedFile.detach();
        bindedFile = null;
    }
    setImageURI(null);
    this.fileReference = fileReference;
    bindedFile = messenger().bindFile(fileReference, true, new FileVMCallback() {

        private boolean isFastThumbLoaded = false;

        private void checkFastThumb() {
            if (!isFastThumbLoaded) {
                isFastThumbLoaded = true;
            //                    if (sticker.getThumb() != null) {
            //                        fastThumbLoader.request(sticker.getThumb());
            //                    }
            }
        }

        @Override
        public void onNotDownloaded() {
            checkFastThumb();
        }

        @Override
        public void onDownloading(float progress) {
            checkFastThumb();
        }

        @Override
        public void onDownloaded(FileSystemReference reference) {
            imageFile = new File(reference.getDescriptor());
            ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(imageFile)).setAutoRotateEnabled(true).build();
            PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder().setOldController(getController()).setImageRequest(request).build();
            setController(controller);
            loaded = true;
        }
    });
}
Also used : FileSystemReference(im.actor.runtime.files.FileSystemReference) PipelineDraweeController(com.facebook.drawee.backends.pipeline.PipelineDraweeController) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) File(java.io.File) FileVMCallback(im.actor.core.viewmodel.FileVMCallback)

Example 9 with FileSystemReference

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

the class AvatarView method bind.

public void bind(Avatar avatar, String title, int id) {
    // Same avatar
    if (avatar != null && getImage(avatar) != null && getImage(avatar).getFileReference().getFileId() == currentId) {
        return;
    }
    getHierarchy().setPlaceholderImage(new AvatarPlaceholderDrawable(title, id, placeholderTextSize, getContext()));
    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) {
            ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(new File(reference.getDescriptor()))).setResizeOptions(new ResizeOptions(size, size)).build();
            PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder().setOldController(getController()).setImageRequest(request).build();
            setController(controller);
        }
    });
}
Also used : FileSystemReference(im.actor.runtime.files.FileSystemReference) PipelineDraweeController(com.facebook.drawee.backends.pipeline.PipelineDraweeController) ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) File(java.io.File) FileVMCallback(im.actor.core.viewmodel.FileVMCallback)

Example 10 with FileSystemReference

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

the class DialogView method buildLayout.

@Override
public DialogLayout buildLayout(Dialog arg, int width, int height) {
    if (!isStylesLoaded) {
        isStylesLoaded = true;
        ActorStyle style = ActorSDK.sharedActor().style;
        Context context = getContext();
        titlePaint = createTextPaint(Fonts.medium(), 16, style.getDialogsTitleColor());
        titleSecurePaint = createTextPaint(Fonts.medium(), 16, style.getDialogsTitleSecureColor());
        datePaint = createTextPaint(Fonts.regular(), 14, style.getDialogsTimeColor());
        textPaint = createTextPaint(Fonts.regular(), 16, style.getDialogsTimeColor());
        textActivePaint = createTextPaint(Fonts.regular(), 16, style.getDialogsActiveTextColor());
        senderTextColor = style.getDialogsActiveTextColor();
        groupIcon = new TintDrawable(context.getResources().getDrawable(R.drawable.ic_group_black_18dp), style.getDialogsTitleColor());
        channelIcon = new TintDrawable(context.getResources().getDrawable(R.drawable.ic_megaphone_18dp_black), style.getDialogsTitleColor());
        botIcon = new TintDrawable(context.getResources().getDrawable(R.drawable.ic_robot_black_18dp), style.getDialogsTitleColor());
        secretIcon = new TintDrawable(context.getResources().getDrawable(R.drawable.ic_lock_black_18dp), style.getDialogsTitleSecureColor());
        counterTextPaint = createTextPaint(Fonts.medium(), 14, style.getDialogsCounterTextColor());
        counterTextPaint.setTextAlign(Paint.Align.CENTER);
        counterBgPaint = createFilledPaint(style.getDialogsCounterBackgroundColor());
        fillPaint = createFilledPaint(Color.BLACK);
        placeholderColors = ActorSDK.sharedActor().style.getDefaultAvatarPlaceholders();
        avatarBorder = new Paint();
        avatarBorder.setStyle(Paint.Style.STROKE);
        avatarBorder.setAntiAlias(true);
        avatarBorder.setColor(0x19000000);
        avatarBorder.setStrokeWidth(1);
        avatarTextColor = createTextPaint(Fonts.regular(), 20, Color.WHITE);
        avatarTextColor.setTextAlign(Paint.Align.CENTER);
        typingText = messenger().getFormatter().formatTyping();
        stateSent = new TintDrawable(context.getResources().getDrawable(R.drawable.msg_check_1), style.getDialogsStateSentColor());
        stateReceived = new TintDrawable(context.getResources().getDrawable(R.drawable.msg_check_2), style.getDialogsStateDeliveredColor());
        stateRead = new TintDrawable(context.getResources().getDrawable(R.drawable.msg_check_2), style.getDialogsStateReadColor());
    }
    DialogLayout res = new DialogLayout();
    res.setPlaceholderIndex(Math.abs(arg.getPeer().getPeerId()) % placeholderColors.length);
    res.setShortName(buildShortName(arg.getDialogTitle()));
    if (arg.getDialogAvatar() != null) {
        AvatarImage image = getAvatarImage(arg.getDialogAvatar());
        if (image != null) {
            String desc = messenger().findDownloadedDescriptor(image.getFileReference().getFileId());
            if (desc != null) {
                ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(new File(desc))).setResizeOptions(new ResizeOptions(Screen.dp(52), Screen.dp(52))).setImageType(ImageRequest.ImageType.SMALL).build();
                res.setImageRequest(request);
            } else {
                InvalidationContext invalidationContext = getCurrentLayoutContext();
                messenger().bindRawFile(image.getFileReference(), true, new FileCallback() {

                    @Override
                    public void onNotDownloaded() {
                        if (invalidationContext.isCancelled()) {
                            messenger().unbindRawFile(image.getFileReference().getFileId(), false, this);
                        }
                    }

                    @Override
                    public void onDownloading(float progress) {
                        if (invalidationContext.isCancelled()) {
                            messenger().unbindRawFile(image.getFileReference().getFileId(), false, this);
                        }
                    }

                    @Override
                    public void onDownloaded(FileSystemReference reference) {
                        messenger().unbindRawFile(image.getFileReference().getFileId(), false, this);
                        invalidationContext.invalidate();
                    }
                });
            }
        }
    }
    // Top Row
    int maxTitleWidth = (width - Screen.dp(72)) - Screen.dp(8);
    if (arg.getDate() > 0) {
        String dateText = messenger().getFormatter().formatShortDate(arg.getDate());
        int dateWidth = (int) datePaint.measureText(dateText);
        res.setDate(dateText, dateWidth);
        maxTitleWidth -= dateWidth + Screen.dp(16);
    }
    if (arg.getPeer().getPeerType() == PeerType.GROUP) {
        if (arg.isChannel()) {
            res.setTitleIcon(channelIcon);
            res.setTitleIconTop(Screen.dp(33));
        } else {
            res.setTitleIcon(groupIcon);
            res.setTitleIconTop(Screen.dp(33));
        }
        maxTitleWidth -= Screen.dp(16 + /*icon width*/
        4);
    } else if (arg.getPeer().getPeerType() == PeerType.PRIVATE_ENCRYPTED) {
        res.setTitleIcon(secretIcon);
        res.setTitleIconTop(Screen.dp(31));
        maxTitleWidth -= Screen.dp(16 + /*icon width*/
        4);
    } else if (arg.getPeer().getPeerType() == PeerType.PRIVATE) {
        if (arg.isBot()) {
            res.setTitleIcon(botIcon);
            res.setTitleIconTop(Screen.dp(33));
            maxTitleWidth -= Screen.dp(16 + /*icon width*/
            4);
        }
    }
    if (arg.getSenderId() == messenger().myUid()) {
        if (arg.isRead()) {
            res.setState(stateRead);
        } else if (arg.isReceived()) {
            res.setState(stateReceived);
        } else {
            res.setState(stateSent);
        }
        maxTitleWidth -= Screen.dp(20);
    }
    res.setTitleLayout(singleLineText(arg.getDialogTitle(), arg.getPeer().getPeerType() == PeerType.PRIVATE_ENCRYPTED ? titleSecurePaint : titlePaint, maxTitleWidth));
    // Second Row
    int maxWidth = width - Screen.dp(72) - Screen.dp(8);
    if (arg.getUnreadCount() > 0) {
        String counterText = "" + arg.getUnreadCount();
        int counterWidth = (int) counterTextPaint.measureText(counterText) + Screen.sp(10);
        counterWidth = Math.max(counterWidth, Screen.dp(22));
        res.setCounter(counterText, counterWidth);
        maxWidth -= counterWidth + Screen.dp(8);
    }
    if (arg.getSenderId() > 0) {
        String contentText = messenger().getFormatter().formatContentText(arg.getSenderId(), arg.getMessageType(), arg.getText().replace("\n", " "), arg.getRelatedUid(), arg.isChannel());
        if (arg.getPeer().getPeerType() == PeerType.GROUP) {
            if (messenger().getFormatter().isLargeDialogMessage(arg.getMessageType())) {
                res.setTextLayout(singleLineText(handleEmoji(contentText), textActivePaint, maxWidth));
            } else {
                String senderName = messenger().getFormatter().formatPerformerName(arg.getSenderId()) + ": ";
                if (arg.getMessageType() == ContentType.TEXT) {
                    SpannableStringBuilder builder = new SpannableStringBuilder();
                    builder.append(senderName);
                    builder.setSpan(new ForegroundColorSpan(senderTextColor), 0, senderName.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
                    builder.append(contentText);
                    res.setTextLayout(singleLineText(builder, textPaint, maxWidth));
                } else {
                    CharSequence contentResult = handleEmoji(senderName, contentText);
                    res.setTextLayout(singleLineText(contentResult, textActivePaint, maxWidth));
                }
            }
        } else {
            if (arg.getMessageType() == ContentType.TEXT) {
                res.setTextLayout(singleLineText(handleEmoji(contentText), textPaint, maxWidth));
            } else {
                res.setTextLayout(singleLineText(handleEmoji(contentText), textActivePaint, maxWidth));
            }
        }
    }
    return res;
}
Also used : Context(android.content.Context) FileSystemReference(im.actor.runtime.files.FileSystemReference) ForegroundColorSpan(android.text.style.ForegroundColorSpan) TintDrawable(im.actor.sdk.view.TintDrawable) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) FileCallback(im.actor.core.viewmodel.FileCallback) ActorStyle(im.actor.sdk.ActorStyle) ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) AvatarImage(im.actor.core.entity.AvatarImage) File(java.io.File) SpannableStringBuilder(android.text.SpannableStringBuilder)

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