Ejemplo n.º 1
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var file = await Package.Current.InstalledLocation.GetFileAsync($"{_stickers[index]}.tgs");

                var result = await file.CopyAsync(ApplicationData.Current.LocalFolder, file.Name, NameCollisionOption.ReplaceExisting);

                var cache = await ApplicationData.Current.LocalFolder.TryGetItemAsync($"{file.Name}.cache");

                if (cache != null)
                {
                    await file.DeleteAsync();
                }

                //await Task.Run(() => LottieAnimation.LoadFromFile(result.Path, false, null).RenderSync(Path.Combine(ApplicationData.Current.LocalFolder.Path, "test.png"), 512, 512, 0));
            }
            catch { }

            //return;

            var player = new LottieView
            {
                AutoPlay = true,
                Width    = 200,
                Height   = 200,
                Source   = new Uri($"ms-appdata://local/{_stickers[index]}.tgs")
            };

            Panel.Children.Add(player);

            index = (index + 1) % _stickers.Length;
        }
Ejemplo n.º 2
0
        private void CommonInit()
        {
            ContentView = ViewFromNib();

            NoDataLabel.Text = Localize.GetText("State.NoDate");

            ContentView.Frame            = Frame;
            ContentView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight & UIViewAutoresizing.FlexibleWidth;
            AutoresizingMask             = UIViewAutoresizing.FlexibleHeight & UIViewAutoresizing.FlexibleWidth;

            AddSubview(ContentView);

            TranslatesAutoresizingMaskIntoConstraints             = false;
            ContentView.TranslatesAutoresizingMaskIntoConstraints = false;

            ContentView.LeadingAnchor.ConstraintEqualTo(LeadingAnchor).Active   = true;
            ContentView.TrailingAnchor.ConstraintEqualTo(TrailingAnchor).Active = true;
            ContentView.BottomAnchor.ConstraintEqualTo(BottomAnchor).Active     = true;
            ContentView.TopAnchor.ConstraintEqualTo(TopAnchor).Active           = true;

            LOTAnimationView lottie = LOTAnimationView.AnimationNamed("no-data");

            lottie.ContentMode = UIViewContentMode.ScaleAspectFit;
            LottieView.Frame   = new CGRect(LottieView.Frame.X, LottieView.Frame.Y, Frame.Width, Frame.Width);
            lottie.Frame       = LottieView.Frame;
            LottieView.AddSubview(lottie);
            lottie.SetFillXContraintTo(LottieView, 16);
            lottie.SetFillYContraintTo(LottieView, 16);
            lottie.SetBottomContraintTo(LottieView, 0, NSLayoutRelation.GreaterThanOrEqual);
            AddConstraint(NSLayoutConstraint.Create(lottie, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1, 0));
            lottie.Play();
        }
Ejemplo n.º 3
0
        private void CommonInit()
        {
            ContentView       = ViewFromNib();
            ContentView.Frame = Frame;

            NoInternetLabel.Text        = Localize.GetText("State.NoInternet.Message");
            UpdateButton.TouchUpInside += (sender, e) => {
                RefreshCommand.Execute();
            };
            AddSubview(ContentView);

            ContentView.LeadingAnchor.ConstraintEqualTo(LeadingAnchor).Active   = true;
            ContentView.TrailingAnchor.ConstraintEqualTo(TrailingAnchor).Active = true;
            ContentView.BottomAnchor.ConstraintEqualTo(BottomAnchor).Active     = true;
            ContentView.TopAnchor.ConstraintEqualTo(TopAnchor).Active           = true;

            LOTAnimationView lottie = LOTAnimationView.AnimationNamed("no-internet-connection");

            lottie.ContentMode = UIViewContentMode.ScaleAspectFit;
            LottieView.Frame   = new CGRect(LottieView.Frame.X, LottieView.Frame.Y, Frame.Width, Frame.Width);

            LottieView.AddSubview(lottie);
            lottie.Frame = LottieView.Bounds;
            lottie.SetFillXContraintTo(LottieView);
            lottie.LoopAnimation = true;
            lottie.Play();
        }
