/// <summary>
        /// Gets the NavigationHelper used to aid in navigation and process lifetime management.
        /// </summary>


        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            // TODO: Create an appropriate data model for your problem domain to replace the sample data
            Debug.WriteLine("LoadState");

#if WINDOWS_PHONE_APP
            IndexPanel.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            //this.BottomAppBar = PageBottomCommandBar;
            //this.BottomAppBar.Visibility = Visibility.Visible;
            var statusBar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView();
            await statusBar.HideAsync();
#endif
            //Relayout_ContentColumn(ContentRegion.RenderSize);
            if (e.PageState == null)
            {
                var nav = navigationId = NovelPositionIdentifier.Parse((string)e.NavigationParameter);

                if (nav.SeriesId != null && (nav.VolumeNo == -1 || nav.ChapterNo == -1))
                {
                    IsIndexPanelOpen = true;
                }
                else
                {
                    IsIndexPanelOpen = false;
                }

                await viewModel.LoadDataAsync(nav);
            }
            else
            {
                IsIndexPanelOpen = false;
                if (e.PageState.ContainsKey("LoadingBreak"))
                {
                    var nav = navigationId = NovelPositionIdentifier.Parse((string)e.PageState["LoadingBreak"]);
                    await viewModel.LoadDataAsync(nav);
                }
                else
                {
                    var volumeNo  = (int)e.PageState["VolumeNo"];
                    var chapterNo = (int)e.PageState["ChapterNo"];
                    var seriesId  = (int)e.PageState["SeriesId"];
                    var lineNo    = (int)e.PageState["LineNo"];
                    await viewModel.LoadDataAsync(seriesId, volumeNo, chapterNo, lineNo);
                }
#if WINDOWS_APP
                var horizontalOffset = (double)e.PageState["HorizontalOffset"];
                var verticalOffset   = (double)e.PageState["VerticalOffset"];
                ContentScrollViewer.ChangeView(horizontalOffset, verticalOffset, null, true);
#endif
                //SyncIndexSelectedItem();
            }
            ViewModel.NotifyPropertyChanged("IsPinned");
            ViewModel.NotifyPropertyChanged("IsFavored");
        }
        async Task NavigateToReadingPageAsync(string seriesTitle, NovelPositionIdentifier nav, bool newWindows = false)
        {
#if WINDOWS_APP || WINDOWS_UWP
            var view = AppGlobal.SecondaryViews.FirstOrDefault(v => v.Title == seriesTitle);
            if (view == null && !newWindows)
            {
                this.Frame.Navigate(typeof(ReadingPage), nav.ToString());
            }
            else
            {
                try
                {
                    if (view == null)
                    {
                        view = await ReadingPage.CreateInNewViewAsync(seriesTitle, nav);
                    }

                    // Prevent the view from closing while
                    // switching to it
                    view.StartViewInUse();

                    // Show the previously created secondary view, using the size
                    // preferences the user specified. In your app, you should
                    // choose a size that's best for your scenario and code it,
                    // instead of requiring the user to decide.
                    var viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(
                        view.Id,
                        ViewSizePreference.Default,
                        ApplicationView.GetForCurrentView().Id,
                        ViewSizePreference.Default);

                    if (!viewShown)
                    {
                        this.Frame.Navigate(typeof(ReadingPage), nav.ToString());
                    }

                    // Signal that switching has completed and let the view close
                    view.StopViewInUse();
                }
                catch (InvalidOperationException)
                {
                    Debug.WriteLine("Some thing wrong");
                }
            }
#else
            this.Frame.Navigate(typeof(ReadingPage), nav.ToString());
#endif
        }
Beispiel #3
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected async override void OnLaunched(LaunchActivatedEventArgs e)
        {
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
            Debug.WriteLine("AppOnLaunched");
#endif
#if WINDOWS_UWP
            SyncAppAccentColor();
            //var search = await LightKindomHtmlClient.SearchBookAsync("青春");
            //var featured = await LightKindomHtmlClient.GetFeaturedBooks();
            //var comments = await LightKindomHtmlClient.GetCommentsAsync("797", "72");
            //var chptr = await LightKindomHtmlClient.GetChapterAsync("797", "129", "72");
            //var chptr = await LightKindomHtmlClient.GetSeriesAsync("72");

            //var chapter = new Uri("http://linovel.com/book/read?chapterId=798&volId=129&bookId=72");
            //var client = new Windows.Web.Http.HttpClient();
            //var content = await client.GetStringAsync(chapter);
            //var result = await LightKindomHtmlClient.GetCommentedLinesListAsync("4516");
            //var anotherresult = await LightKindomHtmlClient.GetCommentsAsync("36","4516");
            //var chptr = await LightKindomHtmlClient.GetSeriesIndexAsync();
            //var result = await LightKindomHtmlClient.SearchBookAsync("青春");
#endif

            mainDispatcher = Window.Current.Dispatcher;
            mainViewId     = ApplicationView.GetForCurrentView().Id;

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                ExtendedSplash extendedSplash;
                if (Window.Current.Content == null)
                {
                    extendedSplash = new ExtendedSplash(e.SplashScreen);
                }
                else
                {
                    extendedSplash = Window.Current.Content as ExtendedSplash;
                }
                extendedSplash.RegisterFrameArriveDimmsion();
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = extendedSplash.RootFrame;
                // TODO: change this value to a cache size that is appropriate for your application
                rootFrame.CacheSize = 3;

                //Associate the frame with a SuspensionManager key
                try
                {
                    SuspensionManager.RegisterFrame(rootFrame, "AppFrame");
                }
                catch (Exception)
                {
                }

                Window.Current.Content = extendedSplash;
                Window.Current.Activate();
                // Place the frame in the current Window
                // Window.Current.Content = rootFrame;
            }
            else
            {
                Window.Current.Activate();
            }

            #region Preloading
