/// <summary> /// Starts the hero image slide show. /// </summary> public void StartHeroImageSlideShow() { // Only start slideshow if we were able to get // any hero images if (HeroImages != null && HeroImages.Any()) { _heroImageScrollTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(7) }; StartHeroImageSlideshowTimer(); } }
/// <summary> /// Starts a timer which cycles through hero images. /// </summary> private void StartHeroImageSlideshowTimer() { _heroImageScrollTimer.Start(); _heroImageScrollTimer.Tick += (s, e) => { var selectedIndex = HeroImages.IndexOf(SelectedHeroImage); selectedIndex = (selectedIndex + 1) % HeroImages.Count; SelectedHeroImage = HeroImages[selectedIndex]; }; }
/// <summary> /// Instantiates the hero image slideshow timer. /// </summary> public void InstantiateHeroImageSlideShowTimer() { // Only instantiate slideshow timer if we were able to get // any hero images if (HeroImages != null && HeroImages.Any()) { _heroImageScrollTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(HeroImageScrollTimerInterval) }; _heroImageScrollTimer.Tick += (s, e) => { var selectedIndex = HeroImages.IndexOf(SelectedHeroImage); selectedIndex = (selectedIndex + 1) % HeroImages.Count; SelectedHeroImage = HeroImages[selectedIndex]; }; } }
/// <summary> /// Loads the state. /// </summary> public override async Task LoadState() { await base.LoadState(); IsBusy = true; IsStatusContainerVisible = true; try { TopCategories.Clear(); // Load hero images var heroImages = await _photoService.GetHeroImages(NumberOfHeroImages); HeroImages.Clear(); heroImages.ForEach(h => HeroImages.Add(h)); // Load categories var categories = await _photoService.GetTopCategories(AppEnvironment.Instance.CategoryThumbnailsCount); IsEmptyDataMessageVisible = !categories.Any(); IsStatusContainerVisible = !categories.Any(); foreach (var c in categories) { TopCategories.Add(c); // For UI animation purposes, we wait a little until the next // element is inserted. await Task.Delay(200); } } catch (ServiceException) { await _dialogService.ShowGenericServiceErrorNotification(); } finally { IsBusy = false; } }
public async Task RefreshAsync(bool force = false) { // Check connectivity if (!connectivityService.IsConnected()) { await ShowNoConnectionDialog(dialogService); return; } // Check if ViewModel is already loaded or refreshing if (IsLoading || (IsLoaded && !force)) { return; } IsLoading = true; // Don't use placeholders when PullToRefresh is used //if (!force) //{ // // Get Mock Data to show placeholders // HeroImages.ReplaceRange(MockData.GetHeroImages()); // //TopCategories.ReplaceRange(MockData.GetTopCategories()); // TopCategories = new ObservableRangeCollection<GroupedCategoryPreview>(MockData.GetTopCategories()); //} // Get current user try { // Try to restore user credentials if (AzureAppService.Current.CurrentUser == null) { await photoService.RestoreSignInStatusAsync(); } CurrentUser = await photoService.GetCurrentUser(); } catch (Exception ex) { if (ex is UnauthorizedException || ex is ServiceException) { // User not logged in yet CurrentUser = null; } else { throw; } } // Load hero images var heroes = await photoService.GetHeroImages(5); HeroImages.ReplaceRange(heroes); // Load categories var topCat = await photoService.GetTopCategories(6); var grouped = from category in topCat group category by category.Name into categoryGroup select new GroupedCategoryPreview(categoryGroup.First()?.PhotoThumbnails, categoryGroup.Key, categoryGroup.Key.Substring(0, 1), categoryGroup.FirstOrDefault()); //HACK: Re-initializing because FlowListView crashes when Replacing lists at the moment. TopCategories = new ObservableRangeCollection <GroupedCategoryPreview>(grouped); //TopCategories.ReplaceRange(grouped); // Check if loading went right IsLoaded = HeroImages.Count > 0 || TopCategories.Count > 0; IsLoading = false; }