public GenMapView(GenMainPage parentPage) : base(GlobalVars.navigationTitle)
        {
            GlobalVars.View_GenMapView = null;
            this._parentPage           = parentPage;

            navigationListView = new ListView
            {
                ItemTemplate = new DataTemplate(typeof(NavigationCell)),
                ItemsSource  = GlobalVars.NavigationChoices
            };

            navigationListView.ItemTapped += (object sender, ItemTappedEventArgs e) =>
            {
                //GlobalVars.GenConBusiness.ShowLoadingEventMessage("Data is still loading, map may not be up to date");

                if (e != null && e.Item != null)
                {
                    var selectedDetailChoice = (DetailChoice)e.Item;

                    if (selectedDetailChoice.data.ToLower().StartsWith("http:") || selectedDetailChoice.data.ToLower().StartsWith("https:"))
                    {
                        // don't put this in a popup container - it uses a plugin to determine the fastest option to open (uses embedded chrome options)
                        CrossShare.Current.OpenBrowser(selectedDetailChoice.data, null);
                    }
                    else
                    {
                        var page = (PopupPage)Activator.CreateInstance(selectedDetailChoice.pageType);
                        page.BindingContext = selectedDetailChoice;
                        PopupNavigation.Instance.PushAsync(page);
                    }

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        navigationListView.SelectedItem = null;
                    });
                }
            };

            this.OnAppearedHandler += (sender, args) =>
            {
                ClearNavOption(ListView.SelectedItemProperty);
            };

            var content = new StackLayout
            {
                Children =
                {
                    navigationListView
                }
            };

            this.ToolbarItems.Add(new ToolbarItem("Font Size", "baseline_format_size_black_24.png", () =>
            {
                var page = new DisplayOptionsPage();
                PopupNavigation.Instance.PushAsync(page);
            }));

            this.ToolbarItems.Add(new ToolbarItem("Refresh", "ic_refresh_black_24dp.png", () =>
            {
                GlobalVars.View_GenEventsLoadingView.StartLoad();
            }));

            this.Content = content;
            GlobalVars.View_GenMapView = this;
        }
