Ejemplo n.º 1
0
 public override async void OnReceive(Context context, Intent intent)
 {
     if (intent != null)
     {
         string action = intent.Action;
         if (action.Equals(ACTION_PROCESS_LOCATION))
         {
             LocationResult result = LocationResult.ExtractResult(intent);
             if (result != null)
             {
                 var      location = result.LastLocation;
                 Location pwsz     = new Location("PWSZ")
                 {
                     Latitude  = 49.609080,
                     Longitude = 20.704225
                 };
                 float[] results = new float[3];
                 Location.DistanceBetween(location.Latitude, location.Longitude, pwsz.Latitude, pwsz.Longitude, results);
                 var distance = results[0];
                 if (distance < 200)
                 {
                     await WebApiDataController.SetSendNotificationsAsync(true);
                 }
                 else
                 {
                     await WebApiDataController.SetSendNotificationsAsync(false);
                 }
             }
         }
     }
 }
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.MainPage);
            Instance = this;
            var width = Convert.ToInt32(Resources.DisplayMetrics.WidthPixels * 0.96);

            var alarms = await SQLiteDb.GetAlarms(this);

            Alarm alarm = new Alarm();

            if (alarms.Count() > 0)
            {
                alarm = alarms.Last();
            }
            if (alarm != null)
            {
                var floatingButton = FindViewById <FloatingActionButton>(Resource.Id.mainPageFloatingActionButton);
                this.RunOnUiThread(() =>
                {
                    if (DateTime.Now.Subtract(alarm.NotifyDate).TotalHours > 24)
                    {
                        floatingButton.Visibility = ViewStates.Gone;
                    }
                    else
                    {
                        floatingButton.Visibility = ViewStates.Visible;
                    }
                });

                floatingButton.Click += (o, e) =>
                {
                    var intent = new Intent(this, typeof(AlarmActivity));
                    intent.PutExtra("alarmId", alarm.Id);
                    StartActivity(intent);
                };
            }

            ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
            var notificationsAlways  = prefs.GetBoolean("settingsNotifications", true);

            if (notificationsAlways)
            {
                await UpdateLocationAsync(false);

                await WebApiDataController.SetSendNotificationsAsync(true);
            }
            else
            {
                await UpdateLocationAsync(true);
            }

            Button planButton = FindViewById <Button>(Resource.Id.planButton);

            planButton.Click += (o, e) =>
            {
                var intent = new Intent(this, typeof(BuildingPlansActivity));
                StartActivity(intent);
            };
            Button reportButton = FindViewById <Button>(Resource.Id.reportButton);

            reportButton.Click += (o, e) =>
            {
                SQLiteDb.LoadRoomsToDB(this);
                var intent = new Intent(this, typeof(ReportEmergencyActivity));
                StartActivity(intent);
            };
            Button threatsButton = FindViewById <Button>(Resource.Id.threatsButton);

            threatsButton.Click += (o, e) =>
            {
                SQLiteDb.LoadAlarmsToDb(this).GetAwaiter();
                var intent = new Intent(this, typeof(AlarmsHistoryActivity));
                StartActivity(intent);
            };
            Button settingsButton = FindViewById <Button>(Resource.Id.settingsButton);

            settingsButton.Click += (o, e) =>
            {
                var intent = new Intent(this, typeof(SettingsActivity));
                StartActivity(intent);
                Finish();
            };
        }