protected MarkdownComposerViewModel(IStatusIndicatorService status, IAlertDialogService alert, IJsonHttpClientService jsonClient) { var saveCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Text).Select(x => !string.IsNullOrEmpty(x)), t => Save()); saveCommand.IsExecuting.Where(x => x).Subscribe(_ => status.Show("Saving...")); saveCommand.IsExecuting.Where(x => !x).Subscribe(_ => status.Hide()); saveCommand.Subscribe(x => DismissCommand.ExecuteIfCan()); SaveCommand = saveCommand; PostToImgurCommand = ReactiveCommand.CreateAsyncTask(async data => { var uploadData = data as byte[]; if (uploadData == null) { throw new Exception("There is no data to upload!"); } return(await jsonClient.Post <ImgurModel>("https://api.imgur.com/3/image", new { image = Convert.ToBase64String(uploadData) }, new Dictionary <string, string> { { "Authorization", "Client-ID " + AuthorizationClientId } })); }); PostToImgurCommand.IsExecuting.Where(x => x).Subscribe(_ => status.Show("Uploading...")); PostToImgurCommand.IsExecuting.Where(x => !x).Subscribe(_ => status.Hide()); PostToImgurCommand.ThrownExceptions.SubscribeSafe(e => alert.Alert("Error", "Unable to upload image: " + e.Message)); }
public NewCommentViewModel( Func <string, Task> doneAction, IAlertDialogService alertDialogService = null) { alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>(); DoneCommand = ReactiveCommand.CreateFromTask(async _ => { await doneAction(Text); DismissCommand.ExecuteNow(); Text = string.Empty; }, this.WhenAnyValue(x => x.Text).Select(x => x?.Length > 0)); DiscardCommand = ReactiveCommand.CreateFromTask(async _ => { if (Text?.Length > 0) { var result = await alertDialogService.PromptYesNo( "Discard Comment", "Are you sure you want to discard this comment?"); if (!result) { return; } } Text = string.Empty; DismissCommand.ExecuteNow(); }); }
public UpgradesView(IFeaturesService featuresService, INetworkActivityService networkActivityService, IAlertDialogService alertDialogService) : base(style: MonoTouch.UIKit.UITableViewStyle.Plain) { _featuresService = featuresService; _networkActivityService = networkActivityService; _alertDialogService = alertDialogService; }
protected MarkdownComposerView(IAlertDialogService alertDialogService) { _alertDialogService = alertDialogService; _viewSegment = new UISegmentedControl(new [] { "Compose", "Preview" }); _viewSegment.SelectedSegment = 0; NavigationItem.TitleView = _viewSegment; _viewSegment.ValueChanged += SegmentValueChanged; }
public BaseViewModel() { logService = DependencyService.Get <ILogService>(); apiService = DependencyService.Get <IApiService>(); alertDialogService = DependencyService.Get <IAlertDialogService>(); CreateCommands(); }
public FeedbackComposerViewModel( IApplicationService applicationService = null, IAlertDialogService alertDialogService = null) { applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>(); alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>(); this.WhenAnyValue(x => x.IsFeature) .Subscribe(x => Title = x ? "New Feature" : "Bug Report"); SubmitCommand = ReactiveCommand.CreateFromTask(async _ => { if (string.IsNullOrEmpty(Subject)) { throw new ArgumentException(string.Format("You must provide a title for this {0}!", IsFeature ? "feature" : "bug")); } var labels = await applicationService.GitHubClient.Issue.Labels.GetAllForRepository(CodeHubOwner, CodeHubName); var labelName = IsFeature ? "enhancement" : "bug"; var createLabels = labels .Where(x => string.Equals(x.Name, labelName, StringComparison.OrdinalIgnoreCase)) .Select(x => x.Name) .Distinct(); var createIssueRequest = new Octokit.NewIssue(Subject) { Body = Description }; foreach (var label in createLabels) { createIssueRequest.Labels.Add(label); } await applicationService.GitHubClient.Issue.Create(CodeHubOwner, CodeHubName, createIssueRequest); }, this.WhenAnyValue(x => x.Subject).Select(x => !string.IsNullOrEmpty(x))); SubmitCommand .ThrownExceptions .Select(x => new UserError("There was a problem trying to post your feedback: " + x.Message)) .SelectMany(Interactions.Errors.Handle) .Subscribe(); DismissCommand = ReactiveCommand.CreateFromTask(async t => { if (string.IsNullOrEmpty(Description) && string.IsNullOrEmpty(Subject)) { return(true); } var itemType = IsFeature ? "feature" : "bug"; return(await alertDialogService.PromptYesNo( "Discard " + itemType.Transform(To.TitleCase) + "?", "Are you sure you want to discard this " + itemType + "?")); }); }
public EnterpriseSupportViewController(IAlertDialogService alertDialogService = null) { _alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>(); Appearing .Select(_ => NavigationController) .Where(x => x != null) .Subscribe(x => x.NavigationBar.ShadowImage = new UIImage()); }
public RepositoriesViewModel( Uri repositoriesUri, bool showOwner = true, IApplicationService applicationService = null, IAlertDialogService dialogService = null) { _applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>(); _dialogService = dialogService ?? Locator.Current.GetService <IAlertDialogService>(); NextPage = repositoriesUri; var showDescription = _applicationService.Account.ShowRepositoryDescriptionInList; RepositoryItemSelected = ReactiveCommand.Create <RepositoryItemViewModel, RepositoryItemViewModel>(x => x); var repositoryItems = _internalItems.CreateDerivedCollection( x => new RepositoryItemViewModel(x, showOwner, showDescription, GoToRepository)); var searchUpdated = this.WhenAnyValue(x => x.SearchText) .Throttle(TimeSpan.FromMilliseconds(400), RxApp.MainThreadScheduler); Items = repositoryItems .CreateDerivedCollection( x => x, x => x.Name.ContainsKeyword(SearchText), signalReset: searchUpdated); LoadCommand = ReactiveCommand.CreateFromTask(async t => { _internalItems.Clear(); var parameters = new Dictionary <string, string>(); parameters["per_page"] = 75.ToString(); var items = await RetrieveRepositories(repositoriesUri, parameters); _internalItems.AddRange(items); return(items.Count > 0); }); var canLoadMore = this.WhenAnyValue(x => x.NextPage).Select(x => x != null); LoadMoreCommand = ReactiveCommand.CreateFromTask(async _ => { var items = await RetrieveRepositories(NextPage); _internalItems.AddRange(items); return(items.Count > 0); }, canLoadMore); LoadCommand.Select(_ => _internalItems.Count == 0) .ToProperty(this, x => x.IsEmpty, out _isEmpty, true); LoadCommand.ThrownExceptions.Subscribe(LoadingError); LoadMoreCommand.ThrownExceptions.Subscribe(LoadingError); _hasMore = this.WhenAnyValue(x => x.NextPage) .Select(x => x != null) .ToProperty(this, x => x.HasMore); }
public CommitViewModel( string username, string repository, Commit commit, bool showRepository = false, IApplicationService applicationService = null, IActionMenuService actionMenuService = null, IAlertDialogService alertDialogService = null) : this(username, repository, commit.Hash, showRepository, applicationService, actionMenuService, alertDialogService) { Commit = commit; }
public ApplicationService(IAccountsService accounts, IMvxViewDispatcher viewDispatcher, IFeaturesService features, IPushNotificationsService pushNotifications, IAlertDialogService alertDialogService) { _viewDispatcher = viewDispatcher; _pushNotifications = pushNotifications; Accounts = accounts; _features = features; _alertDialogService = alertDialogService; }
public CoinDetailPageViewModel(INavigationService navigationService, ICoinGeckoAPIManager coinGeckoApiManager, IPageDialogService pageDialogService, IDialogService dialogService, IAlertDialogService alertDialogService) { _navigationService = navigationService; _coinGeckoApiManager = coinGeckoApiManager; _alertDialogService = alertDialogService; GoBackCommand = new DelegateCommand(GoBack); }
public PayView(Delivery delivery) { InitializeComponent(); pickerMethod.SelectedIndex = 0; pickerMethod.SelectedItem = pickerMethod.Items[0]; pickerMethod.SelectedIndexChanged += ChangueEnterDataVisibility(); payButton.Clicked += Pay(delivery); enterDataGrid.IsVisible = false; alertDialogService = DependencyService.Get <IAlertDialogService>(); }
public LoginView(IAlertDialogService alertDialogService, INetworkActivityService networkActivityService) : base(networkActivityService) { _alertDialogService = alertDialogService; NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action, (s, e) => ViewModel.ShowLoginOptionsCommand.ExecuteIfCan()); this.WhenViewModel(x => x.Title).IsNotNull().Subscribe(x => Title = x); this.WhenViewModel(x => x.LoginUrl).IsNotNull().Subscribe(LoadRequest); }
public StartupViewModel( IAccountsService accountsService = null, IApplicationService applicationService = null, IAlertDialogService alertDialogService = null) { _accountsService = accountsService ?? Locator.Current.GetService <IAccountsService>(); _applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>(); _alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>(); StartupCommand = ReactiveCommand.CreateFromTask(_ => Startup()); }
public GistFileViewController( string gistId, string filename, Octokit.Gist gist = null, IApplicationService applicationService = null, IAlertDialogService alertDialogService = null, IMessageService messageService = null) : base(false) { _gistId = gistId; _filename = filename; _gist = gist; _applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>(); _alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>(); messageService = messageService ?? Locator.Current.GetService <IMessageService>(); Title = System.IO.Path.GetFileName(filename); var actionButton = new UIBarButtonItem(UIBarButtonSystemItem.Action) { Enabled = false }; NavigationItem.RightBarButtonItem = actionButton; var loadCommand = ReactiveCommand.CreateFromTask(Load); loadCommand .ThrownExceptions .Select(HandleLoadError) .SelectMany(Interactions.Errors.Handle) .Subscribe(); this.OnActivation(d => { d(this.WhenAnyValue(x => x.Gist) .Select(x => x != null) .Subscribe(x => actionButton.Enabled = x)); d(actionButton .GetClickedObservable() .Subscribe(CreateActionSheet)); d(loadCommand .IsExecuting .Subscribe(x => actionButton.Enabled = !x)); }); Appearing .Take(1) .Select(_ => Unit.Default) .InvokeReactiveCommand(loadCommand); }
public LoginViewModel( IApplicationService applicationService = null, IAlertDialogService alertDialogService = null) { applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>(); alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>(); LoginCommand = ReactiveCommand.CreateFromTask <string>(applicationService.Login); LoginCommand.Subscribe(x => MessageBus.Current.SendMessage(new LogoutMessage())); LoginCommand.ThrownExceptions .Select(ex => alertDialogService.Alert("Error", $"Unable to successfully login. {ex.Message}")) .Subscribe(x => x.ToBackground()); }
public OAuthLoginViewController(IAlertDialogService alertDialogService = null) : base(true) { _alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>(); Title = "Login"; OnActivation(d => { d(this.WhenAnyObservable(x => x.ViewModel.LoginCommand.IsExecuting) .SubscribeStatus("Logging in...")); }); }
public CoinViewTikiUnitTests() { _coinGeckoApiManager = new CoinGeckoAPIManager(); _alertDialogService = new Mock <IAlertDialogService>().Object; _navigationService = new Mock <INavigationService>().Object; _pageDialogService = new Mock <IPageDialogService>().Object; _mockConnectivity = new MockConnectivity(); _coinListVM = new CoinListPageViewModel(_navigationService, _coinGeckoApiManager, _alertDialogService, _pageDialogService, _mockConnectivity ); }
public static IDisposable AlertExecuting(this ReactiveCommand @this, IAlertDialogService dialogFactory, string text) { return(@this.IsExecuting.Subscribe(x => { if (x) { dialogFactory.Show(text); } else { dialogFactory.Hide(); } })); }
public static IDisposable Activate(this IAlertDialogService @this, IObservable <bool> observable, string text) { return(observable.Subscribe(x => { if (x) { @this.Show(text); } else { @this.Hide(); } })); }
public static IDisposable Activate(this IAlertDialogService @this, ReactiveCommand command, string text) { return(command.IsExecuting.Subscribe(x => { if (x) { @this.Show(text); } else { @this.Hide(); } })); }
public AddAccountViewModel( ILoginService loginService = null, IAlertDialogService alertDialogService = null) { _loginService = loginService ?? Locator.Current.GetService <ILoginService>(); _alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>(); var canLogin = this .WhenAnyValue(x => x.Username, x => x.Password) .Select(x => !String.IsNullOrEmpty(x.Item1) && !String.IsNullOrEmpty(x.Item2)); LoginCommand = ReactiveCommand.CreateFromTask(Login, canLogin); LoginCommand.ThrownExceptions.Subscribe(HandleLoginException); }
public AddAccountViewModel( ILoginService loginService = null, IAlertDialogService alertDialogService = null) { _loginService = loginService ?? Locator.Current.GetService <ILoginService>(); _alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>(); LoginCommand = ReactiveCommand.CreateFromTask(Login); LoginCommand .Subscribe(x => MessageBus.Current.SendMessage(new LogoutMessage())); LoginCommand .ThrownExceptions .SelectMany(HandleLoginException) .SelectMany(Interactions.Errors.Handle) .Subscribe(); }
public OAuthLoginViewModel( ILoginService loginService = null, IAlertDialogService alertDialogService = null) { _loginService = loginService ?? Locator.Current.GetService <ILoginService>(); _alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>(); LoginCommand = ReactiveCommand.CreateFromTask <string>(async code => { await _loginService.LoginWithToken( Secrets.GithubOAuthId, Secrets.GithubOAuthSecret, code, RedirectUri, WebDomain, GitHubSharp.Client.DefaultApi); MessageBus.Current.SendMessage(new LogoutMessage()); }); LoginCommand .ThrownExceptions .Subscribe(err => _alertDialogService.Alert("Error!", err.Message).ToBackground()); }
public MarkdownComposerView(IAlertDialogService alertDialogService, IStatusIndicatorService statusIndicatorService) { _alertDialogService = alertDialogService; _statusIndicatorService = statusIndicatorService; _viewSegment = new UISegmentedControl(new [] { "Compose", "Preview" }); _viewSegment.SelectedSegment = 0; NavigationItem.TitleView = _viewSegment; _viewSegment.ValueChanged += SegmentValueChanged; var pictureImage = UIImageHelper.FromFileAuto("Images/MarkdownComposer/picture"); var linkImage = UIImageHelper.FromFileAuto("Images/MarkdownComposer/link"); var photoImage = UIImageHelper.FromFileAuto("Images/MarkdownComposer/photo"); var buttons = new [] { CreateAccessoryButton("@", () => TextView.InsertText("@")), CreateAccessoryButton("#", () => TextView.InsertText("#")), CreateAccessoryButton("*", () => TextView.InsertText("*")), CreateAccessoryButton("`", () => TextView.InsertText("`")), CreateAccessoryButton(pictureImage, () => { var range = TextView.SelectedRange; TextView.InsertText("![]()"); TextView.SelectedRange = new MonoTouch.Foundation.NSRange(range.Location + 4, 0); }), CreateAccessoryButton(photoImage, () => SelectImage()), CreateAccessoryButton(linkImage, () => { var range = TextView.SelectedRange; TextView.InsertText("[]()"); TextView.SelectedRange = new MonoTouch.Foundation.NSRange(range.Location + 1, 0); }), CreateAccessoryButton("~", () => TextView.InsertText("~")), CreateAccessoryButton("=", () => TextView.InsertText("=")), CreateAccessoryButton("-", () => TextView.InsertText("-")), CreateAccessoryButton("+", () => TextView.InsertText("+")), CreateAccessoryButton("_", () => TextView.InsertText("_")), CreateAccessoryButton("[", () => TextView.InsertText("[")), CreateAccessoryButton("]", () => TextView.InsertText("]")), CreateAccessoryButton("<", () => TextView.InsertText("<")), CreateAccessoryButton(">", () => TextView.InsertText(">")), }; SetAccesoryButtons(buttons); }
public RepositoriesTrendingViewModel( ITrendingRepository trendingRepository = null, IAlertDialogService dialogService = null) { _trendingRepository = trendingRepository ?? new TrendingRepository(); _dialogService = dialogService ?? Locator.Current.GetService <IAlertDialogService>(); RepositoryItemSelected = ReactiveCommand.Create <RepositoryItemViewModel, RepositoryItemViewModel>(x => x); LoadCommand = ReactiveCommand.CreateFromTask(Load); LoadCommand.ThrownExceptions.Subscribe(LoadingError); SelectedLanguage = _defaultLanguage; this.WhenAnyValue(x => x.SelectedLanguage) .Skip(1) .Select(_ => Unit.Default) .Do(_ => Items = null) .InvokeCommand(LoadCommand); }
public FeedbackComposerViewModel( IApplicationService applicationService = null, IAlertDialogService alertDialogService = null) { applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>(); alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>(); SubmitCommand = ReactiveCommand.CreateFromTask(async _ => { if (string.IsNullOrEmpty(Subject)) { throw new ArgumentException("You must provide a title for this issue!"); } var createIssueRequest = new Octokit.NewIssue(Subject) { Body = Description }; await applicationService.GitHubClient.Issue.Create(CodeHubOwner, CodeHubName, createIssueRequest); }, this.WhenAnyValue(x => x.Subject).Select(x => !string.IsNullOrEmpty(x))); SubmitCommand .ThrownExceptions .Select(ex => new UserError("There was a problem trying to post your feedback.", ex)) .SelectMany(Interactions.Errors.Handle) .Subscribe(); DismissCommand = ReactiveCommand.CreateFromTask(async t => { if (string.IsNullOrEmpty(Description) && string.IsNullOrEmpty(Subject)) { return(true); } return(await alertDialogService.PromptYesNo( "Discard Issue?", "Are you sure you want to discard this issue?")); }); }
public MarkdownAccessoryViewModel( IImgurService imgurService = null, IMedia mediaPicker = null, IAlertDialogService alertDialog = null) { imgurService = imgurService ?? Locator.Current.GetService <IImgurService>(); mediaPicker = mediaPicker ?? Plugin.Media.CrossMedia.Current; alertDialog = alertDialog ?? Locator.Current.GetService <IAlertDialogService>(); PostToImgurCommand = ReactiveCommand.CreateFromTask(async _ => { if (!Settings.HasSeenImgurUploadWarn) { Settings.HasSeenImgurUploadWarn = true; await alertDialog.Alert("Please Read!", IMGUR_UPLOAD_WARN_MESSAGE); } var photo = await mediaPicker.PickPhotoAsync(new PickMediaOptions { CompressionQuality = 80 }); var memoryStream = new MemoryStream(); await photo.GetStream().CopyToAsync(memoryStream); using (alertDialog.Activate("Uploading...")) { var model = await imgurService.SendImage(memoryStream.ToArray()); if (model == null || model.Data == null || model.Data.Link == null) { throw new InvalidOperationException("Unable to upload to Imgur. Please try again later."); } return(model.Data.Link); } }); PostToImgurCommand.ThrownExceptions .Where(x => !(x is TaskCanceledException)) .Subscribe(x => alertDialog.Alert("Upload Error", x.Message)); }
public FoodListPage(List <Food> foods) { alertDialogService = DependencyService.Get <IAlertDialogService>(); InitializeComponent(); ObservableCollection <FoodCombine> fc = new ObservableCollection <FoodCombine>(); for (int i = 0; i < foods.Count; i += 2) { if (i + 1 < foods.Count) { fc.Add(new FoodCombine(foods[i], foods[i + 1])); } else { fc.Add(new FoodCombine(foods[i], null)); } } FoodCombineViewModel fcvm = new FoodCombineViewModel(); fcvm.FoodsCombined = fc; foodListPage.BindingContext = fcvm; }
public RepositoryExploreViewModel( IApplicationService applicationService = null, IAlertDialogService dialogService = null) { _applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>(); dialogService = dialogService ?? Locator.Current.GetService <IAlertDialogService>(); RepositoryItemSelected = ReactiveCommand.Create <RepositoryItemViewModel, RepositoryItemViewModel>(x => x); var showDescription = _applicationService.Account.ShowRepositoryDescriptionInList; var internalItems = new ReactiveList <Repository>(resetChangeThreshold: double.MaxValue); Items = internalItems.CreateDerivedCollection(x => new RepositoryItemViewModel(x, true, showDescription, y => RepositoryItemSelected.ExecuteNow(y))); var canSearch = this.WhenAnyValue(x => x.SearchText).Select(x => !string.IsNullOrEmpty(x)); SearchCommand = ReactiveCommand.CreateFromTask(async t => { try { internalItems.Clear(); var request = new SearchRepositoriesRequest(SearchText); var response = await _applicationService.GitHubClient.Search.SearchRepo(request); internalItems.Reset(response.Items); } catch (Exception e) { var msg = string.Format("Unable to search for {0}. Please try again.", SearchText); throw new Exception(msg, e); } }, canSearch); SearchCommand .ThrownExceptions .Subscribe(err => dialogService.Alert("Error Searching", err.Message).ToBackground()); }