示例#1
0
        private async void SetUpRound()
        {
            try
            {
                // stop the sound if any is being played
                audio.Stop();

                //stop the timer
                deviceTimer.Stop();
            }
            catch
            {
            }
            // clear the options and answer
            buttons.Clear();
            Answer = "";
            timerGuagePointer.Value = 0;

            // set options : wrap the awaited task within a task to make it wait
            this.buttons = Task.Run(async() => await SetDummmyOptionsAsync()).Result;

            // set new synopsis
            lblSynopsis.Text = Task.Run(async() => await GetAnimeSynopsisAsync()).Result;

            buttons = buttons.OrderBy(a => Guid.NewGuid()).ToList();

            this.frameOption1.Content = buttons[0];
            this.frameOption2.Content = buttons[1];
            this.frameOption3.Content = buttons[2];
            this.frameOption4.Content = buttons[3];


            deviceTimer = new DeviceTimer(StartTimer, TimeSpan.FromSeconds(1), true, true);
        }
示例#2
0
 public InfoViewModel() : base()
 {
     Status = new NetPingStatus();
     timer  = new DeviceTimer(TimeSpan.FromSeconds(1), OnlineTimerTick);
 }
示例#3
0
        private void SetTimer()
        {
            if (HabitTimeList.Count <= CurrentIndex)
            {
                HabitTimeList.Add(CurrentHabitTime);
                ElapsedTimeList.Add(ElapsedTime);
            }

            void action()
            {
                if (previousTime == DateTime.MinValue)
                {
                    previousTime = DateTime.Now;
                }

                var currentTime = DateTime.Now;

                var diffTimeSpan = currentTime.Subtract(previousTime);

                var oldHabitTime = CurrentHabitTime;

                ElapsedTime      = ElapsedTime.Add(diffTimeSpan);
                CurrentHabitTime = CurrentHabitTime.Add(-diffTimeSpan);

                if (oldHabitTime.Seconds != CurrentHabitTime.Seconds)
                {
                    Console.WriteLine($"{ElapsedTime.ToString(@"mm\:ss")}");

                    RefreshHabitAndElapsedTimeList();

                    if (!IsSoonFinishTime)
                    {
                        DependencyService.Get <IAlarmSetter>().SetCountAlarm(CurrentHabitTime.Add(TimeSpan.FromSeconds(-10)));
                    }

                    DependencyService.Get <INotifySetter>().NotifyHabitCount(CurrentHabit, CurrentHabitTime, false, !IsNotLastHabit);

                    if (CurrentHabit.TotalTime.TotalSeconds > 20 && CurrentHabitTime.TotalSeconds < 11 && !IsSoonFinishTime)
                    {
                        DependencyService.Get <INotifySetter>().NotifySoonFinishHabit(CurrentHabit, NextHabitName);
                        IsSoonFinishTime = true;
                    }

                    if (CurrentHabitTime.TotalSeconds < 1 && !IsMinusHabitTime)
                    {
                        DependencyService.Get <INotifySetter>().NotifyFinishHabit(CurrentHabit, NextHabitName);
                        IsMinusHabitTime = true;

                        if (Preferences.Get("IsAutoFlipHabit", false))
                        {
                            ShowNextHabitCommand.Execute(null);
                        }
                    }
                    ;
                }

                previousTime = currentTime;
            }

            void stoppingaAction()
            {
                IsCounting = false;
                DependencyService.Get <INotifySetter>().CancelHabitCountNotify();
                DependencyService.Get <INotifySetter>().CancelFinishHabitNotify();
            }

            deviceTimer = new DeviceTimer(action, TimeSpan.FromSeconds(0.1), true, true, stoppingaAction);
        }