Exemple #1
0
 private void ParkingLotListSelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     foreach (var oldItem in e.RemovedItems)
     {
         var oldItemContainer = ParkingLotList.ContainerFromItem(oldItem);
         var oldListViewItem  = oldItemContainer as ListViewItem;
         if (oldListViewItem != null)
         {
             Debug.WriteLine("[MainView] parking lot list: remove selected visual state for " + (oldItem as ParkingLot).Name);
             var element = oldListViewItem.ContentTemplateRoot as Control;
             if (element != null)
             {
                 VisualStateManager.GoToState(element, "Unselected", false);
             }
         }
     }
     foreach (var newItem in e.AddedItems)
     {
         var newItemContainer = ParkingLotList.ContainerFromItem(newItem);
         var newListViewItem  = newItemContainer as ListViewItem;
         if (newListViewItem != null)
         {
             Debug.WriteLine("[MainView] parking lot list: add selected visual state for " + (newItem as ParkingLot).Name);
             var element = newListViewItem.ContentTemplateRoot as Control;
             if (element != null)
             {
                 VisualStateManager.GoToState(element, "Selected", false);
             }
         }
     }
 }
Exemple #2
0
        private async void AddPinOnLoad()
        {
            lat = viewModel.Item.lat;
            lng = viewModel.Item.lon;

            ParkingLotList lots = await parkingLotService.GetParkingLots();

            OldParkingLot lot;

            if (viewModel.Item.Id != "1")
            {
                lot = lots.parkingLotList[1];
            }
            else
            {
                lot = lots.parkingLotList[0];
            }

            CustomPin lotPin = new CustomPin
            {
                Type     = PinType.Place,
                Position = new Position(lot.lat, lot.lon),
                Label    = viewModel.Item.lotName + " Open Spots: " + lot.OpenSpots,
                id       = "lot" + viewModel.Item.Id,
                url      = ""
            };

            customMap.Pins.Add(lotPin);


            customMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(lat, lng), Distance.FromMiles(0.1)));
            Content = customMap;
        }
Exemple #3
0
        public ParkingLot ChooseParkingLot()
        {
            var parkingLotChosen = ParkingLotList.Where(lot => !lot.IsFull).ToList();

            return(parkingLotChosen.Any()
                ? parkingLotChosen.OrderByDescending(lot => lot.LotAvailable).First()
                : ParkingLotList[^ 1]);
Exemple #4
0
        protected override ParkingLot GetParkingLot()
        {
            var maxSpaceParkingLot = ParkingLotList[0];

            foreach (var parkingLot in ParkingLotList.Where(parkingLot => parkingLot.RemianParkingSpace() > maxSpaceParkingLot.RemianParkingSpace()))
            {
                maxSpaceParkingLot = parkingLot;
            }
            return(maxSpaceParkingLot);
        }
Exemple #5
0
        async Task ExecuteLoadItemsCommand()
        {
            ParkingLotList       lotList           = new ParkingLotList();
            List <OldParkingLot> lots              = new List <OldParkingLot>();
            IParkingLotService   parkingLotService = new ParkingLotServiceImpl();

            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Items.Clear();
                lotList = await parkingLotService.GetParkingLots();

                foreach (OldParkingLot lot in lotList.parkingLotList)
                {
                    ParkingLot parkingItem = new ParkingLot();
                    parkingItem.Id          = lot.lotId.ToString();
                    parkingItem.Description = "Number of open parking spots " + lot.OpenSpots;
                    parkingItem.lotName     = lot.lotName;
                    parkingItem.Text        = lot.lotName;
                    parkingItem.address     = lot.address;
                    parkingItem.city        = lot.city;
                    parkingItem.zipCode     = lot.zipCode;
                    parkingItem.state       = lot.state;
                    parkingItem.lat         = lot.lat;
                    parkingItem.lon         = lot.lon;
                    Items.Add(parkingItem);
                }

                /*
                 * var items = await DataStore.GetItemsAsync(true);
                 * foreach (var item in items)
                 * {
                 * Items.Add(item);
                 * }
                 */
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Exemple #6
0
        private async void AddPinOnLoad()
        {
            await MapUtils.RetrieveLocation();

            lat = MapUtils.getLat();
            lng = MapUtils.getLng();

            /*
             *          var customPin = new CustomPin
             *          {
             *              Type = PinType.Place,
             *              Position = new Position(lat, lng),
             *              Label = "My Position!",
             *              id = "myPin"
             *          };
             *
             *          customMap.Pins.Clear();
             *          customMap.Pins.Add(customPin);
             */
            customMap.Pins.Clear();
            ParkingLotList lots = await parkingLotService.GetParkingLots();

            foreach (OldParkingLot lot in lots.parkingLotList)
            {
                var lotPin = new CustomPin
                {
                    Type     = PinType.Place,
                    Position = new Position(lot.lat, lot.lon),
                    Label    = lot.lotName + " Open Spots: " + lot.OpenSpots,
                    id       = "lot" + lot.lotId,
                    url      = ""
                };


                customMap.Pins.Add(lotPin);
            }

            customMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(lat, lng), Distance.FromMiles(0.1)));
        }
