Example #1
0
        /// <summary>
        /// Asynchronously returns a list of all albums in the picture library
        /// </summary>
        /// <returns>A list of all albums in the picture library</returns>
        public Task<List<PixPresenterPortableLib.AlbumViewModel>> GetAlbumsAsync()
        {
            return Task.Run(delegate
            {
                List<AlbumViewModel> result = new List<AlbumViewModel>();

                MediaLibrary mediaLib = new MediaLibrary();
                foreach (var album in mediaLib.RootPictureAlbum.Albums)
                {
                    byte[] thumb = null;

                    // Exclude empty picture albums
                    if (album.Pictures.Count > 0)
                    {
                        Stream stream = album.Pictures[0].GetThumbnail();
                        using (BinaryReader br = new BinaryReader(stream))
                        {
                            thumb =  br.ReadBytes((int)stream.Length);
                        }

                        AlbumViewModel avm = new AlbumViewModel(App.AlbumService, album.Name, album.Name, thumb);
                        avm.Name = album.Name;
                        result.Add(avm);
                    }
                }
                return result;
            });
        }
Example #2
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
          
            // internal navigation or fast resume
            if (_album != null)
                return;

            if (this.NavigationContext.QueryString.ContainsKey("albumname"))
            {
                string albumName = NavigationContext.QueryString["albumname"];
                foreach (var album in App.AlbumsViewModel.Albums)
                {
                    if (album.Name == albumName)
                    {
                        _album = album;
                        break;
                    }
                }
            }
            else
            {
                return;
            }

            await _album.LoadPicturesAsync();
            this.DataContext = _album;
            object token;
          
            if (State.TryGetValue("current_token", out token))
            _album.RestoreCurrentPictureToken(token);
        }
Example #3
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.Parameter != null)
            {
                if (e.Parameter.GetType() == typeof(string))
                {
                    this.AlbumName = e.Parameter.ToString();

                    _album = App.AlbumsViewModel.Albums.First((a) => a.Name == this.AlbumName);

                    // Load the pictures from the album
                    await _album.LoadPicturesAsync();

                    if (_album.Pictures.Count == 0)
                      return;

                    this.DataContext = _album;

                    // Prepare data for carousel view. This creates a copy of the 
                    // pictures in an album, adds the first picture to the end of the list,
                    // and the last picture to the beginning of the list. The selected index
                    // is adjusted in the FlipView.SelectionChanged event to simulate a
                    // "carousel" view of the pictures.
                    var firstPicture = _album.Pictures[0];
                    var lastPicture = _album.Pictures.Last();

                    _pictureCarousel.Add(lastPicture);
                    foreach (var p in _album.Pictures) { _pictureCarousel.Add(p); }
                    _pictureCarousel.Add(firstPicture);

                    picturesViewSource.Source = _pictureCarousel;
                }
            }

            base.OnNavigatedTo(e);
        }