Example #1
0
        public static List <GroupedCategoryPreview> GetTopCategories()
        {
            var mockPhotoThumbnail = new PhotoThumbnail {
                ImageUrl = mockImageUrl
            };
            var thumbnailList = new List <PhotoThumbnail>();

            for (var i = 0; i < 6; i++)
            {
                thumbnailList.Add(mockPhotoThumbnail);
            }

            var mockCategory = new CategoryPreview
            {
                Name            = "",
                PhotoThumbnails = thumbnailList
            };

            var list = new List <GroupedCategoryPreview>();

            for (var i = 0; i < 8; i++)
            {
                list.Add(new GroupedCategoryPreview(thumbnailList, "", "", mockCategory));
            }

            return(list);
        }
 /// <summary>
 /// Converts the given data model to a data contract.
 /// </summary>
 /// <param name="thumbnail">The data model.</param>
 /// <returns>The data contract.</returns>
 public static PhotoThumbnailContract ToDataContract(this PhotoThumbnail thumbnail)
 {
     return(new PhotoThumbnailContract
     {
         ImageUrl = thumbnail.ImageUrl
     });
 }
Example #3
0
 public void Setup()
 {
     _entity          = new FileEntity("test");
     _thumbnailSize   = new Size(100, 100);
     _thumbnailLoader = new Mock <IThumbnailLoader>();
     _thumbnail       = new PhotoThumbnail(_thumbnailLoader.Object, _entity, CancellationToken.None);
 }
Example #4
0
        /// <summary>
        /// Loads the state.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public async Task LoadState(StreamViewModelThumbnailArgs args)
        {
            Category = args.Category;
            SelectedPhotoThumbnail = args.PhotoThumbnail;

            await base.LoadState();
        }
Example #5
0
        private void OnPhotoThumbnailSelected(PhotoThumbnail photoThumbnail)
        {
            var categoryPreview = TopCategories.SingleOrDefault(c => c.PhotoThumbnails.Contains(photoThumbnail));

            if (categoryPreview != null)
            {
                _navigationFacade.NavigateToPhotoStream(categoryPreview, photoThumbnail);
            }
        }
Example #6
0
        /// <summary>
        /// For the given bitmap renders filtered thumbnails for each filter in given list and populates
        /// the given wrap panel with the them.
        ///
        /// For quick rendering, renders 10 thumbnails synchronously and then releases the calling thread.
        /// </summary>
        /// <param name="bitmap">Source bitmap to be filtered</param>
        /// <param name="side">Side length of square thumbnails to be generated</param>
        /// <param name="list">List of filters to be used, one per each thumbnail to be generated</param>
        /// <param name="panel">Wrap panel to be populated with the generated thumbnails</param>
        private async Task RenderThumbnailsAsync(Bitmap bitmap, int side, List <FilterModel> list, WrapPanel panel)
        {
            using (EditingSession session = new EditingSession(bitmap))
            {
                int i = 0;

                foreach (FilterModel filter in list)
                {
                    WriteableBitmap writeableBitmap = new WriteableBitmap(side, side);

                    foreach (IFilter f in filter.Components)
                    {
                        session.AddFilter(f);
                    }

                    Windows.Foundation.IAsyncAction action = session.RenderToBitmapAsync(writeableBitmap.AsBitmap());

                    i++;

                    if (i % 10 == 0)
                    {
                        // async, give control back to UI before proceeding.
                        await action;
                    }
                    else
                    {
                        // synchroneous, we keep the CPU for ourselves.
                        Task task = action.AsTask();
                        task.Wait();
                    }

                    PhotoThumbnail photoThumbnail = new PhotoThumbnail()
                    {
                        Bitmap = writeableBitmap,
                        Text   = filter.Name,
                        Width  = side,
                        Margin = new Thickness(6)
                    };

                    photoThumbnail.Tap += (object sender, System.Windows.Input.GestureEventArgs e) =>
                    {
                        App.PhotoModel.ApplyFilter(filter);
                        App.PhotoModel.Dirty = true;

                        NavigationService.GoBack();
                    };

                    panel.Children.Add(photoThumbnail);

                    session.UndoAll();
                }
            }
        }
