private CGSize showStopResponse(StopTimerIntentResponse response) { entryInfoView.TimeLabel.Text = secondsToString(response.EntryDuration.DoubleValue); var attributedString = new NSMutableAttributedString(response.EntryDescription ?? string.Empty, boldAttributes); var startTime = DateTimeOffset.FromUnixTimeSeconds(response.EntryStart.LongValue).ToLocalTime(); var endTime = DateTimeOffset.FromUnixTimeSeconds(response.EntryStart.LongValue + response.EntryDuration.LongValue).ToLocalTime(); var fromTime = startTime.ToString("HH:mm", CultureInfo.InvariantCulture); var toTime = endTime.ToString("HH:mm", CultureInfo.InvariantCulture); var timeFrameString = new NSAttributedString($"\n{fromTime} - {toTime}", regularAttributes); attributedString.Append(timeFrameString); entryInfoView.DescriptionLabel.AttributedText = attributedString; var width = ExtensionContext?.GetHostedViewMaximumAllowedSize().Width ?? 320; var boundingRect = attributedString.GetBoundingRect(new CGSize(width - 135 - 16 * 2, nfloat.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin | NSStringDrawingOptions.UsesFontLeading, null); View.AddSubview(entryInfoView); var frame = new CGRect(0, 0, width, boundingRect.Height + 12 * 2); entryInfoView.Frame = frame; return(frame.Size); }
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 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)); } ); }
private void showStopResponse(StopTimerIntentResponse response) { descriptionLabel.Text = response.EntryDescription; timeLabel.Text = secondsToString(response.EntryDuration.DoubleValue); var startTime = DateTimeOffset.FromUnixTimeSeconds(response.EntryStart.LongValue).ToLocalTime(); var endTime = DateTimeOffset.FromUnixTimeSeconds(response.EntryStart.LongValue + response.EntryDuration.LongValue).ToLocalTime(); var fromTime = startTime.ToString("HH:mm"); var toTime = endTime.ToString("HH:mm"); timeFrameLabel.Text = $"{fromTime} - {toTime}"; }