示例#1
0
        private void SetWebPSource(ITLTransferable transferable, TLDocument document, int fileSize, int phase)
        {
            if (phase >= Phase && document != null)
            {
                Phase = phase;

                var fileName = document.GetFileName();
                if (File.Exists(FileUtils.GetTempFileName(fileName)))
                {
                    //Image.UriSource = FileUtils.GetTempFileUri(fileName);
                    Image.SetSource(WebPImage.Encode(File.ReadAllBytes(FileUtils.GetTempFileName(fileName))));
                }
                else
                {
                    Execute.BeginOnThreadPool(async() =>
                    {
                        var result = await _downloadFileManager.DownloadFileAsync(fileName, document.DCId, document.ToInputFileLocation(), fileSize).AsTask(transferable?.Download());
                        if (result != null && Phase <= phase)
                        {
                            Execute.BeginOnUIThread(() =>
                            {
                                if (transferable != null)
                                {
                                    transferable.IsTransferring = false;
                                }

                                //Image.UriSource = FileUtils.GetTempFileUri(fileName);
                                Image.SetSource(WebPImage.Encode(File.ReadAllBytes(FileUtils.GetTempFileName(fileName))));
                            });
                        }
                    });
                }
            }
        }
示例#2
0
        private void SetWebPSource(ITLTransferable transferable, TLFileLocation location, int fileSize, int phase)
        {
            if (phase >= Phase && location != null)
            {
                Phase = phase;

                var fileName = string.Format("{0}_{1}_{2}.jpg", location.VolumeId, location.LocalId, location.Secret);
                if (File.Exists(FileUtils.GetTempFileName(fileName)))
                {
                    //Image.UriSource = FileUtils.GetTempFileUri(fileName);
                    _bitmapImage.SetSource(WebPImage.Encode(File.ReadAllBytes(FileUtils.GetTempFileName(fileName))));
                }
                else
                {
                    Execute.BeginOnThreadPool(async() =>
                    {
                        var result = await _downloadManager.DownloadFileAsync(location, fileSize).AsTask(transferable?.Download());
                        if (result != null && Phase <= phase)
                        {
                            Execute.BeginOnUIThread(() =>
                            {
                                if (transferable != null)
                                {
                                    transferable.IsTransferring = false;
                                }

                                //Image.UriSource = FileUtils.GetTempFileUri(fileName);
                                _bitmapImage.SetSource(WebPImage.Encode(File.ReadAllBytes(FileUtils.GetTempFileName(fileName))));
                            });
                        }
                    });
                }
            }
        }
示例#3
0
 public GalleryItem(ITLTransferable source, string caption, ITLDialogWith from, int date, bool stickers)
 {
     Source      = source;
     Caption     = caption;
     From        = from;
     Date        = date;
     HasStickers = stickers;
 }
示例#4
0
        private string UpdateGlyph(ITLTransferable newValue, ITLTransferable oldValue)
        {
            if (newValue is TLPhoto photo)
            {
                return(UpdateGlyph(photo));
            }
            else if (newValue is TLDocument document)
            {
                return(UpdateGlyph(document));
            }

            return("\uE118");
        }
示例#5
0
 private void SetSource(ITLTransferable transferable, TLPhotoSizeBase photoSizeBase, int phase)
 {
     if (photoSizeBase is TLPhotoSize photoSize)
     {
         SetSource(transferable, photoSize.Location as TLFileLocation, photoSize.Size, phase);
     }
     else if (photoSizeBase is TLPhotoCachedSize photoCachedSize)
     {
         if (phase >= Phase)
         {
             Phase = phase;
             _bitmapImage.SetSource(photoCachedSize.Bytes);
         }
     }
 }
        private Progress<double> Upload(ITLTransferable document, Func<int, TLSendMessageActionBase> action, double delta = 0.0, double divider = 1.0)
        {
            document.IsTransferring = true;

            return new Progress<double>((value) =>
            {
                var local = value / divider;

                document.IsTransferring = local < 1 && local > 0;
                document.UploadingProgress = delta + local;
                Debug.WriteLine(value);

                OutputTypingManager.SetTyping(action((int)local * 100));
            });
        }
示例#7
0
        private void SetWebPSource(ITLTransferable transferable, TLPhotoSizeBase photoSizeBase, int phase)
        {
            var photoSize = photoSizeBase as TLPhotoSize;

            if (photoSize != null)
            {
                SetWebPSource(transferable, photoSize.Location as TLFileLocation, photoSize.Size, phase);
            }

            var photoCachedSize = photoSizeBase as TLPhotoCachedSize;

            if (photoCachedSize != null)
            {
                if (phase >= Phase)
                {
                    Phase = phase;
                    _bitmapImage.SetSource(photoCachedSize.Bytes);
                }
            }
        }
示例#8
0
        private void SetDownloadSource(ITLTransferable transferable, TLDocument document, int fileSize, int phase)
        {
            if (phase >= Phase && document != null)
            {
                //Phase = phase;

                var fileName = document.GetFileName();
                if (File.Exists(FileUtils.GetTempFileName(fileName)))
                {
                }
                else
                {
                    Execute.BeginOnThreadPool(async() =>
                    {
                        var result = await _downloadFileManager.DownloadFileAsync(fileName, document.DCId, document.ToInputFileLocation(), fileSize, transferable?.Download());
                        if (result != null && Phase <= phase)
                        {
                            //Phase = phase;
                        }
                    });
                }
            }
        }
示例#9
0
 private void OnTransferableChanged(ITLTransferable newValue, ITLTransferable oldValue)
 {
     Glyph = UpdateGlyph(newValue, oldValue);
 }