Пример #1
0
        private string GetString(int seconds, object parameter)
        {
            var param = parameter as string;

            if (param.Equals("short"))
            {
                //if (seconds >= 1 && seconds < 21)
                //{
                //    return seconds.ToString();
                //}

                //return ((seconds / 5) + 16).ToString();

                return(seconds.ToString());
            }

            if (seconds >= 1 && seconds < 21)
            {
                return(Locale.FormatTTLString(seconds));
            }

            return(Locale.FormatTTLString((seconds - 16) * 5));
        }
Пример #2
0
        public void UpdateFile(MessageViewModel message, File file)
        {
            var photo = GetContent(message.Content);

            if (photo == null)
            {
                return;
            }

            var small = photo.GetSmall();
            var big   = photo.GetBig();

            if (small != null && small.Photo.Id != big.Photo.Id && small.Photo.Id == file.Id)
            {
                UpdateThumbnail(message, file);
                return;
            }
            else if (big == null || big.Photo.Id != file.Id)
            {
                return;
            }

            var size = Math.Max(file.Size, file.ExpectedSize);

            if (file.Local.IsDownloadingActive)
            {
                Button.Glyph    = "\uE10A";
                Button.Progress = (double)file.Local.DownloadedSize / size;

                Button.Opacity  = 1;
                Overlay.Opacity = 0;
            }
            else if (file.Remote.IsUploadingActive)
            {
                Button.Glyph    = "\uE10A";
                Button.Progress = (double)file.Remote.UploadedSize / size;

                Button.Opacity  = 1;
                Overlay.Opacity = 0;
            }
            else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingCompleted)
            {
                Button.Glyph    = "\uE118";
                Button.Progress = 0;

                Button.Opacity  = 1;
                Overlay.Opacity = 0;

                if (message.Delegate.CanBeDownloaded(message))
                {
                    _message.ProtoService.Send(new DownloadFile(file.Id, 32));
                }
            }
            else
            {
                if (message.IsBlurred())
                {
                    Button.Glyph    = "\uE60D";
                    Button.Progress = 1;

                    Button.Opacity  = 1;
                    Overlay.Opacity = 1;

                    Subtitle.Text = Locale.FormatTTLString(message.Ttl, true);
                }
                else
                {
                    Button.Glyph    = "\uE102";
                    Button.Progress = 1;

                    Button.Opacity  = 0;
                    Overlay.Opacity = 0;

                    Texture.Source = new BitmapImage(new Uri("file:///" + file.Local.Path));
                }
            }
        }
 public object Convert(object value, Type targetType, object parameter, string language)
 {
     return(Locale.FormatTTLString(System.Convert.ToInt32(value)));
 }
        public void UpdateFile(MessageViewModel message, File file)
        {
            var video = GetContent(message.Content);

            if (video == null)
            {
                return;
            }

            if (video.Thumbnail != null && video.Thumbnail.Photo.Id == file.Id)
            {
                UpdateThumbnail(message, file);
                return;
            }
            else if (video.VideoValue.Id != file.Id)
            {
                return;
            }

            var size = Math.Max(file.Size, file.ExpectedSize);

            if (file.Local.IsDownloadingActive)
            {
                Button.Glyph    = "\uE10A";
                Button.Progress = (double)file.Local.DownloadedSize / size;

                Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Local.DownloadedSize, size), FileSizeConverter.Convert(size));
            }
            else if (file.Remote.IsUploadingActive || message.SendingState is MessageSendingStateFailed)
            {
                Button.Glyph    = "\uE10A";
                Button.Progress = (double)file.Remote.UploadedSize / size;

                Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Remote.UploadedSize, size), FileSizeConverter.Convert(size));
            }
            else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingCompleted)
            {
                Button.Glyph    = "\uE118";
                Button.Progress = 0;

                Subtitle.Text = video.GetDuration() + ", " + FileSizeConverter.Convert(size);

                if (message.Delegate.CanBeDownloaded(message))
                {
                    _message.ProtoService.Send(new DownloadFile(file.Id, 32));
                }
            }
            else
            {
                if (message.IsSecret())
                {
                    Button.Glyph    = "\uE60D";
                    Button.Progress = 1;

                    Subtitle.Text = Locale.FormatTTLString(Math.Max(message.Ttl, video.Duration), true);
                }
                else
                {
                    Button.Glyph    = "\uE102";
                    Button.Progress = 1;

                    Subtitle.Text = video.GetDuration();
                }
            }
        }