Ejemplo n.º 4
0
        public void PlayPremium(MessageViewModel message, Sticker sticker)
        {
            if (Interactions == null)
            {
                InteractionsPopup = GetTemplateChild(nameof(InteractionsPopup)) as Popup;
                Interactions      = GetTemplateChild(nameof(Interactions)) as Grid;
            }

            var file = sticker.PremiumAnimation;

            if (file.Local.IsFileExisting() && Interactions.Children.Count < 1)
            {
                var dispatcher = DispatcherQueue.GetForCurrentThread();

                var player = new LottieView();
                player.Width            = 270;
                player.Height           = 270;
                player.IsFlipped        = !message.IsOutgoing;
                player.IsLoopingEnabled = false;
                player.IsHitTestVisible = false;
                player.FrameSize        = new Size(270 * 2, 270 * 2);
                player.Source           = UriEx.ToLocal(file.Local.Path);
                player.PositionChanged += (s, args) =>
                {
                    if (args == 1)
                    {
                        dispatcher.TryEnqueue(() =>
                        {
                            Interactions.Children.Remove(player);
                            InteractionsPopup.IsOpen = false;
                        });
                    }
                };

                var left   = 75;
                var right  = 15;
                var top    = 45;
                var bottom = 45;

                if (message.IsOutgoing)
                {
                    player.Margin = new Thickness(-left, -top, -right, -bottom);
                }
                else
                {
                    player.Margin = new Thickness(-right, -top, -left, -bottom);
                }

                Interactions.Children.Add(player);
                InteractionsPopup.IsOpen = true;
            }
            else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive)
            {
                message.Delegate.DownloadFile(message, file);
                UpdateManager.Subscribe(this, message, file, ref _interactionToken, UpdateFile, true);
            }
        }
Ejemplo n.º 5
0
        protected override void OnApplyTemplate()
        {
            Player = GetTemplateChild(nameof(Player)) as LottieView;
            Player.FirstFrameRendered += Player_FirstFrameRendered;

            _templateApplied = true;

            if (_message != null)
            {
                UpdateMessage(_message);
            }
        }
Ejemplo n.º 6
0
        void ReleaseDesignerOutlets()
        {
            if (LottieView != null)
            {
                LottieView.Dispose();
                LottieView = null;
            }

            if (NoDataLabel != null)
            {
                NoDataLabel.Dispose();
                NoDataLabel = null;
            }
        }
Ejemplo n.º 7
0
        protected override void OnAppearing()
        {
            base.OnAppearing();

            MessagingCenter.Subscribe <MainViewModel>(this, AppSettings.PlayMessage, (sender) =>
            {
                LottieView.Play();
            });

            MessagingCenter.Subscribe <MainViewModel>(this, AppSettings.PauseMessage, (sender) =>
            {
                LottieView.Pause();
            });
        }
Ejemplo n.º 8
0
        void ReleaseDesignerOutlets()
        {
            if (LottieView != null)
            {
                LottieView.Dispose();
                LottieView = null;
            }

            if (NoInternetLabel != null)
            {
                NoInternetLabel.Dispose();
                NoInternetLabel = null;
            }

            if (UpdateButton != null)
            {
                UpdateButton.Dispose();
                UpdateButton = null;
            }
        }
Ejemplo n.º 9
0
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            var localDir = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync(@"Assets");

            var file = await localDir.GetFileAsync("test.json");

            var json = await FileIO.ReadTextAsync(file, Windows.Storage.Streams.UnicodeEncoding.Utf8);

            await LottieView.SetAnimationFromJsonAsync(json, "test");

            var compositionResult = await LottieCompositionFactory.FromJsonString(json, "test");

            if (compositionResult.Value != null)
            {
                LottieDrawable.SetComposition(compositionResult.Value);
                LottieDrawable.RepeatCount = -1;
                LottieDrawable.PlayAnimation();
            }

            LottieView.PlayAnimation();
        }
        private void Reaction_Click(object sender, RoutedEventArgs e)
        {
            if (sender is HyperlinkButton button && button.Tag is Reaction reaction && button.Content is LottieView centerView)
            {
                var center = reaction.CenterAnimation.StickerValue;
                var around = reaction.AroundAnimation.StickerValue;

                if (center.Local.IsFileExisting() && around.Local.IsFileExisting())
                {
                    var transform = button.TransformToVisual(this);
                    var point     = transform.TransformPoint(new Windows.Foundation.Point());

                    var dispatcher = DispatcherQueue.GetForCurrentThread();

                    var aroundView = new LottieView();
                    aroundView.Width               = 64 * 3;
                    aroundView.Height              = 64 * 3;
                    aroundView.IsLoopingEnabled    = false;
                    aroundView.FrameSize           = new Size(64 * 3, 64 * 3);
                    aroundView.DecodeFrameType     = DecodePixelType.Logical;
                    aroundView.Source              = UriEx.ToLocal(around.Local.Path);
                    aroundView.Margin              = new Thickness(point.X - 64, point.Y - 64, 0, 0);
                    aroundView.HorizontalAlignment = HorizontalAlignment.Left;
                    aroundView.VerticalAlignment   = VerticalAlignment.Top;
                    aroundView.PositionChanged    += (s, args) =>
                    {
                        if (args == 1)
                        {
                            dispatcher.TryEnqueue(() => Overlay.Children.Remove(aroundView));
                        }
                    };

                    centerView.Play();
                    Overlay.Children.Add(aroundView);
                }
            }
        }