Exemple #7
0
        private async void SetParkingLotListSelectionVisualState(ParkingLot selectedItem = null)
        {
            if (selectedItem == null)
            {
                selectedItem = Vm.SelectedParkingLot;
            }
            if (selectedItem != null)
            {
                ListViewItem listViewItem = null;
                var          count        = 0;
                while (listViewItem == null && count < 10)
                {
                    var itemContainer = ParkingLotList.ContainerFromItem(selectedItem);
                    listViewItem = itemContainer as ListViewItem;
                    await Task.Delay(200);

                    count++;
                }

                if (listViewItem != null)
                {
                    Debug.WriteLine("[MainView] parking lot list: set selected visual state for " + selectedItem.Name);
                    VisualStateManager.GoToState(listViewItem.ContentTemplateRoot as Control, "Selected", false);
                }
                else
                {
                    Debug.WriteLine("[MainVm] parking lot list: list view item is null :/");
                }

                ParkingLotList.ScrollIntoView(selectedItem);
            }
            else
            {
                Debug.WriteLine("[MainView] parking lot list: set selected index to -1");
                ParkingLotList.SelectedIndex = -1;
            }
        }
Exemple #8
0
        private async void AddPinsToMap()
        {
            await MapUtils.RetrieveLocation();

            lat = MapUtils.getLat();
            lng = MapUtils.getLng();

            /*var customPin = new CustomPin
             * {
             *  Type = PinType.Place,
             *  Position = new Position(lat, lng),
             *  Label = "",
             *  id = "userPin"
             * };
             *
             * //Add pin to map
             * customMap.Pins.Clear();
             * customMap.Pins.Add(customPin);
             */
            customMap.Pins.Clear();

            ParkingLotList lots = await parkingLotService.GetParkingLots();

            foreach (OldParkingLot lot in lots.parkingLotList)
            {
                var lotPin = new CustomPin
                {
                    Type     = PinType.Place,
                    Position = new Position(lot.lat, lot.lon),
                    Label    = lot.lotName + " Open Spots: " + lot.OpenSpots,
                    id       = "lot" + lot.lotId,
                    url      = "",
                };
                customMap.Pins.Add(lotPin);
            }
        }
