Esempio n. 1
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.LoadingView);
            SQLiteDb.LoadRoomsToDB(this);
            await SQLiteDb.LoadAlarmsToDb(this);

            await Task.Delay(1000);

            var intent = new Intent(this, typeof(MainPageActivity));

            StartActivity(intent);
            Finish();

            // Create your application here
        }
        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();
            };
        }