Esempio n. 1
0
        private void ShowDepartures(Station[] allStations, Station fromStation, string from, string to, bool actSilently)
        {
            var toStationCandidates = allStations.Where(x => MainAndFilterPage.Filter(to, fromStation, null, x)).ToArray();
            var toStation           = toStationCandidates.Length == 1 ? toStationCandidates[0] : null;

            if (fromStation != null)
            {
                if (toStation != null)
                {
                    var target = DeparturesAndArrivalsTable.Create(fromStation, toStation);
                    NavigationService.Navigate(StationPage.GetUri(this, target, removeBackEntry: true));
                    return;
                }
                else
                {
                    if (string.IsNullOrEmpty(to))
                    {
                        var target = DeparturesAndArrivalsTable.Create(fromStation);
                        NavigationService.Navigate(StationPage.GetUri(this, target));
                    }
                    else
                    {
                        NavigationService.Navigate(MainAndFilterPage.GetUri(this, fromStation, initialFilter: to, removeBackEntry: true));
                    }
                    return;
                }
            }
            else
            {
                NavigationService.Navigate(MainAndFilterPage.GetUri(this, null, initialFilter: from, removeBackEntry: true));
            }
        }
Esempio n. 2
0
        public static List <DeparturesAndArrivalsTable> GetItemsToDisplay(Station fromStation, string excludeStation)
        {
            var recentItemsToDisplay = fromStation == null?allRecentItems.ToList() :
                                           (from item in allRecentItems
                                            let target = item.HasDestinationFilter && item.Station.Code == fromStation.Code && item.CallingAt.Value.Code != excludeStation ? item.CallingAt.Value :
                                                         item.Station.Code != excludeStation && item.Station.Code != fromStation.Code ? item.Station :
                                                         null
                                                             where target != null
                                                         select DeparturesAndArrivalsTable.Create(target)).Distinct().ToList();

            return(recentItemsToDisplay);
        }
Esempio n. 3
0
 public static void Add(DeparturesAndArrivalsTable recentItem)
 {
     if (recentItem.HasDestinationFilter &&
         allRecentItems.Count > 0 &&
         !allRecentItems[0].HasDestinationFilter &&
         allRecentItems[0].Station.Code == recentItem.Station.Code)
     {
         allRecentItems.RemoveAt(0);
     }
     allRecentItems.Remove(recentItem);
     allRecentItems.Insert(0, recentItem);
     Save();
 }
Esempio n. 4
0
 public static void Add(DeparturesAndArrivalsTable recentItem)
 {
     if (recentItem.HasDestinationFilter &&
         allRecentItems.Count > 0 &&
         !allRecentItems[0].HasDestinationFilter &&
         allRecentItems[0].Station.Code == recentItem.Station.Code)
     {
         allRecentItems.RemoveAt(0);
     }
     allRecentItems.Remove(recentItem);
     allRecentItems.Insert(0, recentItem);
     Save();
 }
Esempio n. 5
0
        private void GoToStation(object dataContext)
        {
            var target = dataContext as DeparturesAndArrivalsTable;

            if (target != null)
            {
                if (fromStation != null)
                {
                    Debug.Assert(!target.HasDestinationFilter);
                    target = DeparturesAndArrivalsTable.Create(fromStation, target.Station);
                }
            }
            else
            {
                var station = dataContext as Station ?? ((Tuple <double, Station>)dataContext).Item2;
                target = fromStation == null?DeparturesAndArrivalsTable.Create(station) :
                             DeparturesAndArrivalsTable.Create(fromStation, station);
            }
            NavigationService.Navigate(StationPage.GetUri(this, target, removeBackEntry: fromStation != null));
        }
Esempio n. 6
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (departuresAndArrivalsTable != null)
            {
                ErrorReporting.Log("departuresAndArrivalsTable is not null");
                Load();
                return;
            }

            var stationStr = NavigationContext.QueryString["station"];
            var from = Stations.Get(stationStr);
            var to = NavigationContext.QueryString.ContainsKey("callingAt") ? Stations.Get(NavigationContext.QueryString["callingAt"]) : null;
            var removeBackEntry = NavigationContext.QueryString.ContainsKey("removeBackEntry");
            departuresAndArrivalsTable = DeparturesAndArrivalsTable.Create(from, to);
            title.Text = departuresAndArrivalsTable.ToString();
            if (title.Text.Length > 40)
            {
                title.Text = title.Text.Replace(" calling at ", "\ncalling at ");
            }

            if (e.NavigationMode == NavigationMode.New)
            {
                RecentItems.Add(departuresAndArrivalsTable);
            }

            if (removeBackEntry)
            {
                NavigationService.RemoveBackEntry();
            }

            if (departuresAndArrivalsTable.HasDestinationFilter)
            {
                var filterOrClearFilterItem = ApplicationBar.Buttons.Cast<ApplicationBarIconButton>().Single(button => button.Text == "Filter");
                filterOrClearFilterItem.Text = "Clear Filter";
                filterOrClearFilterItem.IconUri = new Uri("/Assets/Icons/dark/appbar.filter.clear.png", UriKind.Relative);

                var filterByAnotherDestinationItem = new ApplicationBarMenuItem("Filter by another destination");
                filterByAnotherDestinationItem.Click += OnFilterByAnotherDestinationClick;
                ApplicationBar.MenuItems.Insert(0, filterByAnotherDestinationItem);

                var reverseJourneyItem = new ApplicationBarIconButton(new Uri("/Assets/Icons/dark/appbar.arrow.left.right.png", UriKind.Relative)) { Text = "Reverse" };
                reverseJourneyItem.Click += OnReverseJourneyClick;
                ApplicationBar.Buttons.Insert(2, reverseJourneyItem);
            }

            if (!NavigationService.CanGoBack)
            {
                var homeButton = new ApplicationBarIconButton
                {
                    IconUri = new Uri("/Assets/Icons/dark/appbar.list.png", UriKind.Relative),
                    Text = "All Stations",
                };
                homeButton.Click += OnHomeClick;
                ApplicationBar.Buttons.Remove(GetPinToStartButton());
                ApplicationBar.Buttons.Add(homeButton);
            }
            else
            {
                GetPinToStartButton().IsEnabled = !IsStationPinnedToStart();
            }

            CreateDirectionsPivotItem();

            if (!Stations.Country.SupportsArrivals)
            {
                // when supportsArrivals is false PivotSelectionChanged won't be triggered
                Load();
            }
        }
