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 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)); }); }