Example #1
0
        /// <summary>
        /// Contstructor of the MainPage
        /// </summary>
        public MainPage()
        {
            //initialize the graphic components
            InitializeComponent();


            //add the application bar - it has to be done dynamically in order to enable the app bar
            //to be localized
            BuildApplicationBar();

            //tombstonning
            //if there is some Station situation in the State of the application
            if (PhoneApplicationService.Current.State.ContainsKey("City"))
            {
                //get the situation from the current state dictionary - if the app is been run for second time
                var city = PhoneApplicationService.Current.State["City"] as City;
                PhoneApplicationService.Current.State.Remove("City");
                var bikeCity = new BikeCityViewModel(city);


                bikeCity.CityCenter = new GeoCoordinate(city.Lat, city.Lng);

                bikeCity.FromNearStations = new System.Collections.ObjectModel.ObservableCollection <BikeStationViewModel>();

                if (city.FromStations != null)
                {
                    foreach (var station in city.FromStations)
                    {
                        bikeCity.FromNearStations.Add(new BikeStationViewModel(station));
                    }
                }

                if (city.CurrentStation != null)
                {
                    bikeCity.CurrentStation = bikeCity.FromNearStations.FirstOrDefault(x => x.Id == city.CurrentStation.Id);
                }

                CurrentCity = bikeCity;
                //silently update stations
                bikeCity.GetAllStations(false);
            }

            //create the GPS watcher for real device and turn it on
            _watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
            _watcher.MovementThreshold = 200;
            SwitchGPS();


            //create new class to access the web services
            _serviceCaller = new BikeInCity.ServiceCaller.ServiceCaller(BikeConsts.MAPS_KEY);

            //always load cities
            LoadCities();

            if (CurrentCity == null)
            {
                IsMessage = true;
                Message   = AppResources.Message_LoadingCities;
            }

            this.DataContext = this;
        }