Esempio n. 1
0
        public override void ConfirmStartTimerFromClipboard(StartTimerFromClipboardIntent intent, Action <StartTimerFromClipboardIntentResponse> completion)
        {
            var userActivity = new NSUserActivity(activityType);

            if (togglAPI == null)
            {
                userActivity.SetResponseText(Resources.SiriShortcutLoginToUseShortcut);
                completion(new StartTimerFromClipboardIntentResponse(StartTimerFromClipboardIntentResponseCode.FailureNoApiToken, userActivity));
                return;
            }

            userActivity.SetResponseText(clipboardText);
            completion(new StartTimerFromClipboardIntentResponse(StartTimerFromClipboardIntentResponseCode.Ready, userActivity));
        }
Esempio n. 2
0
        private TimeEntry createTimeEntry(StartTimerFromClipboardIntent intent)
        {
            var workspaceId = intent.Workspace == null?SharedStorage.Instance.GetDefaultWorkspaceId() : (long)Convert.ToDouble(intent.Workspace.Identifier);

            return(new TimeEntry(
                       workspaceId,
                       stringToLong(intent.ProjectId?.Identifier),
                       null,
                       intent.Billable != null && intent.Billable.Identifier == "True",
                       DateTimeOffset.Now,
                       null,
                       clipboardText ?? string.Empty,
                       intent.Tags == null ? new long[0] : stringToLongCollection(intent.Tags.Select(tag => tag.Identifier)),
                       (long)SharedStorage.Instance.GetUserId(),
                       0,
                       null,
                       DateTimeOffset.Now
                       ));
        }
Esempio n. 3
0
        public override void HandleStartTimerFromClipboard(StartTimerFromClipboardIntent intent, Action <StartTimerFromClipboardIntentResponse> completion)
        {
            var userActivity = new NSUserActivity(activityType);
            var timeEntry    = createTimeEntry(intent);

            togglAPI.TimeEntries.Create(timeEntry).ToObservable().Subscribe(te =>
            {
                SharedStorage.Instance.SetNeedsSync(true);
                SharedStorage.Instance.AddSiriTrackingEvent(SiriTrackingEvent.StartTimer(te));
                userActivity.SetResponseText(clipboardText);
                var response = new StartTimerFromClipboardIntentResponse(StartTimerFromClipboardIntentResponseCode.Success, userActivity);
                completion(response);
            }, exception =>
            {
                SharedStorage.Instance.AddSiriTrackingEvent(SiriTrackingEvent.Error(exception.Message));
                userActivity.SetResponseText(Resources.SomethingWentWrongTryAgain);
                completion(new StartTimerFromClipboardIntentResponse(StartTimerFromClipboardIntentResponseCode.Failure, userActivity));
            });
        }
        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);
            }
        }