Exemple #9
0
        public ParkingLot ChooseParkingLot()
        {
            var parkingLotsChosen = ParkingLotList.Where(lot => !lot.IsFull).ToList();

            return(parkingLotsChosen.Any() ? parkingLotsChosen.First() : ParkingLotList[^ 1]);
Exemple #10
0
        public MainPage()
        {
            InitializeComponent();

            if (ResponsiveStateGroup.CurrentState == desktopViewVisualState)
            {
                //this should use "-1 * CoreApplication.GetCurrentView().TitleBar.Height" but it returns 0 at this point :(
                SetMapBottomMargin(-32);
            }

            NavigationCacheMode = NavigationCacheMode.Required;

            CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;

            Map.Loaded += async(sender, args) =>
            {
                SetMapBottomMargin(0);

                Debug.WriteLine("[MainView] map: map loaded");
                if (_initialMapBbox != null)
                {
                    Debug.WriteLine("[MainView] map: map loaded, set initial bounds");
                    await Map.TrySetViewBoundsAsync(_initialMapBbox, null, MapAnimationKind.None);

                    _zoomedToInitialView = true;
                }
                else if (_initialCoordinates != null)
                {
                    Debug.WriteLine("[MainView] map: map loaded, set initial coords");
                    await Map.TrySetViewAsync(_initialCoordinates, null, null, null, MapAnimationKind.None);

                    _zoomedToInitialView = true;
                }
                _mapLoaded = true;
            };

            Messenger.Default.Register(this, (ZoomMapToBoundsMessage msg) =>
            {
                if (!_mapLoaded)
                {
                    _initialMapBbox = msg.BoundingBox;
                    //set initial bbox as the following won't work while splash screen is still visible
                }
                else
                {
                    DispatcherHelper.CheckBeginInvokeOnUI(async() =>
                    {
                        Debug.WriteLine("[MainView] map: zoom map to bounds msg");
                        await Map.TrySetViewBoundsAsync(msg.BoundingBox, null, MapAnimationKind.Bow);
                        _zoomedToInitialView = _mapLoaded;
                    });
                }
            });

            Messenger.Default.Register(this, (ZoomMapToCoordinateMessage msg) =>
            {
                if (!_mapLoaded)
                {
                    _initialCoordinates = msg.Point;
                    //set initial coordinates as the following won't work while splash screen is still visible
                }
                else
                {
                    DispatcherHelper.CheckBeginInvokeOnUI(async() =>
                    {
                        Debug.WriteLine("[MainView] map: zoom map to coordinates msg");
                        await
                        Map.TrySetViewAsync(msg.Point, null, null, null, MapAnimationKind.Bow);
                        _zoomedToInitialView = _mapLoaded;
                    });
                }
            });

            Messenger.Default.Register(this, (ShowSearchResultOnMapMessage msg) =>
            {
                DispatcherHelper.CheckBeginInvokeOnUI(async() =>
                {
                    DrawingService.DrawSearchResult(Map, msg.Result);
                    Debug.WriteLine("[MainView] map: show search result - wait until initial view was zoomed to");
                    await WaitForInitialMapZoom();
                    Debug.WriteLine("[MainView] map: show search result");
                    await Map.TrySetViewAsync(msg.Result.Point, null, null, null, MapAnimationKind.Bow);
                });
            });

            Messenger.Default.Register(this, (HideSearchResultOnMapMessage msg) =>
            {
                DrawingService.RemoveSearchResult(Map);
            });

            Messenger.Default.Register(this, (InfoDialogToggleVisibilityMessage msg) =>
            {
                FindName(nameof(InfoDialog));
                _infoDialogVisible    = msg.IsVisible;
                InfoDialog.Visibility = msg.Visibility;
            });

            Messenger.Default.Register(this, async(UpdateParkingLotListSelectionMessage msg) =>
            {
                Debug.WriteLine("[MainView] update parking lot list: message received");
                SetParkingLotListSelectionVisualState();
            });

            Vm.PropertyChanged += OnViewModelPropertyChanged;

            ParkingLotList.SelectionChanged += (sender, args) =>
            {
                try
                {
                    ParkingLotList.ScrollIntoView(ParkingLotList.SelectedItem);
                }
                catch (Exception)
                {
                    Debug.WriteLine("Cannot scroll currenct parking lot list item...");
                }
            };

            Map.MapElementClick += (sender, args) =>
            {
                Vm.SelectedParkingLot = DrawingService.GetParkingLotOfIcon(args.MapElements.GetTopmostIcon());
            };

            SystemNavigationManager.GetForCurrentView().BackRequested += (sender, args) =>
            {
                if (_infoDialogVisible)
                {
                    Messenger.Default.Send(new InfoDialogToggleVisibilityMessage(false));
                    args.Handled = true;
                }
            };

            UpdateParkingLotFilter();
        }
Exemple #11
0
 protected override ParkingLot GetParkingLot()
 {
     return(ParkingLotList.FirstOrDefault(parkingLot => parkingLot.IsAvailable()) ?? ParkingLotList[0]);
 }