示例#2
0
        public GenSearchView(GenMainPage parentPage) : base(GlobalVars.searchTitle)
        {
            GlobalVars.View_GenSearchView = null;
            _parentPage   = parentPage;
            _lastSyncTime = DateTime.Now;

            outerContainer = new AbsoluteLayout {
                Padding = 0
            };

            var wholePage = new StackLayout
            {
                Orientation       = StackOrientation.Vertical,
                Padding           = 0,
                Spacing           = 0,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand
            };

            var searchNavSectionTwo = new Grid
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Padding           = 1,
                ColumnSpacing     = 1,
                ColumnDefinitions = new ColumnDefinitionCollection()
                {
                    new ColumnDefinition()
                    {
                        Width = new GridLength(4, GridUnitType.Star)
                    },
                    new ColumnDefinition()
                    {
                        Width = new GridLength(4, GridUnitType.Star)
                    },
                    new ColumnDefinition()
                    {
                        Width = new GridLength(4, GridUnitType.Star)
                    },
                    new ColumnDefinition()
                    {
                        Width = new GridLength(3, GridUnitType.Star)
                    },
                    new ColumnDefinition()
                    {
                        Width = new GridLength(1, GridUnitType.Star)
                    }
                },
                RowDefinitions = new RowDefinitionCollection()
                {
                    new RowDefinition()
                    {
                        Height = GridLength.Auto
                    }
                }
            };

            //START OF UPPER SEARCH SECTION
            StackLayout searchNavSection = new StackLayout
            {
                Orientation       = StackOrientation.Horizontal,
                Padding           = 2,
                Spacing           = 0,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            searchEntry = new Entry
            {
                Keyboard          = Keyboard.Create(0),
                Placeholder       = "Search Here",
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            searchTerm = new SearchTerm();
            searchEntry.BindingContext = searchTerm;
            searchEntry.SetBinding(Entry.TextProperty, "searchTerm", BindingMode.TwoWay);

            searchEntry.Completed += (sender, e) =>
            {
                SetGenListContent();
            };

            //run the below on every keypress
            var clearWatcher = searchTerm.observer
                               .ObserveOn(SynchronizationContext.Current)
                               .Subscribe(final =>
            {
                searchTerm.isIgnoringNextEvent = false;
                outerContainer.Children.Remove(autoCompleteHolder);
            });

            //only run the below on legit text entry
            var autoCompleteWatcher = searchTerm.observer
                                      .Throttle(TimeSpan.FromMilliseconds(300))             //Wait for the user to pause typing
                                      .Where(x => !string.IsNullOrEmpty(x) && x.Length > 2) //Make sure the search term is long enough
                                      .DistinctUntilChanged()
                                      .ObserveOn(SynchronizationContext.Current)
                                      .Subscribe((x) =>
            {
                Observable.FromAsync((_) => {
                    string term = x.Trim();
                    if ((term.Length == 10 || term.Length == 11) && GlobalVars.isTypedEventID(term))
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            SetGenListContent();
                        });
                        return(new Task <IList <GenEvent> >(() =>
                        {
                            var returnMe = new List <GenEvent>();
                            return returnMe;
                        }));
                    }
                    return(GlobalVars.db.GetItemsFTS4(term, new GenconMobileDatabase.DBOptions[] { }));
                })                                         //MatchOnEmail returns Task<IEnumerable<T>>
                .TakeUntil(searchTerm.observer)            //If searchterm changes abandon the current request
                .ObserveOn(SynchronizationContext.Current) //To be safe marshall response to the UI thread
                .Subscribe(final =>                        //final holds the IEnumerable<T>
                {
                    try
                    {
                        if (!searchTerm.isIgnoringNextEvent)
                        {
                            AutoCompleteMatches.Clear();
                            if (final == null || !final.Any())
                            {
                                MatchCount = 0;
                                //ShowResult = false;
                                RemoveAutoCompleteView();
                            }
                            else
                            {
                                foreach (var g in final.DistinctBy(d => d.Title).OrderBy(d => d.Title).Take(5))
                                {
                                    AutoCompleteMatches.Add(g);
                                }
                                MatchCount = AutoCompleteMatches.Count;
                                matchListView.ItemsSource = AutoCompleteMatches;
                                var r    = AbsoluteLayout.GetLayoutBounds(autoCompleteHolder);
                                r.Y      = searchEntry.Y + (searchEntry.Height);
                                r.Height = wholePage.Height;
                                AbsoluteLayout.SetLayoutFlags(autoCompleteHolder, AbsoluteLayoutFlags.HeightProportional);
                                AbsoluteLayout.SetLayoutBounds(autoCompleteHolder, r);
                                //autoCompleteHolder.MinimumHeightRequest = wholePage.Height;
                                matchListView.HeightRequest = searchEntry.Height * Math.Min(AutoCompleteMatches.Count, 3);
                                //ShowResult = true;
                                if (!outerContainer.Children.Contains(autoCompleteHolder))
                                {
                                    outerContainer.Children.Add(autoCompleteHolder);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        string error = ex.Message;
                    }
                });
            });


            var clearSearchButton = new Image {
                Aspect = Aspect.AspectFit, HorizontalOptions = LayoutOptions.End
            };

            clearSearchButton.Source = ImageSource.FromFile("ic_cancel_black_24dp.png");

            TapGestureRecognizer clearSearchTap = new TapGestureRecognizer();

            clearSearchTap.Tapped += ClearSearchTap_Tapped;

            clearSearchButton.GestureRecognizers.Add(clearSearchTap);

            var searchStartButton = new Image {
                Aspect = Aspect.AspectFit, HorizontalOptions = LayoutOptions.End
            };

            searchStartButton.Source = ImageSource.FromFile("ic_search_black_24dp.png");

            TapGestureRecognizer startSearchTap = new TapGestureRecognizer();

            startSearchTap.Tapped += StartSearchTap_Tapped;
            //startSearchTap.Tapped += DEBUGDEMO_Tapped;
            searchStartButton.GestureRecognizers.Add(startSearchTap);
            autoCompleteHolder = new StackLayout
            {
                Padding           = 0,
                Spacing           = 0,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Orientation       = StackOrientation.Vertical,
                BackgroundColor   = Color.FromRgba(0.2, 0.2, 0.2, 0.5)
            };
            var matchListTemplate = new DataTemplate(typeof(TextCell));

            matchListTemplate.SetBinding(TextCell.TextProperty, "Title");

            itemTemplate = new DataTemplate(typeof(GenEventCell));
            itemTemplate.CreateContent();

            matchListView = new ListView
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.Start,
                BindingContext    = this,
                ItemTemplate      = matchListTemplate,
                BackgroundColor   = Color.White
            };

            autoCompleteHolder.Children.Add(matchListView);

            searchNavSection.Children.Add(searchEntry);
            searchNavSection.Children.Add(clearSearchButton);
            searchNavSection.Children.Add(searchStartButton);

            wholePage.Children.Add(searchNavSection);

            //searchNavSectionTwo
            dayPicker = new Picker
            {
                Title             = "Days",
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            dayPicker.Items.Add("ALL");
            dayPicker.Items.Add("WED");
            dayPicker.Items.Add("THU");
            dayPicker.Items.Add("FRI");
            dayPicker.Items.Add("SAT");
            dayPicker.Items.Add("SUN");

            afterPicker = new Picker
            {
                Title             = "After",
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            afterPicker.Items.Add("---");
            afterPicker.Items.Add("01:00AM");
            afterPicker.Items.Add("02:00AM");
            afterPicker.Items.Add("03:00AM");
            afterPicker.Items.Add("04:00AM");
            afterPicker.Items.Add("05:00AM");
            afterPicker.Items.Add("06:00AM");
            afterPicker.Items.Add("07:00AM");
            afterPicker.Items.Add("08:00AM");
            afterPicker.Items.Add("09:00AM");
            afterPicker.Items.Add("10:00AM");
            afterPicker.Items.Add("11:00AM");
            afterPicker.Items.Add("12:00PM");
            afterPicker.Items.Add("01:00PM");
            afterPicker.Items.Add("02:00PM");
            afterPicker.Items.Add("03:00PM");
            afterPicker.Items.Add("04:00PM");
            afterPicker.Items.Add("05:00PM");
            afterPicker.Items.Add("06:00PM");
            afterPicker.Items.Add("07:00PM");
            afterPicker.Items.Add("08:00PM");
            afterPicker.Items.Add("09:00PM");
            afterPicker.Items.Add("10:00PM");
            afterPicker.Items.Add("11:00PM");

            beforePicker = new Picker
            {
                Title             = "Before",
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };


            beforePicker.Items.Add("---");
            beforePicker.Items.Add("01:00AM");
            beforePicker.Items.Add("02:00AM");
            beforePicker.Items.Add("03:00AM");
            beforePicker.Items.Add("04:00AM");
            beforePicker.Items.Add("05:00AM");
            beforePicker.Items.Add("06:00AM");
            beforePicker.Items.Add("07:00AM");
            beforePicker.Items.Add("08:00AM");
            beforePicker.Items.Add("09:00AM");
            beforePicker.Items.Add("10:00AM");
            beforePicker.Items.Add("11:00AM");
            beforePicker.Items.Add("12:00PM");
            beforePicker.Items.Add("01:00PM");
            beforePicker.Items.Add("02:00PM");
            beforePicker.Items.Add("03:00PM");
            beforePicker.Items.Add("04:00PM");
            beforePicker.Items.Add("05:00PM");
            beforePicker.Items.Add("06:00PM");
            beforePicker.Items.Add("07:00PM");
            beforePicker.Items.Add("08:00PM");
            beforePicker.Items.Add("09:00PM");
            beforePicker.Items.Add("10:00PM");
            beforePicker.Items.Add("11:00PM");

            sortPicker = new Picker
            {
                Title             = "Sort",
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            sortPicker.Items.Add("Time");
            sortPicker.Items.Add("Title");
            sortPicker.Items.Add("Ticket");
            sortPicker.Items.Add("Price");

            changeSortButton = new Image {
                Aspect = Aspect.AspectFit
            };
            changeSortButton.Source = ImageSource.FromFile("ic_arrow_downward_black_24dp.png");

            TapGestureRecognizer changeSortTap = new TapGestureRecognizer();

            changeSortTap.Tapped += ChangeSort_Tapped;

            changeSortButton.GestureRecognizers.Add(changeSortTap);

            searchNavSectionTwo.Children.Add(dayPicker, 0, 0);
            searchNavSectionTwo.Children.Add(afterPicker, 1, 0);
            searchNavSectionTwo.Children.Add(beforePicker, 2, 0);
            searchNavSectionTwo.Children.Add(sortPicker, 3, 0);
            searchNavSectionTwo.Children.Add(changeSortButton, 4, 0);

            wholePage.Children.Add(searchNavSectionTwo);

            //START OF LOWER EVENT SECTION
            eventDisplayWrapper = new StackLayout {
                Orientation = StackOrientation.Vertical, Padding = paddingAmount, Spacing = 0, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand
            };
            eventDisplay = new StackLayout {
                Orientation = StackOrientation.Vertical, Padding = 0, Spacing = 6, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand
            };

            lastUpdatedEventsLabel = new Label
            {
                Text                    = GlobalVars.eventsLastUpdatedPretty,
                FontSize                = 10,
                FontAttributes          = FontAttributes.Italic,
                HorizontalOptions       = LayoutOptions.FillAndExpand,
                HorizontalTextAlignment = TextAlignment.Center
            };

            eventsTotalCountLabel = new Label
            {
                Text                    = GlobalVars.eventsTotalCountPretty,
                FontSize                = 12,
                FontAttributes          = FontAttributes.Bold,
                HorizontalOptions       = LayoutOptions.FillAndExpand,
                HorizontalTextAlignment = TextAlignment.Center
            };

            var thirdString = new Label
            {
                Text                    = GlobalVars.eventsExplanationPretty,
                FontSize                = 10,
                HorizontalOptions       = LayoutOptions.FillAndExpand,
                HorizontalTextAlignment = TextAlignment.Center
            };

            var showAllButton = new Button
            {
                Text = "SHOW ALL",
                HorizontalOptions = LayoutOptions.Center
            };

            var fourthString = new Label
            {
                Text                    = GlobalVars.eventsFinalInfoPretty,
                FontSize                = 12,
                HorizontalOptions       = LayoutOptions.FillAndExpand,
                HorizontalTextAlignment = TextAlignment.Center
            };

            eventDisplay.Children.Add(lastUpdatedEventsLabel);
            eventDisplay.Children.Add(eventsTotalCountLabel);
            eventDisplay.Children.Add(thirdString);
            eventDisplay.Children.Add(showAllButton);
            eventDisplay.Children.Add(fourthString);

            eventDisplayWrapper.Children.Add(eventDisplay);

            wholePage.Children.Add(eventDisplayWrapper);

            genEventList = new GenEventList
            {
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            genEventListView = new ListView(ListViewCachingStrategy.RecycleElement)
            {
                RowHeight = (int)GlobalVars.sizeListCellHeight,

                SeparatorVisibility = SeparatorVisibility.None
            };

            loadingListView = new ListView
            {
                RowHeight           = (int)GlobalVars.sizeListCellHeight,
                SeparatorVisibility = SeparatorVisibility.None
            };

            loadingIndicator = new ActivityIndicator()
            {
                IsRunning            = true,
                IsVisible            = false,
                VerticalOptions      = LayoutOptions.FillAndExpand,
                HorizontalOptions    = LayoutOptions.FillAndExpand,
                BackgroundColor      = Color.Transparent,
                MinimumWidthRequest  = 400,
                MinimumHeightRequest = 400
            };

            outerContainer.Children.Add(wholePage);
            outerContainer.Children.Add(loadingIndicator);

            AbsoluteLayout.SetLayoutBounds(wholePage, new Rectangle(0, 0, 1, 1));
            AbsoluteLayout.SetLayoutFlags(wholePage, AbsoluteLayoutFlags.All);

            AbsoluteLayout.SetLayoutFlags(loadingIndicator,
                                          AbsoluteLayoutFlags.PositionProportional);
            AbsoluteLayout.SetLayoutBounds(loadingIndicator,
                                           new Rectangle(0.5,
                                                         0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));


            Content = outerContainer;

            this.ToolbarItems.Add(new ToolbarItem("Font Size", "baseline_format_size_black_24.png", () =>
            {
                var page = new DisplayOptionsPage();
                PopupNavigation.Instance.PushAsync(page);
            }));

            this.ToolbarItems.Add(new ToolbarItem("Refresh", "ic_refresh_black_24dp.png", () =>
            {
                GlobalVars.View_GenEventsLoadingView.StartLoad();
            }));


            //Start of hidden event portion RESUME CODING HERE

            showAllButton.Clicked             += OnShowAllClicked;
            dayPicker.SelectedIndexChanged    += OnDayPickerSelected;
            sortPicker.SelectedIndexChanged   += OnSortPickerSelected;
            afterPicker.SelectedIndexChanged  += OnAfterPickerSelected;
            beforePicker.SelectedIndexChanged += OnBeforePickerSelected;

            matchListView.ItemSelected += MatchListView_ItemSelected;
            //genEventListView.ItemTapped += GenEventListView_ItemTapped;

            genEventListView.ItemSelected += GenEventListView_ItemSelected;

            TapGestureRecognizer clearAutoCompleteTap = new TapGestureRecognizer();

            clearAutoCompleteTap.Tapped += ClearAutoCompleteTap_Tapped;

            autoCompleteHolder.GestureRecognizers.Add(clearAutoCompleteTap);

            this.LayoutChanged += GenNavigationPage_LayoutChanged;

            this.OnAppearedHandler     += Event_CheckForUpdates;
            this.CheckForUpdateHandler += Event_CheckForUpdates;

            GlobalVars.View_GenSearchView = this;
        }