Esempio n. 7
0
 public static Uri GetUri(PhoneApplicationPage page, DeparturesAndArrivalsTable departuresAndArrivalsTable, bool removeBackEntry = false)
 {
     return page.GetUri<StationPage>().WithParameters("station", departuresAndArrivalsTable.Station.Code)
                                      .WithParametersIf(departuresAndArrivalsTable.HasDestinationFilter, () => "callingAt", () => departuresAndArrivalsTable.CallingAt.Value.Code)
                                      .WithParametersIf(removeBackEntry, "removeBackEntry");
 }
Esempio n. 8
0
 private Uri GetUri(DeparturesAndArrivalsTable departuresAndArrivalsTable, bool removeBackEntry = false)
 {
     return GetUri(this, departuresAndArrivalsTable, removeBackEntry);
 }
Esempio n. 9
0
 public static void Remove(DeparturesAndArrivalsTable recentItem)
 {
     allRecentItems.Remove(recentItem);
     Save();
 }
Esempio n. 10
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (departuresAndArrivalsTable != null)
            {
                ErrorReporting.Log("departuresAndArrivalsTable is not null");
                Load();
                return;
            }

            var stationStr      = NavigationContext.QueryString["station"];
            var from            = Stations.Get(stationStr);
            var to              = NavigationContext.QueryString.ContainsKey("callingAt") ? Stations.Get(NavigationContext.QueryString["callingAt"]) : null;
            var removeBackEntry = NavigationContext.QueryString.ContainsKey("removeBackEntry");

            departuresAndArrivalsTable = DeparturesAndArrivalsTable.Create(from, to);
            title.Text = departuresAndArrivalsTable.ToString();
            if (title.Text.Length > 40)
            {
                title.Text = title.Text.Replace(" calling at ", "\ncalling at ");
            }

            if (e.NavigationMode == NavigationMode.New)
            {
                RecentItems.Add(departuresAndArrivalsTable);
            }

            if (removeBackEntry)
            {
                NavigationService.RemoveBackEntry();
            }

            if (departuresAndArrivalsTable.HasDestinationFilter)
            {
                var filterOrClearFilterItem = ApplicationBar.Buttons.Cast <ApplicationBarIconButton>().Single(button => button.Text == "Filter");
                filterOrClearFilterItem.Text    = "Clear Filter";
                filterOrClearFilterItem.IconUri = new Uri("/Assets/Icons/dark/appbar.filter.clear.png", UriKind.Relative);

                var filterByAnotherDestinationItem = new ApplicationBarMenuItem("Filter by another destination");
                filterByAnotherDestinationItem.Click += OnFilterByAnotherDestinationClick;
                ApplicationBar.MenuItems.Insert(0, filterByAnotherDestinationItem);

                var reverseJourneyItem = new ApplicationBarIconButton(new Uri("/Assets/Icons/dark/appbar.arrow.left.right.png", UriKind.Relative))
                {
                    Text = "Reverse"
                };
                reverseJourneyItem.Click += OnReverseJourneyClick;
                ApplicationBar.Buttons.Insert(2, reverseJourneyItem);
            }

            if (!NavigationService.CanGoBack)
            {
                var homeButton = new ApplicationBarIconButton
                {
                    IconUri = new Uri("/Assets/Icons/dark/appbar.list.png", UriKind.Relative),
                    Text    = "All Stations",
                };
                homeButton.Click += OnHomeClick;
                ApplicationBar.Buttons.Remove(GetPinToStartButton());
                ApplicationBar.Buttons.Add(homeButton);
            }
            else
            {
                GetPinToStartButton().IsEnabled = !IsStationPinnedToStart();
            }

            CreateDirectionsPivotItem();

            if (!Stations.Country.SupportsArrivals)
            {
                // when supportsArrivals is false PivotSelectionChanged won't be triggered
                Load();
            }
        }
Esempio n. 11
0
 public static Uri GetUri(PhoneApplicationPage page, DeparturesAndArrivalsTable departuresAndArrivalsTable, bool removeBackEntry = false)
 {
     return(page.GetUri <StationPage>().WithParameters("station", departuresAndArrivalsTable.Station.Code)
            .WithParametersIf(departuresAndArrivalsTable.HasDestinationFilter, () => "callingAt", () => departuresAndArrivalsTable.CallingAt.Value.Code)
            .WithParametersIf(removeBackEntry, "removeBackEntry"));
 }
Esempio n. 12
0
 private Uri GetUri(DeparturesAndArrivalsTable departuresAndArrivalsTable, bool removeBackEntry = false)
 {
     return(GetUri(this, departuresAndArrivalsTable, removeBackEntry));
 }
Esempio n. 13
0
 public static void Remove(DeparturesAndArrivalsTable recentItem)
 {
     allRecentItems.Remove(recentItem);
     Save();
 }