protected override void OnAppearing()
        {
            base.OnAppearing();


            Device.OnPlatform(() =>
            {
                // Start listener for pushpin events
                MessagingCenter.Subscribe <CustomPin>(this, "ShowCrimeReport", (obj) =>
                {
                    var crimeDetailPage = new CrimeDetailPage(obj);
                    Navigation.PushAsync(crimeDetailPage);
                });

                DataFill(_crimes);
                _initialized = true;
            }, () => {
                MyMap.PropertyChanged += (sender, e) =>
                {
                    if (!_initialized)
                    {
                        // Start listener for pushpin events
                        MessagingCenter.Subscribe <CustomPin>(this, "ShowCrimeReport", (obj) =>
                        {
                            var crimeDetailPage = new CrimeDetailPage(obj);
                            Navigation.PushAsync(crimeDetailPage);
                        });

                        DataFill(_crimes);
                        _initialized = true;
                    }
                };
            }, null);
        }
Beispiel #2
0
        public void Handle_ItemSelected(object sender, Xamarin.Forms.SelectedItemChangedEventArgs e)
        {
            ArrestReport report          = (ArrestReport)e.SelectedItem;
            var          crimeDetailPage = new CrimeDetailPage(report.DCN, report.CrimeType);

            Navigation.PushAsync(crimeDetailPage);
        }
Beispiel #3
0
        async Task <bool> Refresh()
        {
            if (_querycomplete)
            {
                return(true);
            }

            if (_distanceFormat)
            {
                // If there's no lat/long, don't load this screen but change the warning.
                if (Math.Abs(Settings.PrimaryLat) < Double.Epsilon)
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        warningPanel.IsVisible = true;
                        labelNoRecords.Text    = "You need to set a primary location in order to use this feature.";
                        buttonSettings.Text    = "Set Primary Location...";
                        activity.IsRunning     = false;
                        activity.IsVisible     = false;
                    });
                    return(true);
                }
            }

            //Look for neighborhoods user subscribes to.
            var ids = Global.Neighborhoods.Where(p => p.Selected).Select(p => p.ID);

            // Set the title based on blotter/search result type
            if (_distanceFormat)
            {
                Title = "1 Mile Blotter";
            }
            else if (_searchResults)
            {
                Title = "Search Results";
            }
            else
            {
                if (ids.Count() == 0)
                {
                    // You need to select a primary neighborhood.
                    warningPanel.IsVisible    = true;
                    blotterListView.IsVisible = false;
                    activity.IsRunning        = false;
                    activity.IsVisible        = false;
                    return(true);
                }
                else
                {
                    if (_selectedHood == -1)
                    {
                        var    nameList  = Global.Neighborhoods.Where(p => p.Selected).Select(p => p.Name);
                        string hoodNames = string.Join("/", nameList);
                        Title = hoodNames;
                    }
                    else
                    {
                        var    nameList  = Global.Neighborhoods.Where(p => p.ID.Equals(_selectedHood)).Select(p => p.Name);
                        string hoodNames = string.Join("/", nameList);
                        Title = hoodNames;
                    }
                }
            }

            // Populate the blotter data
            if (_distanceFormat)
            {
                var crimes = await Data.GetLocalBlotter(Settings.PrimaryLat, Settings.PrimaryLong, 5280.00);

                var proximitygroup = crimes.GroupBy(item => item.Proximity, (key, group) => new Group(key, group.ToArray()));
                blotterListView.ItemsSource = proximitygroup;
            }
            else if (_searchResults)
            {
                var crimes = await Data.SearchCrimes(_crimeSearchCriteria);

                // if there's only 1 crime result, jump straight to it!
                if (crimes.Length == 1)
                {
                    var crimeDetailPage = new CrimeDetailPage((CrimeReport)crimes[0]);
                    await Navigation.PushAsync(crimeDetailPage, true);
                }

                // Nothing came back in the search
                if (crimes.Length == 0)
                {
                    labelNoRecords.Text      = "Nothing came back for your search.";
                    warningPanel.IsVisible   = true;
                    buttonSettings.IsVisible = false;
                    activity.IsRunning       = false;
                    activity.IsVisible       = false;
                    return(true);
                }
                else
                {
                    _data = crimes;
                    blotterListView.ItemsSource = crimes;
                }
            }
            else
            {
                if (_selectedHood == -1)
                {
                    var hoods = await Data.GetBlotter(ids.ToArray());

                    var dategroup = hoods.GroupBy(item => item.OccurredDateType, (key, group) => new Group(key, group.ToArray()));
                    blotterListView.ItemsSource = dategroup;
                    if (dategroup.Count() == 0)
                    {
                        labelNoRecords.Text = "There's no crime information for the past 10 days.";
                    }
                }
                else
                {
                    int[] selhoodarray = new int[1];
                    selhoodarray[0] = _selectedHood;
                    var hoods = await Data.GetBlotter(selhoodarray);

                    var dategroup = hoods.GroupBy(item => item.OccurredDateType, (key, group) => new Group(key, group.ToArray()));
                    blotterListView.ItemsSource = dategroup;
                    if (dategroup.Count() == 0)
                    {
                        labelNoRecords.Text = "There's no crime information for the past 10 days.";
                    }
                }
            }

            warningPanel.IsVisible    = false;
            blotterListView.IsVisible = true;
            activity.IsRunning        = false;
            activity.IsVisible        = false;

            blotterListView.EndRefresh();

            _querycomplete = true;

            return(true);
        }
