Example #1
0
        public static async Task <List <MediaMetadata> > GetAllMetadatasAsync(this MediaMetaDatabaseContext context)
        {
            List <MediaMetaJson> metaJsons = null;

            using (new DisposableLogger(
                       DatabaseLog.QueryBegin,
                       (sw) => DatabaseLog.QueryEnd(sw, metaJsons?.Count ?? 0)
                       ))
            {
                // Get all MediaMetaJsons from database using this LINQ query.
                metaJsons = await context.MediaMetaJsons
                            .Include(j => j.Labels)
                            .ToListAsync();
            }

            var metas = new List <MediaMetadata>();

            using (new DisposableLogger(
                       DatabaseLog.DeserializationBegin,
                       (sw) => DatabaseLog.DeserializationEnd(sw, metas?.Count ?? 0)
                       ))
            {
                // Deserialize the JSON data in each MediaMetaJson object into a MediaMetadata object and add it to metas.
                foreach (var metaJson in metaJsons)
                {
                    var meta = await Task.Run(() => JsonConvert.DeserializeObject <MediaMetadata>(metaJson.Json));

                    meta.Labels = new ObservableCollection <Label>(metaJson.Labels);
                    metas.Add(meta);
                }
            }

            return(metas);
        }
Example #2
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            var bitmapLoadLogger = new DisposableLogger(UILog.BitmapLoadBegin, UILog.BitmapLoadEnd);

            #region Stuff from ViewModel

            var vm = DataContext as DetailsPageViewModel;

            vm.MediaDataKey = e.Parameter?.ToString();

            StorageFile mediaFile;
            // Log deserialization of media file.
            using (new DisposableLogger(DatabaseLog.DeserializationBegin, (sw) => DatabaseLog.DeserializationEnd(sw, 1)))
            {
                var SerializationService = Template10.Services.SerializationService.SerializationService.Json;
                mediaFile = App.Files[SerializationService.Deserialize(vm.MediaDataKey)?.ToString()];
            }

            var mediaData = App.Gallery.GetMediaDataFromPath(mediaFile.Path, App.Gallery.MediaDatas);

            vm.MediaData = mediaData;

            #endregion

            Frame.Background = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 0, 0, 0));

            var imageAnimation = ConnectedAnimationService.GetForCurrentView().GetAnimation("detailsImage1");
            var gifAnimation   = ConnectedAnimationService.GetForCurrentView().GetAnimation("detailsGif1");
            var videoAnimation = ConnectedAnimationService.GetForCurrentView().GetAnimation("detailsVideo1");

            /* var compositor = ElementCompositionPreview.GetElementVisual(BackgroundPanel).Compositor;
             * var fadeAnimation = compositor.CreateScalarKeyFrameAnimation();
             * fadeAnimation.InsertKeyFrame(0, 0f);
             * fadeAnimation.InsertKeyFrame(1, 1f);
             * fadeAnimation.Duration = TimeSpan.FromMilliseconds(500);
             * fadeAnimation.Target = "Opacity";
             *
             * ElementCompositionPreview.SetImplicitShowAnimation(BackgroundPanel, fadeAnimation);
             * await Task.Delay(100);*/

            // Set ViewBox, GenericMediaDataElement, VideoElement and ImageElement size to viewbox size or native size.
            MediaScrollViewer.UpdateLayout();
            MediaViewBox.Width                          = Math.Min(MediaScrollViewer.ViewportWidth, mediaData.Meta.Width);
            MediaViewBox.Height                         = Math.Min(MediaScrollViewer.ViewportHeight, mediaData.Meta.Height);
            GenericMediaDataElement.Width               = Math.Min(MediaScrollViewer.ViewportWidth, mediaData.Meta.Width);
            GenericMediaDataElement.Height              = Math.Min(MediaScrollViewer.ViewportHeight, mediaData.Meta.Height);
            GenericMediaDataElement.ImageElement.Width  = Math.Min(MediaScrollViewer.ViewportWidth, mediaData.Meta.Width);
            GenericMediaDataElement.ImageElement.Height = Math.Min(MediaScrollViewer.ViewportHeight, mediaData.Meta.Height);
            GenericMediaDataElement.VideoElement.Width  = Math.Min(MediaScrollViewer.ViewportWidth, mediaData.Meta.Width);
            GenericMediaDataElement.VideoElement.Height = Math.Min(MediaScrollViewer.ViewportHeight, mediaData.Meta.Height);
            if (imageAnimation != null)
            {
                _image = true;
                imageAnimation.Completed += (sender, arg) => _animFinished = true;
                // Start connected animation.
                imageAnimation.TryStart(GenericMediaDataElement.ImageElement);

                // Set up image loaded action.
                GenericMediaDataElement.ImageElement.ImageLoadedAction = () =>
                {
                    ZoomToFit();
                    App.Current.NavigationService.Frame.SizeChanged += MediaScrollViewer_SizeChanged;
                    MediaScrollViewer.RegisterPropertyChangedCallback(ScrollViewer.ZoomFactorProperty, ScrollViewerZoomFactorChanged);

                    // Log bitmap load.
                    bitmapLoadLogger.Dispose();

                    imageAnimation.Completed += (anim, obj) => vm.SearchForHigherResolutionOnlineAsync();
                };
            }
            if (gifAnimation != null)
            {
                _gif = true;
                gifAnimation.Completed += (sender, arg) => _animFinished = true;
                // Start connected animation.
                gifAnimation.TryStart(GenericMediaDataElement.ImageElement);
                // Set up image loaded action.
                GenericMediaDataElement.ImageElement.ImageLoadedAction = () =>
                {
                    ZoomToFit();
                    App.Current.NavigationService.Frame.SizeChanged += MediaScrollViewer_SizeChanged;
                    MediaScrollViewer.RegisterPropertyChangedCallback(ScrollViewer.ZoomFactorProperty, ScrollViewerZoomFactorChanged);

                    // Log bitmap load.
                    bitmapLoadLogger.Dispose();

                    gifAnimation.Completed += (anim, obj) => vm.SearchForHigherResolutionOnlineAsync();
                };
            }
            if (videoAnimation != null)
            {
                _video = true;
                videoAnimation.Completed += (sender, arg) => _animFinished = true;
                // Start connected animation on UI thread.
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => videoAnimation.TryStart(GenericMediaDataElement.VideoElement));

                // Set up video loaded action.
                GenericMediaDataElement.VideoElement.VideoLoadedAction += () =>
                {
                    ZoomToFit();
                    App.Current.NavigationService.Frame.SizeChanged += MediaScrollViewer_SizeChanged;
                    MediaScrollViewer.RegisterPropertyChangedCallback(ScrollViewer.ZoomFactorProperty, ScrollViewerZoomFactorChanged);

                    // Log bitmap load.
                    bitmapLoadLogger.Dispose();
                };
                GenericMediaDataElement.VideoElement.Detailed = true;
            }

            //TODO: Create File Memory Cache system by copying https://github.com/Microsoft/WindowsCommunityToolkit/blob/master/Microsoft.Toolkit.Uwp.UI/Cache/CacheBase.cs
            //TODO: General tips about file performance and property fetching: https://docs.microsoft.com/en-us/windows/uwp/files/fast-file-properties
            //TODO: Make transition to detailsPage smoother, step 1 try making it into a Modal, step 2 try this https://www.eternalcoding.com/?p=2723

            // Pick up on property changes inside of GenericMediaDataElement.

            /*GenericMediaDataElement.PropertyChanged += (sender, args) =>
             * {
             *  if (args.PropertyName == nameof(GenericMediaDataElement.ImageMediaData.Meta))
             *  {
             *      // Update width and height of local media datas based on new values of ImageMediaData.Meta.
             *      mediaData.Meta.Height = GenericMediaDataElement.ImageMediaData.Meta.Height;
             *      mediaData.Meta.Width = GenericMediaDataElement.ImageMediaData.Meta.Width;
             *      vm.MediaData.Meta.Height = GenericMediaDataElement.ImageMediaData.Meta.Height;
             *      vm.MediaData.Meta.Width = GenericMediaDataElement.ImageMediaData.Meta.Width;
             *      vm.RaisePropertyChanged(nameof(vm.Dimensions));
             *  }
             * };*/

            // If there is dominant color data.
            if (mediaData?.Meta?.AnnotationData?.ImagePropertiesAnnotation?.DominantColors?.Colors != null)
            {
                var dominantColor = mediaData.Meta.AnnotationData.ImagePropertiesAnnotation.DominantColors.Colors.OrderBy(ci => ci.PixelFraction).LastOrDefault();
                if (dominantColor != null && dominantColor.Color != null)
                {
                    // Turn Google Color into Windows Color.
                    var color      = dominantColor.Color.GetColor();
                    var brightness = color.GetBrightness();
                    // If color is not bright.
                    if (brightness < 0.4f)
                    {
                        // Set page background to dominant color.
                        Background = new SolidColorBrush(dominantColor.Color.GetColor());
                    }
                }
            }

            // Allow back-navigation if all animations are null.
            if (imageAnimation == null && gifAnimation == null && videoAnimation == null)
            {
                _animFinished = true;
            }
        }
