Example #1
0
        protected override async void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            var add       = FindViewById <Button>(Resource.Id.Add);
            var vibrate   = FindViewById <CheckBox>(Resource.Id.Vibrate);
            var from      = FindViewById <EditText>(Resource.Id.From);
            var to        = FindViewById <EditText>(Resource.Id.To);
            var mon       = FindViewById <CheckBox>(Resource.Id.Mon);
            var tue       = FindViewById <CheckBox>(Resource.Id.Tue);
            var wed       = FindViewById <CheckBox>(Resource.Id.Wed);
            var thu       = FindViewById <CheckBox>(Resource.Id.Thu);
            var fri       = FindViewById <CheckBox>(Resource.Id.Fri);
            var sat       = FindViewById <CheckBox>(Resource.Id.Sat);
            var sun       = FindViewById <CheckBox>(Resource.Id.Sun);
            var scheduled = FindViewById <ListView>(Resource.Id.Scheduled);

#if DEBUG
            await _repository.ClearSchedulesAsync();

            var fromSpan = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second + 20);

            await _repository.AddScheduleAsync(new RingerModeSchedule
            {
                From = fromSpan,
                To   = fromSpan.Add(new TimeSpan(0, 1, 0)),
                Name = "System generated",
                Mode = RingerMode.Vibrate,
                Days = DateTime.Now.DayOfWeek.ToWeekDay()
            });
#endif

            var schedules = await _repository.GetSchedulesAsync();

            // TODO: This needs to be done at startup instead
            _scheduler.ScheduleNextUpdate(this, schedules);

            UpdateUi(scheduled, this, schedules);

            add.Click += async(_, __) => await AddScheduleAsync(GetModel(vibrate, from, to, mon, tue, wed, thu, fri, sat, sun), scheduled, this);

            scheduled.ItemClick += (_, args) => ConfirmRemoveSchedule(scheduled, args);
        }
Example #2
0
        // We need to cancel schedules if deleted from the app.
        public override async void OnReceive(Context context, Intent intent)
        {
            var mode = (RingerMode)intent.GetIntExtra("RingerMode", 0);
            var to   = intent.GetLongExtra("To", 0);

            var audioManager = (AudioManager)context.GetSystemService(Context.AudioService);

            audioManager.RingerMode = mode;

            if (to != 0)
            {
                _scheduler.ScheduleNextUpdateWithoutEndTime(to.FromUnix(), RingerMode.Normal, context);
            }
            else
            {
                var schedules = await _repository.GetSchedulesAsync();

                _scheduler.ScheduleNextUpdate(context, schedules);
            }
        }