private async void parksListView_ItemSelected(object sender, SelectedItemChangedEventArgs e) { // Get selected parking spot. ParkingSpotPreview parkingSpotPreview = (ParkingSpotPreview)e.SelectedItem; await Navigation.PushModalAsync(new ParkDetailsPage(parkingSpotPreview)); }
private void Button_Clicked(object sender, EventArgs e) { // Get selected parking spot. var button = sender as Button; ParkingSpotPreview parkingSpotPreview = button.BindingContext as ParkingSpotPreview; // Launch Google Maps and navigate to parking spot. var request = string.Format("http://maps.google.com/?daddr=" + parkingSpotPreview.Coordinates[0] + "," + parkingSpotPreview.Coordinates[1]); Device.OpenUri(new Uri(request)); }
private async void SpotsMap_PinClicked(object sender, PinClickedEventArgs e) { string ParkName = e.Pin.Label; // Find the park with the provided name. ParkingSpotPreview parkingSpotPreview = StoredData.ParkingSpotPreviews.FirstOrDefault(park => park.Name == ParkName); if (parkingSpotPreview == null) { CrossToastPopUp.Current.ShowToastError("Parking spot could not be found! Try again later"); return; } // Get park details. parkingSpotPreview.Details = new ParkingSpotDetails(); await Navigation.PushModalAsync(new ParkDetailsPage(parkingSpotPreview)); }
protected override async void OnAppearing() { using (IProgressDialog progress = UserDialogs.Instance.Loading("Loading park details", null, null, true, MaskType.Black)) { var parkingSpot = Barrel.Current.Get <ParkingSpotPreview>("ParkingSpot_" + ParkingSpotPreview.Id); if (parkingSpot != null) { ParkingSpotPreview = parkingSpot; ParkTypesEnum parkTypesEnum = ParkTypesEnum.None; foreach (ParkTypesEnum parkSpot in ParkingSpotPreview.Details.ParkSpots.Keys) { parkTypesEnum |= parkSpot; } ParkingSpotPreview.ParkTypes = (int)parkTypesEnum; // Assign the correct values to the labels. ParkImage.Source = ParkingSpotPreview.Details.Image; ParkName.Text = ParkingSpotPreview.Name; ParkType.Text = new ParkTypeToStringConverter().Convert(ParkingSpotPreview.ParkTypes, null, null, CultureInfo.CurrentCulture).ToString(); ParkUnderground.Text = new BoolToIsUndergroundString().Convert(ParkingSpotPreview.Underground, null, null, CultureInfo.CurrentCulture).ToString(); ParkFloor.Text = "Floor: " + ParkingSpotPreview.Floor; ParkPaid.Text = new BoolToIsPaidStringConverter().Convert(ParkingSpotPreview.Paid, null, null, CultureInfo.CurrentCulture).ToString(); // Check what park spot type the park has. if (((ParkTypesEnum)ParkingSpotPreview.ParkTypes & ParkTypesEnum.Handicap) == ParkTypesEnum.Handicap) { ParkSpotsHandicap.IsVisible = true; ParkSpotsHandicap.Text = "Handicap spots: " + ParkingSpotPreview.Details.ParkSpots[ParkTypesEnum.Handicap]; } if (((ParkTypesEnum)ParkingSpotPreview.ParkTypes & ParkTypesEnum.Family) == ParkTypesEnum.Family) { ParkSpotsFamily.IsVisible = true; ParkSpotsFamily.Text = "Family spots: " + ParkingSpotPreview.Details.ParkSpots[ParkTypesEnum.Family]; } if (((ParkTypesEnum)ParkingSpotPreview.ParkTypes & ParkTypesEnum.Eletric) == ParkTypesEnum.Eletric) { ParkSpotsEletric.IsVisible = true; ParkSpotsEletric.Text = "Eletric vehicle spots: " + ParkingSpotPreview.Details.ParkSpots[ParkTypesEnum.Eletric]; } if (((ParkTypesEnum)ParkingSpotPreview.ParkTypes & ParkTypesEnum.Bike) == ParkTypesEnum.Bike) { ParkSpotsBike.IsVisible = true; ParkSpotsBike.Text = "Bike spots: " + ParkingSpotPreview.Details.ParkSpots[ParkTypesEnum.Bike]; } // Check if the park is currently open. WeekDay currentDay = (WeekDay)DateTime.Today.DayOfWeek - 1; if ((int)currentDay == -1) { currentDay = WeekDay.Sunday; } ParkTime currentDayParkTime = ParkingSpotPreview.Details.ParkTimes.ParkingTimes.First(time => time.Value.WeekDay == currentDay).Value; TimeSpan currentTime = DateTime.Now.TimeOfDay; if (currentDayParkTime.AlwaysOpen) { OpenStatusLabel.Text = "Open all day"; } // Check wether the park close hour is after todays open hour. else if (currentDayParkTime.TimeClose > currentDayParkTime.TimeOpen) { // Check wether the park is currently open. if (currentTime > currentDayParkTime.TimeOpen && currentTime < currentDayParkTime.TimeClose) { OpenStatusLabel.Text = string.Format("Open until {0:hh\\:mm}", currentDayParkTime.TimeClose); } // Check wether the park has already closed. else if (currentTime > currentDayParkTime.TimeClose) { // Check if tomorrow will be open all day. WeekDay tomorrow = currentDay + 1; if ((int)tomorrow == 7) { tomorrow = WeekDay.Monday; } ParkTime tomorrowDayParkTime = ParkingSpotPreview.Details.ParkTimes.ParkingTimes.First(time => time.Value.WeekDay == tomorrow).Value; if (tomorrowDayParkTime.AlwaysOpen) { OpenStatusLabel.Text = "Closed. Will be open tomorrow all day"; } else { // Get tomorrow's opening time. OpenStatusLabel.Text = string.Format("Closed. Will open tomorrow at {0:hh\\:mm}", tomorrowDayParkTime.TimeOpen); } } // The park hasn't opened yet today. else { OpenStatusLabel.Text = string.Format("Closed. Will open today at {0:hh\\:mm}", currentDayParkTime.TimeOpen); } } // The close hour is before the open hour. else { // Check wether the park is currently after it's open hour. if (currentTime > currentDayParkTime.TimeOpen) { OpenStatusLabel.Text = "Open for the rest of the day."; } // Check wether the park is currently before it's close hour. else if (currentTime < currentDayParkTime.TimeClose) { OpenStatusLabel.Text = string.Format("Open until {0:hh\\:mm}", currentDayParkTime.TimeClose); } // The park has already closed but will open later today. else { OpenStatusLabel.Text = string.Format("Closed. Will open today at {0:hh\\:mm}", currentDayParkTime.TimeOpen); } } } else { ParkSpot[] parkSpots = await GetParkingSpot(ParkingSpotPreview.Id); ParkTypesEnum parkTypesEnum = ParkTypesEnum.None; if (ParkingSpotPreview.Details.ParkSpots.Count > 0) { foreach (ParkSpot parkSpot in parkSpots) { parkTypesEnum |= (ParkTypesEnum)parkSpot.CategoryId; } } else { foreach (ParkSpot parkSpot in parkSpots) { parkTypesEnum |= (ParkTypesEnum)parkSpot.CategoryId; ParkingSpotPreview.Details.ParkSpots.Add((ParkTypesEnum)parkSpot.CategoryId, parkSpot.NumSpots); } } ParkingSpotPreview.ParkTypes = (int)parkTypesEnum; ParkingSpotPreview.Details.Image = await GetParkingSpotImage(ParkingSpotPreview.Id); ParkTime[] parkTimes = await GetParkingTimes(ParkingSpotPreview.Id); foreach (ParkTime parkTime in parkTimes) { ParkingSpotPreview.Details.ParkTimes.ParkingTimes[parkTime.WeekDay].AlwaysOpen = parkTime.AlwaysOpen; ParkingSpotPreview.Details.ParkTimes.ParkingTimes[parkTime.WeekDay].TimeOpen = parkTime.TimeOpen; ParkingSpotPreview.Details.ParkTimes.ParkingTimes[parkTime.WeekDay].TimeClose = parkTime.TimeClose; } // Assign the correct values to the labels. ParkImage.Source = ParkingSpotPreview.Details.Image; ParkName.Text = ParkingSpotPreview.Name; ParkType.Text = new ParkTypeToStringConverter().Convert(ParkingSpotPreview.ParkTypes, null, null, CultureInfo.CurrentCulture).ToString(); ParkUnderground.Text = new BoolToIsUndergroundString().Convert(ParkingSpotPreview.Underground, null, null, CultureInfo.CurrentCulture).ToString(); ParkFloor.Text = "Floor: " + ParkingSpotPreview.Floor; ParkPaid.Text = new BoolToIsPaidStringConverter().Convert(ParkingSpotPreview.Paid, null, null, CultureInfo.CurrentCulture).ToString(); // Check what park spot type the park has. if (((ParkTypesEnum)ParkingSpotPreview.ParkTypes & ParkTypesEnum.Handicap) == ParkTypesEnum.Handicap) { ParkSpotsHandicap.IsVisible = true; ParkSpotsHandicap.Text = "Handicap spots: " + ParkingSpotPreview.Details.ParkSpots[ParkTypesEnum.Handicap]; } if (((ParkTypesEnum)ParkingSpotPreview.ParkTypes & ParkTypesEnum.Family) == ParkTypesEnum.Family) { ParkSpotsFamily.IsVisible = true; ParkSpotsFamily.Text = "Family spots: " + ParkingSpotPreview.Details.ParkSpots[ParkTypesEnum.Family]; } if (((ParkTypesEnum)ParkingSpotPreview.ParkTypes & ParkTypesEnum.Eletric) == ParkTypesEnum.Eletric) { ParkSpotsEletric.IsVisible = true; ParkSpotsEletric.Text = "Eletric vehicle spots: " + ParkingSpotPreview.Details.ParkSpots[ParkTypesEnum.Eletric]; } if (((ParkTypesEnum)ParkingSpotPreview.ParkTypes & ParkTypesEnum.Bike) == ParkTypesEnum.Bike) { ParkSpotsBike.IsVisible = true; ParkSpotsBike.Text = "Bike spots: " + ParkingSpotPreview.Details.ParkSpots[ParkTypesEnum.Bike]; } // Check if the park is currently open. WeekDay currentDay = (WeekDay)DateTime.Today.DayOfWeek - 1; if ((int)currentDay == -1) { currentDay = WeekDay.Sunday; } ParkTime currentDayParkTime = ParkingSpotPreview.Details.ParkTimes.ParkingTimes.First(time => time.Value.WeekDay == currentDay).Value; TimeSpan currentTime = DateTime.Now.TimeOfDay; if (currentDayParkTime.AlwaysOpen) { OpenStatusLabel.Text = "Open all day"; } // Check wether the park close hour is after todays open hour. else if (currentDayParkTime.TimeClose > currentDayParkTime.TimeOpen) { // Check wether the park is currently open. if (currentTime > currentDayParkTime.TimeOpen && currentTime < currentDayParkTime.TimeClose) { OpenStatusLabel.Text = string.Format("Open until {0:hh\\:mm}", currentDayParkTime.TimeClose); } // Check wether the park has already closed. else if (currentTime > currentDayParkTime.TimeClose) { // Check if tomorrow will be open all day. WeekDay tomorrow = currentDay + 1; if ((int)tomorrow == 7) { tomorrow = WeekDay.Monday; } ParkTime tomorrowDayParkTime = ParkingSpotPreview.Details.ParkTimes.ParkingTimes.First(time => time.Value.WeekDay == tomorrow).Value; if (tomorrowDayParkTime.AlwaysOpen) { OpenStatusLabel.Text = "Closed. Will be open tomorrow all day"; } else { // Get tomorrow's opening time. OpenStatusLabel.Text = string.Format("Closed. Will open tomorrow at {0:hh\\:mm}", tomorrowDayParkTime.TimeOpen); } } // The park hasn't opened yet today. else { OpenStatusLabel.Text = string.Format("Closed. Will open today at {0:hh\\:mm}", currentDayParkTime.TimeOpen); } } // The close hour is before the open hour. else { // Check wether the park is currently after it's open hour. if (currentTime > currentDayParkTime.TimeOpen) { OpenStatusLabel.Text = "Open for the rest of the day."; } // Check wether the park is currently before it's close hour. else if (currentTime < currentDayParkTime.TimeClose) { OpenStatusLabel.Text = string.Format("Open until {0:hh\\:mm}", currentDayParkTime.TimeClose); } // The park has already closed but will open later today. else { OpenStatusLabel.Text = string.Format("Closed. Will open today at {0:hh\\:mm}", currentDayParkTime.TimeOpen); } } Barrel.Current.Add("ParkingSpot_" + ParkingSpotPreview.Id, ParkingSpotPreview, TimeSpan.FromDays(7)); } } }
public ParkDetailsPage(ParkingSpotPreview parkingSpotPreview) { ParkingSpotPreview = parkingSpotPreview; InitializeComponent(); }