async void ChapterPageViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { var cvm = sender as ChapterViewModel; if (cvm != null && e.PropertyName == "DataContext") { CurrentChapter = cvm.DataContext; var id = CurrentChapter.ParentVolumeId; if (CurrentSeries == null || CurrentSeries.Id != CurrentChapter.ParentSeriesId) { try { CurrentSeries = await CachedClient.GetSeriesAsync(cvm.ParentSeriesId); } catch (Exception exception) { //MessageBox.Show("Exception happend when loading current novel Series."); Debug.WriteLine("Failed to retrive series data when loading a new chapter."); } } if (CurrentSeries == null) { return; } var volume = CurrentSeries.Volumes.FirstOrDefault(vol => vol.Id == id); if (volume != null) { CurrentVolume = volume; } else { throw new Exception("Current Chapter goes beyoung Current Series."); } } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { var series = ViewModel; if (e.NavigationMode == NavigationMode.Back) { return; } //Uri e.Uri string serId = NavigationContext.QueryString["id"]; string volId = null; if (NavigationContext.QueryString.ContainsKey("volume")) { volId = NavigationContext.QueryString["volume"]; } string cptId = null; if (NavigationContext.QueryString.ContainsKey("chapter")) { cptId = NavigationContext.QueryString["chapter"]; } int lineNo = 1; if (NavigationContext.QueryString.ContainsKey("line")) { string line = NavigationContext.QueryString["line"]; lineNo = int.Parse(line); } // Volume specifid view if (String.IsNullOrWhiteSpace(serId) && !String.IsNullOrWhiteSpace(volId)) { ViewModel.IsLoading = true; Volume volData = null; try { volData = await CachedClient.GetVolumeAsync(volId); } catch (Exception exception) { ViewModel.IsLoading = false; MessageBox.Show(exception.Message, "Network issue", MessageBoxButton.OK); NavigationService.GoBack(); return; } serId = volData.ParentSeriesId; ViewModel.Title = volData.Title; ViewModel.VolumeList.Clear(); ViewModel.VolumeList.Add(new VolumeViewModel { DataContext = volData }); ViewModel.Id = serId; App.CurrentVolume = volData; try { var serData = await CachedClient.GetSeriesAsync(serId); for (int i = 0; i < serData.Volumes.Count; i++) { if (serData.Volumes[i].Id == volId) { CurrentVolumeNo = i; break; } } ViewModel.DataContext = serData; if (VolumeViewList.ItemsSource.Count > 0) { VolumeViewList.ItemRealized += VolumeViewList_ItemRealized_ScrollToCurrentLine; } //App.CurrentSeries = serData; } catch (Exception exception) { MessageBox.Show("Exception happend when retriving series data" + exception.Message, "Network issue", MessageBoxButton.OK); } } if (series.Id != serId && !series.IsLoading) { await series.LoadDataAsync(serId); //ViewModel.IsLoading = true; if (VolumeViewList.ItemsSource.Count > 0) { CurrentVolumeNo = 0; VolumeViewList.ItemRealized += VolumeViewList_ItemRealized_ScrollToCurrentLine; } //await Task.WhenAll(ViewModel.VolumeList.Select(vvm => vvm.LoadDataAsync(vvm.Id))); } }