예제 #1
0
 private void List_ItemClick(object sender, ItemClickEventArgs e)
 {
     if (e.ClickedItem is Background wallpaper)
     {
         ViewModel.NavigationService.Navigate(typeof(BackgroundPage), TdBackground.ToString(wallpaper));
     }
 }
예제 #2
0
        public void UpdateMessage(MessageViewModel message)
        {
            _message = message;

            var photo = GetContent(message.Content);

            if (photo == null)
            {
                return;
            }

            Constraint     = message;
            Background     = null;
            Texture.Source = null;

            //UpdateMessageContentOpened(message);

            var small = photo.Thumbnail;
            var big   = photo.DocumentValue;

            if (small != null /*&& small.Photo.Id != big.Photo.Id*/)
            {
                //UpdateThumbnail(message, small.Photo);
            }

            UpdateFile(message, small.File);

            if (message.Content is MessageText text && Uri.TryCreate(text.WebPage?.Url, UriKind.Absolute, out Uri result))
            {
                var background = TdBackground.FromUri(result);
                if (background is BackgroundTypeFill fill)
                {
                    Background      = fill.ToBrush();
                    Texture.Opacity = 1;
                }
                else if (background is BackgroundTypePattern pattern)
                {
                    Background      = pattern.ToBrush();
                    Texture.Opacity = pattern.Intensity / 100d;
                }
                else if (background is BackgroundTypeWallpaper)
                {
                    Background      = null;
                    Texture.Opacity = 1;
                }
            }
        }
예제 #3
0
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            Background background = null;

            if (parameter is string data)
            {
                var split = data.Split('#');
                if (split[0] == Constants.WallpaperLocalFileName && split.Length == 2)
                {
                    background = new Background(Constants.WallpaperLocalId, false, false, split[1], null, new BackgroundTypeWallpaper(false, false));
                }
                else if (split[0] == Constants.WallpaperColorFileName)
                {
                    background = new Background(Constants.WallpaperLocalId, false, false, Constants.WallpaperColorFileName, null, new BackgroundTypeFill(new BackgroundFillSolid(0xdfe4e8)));
                }
                else if (Uri.TryCreate("tg://bg/" + parameter, UriKind.Absolute, out Uri uri))
                {
                    var type = TdBackground.FromUri(uri);
                    if (type is BackgroundTypeFill)
                    {
                        background = new Background(0, false, false, string.Empty, null, type);
                    }
                    else
                    {
                        var response = await ProtoService.SendAsync(new SearchBackground(uri.Segments.Last()));

                        if (response is Background)
                        {
                            background      = response as Background;
                            background.Type = type;
                        }
                        else if (response is Error error)
                        {
                        }
                    }
                }
            }

            if (background == null)
            {
                return;
            }

            Item = background;

            BackgroundFill fill = null;

            if (background.Type is BackgroundTypeFill typeFill)
            {
                fill          = typeFill.Fill;
                Intensity     = 100;
                IsBlurEnabled = false;
            }
            else if (background.Type is BackgroundTypePattern typePattern)
            {
                fill          = typePattern.Fill;
                Intensity     = typePattern.Intensity;
                IsBlurEnabled = false;
            }
            else if (background.Type is BackgroundTypeWallpaper typeWallpaper)
            {
                fill          = null;
                Intensity     = 100;
                IsBlurEnabled = typeWallpaper.IsBlurred;
            }

            if (fill is BackgroundFillSolid fillSolid)
            {
                Color1   = fillSolid.Color.ToColor();
                Color2   = BackgroundColor.Empty;
                Rotation = 0;
            }
            else if (fill is BackgroundFillGradient fillGradient)
            {
                Color1   = fillGradient.TopColor.ToColor();
                Color2   = fillGradient.BottomColor.ToColor();
                Rotation = fillGradient.RotationAngle;
            }

            Delegate?.UpdateBackground(_item);

            if (_item.Type is BackgroundTypePattern || _item.Type is BackgroundTypeFill)
            {
                var response = await ProtoService.SendAsync(new GetBackgrounds());

                if (response is Backgrounds backgrounds)
                {
                    Patterns.ReplaceWith(new[] { new Background(0, true, false, string.Empty, null, new BackgroundTypeFill(new BackgroundFillSolid())) }.Union(backgrounds.BackgroundsValue.Where(x => x.Type is BackgroundTypePattern)));
                    SelectedPattern = backgrounds.BackgroundsValue.FirstOrDefault(x => x.Id == background.Id);
                }
            }

            //if (parameter is string name)
            //{
            //    if (name == Constants.WallpaperLocalFileName)
            //    {
            //        //Item = new Background(Constants.WallpaperLocalId, new PhotoSize[0], 0);
            //    }
            //    else
            //    {
            //        var response = await ProtoService.SendAsync(new SearchBackground(name));
            //        if (response is Background background)
            //        {
            //        }
            //    }

            //}
        }