public void UpdateItem(IGalleryDelegate delegato, GalleryContent item) { _delegate = delegato; _item = item; Tag = item; Panel.Background = null; Texture.Source = null; ScrollingHost.ChangeView(0, 0, 1, true); if (item == null) { return; } var data = item.GetFile(); var thumb = item.GetThumbnail(); Panel.Constraint = item.Constraint; Panel.InvalidateMeasure(); if (thumb != null && (item.IsVideo || (item.IsPhoto && !data.Local.IsDownloadingCompleted))) { UpdateThumbnail(item, thumb); } UpdateFile(item, data); }
public void UpdateFile(GalleryContent item, File file) { var data = item.GetFile(); var thumb = item.GetThumbnail(); if (thumb != null && thumb.Id != data.Id && thumb.Id == file.Id) { UpdateThumbnail(item, file); return; } else if (data == null || data.Id != file.Id) { return; } var size = Math.Max(file.Size, file.ExpectedSize); if (file.Local.IsDownloadingActive) { //Button.Glyph = Icons.Cancel; Button.SetGlyph(file.Id, MessageContentState.Downloading); Button.Progress = (double)file.Local.DownloadedSize / size; Button.Opacity = 1; } else if (file.Remote.IsUploadingActive) { Button.Glyph = Icons.Cancel; Button.SetGlyph(file.Id, MessageContentState.Uploading); Button.Progress = (double)file.Remote.UploadedSize / size; Button.Opacity = 1; } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingCompleted) { Button.Glyph = Icons.Download; Button.SetGlyph(file.Id, MessageContentState.Download); Button.Progress = 0; Button.Opacity = 1; if (item.IsPhoto) { item.ProtoService.DownloadFile(file.Id, 1); } } else { if (item.IsVideo) { Button.Glyph = Icons.Play; Button.SetGlyph(file.Id, MessageContentState.Play); Button.Progress = 1; Button.Opacity = 1; } else if (item.IsPhoto) { Button.SetGlyph(file.Id, MessageContentState.Photo); Button.Opacity = 0; Texture.Source = new BitmapImage(new Uri("file:///" + file.Local.Path)); } } }
public void UpdateItem(IGalleryDelegate delegato, GalleryContent item) { _delegate = delegato; _item = item; Tag = item; Panel.Background = null; Texture.Source = null; ScrollingHost.ChangeView(0, 0, 1, true); if (item == null) { return; } var file = item.GetFile(); var thumbnail = item.GetThumbnail(); Panel.Constraint = item.Constraint; Panel.InvalidateMeasure(); UpdateManager.Subscribe(this, delegato.ProtoService, file, ref _fileToken, UpdateFile); UpdateFile(item, file); if (thumbnail != null && (item.IsVideo || (item.IsPhoto && !file.Local.IsFileExisting()))) { UpdateThumbnail(item, thumbnail, true); } }
private async void Play(Grid parent, GalleryContent item, File file) { try { if (!file.Local.IsDownloadingCompleted && !SettingsService.Current.IsStreamingEnabled) { return; } if (_surface != null && _mediaPlayerElement != null) { _surface.Children.Remove(_mediaPlayerElement); _surface = null; } if (_mediaPlayer == null) { _mediaPlayer = Task.Run(() => new MediaPlayer()).Result; _mediaPlayer.VolumeChanged += OnVolumeChanged; _mediaPlayer.SourceChanged += OnSourceChanged; _mediaPlayer.MediaOpened += OnMediaOpened; _mediaPlayer.PlaybackSession.PlaybackStateChanged += OnPlaybackStateChanged; _mediaPlayerElement.SetMediaPlayer(_mediaPlayer); } var dpi = DisplayInformation.GetForCurrentView().LogicalDpi / 96.0f; _mediaPlayer.SetSurfaceSize(new Size(parent.ActualWidth * dpi, parent.ActualHeight * dpi)); _surface = parent; _surface.Children.Add(_mediaPlayerElement); if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.MediaTransportControls", "ShowAndHideAutomatically")) { Transport.ShowAndHideAutomatically = true; } Transport.DownloadMaximum = file.Size; Transport.DownloadValue = file.Local.DownloadOffset + file.Local.DownloadedPrefixSize; var streamable = SettingsService.Current.IsStreamingEnabled && item.IsStreamable && !file.Local.IsDownloadingCompleted; if (streamable) { _streamingInterop = new FFmpegInteropMSS(new FFmpegInteropConfig()); var interop = await _streamingInterop.CreateFromFileAsync(ViewModel.ProtoService.Client, file); _mediaPlayer.Source = interop.CreateMediaPlaybackItem(); Transport.DownloadMaximum = file.Size; Transport.DownloadValue = file.Local.DownloadOffset + file.Local.DownloadedPrefixSize; } else { _mediaPlayer.Source = MediaSource.CreateFromUri(new Uri("file:///" + file.Local.Path)); } _mediaPlayer.IsLoopingEnabled = item.IsLoop; _mediaPlayer.Play(); } catch { } }
protected override void OnSelectedItemChanged(GalleryContent item) { //var messageItem = item as GalleryLegacyMessageItem; //if (messageItem == null) //{ // return; //} //var message = messageItem.Message as TLMessage; //if (message == null) //{ // return; //} //if (message.GroupedId is long group) //{ // var all = Items.Where(x => x is GalleryLegacyMessageItem msg && msg.Message.GroupedId == group).ToList(); // if (all.Count == _group.Count && group == _current) // { // return; // } // _current = group; // _group.ReplaceWith(all); // RaisePropertyChanged(() => SelectedItem); //} //else //{ // _group.Clear(); //} }
private void Play(Grid parent, GalleryContent item, File file) { try { if (!file.Local.IsDownloadingCompleted && !SettingsService.Current.IsStreamingEnabled) { return; } if (_surface != null && _mediaPlayerElement != null) { _surface.Children.Remove(_mediaPlayerElement); _surface = null; } if (_mediaPlayer == null) { _mediaPlayer = Task.Run(() => new MediaPlayer()).Result; _mediaPlayer.VolumeChanged += OnVolumeChanged; _mediaPlayer.SourceChanged += OnSourceChanged; _mediaPlayer.MediaOpened += OnMediaOpened; _mediaPlayer.PlaybackSession.PlaybackStateChanged += OnPlaybackStateChanged; _mediaPlayerElement.SetMediaPlayer(_mediaPlayer); } var dpi = DisplayInformation.GetForCurrentView().LogicalDpi / 96.0f; _mediaPlayer.SetSurfaceSize(new Size(parent.ActualWidth * dpi, parent.ActualHeight * dpi)); _surface = parent; _surface.Children.Add(_mediaPlayerElement); if (ApiInfo.IsUniversalApiContract5Present) //if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.MediaTransportControls", "ShowAndHideAutomatically")) { Transport.ShowAndHideAutomatically = true; } Transport.DownloadMaximum = file.Size; Transport.DownloadValue = file.Local.DownloadOffset + file.Local.DownloadedPrefixSize; var streamable = SettingsService.Current.IsStreamingEnabled && item.IsStreamable /*&& !file.Local.IsDownloadingCompleted*/; if (streamable) { _streamingInterop = new RemoteFileStream(item.ProtoService, file, TimeSpan.FromSeconds(item.Duration)); _mediaPlayer.Source = MediaSource.CreateFromStream(_streamingInterop, item.MimeType); Transport.DownloadMaximum = file.Size; Transport.DownloadValue = file.Local.DownloadOffset + file.Local.DownloadedPrefixSize; } else { _mediaPlayer.Source = MediaSource.CreateFromUri(UriEx.GetLocal(file.Local.Path)); } _mediaPlayer.IsLoopingEnabled = item.IsLoop; _mediaPlayer.Play(); } catch { } }
private void Play(Grid parent, GalleryContent item, File file) { if (_unloaded) { return; } try { if (!file.Local.IsDownloadingCompleted && !SettingsService.Current.IsStreamingEnabled) { return; } if (_surface != null && _mediaPlayerElement != null) { _surface.Children.Remove(_mediaPlayerElement); _surface = null; } if (_mediaPlayer == null) { _mediaPlayer = Task.Run(() => new MediaPlayer()).Result; _mediaPlayer.VolumeChanged += OnVolumeChanged; _mediaPlayer.SourceChanged += OnSourceChanged; _mediaPlayer.MediaOpened += OnMediaOpened; _mediaPlayer.PlaybackSession.PlaybackStateChanged += OnPlaybackStateChanged; _mediaPlayerElement.SetMediaPlayer(_mediaPlayer); } var dpi = DisplayInformation.GetForCurrentView().LogicalDpi / 96.0f; _mediaPlayer.SetSurfaceSize(new Size(parent.ActualWidth * dpi, parent.ActualHeight * dpi)); _surface = parent; _surface.Children.Add(_mediaPlayerElement); //Transport.DownloadMaximum = file.Size; //Transport.DownloadValue = file.Local.DownloadOffset + file.Local.DownloadedPrefixSize; var streamable = SettingsService.Current.IsStreamingEnabled && item.IsStreamable /*&& !file.Local.IsDownloadingCompleted*/; if (streamable) { _fileStream = new RemoteFileStream(item.ProtoService, file, item.Duration); _mediaPlayer.Source = MediaSource.CreateFromStream(_fileStream, item.MimeType); //Transport.DownloadMaximum = file.Size; //Transport.DownloadValue = file.Local.DownloadOffset + file.Local.DownloadedPrefixSize; } else { _mediaPlayer.Source = MediaSource.CreateFromUri(UriEx.ToLocal(file.Local.Path)); } _mediaPlayer.IsLoopingEnabled = item.IsLoop; _mediaPlayer.Play(); } catch { } }
public SingleGalleryViewModel(IProtoService protoService, IEventAggregator aggregator, GalleryContent item) : base(protoService, aggregator) { Items = new MvxObservableCollection <GalleryContent> { item }; SelectedItem = item; FirstItem = item; }
public static bool LaunchGallery(GalleryContent contentType, string callback) { if (Application.platform == RuntimePlatform.Android) { return(_plugin.CallStatic <bool> ("LaunchGallery", (int)contentType, callback)); } return(false); }
private bool TrySet(GalleryContentView element, GalleryContent content) { if (object.Equals(element.Item, content)) { return(false); } element.UpdateItem(this, content); return(true); }
public void OpenItem(GalleryContent item) { if (Transport.IsVisible) { Transport.Hide(); } else { Transport.Show(); } }
private Visibility ConvertCompactVisibility(GalleryContent item) { if (item != null && item.IsVideo && !item.IsLoop) { if (item is GalleryMessage message && message.IsHot) { return(Visibility.Collapsed); } return(ApplicationView.GetForCurrentView().IsViewModeSupported(ApplicationViewMode.CompactOverlay) ? Visibility.Visible : Visibility.Collapsed); } return(Visibility.Collapsed); }
private void UpdateThumbnail(GalleryContent item, File file) { if (file.Local.IsDownloadingCompleted) { //Texture.Source = new BitmapImage(new Uri("file:///" + file.Local.Path)); Panel.Background = new ImageBrush { ImageSource = PlaceholderHelper.GetBlurred(file.Local.Path), Stretch = Stretch.UniformToFill }; } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { item.ProtoService.DownloadFile(file.Id, 1); } }
private void PrepareNext(int direction) { if (ViewModel == null) { return; } GalleryContent previous = null; GalleryContent target = null; GalleryContent next = null; if (Grid.GetColumn(Element1) == direction + 1) { previous = Element0; target = Element1; next = Element2; } else if (Grid.GetColumn(Element0) == direction + 1) { previous = Element2; target = Element0; next = Element1; } else if (Grid.GetColumn(Element2) == direction + 1) { previous = Element1; target = Element2; next = Element0; } Grid.SetColumn(target, 1); Grid.SetColumn(previous, 0); Grid.SetColumn(next, 2); var index = ViewModel.SelectedIndex; var set = TrySet(target, ViewModel.Items[index]); TrySet(previous, ViewModel.SelectedIndex > 0 ? ViewModel.Items[index - 1] : null); TrySet(next, ViewModel.SelectedIndex < ViewModel.Items.Count - 1 ? ViewModel.Items[index + 1] : null); if (set) { Dispose(); ViewModel.OpenMessage(ViewModel.Items[index]); } //_selecting = false; }
private void Play(GalleryContent item, File file) { try { if (_surface != null && _mediaPlayerElement != null) { _surface.Children.Remove(_mediaPlayerElement); } var container = GetContainer(0); //if (container != null && container.ContentTemplateRoot is Grid parent) //{ // Play(parent, item); //} Play(container.Presenter, item, file); } catch { } }
private void UpdateThumbnail(GalleryContent item, File file, bool download) { if (file.Local.IsFileExisting()) { //Texture.Source = new BitmapImage(UriEx.GetLocal(file.Local.Path)); Panel.Background = new ImageBrush { ImageSource = PlaceholderHelper.GetBlurred(file.Local.Path), Stretch = Stretch.UniformToFill }; } else if (download) { if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { item.ProtoService.DownloadFile(file.Id, 1); } UpdateManager.Subscribe(this, _delegate.ProtoService, file, ref _thumbnailToken, UpdateThumbnail, true); } }
public void OpenFile(GalleryContent item, File file) { Play(item, file); }
private async void UpdateFile(GalleryContent item, File file) { var reference = item?.GetFile(); if (reference == null || reference.Id != file.Id) { return; } var size = Math.Max(file.Size, file.ExpectedSize); if (file.Local.IsDownloadingActive) { Button.SetGlyph(file.Id, MessageContentState.Downloading); Button.Progress = (double)file.Local.DownloadedSize / size; Button.Opacity = 1; } else if (file.Remote.IsUploadingActive) { Button.SetGlyph(file.Id, MessageContentState.Uploading); Button.Progress = (double)file.Remote.UploadedSize / size; Button.Opacity = 1; } else if (file.Local.CanBeDownloaded && !file.Local.IsFileExisting()) { Button.SetGlyph(file.Id, MessageContentState.Download); Button.Progress = 0; Button.Opacity = 1; if (item.IsPhoto) { item.ProtoService.DownloadFile(file.Id, 1); } } else { if (item.IsVideo) { Button.SetGlyph(file.Id, MessageContentState.Play); Button.Progress = 1; Button.Opacity = 1; } else if (item.IsPhoto) { Button.SetGlyph(file.Id, MessageContentState.Photo); Button.Opacity = 0; try { BitmapImage image; Texture.Source = image = new BitmapImage(); // (UriEx.GetLocal(file.Local.Path)); var test = await item.ProtoService.GetFileAsync(file); using (var stream = await test.OpenReadAsync()) { await image.SetSourceAsync(stream); } Texture.Source = image; } catch { Texture.Source = null; } } } }
public void OpenItem(GalleryContent item) { OnBackRequested(new HandledEventArgs()); }