protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { m_isFromLiveTile = false; m_type = ListType.Unknow; // Retrieve aimed id //------------------------------------------------------------------------------------ int elementId = -128; // Retrieve the element ID to get its details if (NavigationContext.QueryString.Keys.Contains("id")) { var number = NavigationContext.QueryString["id"]; try { elementId = Convert.ToInt32(number); } catch (Exception) { } } if (elementId == -128) { errorGoBack(); } else if (elementId == -1) { // Special id: element stored for live tile if (m_isFromLiveTile == false) { m_isFromLiveTile = true; } elementId = Settings.LiveTileElementId; } // Cache not loaded (we're coming from tile) ? Load it if (CacheManager.Instance.IsInitialized == false) { CacheManager.Instance.Initialize(InitializeLevel.Update); } // Get the element from WS Element element = getElementFromId(elementId); // Create view models ElementViewModel elementVM = null; if (element is Word) { elementVM = new WordViewModel(element as Word); } else if (element is Contrepeterie) { var ctpVM = new ContrepeterieViewModel(element as Contrepeterie); ctpVM.IsSolutionRevealed = false; elementVM = ctpVM; } else { errorGoBack(); return; } if (elementVM.IsRead == false) elementVM.IsRead = true; m_viewModel = new DetailsPageViewModel(elementVM); m_viewModel.Orientation = Orientation; // Load data fetcher //------------------------------------------------------------------------------------ string fetcherType = ""; string param = ""; if (NavigationContext.QueryString.Keys.Contains("type")) { fetcherType = NavigationContext.QueryString["type"]; if (NavigationContext.QueryString.Keys.Contains("param")) { param = NavigationContext.QueryString["param"]; } } else if (m_isFromLiveTile) { if (element is Word) fetcherType = ListType.Words.ToString(); else fetcherType = ListType.Contrepeteries.ToString(); } else { throw new ArgumentException("fetcher type"); } m_dataList = getAllData((ListType)Enum.Parse(typeof(ListType), fetcherType, true), param); bufferNextAndPreviousPage(element.Id); // ------------------ m_viewModel.IsRead = true; setDataContext(m_viewModel); // Mark as read if from tile if (m_isFromLiveTile) { BackgroundWorker bworker = new BackgroundWorker(); bworker.DoWork += (o, args) => { // Delay Thread.Sleep(1000); Dispatcher.BeginInvoke(() => { TileData.FindAndUpdateTile(); }); }; bworker.RunWorkerAsync(); } // Dynamically load app bar icons updateAppBar(); base.OnNavigatedTo(e); }
/// <summary> /// Select a CTP in the list /// </summary> /// <param name="contrepeterieViewModel"></param> /// <returns></returns> public string SelectContrepeterie(ContrepeterieViewModel contrepeterieViewModel) { contrepeterieViewModel.IsRead = true; RaisePropertyChanged("CTPs"); return string.Format("/Views/DetailsPage.xaml?id={0}&type=contrepeteries", contrepeterieViewModel.Id); }
/// <summary> /// Bufferize previous and buffer detail page /// </summary> /// <param name="currentId"></param> private void bufferNextAndPreviousPage(int currentId) { int index = m_dataList.IndexOf(currentId); m_isPreviousEnable = (index > 0); m_isNextEnable = (index + 1 < m_dataList.Count); if (m_isPreviousEnable) { var previousElement = CacheManager.Instance.GetCacheElementFromId<Element>(m_dataList[index - 1]); ElementViewModel previousElementViewModel = null; if (previousElement is Word) previousElementViewModel = new WordViewModel(previousElement as Word); else if (previousElement is Contrepeterie) previousElementViewModel = new ContrepeterieViewModel(previousElement as Contrepeterie); m_previousViewModel = new DetailsPageViewModel(previousElementViewModel); } if (m_isNextEnable) { var nextElement = CacheManager.Instance.GetCacheElementFromId<Element>(m_dataList[index + 1]); ElementViewModel nextElementViewModel = null; if (nextElement is Word) nextElementViewModel = new WordViewModel(nextElement as Word); else if (nextElement is Contrepeterie) nextElementViewModel = new ContrepeterieViewModel(nextElement as Contrepeterie); m_nextViewModel = new DetailsPageViewModel(nextElementViewModel); } }