Ejemplo n.º 1
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            string hubId;
            if (App.Hub == null && NavigationContext.QueryString.TryGetValue("hubId", out hubId))
            {
                if (!await MainPage.GetCredentials())
                {
                    NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
                    return;
                }

                var mockHub = new Hub { Id = int.Parse(hubId) };
                App.Hub = new HubViewModel(await mockHub.Get());
            }

            this.DataContext = App.Hub;

            await App.MobileServiceClient.GetPush().RegisterNativeAsync(App.CurrentChannel.ChannelUri.ToString(), new string[] { App.Hub.Id.ToString() });
            App.CurrentChannel.ChannelUriUpdated += OnNotificationChannelEvent;
            App.CurrentChannel.ShellToastNotificationReceived += QueryPosts;

            App.Geolocator.PositionChanged += OnPositionChanged;

            await App.Hub.Source.Join();

            this.isInRange = true;

            QueryPosts(this, null);

            base.OnNavigatedTo(e);
        }
Ejemplo n.º 2
0
        public void OnLocationChanged(Location location)
        {
            var referenceHub = new Hub
            {
                Lat = location.Latitude,
                Lng = location.Longitude,
                Radius = 1 * 1000
            };

            this.hubAdapter.RefreshHubs(referenceHub, 5);
        }
Ejemplo n.º 3
0
        public PostAdapter(Activity activity, Hub hub)
        {
            this.activity = activity;
            this.posts = new List<Post>();
            this.hub = hub;

            timer = new Timer();
            timer.Interval = 2000;
            timer.Elapsed += OnTimedEvent;

            timer.Start();
        }
Ejemplo n.º 4
0
        public async void RefreshHubs(Hub reference, int quantity)
        {
            progress.Visibility = ViewStates.Visible;

            List<Hub> nearHubs = await reference.NearHubs(quantity);

            this.hubs.Clear();
            this.hubs.AddRange(nearHubs);

            progress.Visibility = ViewStates.Gone;

            this.NotifyDataSetChanged();
        }
Ejemplo n.º 5
0
        private void OnPositionChanged(Geolocator sender, PositionChangedEventArgs e)
        {
            var geoCoordinate = new GeoCoordinate(e.Position.Coordinate.Latitude, e.Position.Coordinate.Longitude);
            var accuracy = e.Position.Coordinate.Accuracy;

            Dispatcher.BeginInvoke(async () =>
            {
                pbLoading.Visibility = Visibility.Visible;

                mLocation.SetView(geoCoordinate, App.MAP_ZOOM);

                RefreshPin(geoCoordinate, accuracy);

                var mockHub = new Hub
                {
                    Lat = geoCoordinate.Latitude,
                    Lng = geoCoordinate.Longitude
                };

                IList<HubViewModel> nearHubs = Enumerable.Empty<HubViewModel>().ToList();
                try
                {
                    nearHubs = (await mockHub.NearHubs(App.HUBS_IN_PROXIMITY, accuracy))
                        .Select(nh => new HubViewModel(nh))
                        .ToList();
                }
                catch
                {
                    MessageBox.Show("There was an error downloading the list of hubs. Please try again.", "error", MessageBoxButton.OK);
                }

                RefreshHubs(nearHubs);

                pbLoading.Visibility = Visibility.Collapsed;
            });
        }