public override void HandleStopTimer(StopTimerIntent intent, Action <StopTimerIntentResponse> completion)
        {
            SharedStorage.instance.SetNeedsSync(true);

            stopTimeEntry(runningEntry)
            .Subscribe(
                stoppedTimeEntry =>
            {
                var timeSpan = TimeSpan.FromSeconds(stoppedTimeEntry.Duration ?? 0);

                var response = string.IsNullOrEmpty(stoppedTimeEntry.Description)
                            ? StopTimerIntentResponse.SuccessWithEmptyDescriptionIntentResponseWithEntryDurationString(
                    durationStringForTimeSpan(timeSpan))
                            : StopTimerIntentResponse.SuccessIntentResponseWithEntryDescription(
                    stoppedTimeEntry.Description, durationStringForTimeSpan(timeSpan)
                    );
                response.EntryStart    = stoppedTimeEntry.Start.ToUnixTimeSeconds();
                response.EntryDuration = stoppedTimeEntry.Duration;

                SharedStorage.instance.AddSiriTrackingEvent(SiriTrackingEvent.StopTimer());

                completion(response);
            },
                exception =>
            {
                SharedStorage.instance.AddSiriTrackingEvent(SiriTrackingEvent.Error(exception.Message));
                completion(responseFromException(exception));
            }
                );
        }
        public override void ConfirmStopTimer(StopTimerIntent intent, Action <StopTimerIntentResponse> completion)
        {
            if (togglAPI == null)
            {
                var userActivity = new NSUserActivity(stopTimerActivityType);
                userActivity.SetResponseText("Log in to use this shortcut.");
                completion(new StopTimerIntentResponse(StopTimerIntentResponseCode.FailureNoApiToken, userActivity));
                return;
            }

            var lastUpdated = SharedStorage.instance.GetLastUpdateDate();

            togglAPI.TimeEntries.GetAll()
            .Select(checkSyncConflicts(lastUpdated))
            .Select(getRunningTimeEntry)
            .Subscribe(
                runningTE =>
            {
                runningEntry     = runningTE;
                var userActivity = new NSUserActivity(stopTimerActivityType);
                userActivity.SetEntryDescription(runningTE.Description);
                completion(new StopTimerIntentResponse(StopTimerIntentResponseCode.Ready, userActivity));
            },
                exception =>
            {
                SharedStorage.instance.AddSiriTrackingEvent(SiriTrackingEvent.Error(exception.Message));
                completion(responseFromException(exception));
            });
        }
        public override void ConfirmStopTimer(StopTimerIntent intent, Action <StopTimerIntentResponse> completion)
        {
            if (togglAPI == null)
            {
                var userActivity = new NSUserActivity(stopTimerActivityType);
                userActivity.SetResponseText(Resources.SiriShortcutLoginToUseShortcut);
                completion(new StopTimerIntentResponse(StopTimerIntentResponseCode.FailureNoApiToken, userActivity));
                return;
            }

            togglAPI.TimeEntries.GetAll()
            .Select(getRunningTimeEntry)
            .Subscribe(
                runningTE =>
            {
                runningEntry     = runningTE;
                var userActivity = new NSUserActivity(stopTimerActivityType);
                userActivity.SetEntryDescription(runningTE.Description);
                completion(new StopTimerIntentResponse(StopTimerIntentResponseCode.Ready, userActivity));
            },
                exception =>
            {
                SharedStorage.instance.AddSiriTrackingEvent(SiriTrackingEvent.Error(exception.Message));
                completion(responseFromException(exception));
            });
        }
        public override void HandleStopTimer(StopTimerIntent intent, Action <StopTimerIntentResponse> completion)
        {
            togglAPI.TimeEntries.GetAll()
            .Select(getRunningTimeEntry)
            .SelectMany(stopTimeEntry)
            .Subscribe(
                te =>
            {
                SharedStorage.instance.SetNeedsSync(true);

                var timeSpan       = TimeSpan.FromSeconds(te.Duration ?? 0);
                var durationString = $"{timeSpan.Hours} hours, {timeSpan.Minutes} minutes and {timeSpan.Seconds} seconds";

                var response = StopTimerIntentResponse.SuccessIntentResponseWithEntryDescription(
                    te.Description,
                    durationString
                    );
                response.EntryStart    = te.Start.ToUnixTimeSeconds();
                response.EntryDuration = te.Duration;

                // Once Xamarin's bug if fixed we have to use tha above response instead of this one.
                //var response = new StopTimerIntentResponse(StopTimerIntentResponseCode.Success, null);
                completion(response);
            },
                exception =>
            {
                completion(responseFromException(exception));
            });
        }
        public override void ConfirmStopTimer(StopTimerIntent intent, Action <StopTimerIntentResponse> completion)
        {
            if (togglAPI == null)
            {
                completion(new StopTimerIntentResponse(StopTimerIntentResponseCode.FailureNoApiToken, null));
                return;
            }

            completion(new StopTimerIntentResponse(StopTimerIntentResponseCode.Ready, null));
        }
        private void setupDefaultShortcuts(IWorkspace workspace)
        {
            var startTimerIntent = new StartTimerIntent();

            startTimerIntent.Workspace = new INObject(workspace.Id.ToString(), workspace.Name);
            startTimerIntent.SuggestedInvocationPhrase = Resources.StartTimerInvocationPhrase;
            var startShortcut        = new INShortcut(startTimerIntent);
            var startRelevantShorcut = new INRelevantShortcut(startShortcut);

            INRelevanceProvider[] startTimerProviders =
            {
                new INDailyRoutineRelevanceProvider(INDailyRoutineSituation.Work),
                new INDailyRoutineRelevanceProvider(INDailyRoutineSituation.Gym),
                new INDailyRoutineRelevanceProvider(INDailyRoutineSituation.School)
            };
            startRelevantShorcut.RelevanceProviders = startTimerProviders;

            var stopTimerIntent = new StopTimerIntent();

            stopTimerIntent.SuggestedInvocationPhrase = Resources.StopTimerInvocationPhrase;
            var stopShortcut         = new INShortcut(stopTimerIntent);
            var stopRelevantShortcut = new INRelevantShortcut(stopShortcut);

            stopRelevantShortcut.RelevanceProviders = new[]
            {
                new INDailyRoutineRelevanceProvider(INDailyRoutineSituation.Home)
            };

            var showReportIntent = new ShowReportIntent();

            showReportIntent.SuggestedInvocationPhrase = Resources.ShowReportsInvocationPhrase;
            var reportShortcut = new INShortcut(showReportIntent);

            var continueTimerIntent = new ContinueTimerIntent
            {
                SuggestedInvocationPhrase = Resources.ContinueTimerInvocationPhrase
            };

            continueTimerIntent.Workspace = new INObject(workspace.Id.ToString(), workspace.Name);
            var continueTimerShortcut         = new INShortcut(continueTimerIntent);
            var continueTimerRelevantShortcut = new INRelevantShortcut(continueTimerShortcut)
            {
                RelevanceProviders = startTimerProviders
            };

            var shortcuts = new[] { startShortcut, stopShortcut, reportShortcut, continueTimerShortcut };

            INVoiceShortcutCenter.SharedCenter.SetShortcutSuggestions(shortcuts);

            var relevantShortcuts = new[] { startRelevantShorcut, stopRelevantShortcut, continueTimerRelevantShortcut };

            INRelevantShortcutStore.DefaultStore.SetRelevantShortcuts(relevantShortcuts, trackError);
        }
