protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var logic = new Logic();
            var expires = logic.GetExpiration();

            RegisterBackgroundTask();
        }
Example #2
0
        public async void Update()
        {
            var state = await State.Load();
            var logic = new Logic();
            var streak = logic.GetStreak(state);

            StreakValue.Text = string.Format("{0} day{1}", streak, streak != 1 ? "s" : "");
        }
        private async void OnLoad(object sender, RoutedEventArgs args)
        {
            var state = await State.Load();
            var logic = new Logic();

            if (logic.HasCompletedToday(state))
            {
                DidComplete();
            }
        }
Example #4
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));
        }
Example #5
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();
            }
        }
Example #6
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            var deferral = taskInstance.GetDeferral();

            try
            {
                var logic = new Logic();
                var state = await State.Load();
                var timeLeft = logic.GetTimeUntilExpiration();

                UpdateTile(timeLeft, logic, state);
                await UpdateToast(timeLeft, logic, state);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to notify {0}", ex);
            }

            deferral.Complete();
        }
        private async void IDidThem(object sender, RoutedEventArgs args)
        {
            var dialog = new MessageDialog(
                "Don't push this button if you didn't ;)",
                "Are you sure you did them?"
                );
            var ok = new UICommand("I'm sure!");
            var cancel = new UICommand("No I didn't :(");
            dialog.Commands.Add(ok);
            dialog.Commands.Add(cancel);
            dialog.CancelCommandIndex = 1;

            var result = await dialog.ShowAsync();
            if (result == ok)
            {
                try
                {
                    var state = await State.Load();
                    var logic = new Logic();
                    logic.MarkCompletion(state);
                    await state.Save();
                }
                catch
                {
                    dialog = new MessageDialog(
                        "Something went wrong trying to save your status :(",
                        "Oh noes!"
                        );
                    dialog.Commands.Add(new UICommand("Sad face!"));
                    await dialog.ShowAsync();
                    return;
                }

                DidComplete();
                MainPage.Changed = true;
            }
        }