Beispiel #4
0
        public void Handle_ItemTapped(object sender, Xamarin.Forms.ItemTappedEventArgs e)
        {
            var crimeDetailPage = new CrimeDetailPage((CrimeReport)e.Item);

            Navigation.PushAsync(crimeDetailPage);
        }
        public CrimesNearMeView()
        {
            InitializeComponent();

            MyMap.MoveToRegion(
                MapSpan.FromCenterAndRadius(
                    new Position(39.952062, -75.163543), Distance.FromMiles(0.5)));
            MyMap.CustomPins = new List <CustomPin>();

            Disappearing += (object sender, EventArgs e) =>
            {
                if (MyMap != null)
                {
                    MyMap.IsShowingUser = false;
                }
                MessagingCenter.Unsubscribe <CustomPin>(this, "ShowCrimeReport");
                MessagingCenter.Unsubscribe <App>(this, "GoingToSleep");
                MessagingCenter.Unsubscribe <App>(this, "WakingUp");
            };

            //bool _needsRefresh = false;
            //var timer = new Timer(delegate
            //{
            //    Debug.WriteLine("Writing a line with a timer");
            //}, _needsRefresh, 300, 300, true);

            // User moved map.
            MyMap.PropertyChanged += (sender, e) =>
            {
                try
                {
                    if (_initialized)
                    {
                        if (!(MyMap.VisibleRegion.Equals(lastPosition)) || lastPosition == null)
                        {
                            lastPosition = MyMap.VisibleRegion;
                            UpdateMap();
                            System.GC.Collect();
                        }
                    }
                }
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
                catch (Exception mapex) { Debug.WriteLine($"Map PropertyChanged problem: {mapex.Message}"); }
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
            };

            // User is coming to look at the map
            Appearing += (sender, e) =>
            {
                // Start listener for pushpin events
                MessagingCenter.Subscribe <CustomPin>(this, "ShowCrimeReport", (obj) =>
                {
                    var crimeDetailPage = new CrimeDetailPage(obj);
                    Navigation.PushAsync(crimeDetailPage);
                });

                // When app sleeps, shut off location tracing
                MessagingCenter.Subscribe <App>(this, "GoingToSleep", (App obj) =>
                {
                    if (MyMap != null)
                    {
                        MyMap.IsShowingUser = false;
                    }
                });

                // When app wakes up, turn on location tracing
                MessagingCenter.Subscribe <App>(this, "WakingUp", (App obj) =>
                {
                    if (MyMap != null)
                    {
                        MyMap.IsShowingUser = true;
                    }
                });

                // Do we have filters set?

                Models.Filter setFilter = Settings.Filter;
                currentFilter = setFilter;
                LoadFilters();

                if (!_initialized)
                {
                    CenterTheMap();
                    _initialized = true;
                }
                UpdateMap();
                MyMap.IsShowingUser = true;
            };

            // Initialization should be complete, attempt to center the map.
            Device.BeginInvokeOnMainThread(() =>
            {
                if (!_initialized)
                {
                    _initialized = true;
                    CenterTheMap();
                }
            });
        }