Esempio n. 7
0
        public void DonateStopCurrentTimeEntry()
        {
            if (!UIDevice.CurrentDevice.CheckSystemVersion(12, 0))
            {
                return;
            }

            var intent = new StopTimerIntent();

            intent.SuggestedInvocationPhrase = "Stop timer";

            var interaction = new INInteraction(intent, null);

            interaction.DonateInteraction(onCompletion);
        }
        public void DonateStopCurrentTimeEntry()
        {
            if (!UIDevice.CurrentDevice.CheckSystemVersion(12, 0))
            {
                return;
            }

            var intent = new StopTimerIntent();

            intent.SuggestedInvocationPhrase = Resources.StopTimerInvocationPhrase;

            var interaction = new INInteraction(intent, null);

            interaction.DonateInteraction(trackError);

            var shortcut = createRelevantShortcut(intent);

            donateRelevantShortcuts(shortcut);
        }
        public INIntent CreateIntent(SiriShortcutType shortcutType)
        {
            switch (shortcutType)
            {
            case SiriShortcutType.Start:
                var startTimerIntent = new StartTimerIntent();
                startTimerIntent.SuggestedInvocationPhrase = Resources.StartTimerInvocationPhrase;
                return(startTimerIntent);

            case SiriShortcutType.StartFromClipboard:
                var startTimerWithClipboardIntent = new StartTimerFromClipboardIntent();
                return(startTimerWithClipboardIntent);

            case SiriShortcutType.Continue:
                var continueTimerIntent = new ContinueTimerIntent();
                continueTimerIntent.SuggestedInvocationPhrase = Resources.ContinueTimerInvocationPhrase;
                return(continueTimerIntent);

            case SiriShortcutType.Stop:
                var stopTimerIntent = new StopTimerIntent();
                stopTimerIntent.SuggestedInvocationPhrase = Resources.StopTimerInvocationPhrase;
                return(stopTimerIntent);

            case SiriShortcutType.ShowReport:
                var showReportIntent = new ShowReportIntent();
                showReportIntent.SuggestedInvocationPhrase = Resources.ShowReportsInvocationPhrase;
                return(showReportIntent);

            /*
             * case SiriShortcutType.CustomStart:
             *  break;
             * case SiriShortcutType.CustomReport:
             *  break;
             */
            default:
                throw new ArgumentOutOfRangeException(nameof(shortcutType), shortcutType, null);
            }
        }