public void DonateStartTimeEntry(IWorkspace workspace, ITimeEntry timeEntry) { if (!UIDevice.CurrentDevice.CheckSystemVersion(12, 0)) { return; } var intent = new StartTimerIntent(); intent.Workspace = new INObject(workspace.Id.ToString(), workspace.Name); if (!string.IsNullOrEmpty(timeEntry.Description)) { // If any of the tags or the project id were just created and haven't sync we ignore this action until the user repeats it if (timeEntry.ProjectId < 0 || timeEntry.TagIds.Any(tagId => tagId < 0)) { return; } intent.EntryDescription = timeEntry.Description; intent.ProjectId = new INObject(timeEntry.ProjectId.ToString(), timeEntry.ProjectId.ToString()); intent.Tags = timeEntry.TagIds.Select(tag => new INObject(tag.ToString(), tag.ToString())).ToArray(); intent.Billable = new INObject(timeEntry.Billable.ToString(), timeEntry.Billable.ToString()); intent.SuggestedInvocationPhrase = timeEntry.Description; } else { intent.SuggestedInvocationPhrase = "Start timer"; } var interaction = new INInteraction(intent, null); interaction.DonateInteraction(onCompletion); }
// Each time an order is placed we instantiate an INInteraction object // and donate it to the system (see SoupOrderDataManager extension). // After instantiating the INInteraction, its identifier property is // set to the same value as the identifier property for the // corresponding order. Compile a list of all the order identifiers to // pass to the INInteraction delete method. void RemoveDonation(MenuItem menuItem) { if (!menuItem.IsAvailable) { Order[] orderHistory = OrderManager?.OrderHistory.ToArray <Order>(); if (orderHistory is null) { return; } string[] orderIdentifiersToRemove = orderHistory .Where <Order>((order) => order.MenuItem.ItemNameKey == menuItem.ItemNameKey) .Select <Order, string>((order) => order.Identifier.ToString()) .ToArray <string>(); INInteraction.DeleteInteractions(orderIdentifiersToRemove, (error) => { if (!(error is null)) { Console.WriteLine($"Failed to delete interactions with error {error.ToString()}"); } else { Console.WriteLine("Successfully deleted interactions"); } });
public void Configure (INInteraction interaction, INUIHostedViewContext context, Action<CGSize> completion) { // Do configuration here, including preparing views and calculating a desired size for presentation. if (completion != null) completion (DesiredSize ()); }
private INInteraction CreateInteractionOrDefault(Measure measure) { var breadUnits = measure.Products .Select(v => _breadUnitsCalculator.Calculate(v.Amount, v.ProductMeasureUnit.Carbohydrates)) .DefaultIfEmpty(0) .Sum(); var isEmpty = !measure.Level.HasValue && breadUnits < Double.Epsilon && measure.ShortInsulin == 0; if (isEmpty) { return(null); } var intent = measure.Level.HasValue ? CreateAddMeasureIntent(measure, breadUnits) : CreateAddShortInsulinIntent(measure, breadUnits); var interaction = new INInteraction(intent, null) { Identifier = measure.Id.ToString() }; return(interaction); }
public void DonateStartTimeEntry(IThreadSafeTimeEntry timeEntry) { if (!UIDevice.CurrentDevice.CheckSystemVersion(12, 0)) { return; } var relevantShortcuts = new List <INRelevantShortcut>(); var startTimerIntent = new StartTimerIntent(); startTimerIntent.Workspace = new INObject(timeEntry.Workspace.Id.ToString(), timeEntry.Workspace.Name); if (!string.IsNullOrEmpty(timeEntry.Description)) { // If any of the tags or the project id were just created and haven't sync we ignore this action until the user repeats it if (timeEntry.ProjectId < 0 || timeEntry.TagIds.Any(tagId => tagId < 0)) { return; } if (timeEntry.ProjectId is long projectId) { var projectINObject = new INObject(timeEntry.ProjectId.ToString(), timeEntry.Project.Name); startTimerIntent.ProjectId = projectINObject; } startTimerIntent.EntryDescription = timeEntry.Description; var tags = timeEntry.TagIds.Select(tag => new INObject(tag.ToString(), tag.ToString())).ToArray(); startTimerIntent.Tags = tags; var billable = new INObject(timeEntry.Billable.ToString(), timeEntry.Billable.ToString()); startTimerIntent.Billable = billable; startTimerIntent.SuggestedInvocationPhrase = string.Format(Resources.SiriTrackEntrySuggestedInvocationPhrase, timeEntry.Description); // Relevant shortcut for the Siri Watch Face relevantShortcuts.Add(createRelevantShortcut(startTimerIntent)); } else { startTimerIntent.SuggestedInvocationPhrase = Resources.StartTimerInvocationPhrase; } var startTimerInteraction = new INInteraction(startTimerIntent, null); startTimerInteraction.DonateInteraction(trackError); // Descriptionless Relevant Shortcut. Always added even if the intent has one var descriptionlessIntent = new StartTimerIntent(); descriptionlessIntent.Workspace = new INObject(timeEntry.Workspace.Id.ToString(), timeEntry.Workspace.Name); var descriptionlessShortcut = createRelevantShortcut(descriptionlessIntent); relevantShortcuts.Add(descriptionlessShortcut); donateRelevantShortcuts(relevantShortcuts.ToArray()); }
public void ClearAll() { if (!UIDevice.CurrentDevice.CheckSystemVersion(12, 0)) { return; } INInteraction.DeleteAllInteractions(_ => { }); }
public void Configure(INInteraction interaction, INUIHostedViewContext context, Action <CGSize> completion) { // Do configuration here, including preparing views and calculating a desired size for presentation. if (completion != null) { completion(DesiredSize()); } }
// Converts an `Order` into `OrderSoupIntent` and donates it as an // interaction to the system so that this order can be suggested in the // future or turned into a voice shortcut for quickly placing the same // order in the future. void DonateInteraction(Order order) { var interaction = new INInteraction(order.Intent, null); interaction.DonateInteraction((error) => { if (!(error is null)) { Console.WriteLine($"Interaction donation failed: {error}"); }
public void ClearAll() { if (!UIDevice.CurrentDevice.CheckSystemVersion(12, 0)) { return; } INInteraction.DeleteAllInteractions(_ => { }); INVoiceShortcutCenter.SharedCenter.SetShortcutSuggestions(new INShortcut[0]); }
public void DonateShowReport(ReportPeriod period) { if (!UIDevice.CurrentDevice.CheckSystemVersion(12, 0)) { return; } var intent = new ShowReportPeriodIntent(); switch (period) { case ReportPeriod.Today: intent.Period = ShowReportPeriodReportPeriod.Today; intent.SuggestedInvocationPhrase = $"Show {Resources.Today.ToLower()}'s time"; break; case ReportPeriod.Yesterday: intent.Period = ShowReportPeriodReportPeriod.Yesterday; intent.SuggestedInvocationPhrase = $"Show {Resources.Yesterday.ToLower()}'s time"; break; case ReportPeriod.LastWeek: intent.Period = ShowReportPeriodReportPeriod.LastWeek; intent.SuggestedInvocationPhrase = $"Show {Resources.LastWeek.ToLower()}'s time"; break; case ReportPeriod.LastMonth: intent.Period = ShowReportPeriodReportPeriod.LastMonth; intent.SuggestedInvocationPhrase = $"Show {Resources.LastMonth.ToLower()}'s time"; break; case ReportPeriod.ThisMonth: intent.Period = ShowReportPeriodReportPeriod.ThisMonth; intent.SuggestedInvocationPhrase = $"Show {Resources.ThisMonth.ToLower()}'s time"; break; case ReportPeriod.ThisWeek: intent.Period = ShowReportPeriodReportPeriod.ThisWeek; intent.SuggestedInvocationPhrase = $"Show {Resources.ThisWeek.ToLower()}'s time"; break; case ReportPeriod.ThisYear: intent.Period = ShowReportPeriodReportPeriod.ThisYear; intent.SuggestedInvocationPhrase = $"Show {Resources.ThisYear.ToLower()}'s time"; break; case ReportPeriod.Unknown: intent.Period = ShowReportPeriodReportPeriod.Unknown; break; } var interaction = new INInteraction(intent, null); interaction.DonateInteraction(trackError); }
public void DonateShowReport() { if (!UIDevice.CurrentDevice.CheckSystemVersion(12, 0)) { return; } var intent = new ShowReportIntent(); var interaction = new INInteraction(intent, null); interaction.DonateInteraction(onCompletion); }
public void DonateShowReport(ReportPeriod period) { if (!UIDevice.CurrentDevice.CheckSystemVersion(12, 0)) { return; } var intent = new ShowReportPeriodIntent(); switch (period) { case ReportPeriod.Today: intent.Period = ShowReportPeriodReportPeriod.Today; break; case ReportPeriod.Yesterday: intent.Period = ShowReportPeriodReportPeriod.Yesterday; break; case ReportPeriod.LastWeek: intent.Period = ShowReportPeriodReportPeriod.LastWeek; break; case ReportPeriod.LastMonth: intent.Period = ShowReportPeriodReportPeriod.LastMonth; break; case ReportPeriod.ThisMonth: intent.Period = ShowReportPeriodReportPeriod.ThisMonth; break; case ReportPeriod.ThisWeek: intent.Period = ShowReportPeriodReportPeriod.ThisWeek; break; case ReportPeriod.ThisYear: intent.Period = ShowReportPeriodReportPeriod.ThisYear; break; case ReportPeriod.Unknown: intent.Period = ShowReportPeriodReportPeriod.Unknown; break; } intent.SuggestedInvocationPhrase = string.Format( Resources.SiriShowReportSuggestedInvocationPhrase, period.ToHumanReadableString().ToLower()); var interaction = new INInteraction(intent, null); interaction.DonateInteraction(trackError); }
public void DonateShowReport() { if (!UIDevice.CurrentDevice.CheckSystemVersion(12, 0)) { return; } var intent = new ShowReportIntent(); intent.SuggestedInvocationPhrase = Resources.ShowReportsInvocationPhrase; var interaction = new INInteraction(intent, null); interaction.DonateInteraction(trackError); }
private void siriButtonHandler(object sender, EventArgs args) { var intent = constructStartTimerIntent(ViewModel.PasteFromClipboard.Value); var interaction = new INInteraction(intent, null); interaction.DonateInteraction(null); var vc = new INUIAddVoiceShortcutViewController(new INShortcut(intent)); vc.ModalPresentationStyle = UIModalPresentationStyle.FormSheet; vc.Delegate = this; PresentViewController(vc, true, null); }
public void ConfigureView( NSSet <INParameter> parameters, INInteraction interaction, INUIInteractiveBehavior interactiveBehavior, INUIHostedViewContext context, INUIHostedViewControllingConfigureViewHandler completion) { var success = true; var desiredSize = CGSize.Empty; switch (interaction.Intent) { case StartTimerIntent startTimerIntent: if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Success) { desiredSize = showStartTimerSuccess(startTimerIntent.EntryDescription); } if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Ready) { desiredSize = showConfirmation($"Start {startTimerIntent.EntryDescription}?"); } break; case StopTimerIntent _: if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Success) { var response = interaction.IntentResponse as StopTimerIntentResponse; if (!(response is null)) { desiredSize = showStopResponse(response); } } if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Ready) { desiredSize = showConfirmation("Stop current entry?"); } break; default: success = false; break; } completion(success, parameters, desiredSize); }
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); }
private void DonateInteraction(INInteraction interaction) { interaction.DonateInteraction( error => { if (error != null) { _logger.Error($"Interaction donation failed: {error}"); } else { _logger.Info("Successfully donated interaction."); } }); }
public void DonateShowReport(ReportPeriod period) { if (!UIDevice.CurrentDevice.CheckSystemVersion(12, 0)) { return; } var intent = new ShowReportPeriodIntent(); switch (period) { case ReportPeriod.Today: intent.Period = ShowReportPeriodReportPeriod.Today; break; case ReportPeriod.Yesterday: intent.Period = ShowReportPeriodReportPeriod.Yesterday; break; case ReportPeriod.LastWeek: intent.Period = ShowReportPeriodReportPeriod.LastWeek; break; case ReportPeriod.LastMonth: intent.Period = ShowReportPeriodReportPeriod.LastMonth; break; case ReportPeriod.ThisMonth: intent.Period = ShowReportPeriodReportPeriod.ThisMonth; break; case ReportPeriod.ThisWeek: intent.Period = ShowReportPeriodReportPeriod.ThisWeek; break; case ReportPeriod.ThisYear: intent.Period = ShowReportPeriodReportPeriod.ThisYear; break; case ReportPeriod.Unknown: intent.Period = ShowReportPeriodReportPeriod.Unknown; break; } 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 void ConfigureView( NSSet <INParameter> parameters, INInteraction interaction, INUIInteractiveBehavior interactiveBehavior, INUIHostedViewContext context, INUIHostedViewControllingConfigureViewHandler completion) { switch (interaction.Intent) { case StartTimerIntent startTimerIntent: var desiredSize = CGSize.Empty; if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Success) { showStartTimerSuccess(startTimerIntent.EntryDescription); desiredSize = new CGSize(200, 60); } completion(true, parameters, desiredSize); break; case StopTimerIntent _: desiredSize = CGSize.Empty; if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Success) { var response = interaction.IntentResponse as StopTimerIntentResponse; if (!(response is null)) { showStopResponse(response); desiredSize = new CGSize(300, 60); } } completion(true, parameters, desiredSize); break; default: completion(false, new NSSet <INParameter>(), CGSize.Empty); break; } }
public void ConfigureView( NSSet <INParameter> parameters, INInteraction interaction, INUIInteractiveBehavior interactiveBehavior, INUIHostedViewContext context, INUIHostedViewControllingConfigureViewHandler completion) { var intent = interaction.Intent as OrderSoupIntent; if (intent is null) { completion(false, new NSSet <INParameter>(), CGSize.Empty); } var order = Order.FromOrderSoupIntent(intent); foreach (var view in View.Subviews) { view.RemoveFromSuperview(); } // Different UIs can be displayed depending if the intent is in the // confirmation phase or the handle phase. var desiredSize = CGSize.Empty; if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Ready) { desiredSize = DisplayInvoice(order, intent); } else if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Success) { var response = interaction.IntentResponse as OrderSoupIntentResponse; if (!(response is null)) { desiredSize = DisplayOrderConfirmation(order, intent, response); } } completion(true, parameters, desiredSize); }
private void siriButtonHandler(object sender, EventArgs args) { if (!(ViewModel.SelectedWorkspace.Value is IThreadSafeWorkspace workspace)) { return; } var intent = new ShowReportPeriodIntent(); intent.Period = ViewModel.SelectReportPeriod.Value.ToShowReportPeriodReportPeriod(); intent.Workspace = new INObject(workspace.Id.ToString(), workspace.Name); var interaction = new INInteraction(intent, null); interaction.DonateInteraction(null); var vc = new INUIAddVoiceShortcutViewController(new INShortcut(intent)); vc.ModalPresentationStyle = UIModalPresentationStyle.FormSheet; vc.Delegate = this; PresentViewController(vc, true, null); }
public void ConfigureView( NSSet <INParameter> parameters, INInteraction interaction, INUIInteractiveBehavior interactiveBehavior, INUIHostedViewContext context, INUIHostedViewControllingConfigureViewHandler completion) { var success = true; var desiredSize = CGSize.Empty; switch (interaction.Intent) { case StartTimerIntent startTimerIntent: if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Success) { desiredSize = showStartTimerSuccess(startTimerIntent.EntryDescription); } if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Ready) { desiredSize = showMessage($"Start tracking {startTimerIntent.EntryDescription ?? "time"}?"); } break; case StopTimerIntent _: if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Success) { if (interaction.IntentResponse is StopTimerIntentResponse response) { desiredSize = showStopResponse(response); } } if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Ready) { var entryDescription = interaction.IntentResponse.UserActivity.GetEntryDescription(); desiredSize = showMessage( $"Stop tracking {(!string.IsNullOrEmpty(entryDescription) ? entryDescription : "time")}?"); } if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Failure) { if (interaction.IntentResponse is StopTimerIntentResponse response) { var message = interaction.IntentResponse.UserActivity.GetResponseText(); desiredSize = showMessage(message); } } break; case ContinueTimerIntent _: if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Success) { if (interaction.IntentResponse is ContinueTimerIntentResponse response) { desiredSize = showStartTimerSuccess(response.EntryDescription); } } if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Ready) { var entryDescription = interaction.IntentResponse.UserActivity.GetEntryDescription(); desiredSize = showMessage( $"Start tracking {(!string.IsNullOrEmpty(entryDescription) ? entryDescription : "time")}?"); } break; default: success = false; break; } completion(success, parameters, desiredSize); }
public void ConfigureView( NSSet <INParameter> parameters, INInteraction interaction, INUIInteractiveBehavior interactiveBehavior, INUIHostedViewContext context, INUIHostedViewControllingConfigureViewHandler completion) { var success = true; var desiredSize = CGSize.Empty; switch (interaction.Intent) { case StartTimerIntent startTimerIntent: if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Success) { desiredSize = showStartTimerSuccess(startTimerIntent.EntryDescription); } if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Ready) { var message = string.IsNullOrEmpty(startTimerIntent.EntryDescription) ? Resources.SiriStartTimerWithEmptyDescConfirmationMessage : string.Format(Resources.SiriStartTimerConfirmationMessage, startTimerIntent.EntryDescription); desiredSize = showMessage(message); } if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Failure) { if (interaction.IntentResponse is StartTimerIntentResponse response) { var message = response.UserActivity.GetResponseText(); desiredSize = showMessage(message); } } break; case StartTimerFromClipboardIntent _: var description = interaction.IntentResponse.UserActivity.GetResponseText(); if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Success) { desiredSize = showStartTimerSuccess(description); } if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Ready) { var message = string.IsNullOrEmpty(description) ? Resources.SiriStartTimerWithEmptyDescConfirmationMessage : string.Format(Resources.SiriStartTimerConfirmationMessage, description); desiredSize = showMessage(message); } if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Failure) { if (interaction.IntentResponse is StartTimerFromClipboardIntentResponse response) { var message = response.UserActivity.GetResponseText(); desiredSize = showMessage(message); } } break; case StopTimerIntent _: if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Success) { if (interaction.IntentResponse is StopTimerIntentResponse response) { desiredSize = showStopResponse(response); } } if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Ready) { var entryDescription = interaction.IntentResponse.UserActivity.GetEntryDescription(); var message = string.IsNullOrEmpty(entryDescription) ? Resources.SiriStopTimerWithEmptyDescConfirmationMessage : string.Format(Resources.SiriStopTimerConfirmationMessage, entryDescription); desiredSize = showMessage(message); } if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Failure) { if (interaction.IntentResponse is StopTimerIntentResponse response) { var message = response.UserActivity.GetResponseText(); desiredSize = showMessage(message); } } break; case ContinueTimerIntent _: if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Success) { if (interaction.IntentResponse is ContinueTimerIntentResponse response) { desiredSize = showStartTimerSuccess(response.EntryDescription); } } if (interaction.IntentHandlingStatus == INIntentHandlingStatus.Ready) { var entryDescription = interaction.IntentResponse.UserActivity.GetEntryDescription(); var message = string.IsNullOrEmpty(entryDescription) ? Resources.SiriStartTimerWithEmptyDescConfirmationMessage : string.Format(Resources.SiriStartTimerConfirmationMessage, entryDescription); desiredSize = showMessage(message); } break; default: success = false; break; } completion(success, parameters, desiredSize); }
public void Configure(INInteraction interaction, INUIHostedViewContext context, Action <CGSize> completion) { throw new NotImplementedException(); }