public static async Task<ViewLifetimeControl> CreateInNewViewAsync(string seriesTitle, NovelPositionIdentifier nav)
        {
            ViewLifetimeControl viewControl = null;

            await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
            {
                // 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);

                CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;

                var appView = ApplicationView.GetForCurrentView();
                appView.Title = viewControl.Title;
                appView.SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow);

                var titleBar = appView.TitleBar;
                titleBar.BackgroundColor = Colors.Transparent;
                titleBar.ButtonBackgroundColor = (Color)App.Current.Resources["AppAccentColor"];
                titleBar.ButtonInactiveBackgroundColor = (Color)App.Current.Resources["AppAccentColor"];

                await Task.Delay(TimeSpan.FromMilliseconds(200));

                var frame = new Frame();
                Window.Current.Content = frame;
                frame.Navigate(typeof(ReadingPage), nav.ToString());
                var readingPage = frame.Content as ReadingPage;

                if (readingPage != null)
                    viewControl.Released += readingPage.ViewControl_Released;


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

            return viewControl;
        }
Example #2
0
        //public static Task<Series> GetSeriesAsync(string id, bool forceRefresh = false)
        //{
        //    if (forceRefresh == false && SeriesCache.ContainsKey(id) && !SeriesCache[id].IsFaulted)
        //        return SeriesCache[id];

        //    if (SeriesCache.Count > MaxCachedUnit)
        //    {
        //        var outdates = (from item in SeriesCache where item.Value.IsCompleted select item.Key).ToArray(); ;
        //        foreach (var key in outdates)
        //        {
        //            SeriesCache.Remove(key);
        //            if (SeriesCache.Count < MaxCachedUnit)
        //                break;
        //        }
        //    }

        //    var task = GetAsync("series-" + id, () => LightKindomHtmlClient.GetSeriesAsync(id), DateTime.Now.AddDays(7), forceRefresh);
        //    SeriesCache[id] = task;
        //    CachedSeriesSet.Add(id);
        //    return task;
        //}

        public Task <Chapter> GetChapterAsync(NovelPositionIdentifier pos, bool forceRefresh = false)
        {
            return(GetChapterAsync(pos.ChapterId, pos.VolumeId, pos.SeriesId));
        }
        /// <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");
        }
 static NovelPositionIdentifier ParseIDFromReadLink(string link)
 {
     var pos = new NovelPositionIdentifier();
     Uri uri = new Uri(SeverBaseUri, link);
     var decoder = new WwwFormUrlDecoder(uri.Query);
     pos.ChapterId = decoder.GetFirstValueByName("chapterId");
     pos.VolumeId = decoder.GetFirstValueByName("volId");
     pos.SeriesId = decoder.GetFirstValueByName("bookId");
     return pos;
 }
        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
        }