public static IObservable<T> ObserveOn<T>(this IObservable<T> source, IMvxMainThreadDispatcher dispatcher) { Contract.Requires(source != null); Contract.Requires(dispatcher != null); return Observable.Create<T>(observer => source.Subscribe( value => dispatcher.RequestMainThreadAction(() => observer.OnNext(value)), ex => dispatcher.RequestMainThreadAction(() => observer.OnError(ex)), () => dispatcher.RequestMainThreadAction(observer.OnCompleted))); }
/// <summary> /// Setup the execution of the task with a progress indicator /// </summary> /// <typeparam name="T">Type of task return value</typeparam> /// <param name="task">Task that is executing</param> /// <param name="onCompletion">Action that will be executed when the task is complete</param> /// <param name="startProgressAction">Action that will show the progress indicator</param> /// <param name="stopProgressAction">Action that will hide the progress indicator</param> public void SetupTask <T>(Task <T> task, Action <Task <T> > onCompletion, Action startProgressAction, Action stopProgressAction) { _progressIndicatorCount++; _dispatcher.RequestMainThreadAction(startProgressAction); task.ContinueWith(x => { onCompletion(task); if (--_progressIndicatorCount == 0) { _dispatcher.RequestMainThreadAction(stopProgressAction); } }); }
public Task ShowAsync(string title, string message, string ok = Text.Ok) { var tcs = new TaskCompletionSource <bool>(); dispathcher.RequestMainThreadAction(() => { var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController; if (rootController == null) { tcs.TrySetResult(false); return; } UIAlertController alert = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert); var okAction = UIAlertAction.Create(ok, UIAlertActionStyle.Default, act => tcs.TrySetResult(true)); alert.AddAction(okAction); rootController.PresentViewController(alert, true, null); }); return(tcs.Task); }
/// <summary> /// Displaies a dialog with buttons /// </summary> /// <param name="message">Message that will be displayed</param> /// <param name="title">Title of the dialog box</param> /// <param name="buttonBuilder">Button builder.</param> private void DisplayDialogWithButtons(string message, string title, Action <AlertDialog.Builder> buttonBuilder) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(_topActivity.Activity); alertDialogBuilder.SetMessage(message); if (title != null) { alertDialogBuilder.SetTitle(title); } buttonBuilder(alertDialogBuilder); AlertDialog alertDialog = alertDialogBuilder.Create(); _dispatcher.RequestMainThreadAction(() => alertDialog.Show()); }
private async Task DoGetAllWifiInfoCommand(CancellationToken token = default(CancellationToken)) { IsScanning = true; try { var allInfo = await _wifi.GetAllWifiInfoAsync(token).ConfigureAwait(false); _dispatcher.RequestMainThreadAction(() => { WifiInfo.Clear(); WifiInfo.AddRange(allInfo.Select(info => new WifiInfoViewModel(info))); }); } catch (Exception e) { Mvx.TaggedError("WifiViewModel", $"Failed getting All Wifi Info: {e}"); } finally { IsScanning = false; } }
private void StartObservingMessages() { RealtimeService.ObserveMessages((message, key) => { _dispatcher.RequestMainThreadAction(() => { ChatMessageViewModel existingMessage = Messages.FirstOrDefault(m => m.Key == key); if (existingMessage == null) { Debug.WriteLine(key); Messages.Add(new ChatMessageViewModel() { Key = key, Content = message.Content, UserName = message.UserName }); } else { existingMessage.IsBusy = false; } }); }); }
/// <summary> /// Shows a message box with the specified message /// </summary> /// <param name="message">Message that should be displayed</param> /// <param name="title">Title of the message box</param> public void Alert(string message, string title) { _dispatcher.RequestMainThreadAction(() => MessageBox.Show(message, title ?? string.Empty, MessageBoxButton.OK)); }
/// <summary> /// Shows a message box with the specified message /// </summary> /// <param name="message">Message that should be displayed</param> /// <param name="title">Title of the message box</param> public void Alert(string message, string title) { var alert = new UIAlertView(title ?? string.Empty, message, null, "Ok", null); _dispatcher.RequestMainThreadAction(() => alert.Show()); }