Ejemplo n.º 11
0
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            var localDir = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync(@"Assets");

            var file = await localDir.GetFileAsync("test.json");

            var json = await FileIO.ReadTextAsync(file, Windows.Storage.Streams.UnicodeEncoding.Utf8);

            _drawForCanvas = new LottieDrawable();

            await LottieView.SetAnimationFromJsonAsync(json);

            var composition = await LottieComposition.Factory.FromJsonStringAsync(json);

            LottieDrawable.SetComposition(composition);
            LottieDrawable.RepeatCount = -1;
            _drawForCanvas.SetComposition(composition);
            _drawForCanvas.RepeatCount = -1;
            _inited = true;

            LottieView.PlayAnimation();
            LottieDrawable.PlayAnimation();
            _drawForCanvas.PlayAnimation();
        }
        public void UpdateFeature(IProtoService protoService)
        {
            var reactions = protoService.Reactions.Values.Where(x => x.IsPremium).ToList();

            var cols = 4;
            var rows = (int)Math.Ceiling((double)reactions.Count / cols);

            Presenter.ColumnDefinitions.Clear();
            Presenter.RowDefinitions.Clear();

            for (int y = 0; y < rows; y++)
            {
                for (int x = 0; x < cols; x++)
                {
                    var i = x + y * cols;

                    var button = Presenter.Children[i] as HyperlinkButton;
                    if (button == null)
                    {
                        if (i < reactions.Count)
                        {
                            var item = reactions[i];

                            var view2 = new LottieView();
                            view2.AutoPlay         = false;
                            view2.IsLoopingEnabled = false;
                            view2.FrameSize        = new Size(64, 64);
                            view2.DecodeFrameType  = DecodePixelType.Logical;
                            view2.Width            = 64;
                            view2.Height           = 64;

                            protoService.DownloadFile(item.AroundAnimation.StickerValue.Id, 32);

                            var file = item.CenterAnimation.StickerValue;
                            if (file.Local.IsFileExisting())
                            {
                                view2.Source = UriEx.ToLocal(file.Local.Path);
                            }
                            else
                            {
                                view2.Source = null;

                                UpdateManager.Subscribe(view2, protoService, file, /*UpdateReaction*/ UpdateFile, true);

                                if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive)
                                {
                                    protoService.DownloadFile(file.Id, 32);
                                }
                            }

                            button = new HyperlinkButton
                            {
                                Tag     = reactions[i],
                                Content = view2,
                                Style   = BootStrapper.Current.Resources["EmptyHyperlinkButtonStyle"] as Style
                            };

                            button.Click += Reaction_Click;
                            Presenter.Children.Add(button);
                        }
                        else
                        {
                            continue;
                        }
                    }

                    Grid.SetColumn(button, x);
                    Grid.SetRow(button, y);

                    if (y == 0)
                    {
                        Presenter.ColumnDefinitions.Add(new ColumnDefinition {
                            Width = new GridLength(1, GridUnitType.Auto)
                        });
                    }
                }

                Presenter.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(1, GridUnitType.Auto)
                });
            }
        }