Example #7
0
        /// <summary>
        /// For the given bitmap renders filtered thumbnails for each filter in given list and populates
        /// the given wrap panel with the them.
        ///
        /// For quick rendering, renders 10 thumbnails synchronously and then releases the calling thread.
        /// </summary>
        /// <param name="bitmap">Source bitmap to be filtered</param>
        /// <param name="side">Side length of square thumbnails to be generated</param>
        /// <param name="list">List of filters to be used, one per each thumbnail to be generated</param>
        /// <param name="panel">Wrap panel to be populated with the generated thumbnails</param>
        private async Task RenderThumbnailsAsync(Bitmap bitmap, int side, List <FilterModel> list, WrapPanel panel)
        {
            using (var source = new BitmapImageSource(bitmap))
                using (var effect = new FilterEffect(source))
                {
                    foreach (FilterModel filter in list)
                    {
                        effect.Filters = filter.Components;

                        WriteableBitmap writeableBitmap = new WriteableBitmap(side, side);

                        using (var renderer = new WriteableBitmapRenderer(effect, writeableBitmap))
                        {
                            await renderer.RenderAsync();

                            writeableBitmap.Invalidate();

                            var photoThumbnail = new PhotoThumbnail()
                            {
                                Bitmap = writeableBitmap,
                                Text   = filter.Name,
                                Width  = side,
                                Margin = new Thickness(6)
                            };

                            FilterModel tempFilter = filter;

                            photoThumbnail.Tap += (object sender, System.Windows.Input.GestureEventArgs e) =>
                            {
                                App.PhotoModel.ApplyFilter(tempFilter);
                                App.PhotoModel.Dirty = true;

                                NavigationService.GoBack();
                            };

                            panel.Children.Add(photoThumbnail);
                        }
                    }
                }
        }
        /// <summary>
        /// For the given bitmap renders filtered thumbnails for each filter in given list and populates
        /// the given wrap panel with the them.
        ///
        /// For quick rendering, renders 10 thumbnails synchronously and then releases the calling thread.
        /// </summary>
        /// <param name="bitmap">Source bitmap to be filtered</param>
        /// <param name="side">Side length of square thumbnails to be generated</param>
        /// <param name="list">List of filters to be used, one per each thumbnail to be generated</param>
        /// <param name="panel">Wrap panel to be populated with the generated thumbnails</param>
        private async Task RenderThumbnailsAsync(Bitmap bitmap, int side, List <FilterModel> list, WrapPanel FiltersWrapPanel)
        {
            using (EditingSession session = new EditingSession(bitmap))
            {
                //render filtered photo
                int i = 0;
                foreach (FilterModel filter in list)
                {
                    WriteableBitmap writeableBitmap = new WriteableBitmap(side, side);

                    //crop the bitmap
                    foreach (IFilter f in filter.Components)
                    {
                        session.AddFilter(f);
                    }

                    Windows.Foundation.IAsyncAction action = session.RenderToBitmapAsync(writeableBitmap.AsBitmap());

                    i++;
                    if (i % 10 == 0)
                    {
                        // async, give control back to UI before proceeding.
                        await action;
                    }
                    else
                    {
                        // synchroneous, we keep the CPU for ourselves.
                        Task task = action.AsTask();
                        task.Wait();
                    }

                    PhotoThumbnail photoThumbnail = new PhotoThumbnail()
                    {
                        Bitmap = writeableBitmap,
                        Text   = filter.Name,
                        Width  = side,
                        Margin = new Thickness(6)
                    };

                    photoThumbnail.Tap += async delegate
                    {
                        ProgressIndicator.IsRunning = true;
                        SetScreenButtonsEnabled(false);

                        App.ThumbnailModel.UndoAllFilters();
                        App.ThumbnailModel.ApplyFilter(filter, _shouldCrop);
                        App.ThumbnailModel.Dirty = true;

                        WriteableBitmap photo = new WriteableBitmap((int)App.ThumbnailModel.Width, (int)App.ThumbnailModel.Height);
                        await App.ThumbnailModel.RenderBitmapAsync(photo);

                        PhotoViewer.Source = photo;

                        SetScreenButtonsEnabled(true);
                        ProgressIndicator.IsRunning = false;
                    };

                    FiltersWrapPanel.Children.Add(photoThumbnail);

                    session.UndoAll();
                }
            }
            ProgressIndicator.IsRunning = false;
        }
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="category">The category to show data for.</param>
 /// <param name="photoThumbnail">The photo thumbnail that is used for
 /// determining the scroll position of the photo stream.</param>
 public StreamViewModelThumbnailArgs(CategoryPreview category, PhotoThumbnail photoThumbnail)
 {
     Category       = category;
     PhotoThumbnail = photoThumbnail;
 }
 /// <summary>
 /// Navigates to the photo stream view.
 /// </summary>
 /// <param name="categoryPreview">The category preview instance.</param>
 /// <param name="photoThumbnail">
 /// The photo thumbnail that will determine the scroll position.
 /// </param>
 public void NavigateToPhotoStream(CategoryPreview categoryPreview, PhotoThumbnail photoThumbnail)
 {
     Navigate(typeof(StreamViewModel), new StreamViewModelThumbnailArgs(categoryPreview, photoThumbnail));
 }
Example #11
0
 public CategoryThumbnailBundle(CategoryPreview preview, PhotoThumbnail thumbnail)
 {
     this.Preview   = preview;
     this.Thumbnail = thumbnail;
 }
Example #12
0
 /// <summary>
 /// Searches for a photo in the given photo list that matches the given
 /// photo thumbnail.
 /// </summary>
 /// <param name="photos">The photo list to search in.</param>
 /// <param name="photoThumbnail">The thumbnail to search for.</param>
 /// <returns>The photo that matches the given thumbnail.</returns>
 public static Photo FindPhotoForThumbnail(this IList <Photo> photos, PhotoThumbnail photoThumbnail)
 {
     return(photos.FirstOrDefault(p => p.ThumbnailUrl.Equals(photoThumbnail.ImageUrl)));
 }