#if WINDOWS_PHONE_APP
            //Windows.UI.ViewManagement.ApplicationView.GetForCurrentView()
            //	 .SetDesiredBoundsMode(Windows.UI.ViewManagement.ApplicationViewBoundsMode.UseVisible);
            var statusBar = StatusBar.GetForCurrentView();
            statusBar.BackgroundOpacity = 0;
            statusBar.ForegroundColor   = (Windows.UI.Color)Resources["AppBackgroundColor"];
#endif
            //return;

            await AppGlobal.LoadHistoryDataAsync();

            await AppGlobal.LoadBookmarkDataAsync();

            await CachedClient.InitializeCachedSetAsync();

            AppGlobal.RefreshAutoLoadPolicy();
            #endregion

            if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
                // Restore the saved session state only when appropriate
                try
                {
#if WINDOWS_PHONE_APP
                    rootFrame.ContentTransitions = new TransitionCollection()
                    {
                        new NavigationThemeTransition()
                        {
                            DefaultNavigationTransitionInfo = new ContinuumNavigationTransitionInfo()
                        }
                    };
#endif
                    await SuspensionManager.RestoreAsync();

                    if (rootFrame.Content != null && Window.Current.Content != rootFrame)
                    {
                        Window.Current.Content = rootFrame;
                        return;
                    }
                }
                catch (SuspensionManagerException)
                {
                    // Something went wrong restoring state.
                    // Assume there is no state and continue
                }
            }

            if (rootFrame.Content == null)
            {
#if WINDOWS_PHONE_APP
                // Removes the turnstile navigation for startup.
                rootFrame.ContentTransitions = null;
                rootFrame.Navigated         += this.RootFrame_FirstNavigated;
#endif
            }

            // When the navigation stack isn't restored navigate to the first page,
            // configuring the new page by passing required information as a navigation
            // parameter

            bool navResult = true;

            if (string.IsNullOrEmpty(e.Arguments))
            {
                var entity = rootFrame.BackStack.FirstOrDefault(pse => pse.SourcePageType == typeof(HubPage));
                if (rootFrame.CurrentSourcePageType != typeof(HubPage) && entity == null)
                {
                    navResult = rootFrame.Navigate(typeof(HubPage), e.Arguments);
                }
                else
                {
                    while (rootFrame.CurrentSourcePageType != typeof(HubPage) && rootFrame.CanGoBack)
                    {
                        rootFrame.GoBack();
                    }
                }
            }
            else
            {
                var entity = rootFrame.BackStack.FirstOrDefault(pse => pse.SourcePageType == typeof(ReadingPage));
                if (entity == null && rootFrame.CurrentSourcePageType != typeof(ReadingPage))
                {
                    navResult = rootFrame.Navigate(typeof(ReadingPage), e.Arguments);
                }
                else
                {
                    while (rootFrame.CurrentSourcePageType != typeof(ReadingPage) && rootFrame.CanGoBack)
                    {
                        rootFrame.GoBack();
                    }
                    var page         = rootFrame.Content as ReadingPage;
                    var navigationId = NovelPositionIdentifier.Parse((string)e.Arguments);
                    if (navigationId.SeriesId != page.ViewModel.SeriesId.ToString())
                    {
                        navResult = rootFrame.Navigate(typeof(ReadingPage), e.Arguments);
                    }
                }
            }
            if (!navResult)
            {
                navResult = rootFrame.Navigate(typeof(HubPage), null);
            }


            AppGlobal.Settings.UpdateSavedAppVersion();
            //App.CurrentState.SignInAutomaticlly();
            // Ensure the current window is active
            //Window.Current.Activate();
        }
		public static async Task<ViewLifetimeControl> CreateInNewViewAsync(string seriesTitle, NovelPositionIdentifier nav)
		{
			ViewLifetimeControl viewControl = null;
			await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
			{
				// This object is used to keep track of the views and important
				// details about the contents of those views across threads
				// In your app, you would probably want to track information
				// like the open document or page inside that window
				viewControl = ViewLifetimeControl.CreateForCurrentView();
				viewControl.Title = seriesTitle;
				AppGlobal.SecondaryViews.Add(viewControl);

				var frame = new Frame();
				frame.Navigate(typeof(ReadingPage), nav.ToString());
				Window.Current.Content = frame;
				var readingPage = frame.Content as ReadingPage;
                readingPage.OpenInNewViewButton.Visibility = Visibility.Collapsed;
                if (readingPage != null)
					viewControl.Released += readingPage.ViewControl_Released;

				ApplicationView.GetForCurrentView().Title = viewControl.Title;
				//ApplicationView.GetForCurrentView().Consolidated += readingPage.ReadingPage_Consolidated;
				//viewControl.StartViewInUse();
			});

			return viewControl;
		}
        /// <summary>
        /// Gets the NavigationHelper used to aid in navigation and process lifetime management.
        /// </summary>


        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            // TODO: Create an appropriate data model for your problem domain to replace the sample data
            Debug.WriteLine("LoadState");
            VisualStateManager.GoToState(this, IndexClosedState, false);

