Beispiel #1
0
        public int GetStreak(State state)
        {
            int count = 0;
            var expiration = GetExpiration().AddDays(-1);
            var times = state.Data.CompletionTimes;
            var start = times.Count - 1;

            if (HasCompletedToday(state))
            {
                start--;
                count++;
            }

            for (int i = start; i >= 0; --i)
            {
                expiration = expiration.AddDays(-1);
                if (times[i] > expiration)
                {
                    count++;
                }
                else
                {
                    break;
                }
            }

            return count;
        }
Beispiel #2
0
        public void MarkCompletion(State state)
        {
            if (HasCompletedToday(state))
            {
                return;
            }

            state.Data.CompletionTimes.Add(DateTime.UtcNow);
        }
Beispiel #3
0
        private void UpdateTile(TimeSpan timeLeft, Logic logic, State state)
        {
            var updater = TileUpdateManager.CreateTileUpdaterForApplication();
            updater.Clear();

            if (logic.HasCompletedToday(state))
            {
                return;
            }

            XmlDocument tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Text01);
            tileXml.GetElementsByTagName("text")[0].InnerText =
                string.Format("You have {0} hour{1}!", timeLeft.Hours, timeLeft.Hours == 1 ? "" : "s");

            updater.Update(new TileNotification(tileXml));
        }
Beispiel #4
0
        private async Task UpdateToast(TimeSpan timeLeft, Logic logic, State state)
        {
            if (logic.ShouldNotify(state))
            {
                if (timeLeft.Hours >= 2)
                {
                    SendNotification(string.Format("You have {0} hours!", timeLeft.Hours));
                }
                else
                {
                    SendNotification(string.Format("You only have {0:hh\\:mm}!", timeLeft));
                }

                logic.OnNotify(state);
                await state.Save();
            }
        }
Beispiel #5
0
        public bool ShouldNotify(State state)
        {
            if (HasCompletedToday(state))
            {
                return false;
            }

            var expires = GetExpiration();
            var now = DateTime.UtcNow;
            var timeLeft = expires - now;
            var timeSince = now - state.Data.LastNotification;

            if (timeLeft.Hours > 9)
            {
                return false;
            }

            if (timeLeft.Hours >= 4 && timeSince.Hours < 3)
            {
                return false;
            }

            if (timeLeft.Hours >= 2 && timeSince.Hours < 1)
            {
                return false;
            }

            return true;
        }
Beispiel #6
0
 public void OnNotify(State state)
 {
     state.Data.LastNotification = DateTime.UtcNow;
 }
Beispiel #7
0
 public bool HasCompletedToday(State state)
 {
     var times = state.Data.CompletionTimes;
     var expiration = GetExpiration().AddDays(-1);
     return times.Any() && times.Last() > expiration;
 }