Example #1
0
        /// <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="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected async override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            var queryText = navigationParameter as String;

            this.DefaultViewModel["QuoteDataSource"] = ThinkDataSource.Instance;
            this.DefaultViewModel["BackgroundColor"] = App.Current.RequestedTheme == ApplicationTheme.Light ? App.Current.Resources["LightBackground"] as string : App.Current.Resources["DarkBackground"] as string;

            // TODO: Application-specific searching logic.  The search process is responsible for
            //       creating a list of user-selectable result categories:
            //
            //       filterList.Add(new Filter("<filter name>", <result count>));
            //
            //       Only the first filter, typically "All", should pass true as a third argument in
            //       order to start in an active state.  Results for the active filter are provided
            //       in Filter_SelectionChanged below.

            var filterList = new List <Filter>();

            filterList.Add(new Filter(loader.GetString("SearchAllFilter"), 0, true));

            // Search recipes and tabulate results
            string query = queryText.ToLower();
            var    all   = new List <QuoteItem>();

            _results.Add(loader.GetString("SearchAllFilter"), all);


            while (ThinkDataSource.GetStatusLoad() == 0)
            {
                await Task.Delay(20);
            }

            foreach (var group in ThinkDataSource.GetGroups("AllGroups"))
            {
                var items = new List <QuoteItem>();
                _results.Add(group.Title, items);

                foreach (var item in group.Items)
                {
                    if (item.Autor.ToLower().Contains(query) || item.Quote.ToLower().Contains(query))
                    {
                        all.Add(item);
                        items.Add(item);
                    }
                }

                filterList.Add(new Filter(group.Title, items.Count, false));
            }

            filterList[0].Count = all.Count;


            // Communicate results through the view model
            this.DefaultViewModel["QueryText"]   = '\u201c' + queryText + '\u201d';
            this.DefaultViewModel["CanGoBack"]   = this._previousContent != null;
            this.DefaultViewModel["Filters"]     = filterList;
            this.DefaultViewModel["ShowFilters"] = filterList.Count > 1;
        }
        public async void LoadingAsync()
        {
            progressRing.IsActive = true;

            while (ThinkDataSource.GetStatusLoad() == ThinkDataSource.Loading)
            {
                await Task.Delay(100);
            }

            progressRing.IsActive = false;


            if (ThinkDataSource.Instance.AllGroups.Count == 0)
            {
                VisualStateManager.GoToState(this, "AllHaveNoItems", true);
            }
            else
            {
                VisualStateManager.GoToState(this, "AllHaveItems", true);
            }


            if (ThinkDataSource.GetStatusLoad() == ThinkDataSource.InternetError)
            {
                VisualStateManager.GoToState(this, "InternetError", true);
            }
            else if (ThinkDataSource.GetStatusLoad() == ThinkDataSource.XMLCorruptedError)
            {
                VisualStateManager.GoToState(this, "CorruptedXMLError", true);
            }
            else
            {
                VisualStateManager.GoToState(this, "NoError", true);
            }

            while (groupedItemsViewSource.View == null)
            {
                await Task.Delay(100);
            }
            (zoomItemLandscape.ZoomedOutView as ListViewBase).ItemsSource = groupedItemsViewSource.View.CollectionGroups;
            (zoomItemPortrait.ZoomedOutView as ListViewBase).ItemsSource  = groupedItemsViewSource.View.CollectionGroups;
        }