Example #3
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            #region Stuff from ViewModel

            var vm = DataContext as AlternateDetailsPageViewModel;

            vm.MediaDataKey = e.Parameter?.ToString();

            StorageFile mediaFile;
            // Log deserialization of media file.
            using (new DisposableLogger(DatabaseLog.DeserializationBegin, (sw) => DatabaseLog.DeserializationEnd(sw, 1)))
            {
                var SerializationService = Template10.Services.SerializationService.SerializationService.Json;
                mediaFile = App.Files[SerializationService.Deserialize(vm.MediaDataKey)?.ToString()];
            }

            var mediaData = App.Gallery.GetMediaDataFromPath(mediaFile.Path, App.Gallery.MediaDatas);

            vm.MediaData = mediaData;

            vm.RaisePropertyChanged(nameof(vm.MediaSource));

            #endregion

            Frame.Background = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 0, 0, 0));

            var imageAnimation = ConnectedAnimationService.GetForCurrentView().GetAnimation("detailsImage1");
            var gifAnimation   = ConnectedAnimationService.GetForCurrentView().GetAnimation("detailsGif1");
            var videoAnimation = ConnectedAnimationService.GetForCurrentView().GetAnimation("detailsVideo1");

            /* var compositor = ElementCompositionPreview.GetElementVisual(BackgroundPanel).Compositor;
             * var fadeAnimation = compositor.CreateScalarKeyFrameAnimation();
             * fadeAnimation.InsertKeyFrame(0, 0f);
             * fadeAnimation.InsertKeyFrame(1, 1f);
             * fadeAnimation.Duration = TimeSpan.FromMilliseconds(500);
             * fadeAnimation.Target = "Opacity";
             *
             * ElementCompositionPreview.SetImplicitShowAnimation(BackgroundPanel, fadeAnimation);
             * await Task.Delay(100);*/
            /*if (imageAnimation != null)
             * {
             *  _image = true;
             *  imageAnimation.Completed += (sender, arg) => _animFinished = true;
             *  ImageElement.Loaded += (s, o) =>
             *  {
             *      DeasdasdasdLine($"{DateTime.Now.Second}:{DateTime.Now.Millisecond} Detailed image loaded.");
             *      imageAnimation.TryStart(ImageElement);
             *
             *      imageAnimation.Completed += (anim, obj) => vm.SearchForHigherResolutionOnlineAsync();
             *  };
             * }
             * if (gifAnimation != null)
             * {
             *  _gif = true;
             *  gifAnimation.Completed += (sender, arg) => _animFinished = true;
             *  GenericMediaDataElement.ImageElement.ImageLoadedAction = () =>
             *  {
             *      gifAnimation.TryStart(GenericMediaDataElement.ImageElement);
             *
             *      gifAnimation.Completed += (anim, obj) => vm.SearchForHigherResolutionOnlineAsync();
             *  };
             * }
             * if (videoAnimation != null)
             * {
             *  _video = true;
             *  videoAnimation.Completed += (sender, arg) => _animFinished = true;
             *  GenericMediaDataElement.VideoElement.VideoLoadedAction += async () =>
             *      await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => videoAnimation.TryStart(GenericMediaDataElement.VideoElement));
             *  GenericMediaDataElement.VideoElement.Detailed = true;
             * }
             *
             * // Pick up on property changes inside of GenericMediaDataElement.
             * GenericMediaDataElement.PropertyChanged += (sender, args) =>
             * {
             *  if (args.PropertyName == nameof(GenericMediaDataElement.ImageMediaData.Meta))
             *  {
             *      // Update width and height of local media datas based on new values of ImageMediaData.Meta.
             *      mediaData.Meta.Height = GenericMediaDataElement.ImageMediaData.Meta.Height;
             *      mediaData.Meta.Width = GenericMediaDataElement.ImageMediaData.Meta.Width;
             *      vm.MediaData.Meta.Height = GenericMediaDataElement.ImageMediaData.Meta.Height;
             *      vm.MediaData.Meta.Width = GenericMediaDataElement.ImageMediaData.Meta.Width;
             *      vm.RaisePropertyChanged(nameof(vm.Dimensions));
             *  }
             * };*/

            // Allow back-navigation if all animations are null.

            /*if (imageAnimation == null && gifAnimation == null && videoAnimation == null)
             *  _animFinished = true;*/
        }