示例#1
0
        private async void Photo_Click(object sender, RoutedEventArgs e)
        {
            var chat = ViewModel.Chat;

            if (chat == null)
            {
                return;
            }

            if (chat.Type is ChatTypePrivate || chat.Type is ChatTypeSecret)
            {
                var user = ViewModel.ProtoService.GetUser(chat);
                if (user == null || user.ProfilePhoto == null)
                {
                    return;
                }

                var viewModel = new UserPhotosViewModel(ViewModel.ProtoService, ViewModel.Aggregator, user);
                await GalleryView.GetForCurrentView().ShowAsync(viewModel, () => Photo);
            }

            //var user = ViewModel.Item as TLUser;
            //var userFull = ViewModel.Full as TLUserFull;
            //if (userFull != null && userFull.ProfilePhoto is TLPhoto && user != null)
            //{
            //    var viewModel = new UserPhotosViewModel(ViewModel.LegacyService, userFull, user);
            //    await GalleryView.Current.ShowAsync(viewModel, () => Photo);
            //}
        }
示例#2
0
        private async void Photo_Click(object sender, RoutedEventArgs e)
        {
            var chat = ViewModel.Chat;

            if (chat == null)
            {
                return;
            }

            if (chat.Type is ChatTypePrivate or ChatTypeSecret)
            {
                var user = ViewModel.ProtoService.GetUser(chat);
                if (user == null || user.ProfilePhoto == null)
                {
                    return;
                }

                var userFull = ViewModel.ProtoService.GetUserFull(user.Id);
                if (userFull?.Photo == null)
                {
                    return;
                }

                var viewModel = new UserPhotosViewModel(ViewModel.ProtoService, ViewModel.Aggregator, user, userFull);
                await GalleryView.GetForCurrentView().ShowAsync(viewModel, () => Photo);
            }
        private async void Photo_Click(object sender, RoutedEventArgs e)
        {
            var element = sender as FrameworkElement;
            var message = element.Tag as MessageWithOwner;

            var viewModel = new ChatGalleryViewModel(ViewModel.ProtoService, ViewModel.StorageService, ViewModel.Aggregator, message.ChatId, 0, message.Get(), true);
            await GalleryView.GetForCurrentView().ShowAsync(viewModel, () => element);
        }
示例#4
0
        public async void OpenMedia(MessageViewModel message, FrameworkElement target)
        {
            //ViewModel.Gallery.SelectedItem = item;
            //ViewModel.Gallery.FirstItem = item;
            ViewModel.Gallery.SelectedItem = ViewModel.Gallery.Items.FirstOrDefault();
            ViewModel.Gallery.FirstItem    = ViewModel.Gallery.Items.FirstOrDefault();

            await GalleryView.GetForCurrentView().ShowAsync(ViewModel.Gallery, () => target);
        }
示例#5
0
        private async void Image_Click(object sender, RoutedEventArgs e)
        {
            var image = sender as ImageView;
            var item  = image.DataContext as GalleryItem;

            if (item != null)
            {
                ViewModel.Gallery.SelectedItem = item;
                ViewModel.Gallery.FirstItem    = item;

                await GalleryView.GetForCurrentView().ShowAsync(ViewModel.Gallery, () => image);
            }
        }
示例#6
0
        public async void PlayMessage(MessageViewModel message, FrameworkElement target)
        {
            var text = message.Content as MessageText;

            // If autoplay is enabled and the message contains a video note, then we want a different behavior
            if (ViewModel.Settings.IsAutoPlayAnimationsEnabled && (message.Content is MessageVideoNote || text?.WebPage != null && text.WebPage.Video != null))
            {
                ViewModel.PlaybackService.Play(message, ViewModel.ThreadId);
                //if (_old.TryGetValue(message.Id, out MediaPlayerItem item))
                //{
                //    if (item.Presenter == null || item.Presenter.MediaPlayer == null)
                //    {
                //        return;
                //    }

                //    // If the video player is muted, then let's play the video again with audio turned on
                //    if (item.Presenter.MediaPlayer.IsMuted)
                //    {
                //        TypedEventHandler<MediaPlayer, object> handler = null;
                //        handler = (player, args) =>
                //        {
                //            player.MediaEnded -= handler;
                //            player.IsMuted = true;
                //            player.IsLoopingEnabled = true;
                //            player.Play();
                //        };

                //        item.Presenter.MediaPlayer.MediaEnded += handler;
                //        item.Presenter.MediaPlayer.IsMuted = false;
                //        item.Presenter.MediaPlayer.IsLoopingEnabled = false;
                //        item.Presenter.MediaPlayer.PlaybackSession.Position = TimeSpan.Zero;

                //        // Mark it as viewed if needed
                //        if (message.Content is MessageVideoNote videoNote && !message.IsOutgoing && !videoNote.IsViewed)
                //        {
                //            ViewModel.ProtoService.Send(new OpenMessageContent(message.ChatId, message.Id));
                //        }
                //    }
                //    // If the video player is paused, then resume playback
                //    else if (item.Presenter.MediaPlayer.PlaybackSession.PlaybackState == MediaPlaybackState.Paused)
                //    {
                //        item.Presenter.MediaPlayer.Play();
                //    }
                //    // And last, if the video player can be pause, then pause it
                //    else if (item.Presenter.MediaPlayer.PlaybackSession.CanPause)
                //    {
                //        item.Presenter.MediaPlayer.Pause();
                //    }
                //}
            }
            else if (ViewModel.Settings.IsAutoPlayAnimationsEnabled && (message.Content is MessageAnimation || (text?.WebPage != null && text.WebPage.Animation != null) || (message.Content is MessageGame game && game.Game.Animation != null)))
            {
                if (_prev.TryGetValue(message.AnimationHash(), out WeakReference reference) && reference.Target is IPlayerView item)
                {
                    GalleryViewModelBase viewModel;
                    if (message.Content is MessageAnimation)
                    {
                        viewModel = new ChatGalleryViewModel(ViewModel.ProtoService, ViewModel.StorageService, ViewModel.Aggregator, message.ChatId, ViewModel.ThreadId, message.Get());
                    }
                    else
                    {
                        viewModel = new SingleGalleryViewModel(ViewModel.ProtoService, ViewModel.StorageService, ViewModel.Aggregator, new GalleryMessage(ViewModel.ProtoService, message.Get()));
                    }

                    await GalleryView.GetForCurrentView().ShowAsync(viewModel, () => target);
                }
                else
                {
                    ViewVisibleMessages(false);
                }
            }
        public async void PlayMessage(MessageViewModel message, FrameworkElement target)
        {
            var text = message.Content as MessageText;

            // If autoplay is enabled and the message contains a video note, then we want a different behavior
            if (ViewModel.Settings.IsAutoPlayAnimationsEnabled && (message.Content is MessageVideoNote || text?.WebPage != null && text.WebPage.Video != null))
            {
                if (SettingsService.Current.Diagnostics.SoftwareDecoderEnabled) //TODO: Make audio and video playable like in other clients: together & control on top...
                {
                    ViewModel.PlaybackService.Enqueue(message.Get());
                }
                //if (_old.TryGetValue(message.Id, out MediaPlayerItem item))
                //{
                //    if (item.Presenter == null || item.Presenter.MediaPlayer == null)
                //    {
                //        return;
                //    }

                //    // If the video player is muted, then let's play the video again with audio turned on
                //    if (item.Presenter.MediaPlayer.IsMuted)
                //    {
                //        TypedEventHandler<MediaPlayer, object> handler = null;
                //        handler = (player, args) =>
                //        {
                //            player.MediaEnded -= handler;
                //            player.IsMuted = true;
                //            player.IsLoopingEnabled = true;
                //            player.Play();
                //        };

                //        item.Presenter.MediaPlayer.MediaEnded += handler;
                //        item.Presenter.MediaPlayer.IsMuted = false;
                //        item.Presenter.MediaPlayer.IsLoopingEnabled = false;
                //        item.Presenter.MediaPlayer.PlaybackSession.Position = TimeSpan.Zero;

                //        // Mark it as viewed if needed
                //        if (message.Content is MessageVideoNote videoNote && !message.IsOutgoing && !videoNote.IsViewed)
                //        {
                //            ViewModel.ProtoService.Send(new OpenMessageContent(message.ChatId, message.Id));
                //        }
                //    }
                //    // If the video player is paused, then resume playback
                //    else if (item.Presenter.MediaPlayer.PlaybackSession.PlaybackState == MediaPlaybackState.Paused)
                //    {
                //        item.Presenter.MediaPlayer.Play();
                //    }
                //    // And last, if the video player can be pause, then pause it
                //    else if (item.Presenter.MediaPlayer.PlaybackSession.CanPause)
                //    {
                //        item.Presenter.MediaPlayer.Pause();
                //    }
                //}
                if (_old.TryGetValue(message.Id, out MediaPlayerItem item))
                {
                    if (item.MediaPlayerPresenter?.MediaPlayer == null)
                    {
                        return;
                    }

                    // If the video player is muted, then let's play the video again with audio turned on
                    if (item.MediaPlayerPresenter.MediaPlayer.IsMuted)
                    {
                        item.MediaPlayerPresenter.MediaPlayer.IsMuted                  = false;
                        item.MediaPlayerPresenter.MediaPlayer.IsLoopingEnabled         = false;
                        item.MediaPlayerPresenter.MediaPlayer.PlaybackSession.Position = TimeSpan.Zero;
                        PauseAllOtherVideoNotes(message.Id);

                        // Mark it as viewed if needed
                        if (message.Content is MessageVideoNote videoNote && !message.IsOutgoing && !videoNote.IsViewed)
                        {
                            ViewModel.ProtoService.Send(new OpenMessageContent(message.ChatId, message.Id));
                        }

                        if (item.Container.FindName("Progress") is RadialProgressBar progress)
                        {
                            progress.Maximum = item.MediaPlayerPresenter.MediaPlayer.PlaybackSession.NaturalDuration.TotalSeconds;
                            async void ProgressHandler(Windows.Media.Playback.MediaPlaybackSession session, object args)
                            {
                                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                                {
                                    progress.Value = session.Position.TotalSeconds;
                                });
                            }

                            item.MediaPlayerPresenter.MediaPlayer.PlaybackSession.PositionChanged -= ProgressHandler;
                            item.MediaPlayerPresenter.MediaPlayer.PlaybackSession.PositionChanged += ProgressHandler;
                        }
                        // MediaEnded
                        if (item.Container.FindName("MutedIcon") is StackPanel mutedIcon)
                        {
                            mutedIcon.Visibility = Visibility.Collapsed;
                            async void MediaEndedHandler(Windows.Media.Playback.MediaPlayer player, object args)
                            {
                                player.IsMuted = true;
                                if (player.PlaybackSession.CanPause)
                                {
                                    player.Pause();
                                }
                                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                                {
                                    mutedIcon.Visibility = Visibility.Visible;
                                });

                                //TODO: Play next media content and scroll to that one
                            }

                            item.MediaPlayerPresenter.MediaPlayer.MediaEnded -= MediaEndedHandler;
                            item.MediaPlayerPresenter.MediaPlayer.MediaEnded += MediaEndedHandler;
                        }

                        if (item.MediaPlayerPresenter.MediaPlayer.PlaybackSession.PlaybackState == Windows.Media.Playback.MediaPlaybackState.Paused)
                        {
                            item.MediaPlayerPresenter.MediaPlayer.Play();
                        }
                    }
                    // If the video player is paused, then resume playback
                    else if (item.MediaPlayerPresenter.MediaPlayer.PlaybackSession.PlaybackState == Windows.Media.Playback.MediaPlaybackState.Paused)
                    {
                        item.MediaPlayerPresenter.MediaPlayer.IsMuted = false;
                        item.MediaPlayerPresenter.MediaPlayer.Play();
                        PauseAllOtherVideoNotes(message.Id);
                        if (item.Container.FindName("MutedIcon") is StackPanel mutedIcon)
                        {
                            mutedIcon.Visibility = Visibility.Collapsed;
                        }
                    }
                    // And last, if the video player can be pause, then pause it
                    else if (item.MediaPlayerPresenter.MediaPlayer.PlaybackSession.CanPause)
                    {
                        item.MediaPlayerPresenter.MediaPlayer.Pause();
                        // Note: UWP has no event or public player state property, so it gets hardcoded:
                        if (item.Container.FindName("MutedIcon") is StackPanel mutedIcon)
                        {
                            mutedIcon.Visibility = Visibility.Visible;
                        }
                    }
                }
            }
            else if (ViewModel.Settings.IsAutoPlayAnimationsEnabled && (message.Content is MessageAnimation || (text?.WebPage != null && text.WebPage.Animation != null) || (message.Content is MessageGame game && game.Game.Animation != null)))
            {
                if (_old.TryGetValue(message.AnimationHash(), out MediaPlayerItem item))
                {
                    GalleryViewModelBase viewModel;
                    if (message.Content is MessageAnimation)
                    {
                        viewModel = new ChatGalleryViewModel(ViewModel.ProtoService, ViewModel.Aggregator, message.ChatId, ViewModel.ThreadId, message.Get());
                    }
                    else
                    {
                        viewModel = new SingleGalleryViewModel(ViewModel.ProtoService, ViewModel.Aggregator, new GalleryMessage(ViewModel.ProtoService, message.Get()));
                    }

                    await GalleryView.GetForCurrentView().ShowAsync(viewModel, () => target);
                }
                else
                {
                    ViewVisibleMessages(false);
                }
            }