Ejemplo n.º 13
0
        public void PlayInteraction(MessageViewModel message, Sticker interaction)
        {
            if (Interactions == null)
            {
                InteractionsPopup = GetTemplateChild(nameof(InteractionsPopup)) as Popup;
                Interactions      = GetTemplateChild(nameof(Interactions)) as Grid;
            }

            message.Interaction = null;

            var file = interaction.StickerValue;

            if (file.Local.IsFileExisting() && Interactions.Children.Count < 4)
            {
                var dispatcher = DispatcherQueue.GetForCurrentThread();

                var player = new LottieView();
                player.Width            = Player.Height * 3;
                player.Height           = Player.Height * 3;
                player.IsFlipped        = !message.IsOutgoing;
                player.IsLoopingEnabled = false;
                player.IsHitTestVisible = false;
                player.FrameSize        = new Size(512, 512);
                player.Source           = UriEx.ToLocal(file.Local.Path);
                player.PositionChanged += (s, args) =>
                {
                    if (args == 1)
                    {
                        dispatcher.TryEnqueue(() =>
                        {
                            Interactions.Children.Remove(player);

                            if (Interactions.Children.Count > 0)
                            {
                                return;
                            }

                            InteractionsPopup.IsOpen = false;
                        });
                    }
                };

                var random = new Random();
                var x      = Player.Height * (0.08 - (0.16 * random.NextDouble()));
                var y      = Player.Height * (0.08 - (0.16 * random.NextDouble()));
                var shift  = Player.Width * 0.075;

                var left   = (Player.Width * 2) - shift + x;
                var right  = 0 + shift - x;
                var top    = Player.Height + y;
                var bottom = Player.Height - y;

                if (message.IsOutgoing)
                {
                    player.Margin = new Thickness(-left, -top, -right, -bottom);
                }
                else
                {
                    player.Margin = new Thickness(-right, -top, -left, -bottom);
                }

                Interactions.Children.Add(player);
                InteractionsPopup.IsOpen = true;
            }
            else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive)
            {
                message.Interaction = interaction;
                message.Delegate.DownloadFile(message, file);

                UpdateManager.Subscribe(this, message, file, ref _interactionToken, UpdateFile, true);
            }
        }
Ejemplo n.º 14
0
 public MainPage()
 {
     InitializeComponent();
     LottieView.Play();
 }
Ejemplo n.º 15
0
        private void Animate()
        {
            var reaction = _reaction;

            if (reaction == null)
            {
                return;
            }

            var center = reaction.CenterAnimation?.StickerValue;
            var around = reaction.AroundAnimation?.StickerValue;

            if (center == null || around == null)
            {
                return;
            }

            if (center.Local.IsFileExisting() && around.Local.IsFileExisting())
            {
                var presenter = Presenter;
                var popup     = Overlay;

                var dispatcher = DispatcherQueue.GetForCurrentThread();

                var centerView = new LottieView();
                centerView.Width               = 32;
                centerView.Height              = 32;
                centerView.IsLoopingEnabled    = false;
                centerView.FrameSize           = new Size(32, 32);
                centerView.DecodeFrameType     = DecodePixelType.Logical;
                centerView.Source              = UriEx.ToLocal(center.Local.Path);
                centerView.FirstFrameRendered += (s, args) =>
                {
                    dispatcher.TryEnqueue(Start);
                };
                centerView.PositionChanged += (s, args) =>
                {
                    if (args == 1)
                    {
                        dispatcher.TryEnqueue(Continue1);
                        //dispatcher.TryEnqueue(() => popup.IsOpen = false);
                    }
                };

                var aroundView = new LottieView();
                aroundView.Width            = 32 * 3;
                aroundView.Height           = 32 * 3;
                aroundView.IsLoopingEnabled = false;
                aroundView.FrameSize        = new Size(32 * 3, 32 * 3);
                aroundView.DecodeFrameType  = DecodePixelType.Logical;
                aroundView.Source           = UriEx.ToLocal(around.Local.Path);
                aroundView.PositionChanged += (s, args) =>
                {
                    if (args == 1)
                    {
                        dispatcher.TryEnqueue(Continue2);
                        //dispatcher.TryEnqueue(() => popup.IsOpen = false);
                    }
                };

                var root = new Grid();
                root.Width  = 32 * 3;
                root.Height = 32 * 3;
                root.Children.Add(centerView);
                root.Children.Add(aroundView);

                popup.Child = root;

                popup.IsOpen = true;
            }
            else
            {
                if (center.Local.CanBeDownloaded && !center.Local.IsDownloadingActive)
                {
                    _message.ProtoService.DownloadFile(center.Id, 32);
                }

                if (around.Local.CanBeDownloaded && !around.Local.IsDownloadingActive)
                {
                    _message.ProtoService.DownloadFile(around.Id, 32);
                }
            }
        }