#if WINDOWS_PHONE_APP
            //IndexPanel.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            //this.BottomAppBar = PageBottomCommandBar;
            //this.BottomAppBar.Visibility = Visibility.Visible;
            TranslationType = 0;
            LayoutRootFadeinStory.Begin();
            await UpdateSizeOrientationDependentResourcesAsync();
#elif WINDOWS_APP || WINDOWS_UWP
            if (this.Frame.CanGoBack)
            {
                OpenInNewViewButton.Visibility = Windows.UI.Xaml.Visibility.Visible;
            }
            else
            {
                OpenInNewViewButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }

            Window.Current.SetTitleBar(TitlePanelBackground);
#endif
            if (this.RequestedTheme != AppGlobal.Settings.BackgroundTheme)
            {
                this.RequestedTheme = AppGlobal.Settings.BackgroundTheme;
            }
            //Relayout_ContentColumn(ContentRegion.RenderSize);
            if (e.PageState != null && e.PageState.Count > 0)
            {
                IsIndexPanelOpen = false;
                if (e.PageState.ContainsKey("LoadingBreak"))
                {
                    navigationId = NovelPositionIdentifier.Parse((string)e.PageState["LoadingBreak"]);
                    await viewModel.LoadDataAsync(navigationId);
                }
                else
                {
                    var fullScreen = (bool)e.PageState["IsFullScreen"];
                    if (fullScreen)
                    {
                        VisualStateManager.GoToState(this, "HideTitleBarState", false);
                        ViewModel.IsFullScreen = true;
                    }
                    else
                    {
                        VisualStateManager.GoToState(this, "ShowTitleBarState", false);
                        ViewModel.IsFullScreen = false;
                    }

                    var volumeNo  = (int)e.PageState["VolumeNo"];
                    var chapterNo = (int)e.PageState["ChapterNo"];
                    var seriesId  = (int)e.PageState["SeriesId"];
                    var lineNo    = (int)e.PageState["LineNo"];
                    await viewModel.LoadDataAsync(seriesId, volumeNo, chapterNo, lineNo);
                }
#if WINDOWS_APP
                var horizontalOffset = (double)e.PageState["HorizontalOffset"];
                var verticalOffset   = (double)e.PageState["VerticalOffset"];
                ContentScrollViewer.ChangeView(horizontalOffset, verticalOffset, null, true);
#endif
                //SyncIndexSelectedItem();
            }
            else
            {
                VisualStateManager.GoToState(this, "ShowTitleBarState", false);
                ViewModel.IsFullScreen = false;

                navigationId = NovelPositionIdentifier.Parse((string)e.NavigationParameter);

                if (navigationId.SeriesId != null && (navigationId.VolumeNo == -1 || navigationId.ChapterNo == -1))
                {
                    IsIndexPanelOpen = true;
                }
                else
                {
                    IsIndexPanelOpen = false;
                }

                await viewModel.LoadDataAsync(navigationId);
            }
            ViewModel.NotifyPropertyChanged("IsPinned");
            SyncPinButtonView();
            ViewModel.NotifyPropertyChanged("IsFavored");
        }
        public static async Task <ViewLifetimeControl> CreateInNewViewAsync(string seriesTitle, NovelPositionIdentifier nav)
        {
            ViewLifetimeControl viewControl = null;
            await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                // This object is used to keep track of the views and important
                // details about the contents of those views across threads
                // In your app, you would probably want to track information
                // like the open document or page inside that window
                viewControl       = ViewLifetimeControl.CreateForCurrentView();
                viewControl.Title = seriesTitle;
                AppGlobal.SecondaryViews.Add(viewControl);

                var frame = new Frame();
                frame.Navigate(typeof(ReadingPage), nav.ToString());
                Window.Current.Content = frame;
                var readingPage        = frame.Content as ReadingPage;
                readingPage.OpenInNewViewButton.Visibility = Visibility.Collapsed;
                if (readingPage != null)
                {
                    viewControl.Released += readingPage.ViewControl_Released;
                }

                ApplicationView.GetForCurrentView().Title = viewControl.Title;
                //ApplicationView.GetForCurrentView().Consolidated += readingPage.ReadingPage_Consolidated;
                //viewControl.StartViewInUse();
            });

            return(viewControl);
        }