protected override bool ShouldStartLoad(WKWebView webView, WKNavigationAction navigationAction) { // F*****g BitBucket and their horrible user interface. if (ForbiddenRoutes.Any(navigationAction.Request.Url.AbsoluteString.StartsWith)) { AlertDialogService.ShowAlert("Invalid Request", "Sorry, due to restrictions, you can not sign-up for a new account in CodeBucket."); return(false); } //We're being redirected to our redirect URL so we must have been successful if (navigationAction.Request.Url.Host == "codebucket") { var queryParams = navigationAction .Request.Url.Query.Split('&') .Select(x => x.Split('=').Select(Uri.EscapeDataString).ToArray()) .Where(x => x.Length >= 2) .ToDictionary(x => x[0], x => x[1]); if (queryParams.TryGetValue("code", out string code)) { ViewModel.LoginCommand.Execute(code).LoggedCatch(this).Subscribe(); return(false); } } //if (navigationAction.Request.Url.Path.StartsWith("/socialauth", StringComparison.Ordinal)) //{ // var safari = new SFSafariViewController(new NSUrl(ViewModel.LoginUrl)); // PresentViewController(safari, true, null); // return false; //} return(base.ShouldStartLoad(webView, navigationAction)); }
private void ShareButtonPress(UIBarButtonItem barButtonItem) { var sheet = new UIActionSheet(); var shareButton = sheet.AddButton("Share"); var showButton = sheet.AddButton("Show in GitHub"); var cancelButton = sheet.AddButton("Cancel"); sheet.CancelButtonIndex = cancelButton; sheet.Dismissed += (sender, e) => { BeginInvokeOnMainThread(() => { if (e.ButtonIndex == showButton) { var viewController = new WebBrowserViewController(Readme.HtmlUrl); PresentViewController(viewController, true, null); } else if (e.ButtonIndex == shareButton) { AlertDialogService.Share( $"{_owner}/{_repository} Readme", url: Readme.HtmlUrl, barButtonItem: barButtonItem); } }); sheet.Dispose(); }; sheet.ShowFrom(barButtonItem, true); }
private async Task Save() { if (_model.Files.Count(x => x.Value != null) == 0) { AlertDialogService.ShowAlert("No Files", "You cannot modify a Gist without atleast one file"); return; } var app = MvvmCross.Platform.Mvx.Resolve <Core.Services.IApplicationService>(); var hud = this.CreateHud(); NetworkActivity.PushNetworkActive(); try { hud.Show("Saving..."); var newGist = await app.GitHubClient.Gist.Edit(_originalGist.Id, _model); Created?.Invoke(newGist); DismissViewController(true, null); } catch (Exception e) { AlertDialogService.ShowAlert("Error", "Unable to save gist: " + e.Message); } finally { hud.Hide(); NetworkActivity.PopNetworkActive(); } }
private void ShareButtonPress(object o, EventArgs args) { var sheet = new UIActionSheet(); var shareButton = sheet.AddButton("Share"); var showButton = sheet.AddButton("Show in GitHub"); var cancelButton = sheet.AddButton("Cancel"); sheet.CancelButtonIndex = cancelButton; sheet.Dismissed += (sender, e) => { BeginInvokeOnMainThread(() => { if (e.ButtonIndex == showButton) { ViewModel.GoToGitHubCommand.Execute(null); } else if (e.ButtonIndex == shareButton) { AlertDialogService.Share( $"{ViewModel.RepositoryOwner}/{ViewModel.RepositoryName} Readme", CurrentContent, ViewModel.HtmlUrl, o as UIBarButtonItem); } }); sheet.Dispose(); }; sheet.ShowFrom(_actionButton, true); }
private void ShowExtraMenu(object o, EventArgs arg) { var sheet = CreateActionSheet(Title); var vm = ViewModel; var openButton = !string.IsNullOrEmpty(ViewModel.FilePath) ? sheet.AddButton("Open In") : -1; var shareButton = !string.IsNullOrEmpty(ViewModel.HtmlUrl) ? sheet.AddButton("Share") : -1; var showButton = ViewModel.GoToHtmlUrlCommand.CanExecute(null) ? sheet.AddButton("Show in GitHub") : -1; var cancelButton = sheet.AddButton("Cancel"); sheet.CancelButtonIndex = cancelButton; sheet.Dismissed += (s, e) => BeginInvokeOnMainThread(() => { try { if (e.ButtonIndex == openButton) { var ctrl = new UIDocumentInteractionController(); ctrl.Url = NSUrl.FromFilename(ViewModel.FilePath); ctrl.PresentOpenInMenu(NavigationItem.RightBarButtonItem, true); } else if (e.ButtonIndex == shareButton) { AlertDialogService.ShareUrl(ViewModel?.HtmlUrl, o as UIBarButtonItem); } else if (e.ButtonIndex == showButton) { vm.GoToHtmlUrlCommand.Execute(null); } } catch { } }); sheet.ShowFrom(NavigationItem.RightBarButtonItem, true); }
private async Task Save() { if (_model.Files.Count(x => x.Value != null) == 0) { AlertDialogService.ShowAlert("No Files", "You cannot modify a Gist without atleast one file"); return; } var app = MvvmCross.Platform.Mvx.Resolve <CodeHub.Core.Services.IApplicationService>(); var hud = this.CreateHud(); NetworkActivity.PushNetworkActive(); try { hud.Show("Saving..."); var newGist = await app.Client.ExecuteAsync(app.Client.Gists[_originalGist.Id].EditGist(_model)); Created?.Invoke(newGist.Data); DismissViewController(true, null); } finally { hud.Hide(); NetworkActivity.PopNetworkActive(); } }
private async Task Load() { Web.UserInteractionEnabled = false; Web.LoadHtmlString("", NSBundle.MainBundle.BundleUrl); _activityView.Alpha = 1; _activityView.StartAnimating(); View.Add(_activityView); try { var request = _inAppPurchaseService.RequestProductData(FeaturesService.ProEdition).WithTimeout(TimeSpan.FromSeconds(30)); var productData = (await request).Products.FirstOrDefault(); var enabled = _featuresService.IsProEnabled; var model = new UpgradeDetailsModel(productData != null ? productData.LocalizedPrice() : null, enabled); var content = new UpgradeDetailsRazorView { Model = model }.GenerateString(); LoadContent(content); Web.UserInteractionEnabled = true; } catch (Exception e) { AlertDialogService.ShowAlert("Error Loading Upgrades", e.Message); } finally { UIView.Animate(0.2f, 0, UIViewAnimationOptions.BeginFromCurrentState | UIViewAnimationOptions.CurveEaseInOut, () => _activityView.Alpha = 0, () => { _activityView.RemoveFromSuperview(); _activityView.StopAnimating(); }); } }
private async Task HandleEditButton() { try { var page = ViewModel.CurrentWikiPage(Web.Url.AbsoluteString); var wiki = await Task.Run(() => ViewModel.GetApplication().Client.Users[ViewModel.Username].Repositories[ViewModel.Repository].Wikis[page].GetInfo()); var composer = new Composer { Title = "Edit" + Title, Text = wiki.Data }; composer.NewComment(this, async(text) => { try { await composer.DoWorkAsync("Saving...", () => Task.Run(() => ViewModel.GetApplication().Client.Users[ViewModel.Username].Repositories[ViewModel.Repository].Wikis[page].Update(text, Uri.UnescapeDataString("/" + page)))); composer.CloseComposer(); Refresh(); } catch (Exception ex) { AlertDialogService.ShowAlert("Unable to update page!", ex.Message); composer.EnableSendButton = true; }; }); } catch (Exception e) { AlertDialogService.ShowAlert("Error", e.Message); } }
void ShareButtonTap(object sender) { if (ViewModel.Gist == null) { return; } var app = Mvx.Resolve <IApplicationService>(); var isOwner = string.Equals(app.Account.Username, ViewModel.Gist?.Owner?.Login, StringComparison.OrdinalIgnoreCase); var gist = ViewModel.Gist; var sheet = new UIActionSheet(); var editButton = sheet.AddButton(isOwner ? "Edit" : "Fork"); var starButton = sheet.AddButton(ViewModel.IsStarred ? "Unstar" : "Star"); var shareButton = sheet.AddButton("Share"); var showButton = sheet.AddButton("Show in GitHub"); var cancelButton = sheet.AddButton("Cancel"); sheet.CancelButtonIndex = cancelButton; sheet.DismissWithClickedButtonIndex(cancelButton, true); sheet.Dismissed += (s, e) => { BeginInvokeOnMainThread(() => { try { if (e.ButtonIndex == shareButton) { AlertDialogService.Share( $"Gist {gist.Files?.Select(x => x.Key).FirstOrDefault() ?? gist.Id}", gist.Description, gist.HtmlUrl, sender as UIBarButtonItem); } else if (e.ButtonIndex == showButton) { ViewModel.GoToHtmlUrlCommand.Execute(null); } else if (e.ButtonIndex == starButton) { ViewModel.ToggleStarCommand.Execute(null); } else if (e.ButtonIndex == editButton) { Compose().ToBackground(); } } catch { } }); sheet.Dispose(); }; sheet.ShowFromToolbar(NavigationController.Toolbar); }
private void SelectImage() { var imagePicker = new RotatableUIImagePickerController(); imagePicker.NavigationControllerDelegate = new ImagePickerDelegate(); imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.PhotoLibrary); imagePicker.MediaTypes = imagePicker.MediaTypes.Where(x => !(x.Contains("movie") || x.Contains("video"))).ToArray(); imagePicker.FinishedPickingMedia += (sender, e) => { // determine what was selected, video or image bool isImage = false; switch (e.Info[UIImagePickerController.MediaType].ToString()) { case "public.image": isImage = true; break; } // if it was an image, get the other image info if (isImage) { // get the original image UIImage originalImage = e.Info[UIImagePickerController.OriginalImage] as UIImage; if (originalImage != null) { // do something with the image try { UploadImage(originalImage); } catch { } } } else { // if it's a video AlertDialogService.ShowAlert("Not supported!", "Video upload is currently not supported."); } // dismiss the picker imagePicker.DismissViewController(true, null); UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent; }; imagePicker.Canceled += (sender, e) => { imagePicker.DismissViewController(true, null); UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent; }; NavigationController.PresentViewController(imagePicker, true, null); }
public override void ApplyButtonPressed() { if (string.IsNullOrEmpty(_filterName.Value)) { AlertDialogService.ShowAlert("Filter Name", "You must name your filter!"); return; } CreatedFilterModel(CreateFilterModel()); }
private async Task MergeClick() { try { await this.DoWorkAsync("Merging...", ViewModel.Merge); } catch (Exception e) { AlertDialogService.ShowAlert("Unable to Merge", e.Message); } }
protected override void OnLoadError(NSError error) { base.OnLoadError(error); //Frame interrupted error if (error.Code == 102 || error.Code == -999) { return; } AlertDialogService.ShowAlert("Error", "Unable to communicate with Bitbucket. " + error.LocalizedDescription); }
private void ShowExtraMenu(UIBarButtonItem item) { if (ViewModel.Issue == null) { return; } var issue = ViewModel.Issue; var sheet = new UIActionSheet(); var editButton = ViewModel.IsCollaborator ? sheet.AddButton("Edit") : -1; var openButton = ViewModel.IsCollaborator ? sheet.AddButton(ViewModel.Issue.State == "open" ? "Close" : "Open") : -1; var commentButton = sheet.AddButton("Comment"); var shareButton = sheet.AddButton("Share"); var showButton = sheet.AddButton("Show in GitHub"); var cancelButton = sheet.AddButton("Cancel"); sheet.CancelButtonIndex = cancelButton; sheet.Dismissed += (s, e) => { BeginInvokeOnMainThread(() => { if (e.ButtonIndex == editButton) { ViewModel.GoToEditCommand.Execute(null); } else if (e.ButtonIndex == openButton) { ViewModel.ToggleStateCommand.Execute(null); } else if (e.ButtonIndex == shareButton) { AlertDialogService.Share( Title, issue.Body, issue.HtmlUrl, NavigationItem.RightBarButtonItem); } else if (e.ButtonIndex == showButton) { ViewModel.GoToUrlCommand.Execute(ViewModel.Issue.HtmlUrl); } else if (e.ButtonIndex == commentButton) { AddCommentTapped(); } }); sheet.Dispose(); }; sheet.ShowFrom(item, true); }
private async Task GoToPage(string page) { try { var data = await ViewModel.GetData(page); Web.LoadRequest(new NSUrlRequest(new NSUrl(data))); } catch (Exception e) { AlertDialogService.ShowAlert("Error", e.Message); } }
private void ShowExtraMenu() { var repoModel = ViewModel.Repository; if (repoModel == null || ViewModel.IsStarred == null || ViewModel.IsWatched == null) { return; } var sheet = new UIActionSheet(); var pinButton = sheet.AddButton(ViewModel.IsPinned ? "Unpin from Slideout Menu" : "Pin to Slideout Menu"); var starButton = sheet.AddButton(ViewModel.IsStarred.Value ? "Unstar This Repo" : "Star This Repo"); var watchButton = sheet.AddButton(ViewModel.IsWatched.Value ? "Unwatch This Repo" : "Watch This Repo"); var showButton = ViewModel?.Repository?.HtmlUrl != null?sheet.AddButton("Show in GitHub") : -1; var shareButton = sheet.AddButton("Share"); var cancelButton = sheet.AddButton("Cancel"); sheet.CancelButtonIndex = cancelButton; sheet.Dismissed += (s, e) => { // Pin to menu if (e.ButtonIndex == pinButton) { ViewModel.PinCommand.Execute(null); } else if (e.ButtonIndex == starButton) { ViewModel.ToggleStarCommand.Execute(null); } else if (e.ButtonIndex == watchButton) { ViewModel.ToggleWatchCommand.Execute(null); } else if (e.ButtonIndex == showButton) { ViewModel.GoToHtmlUrlCommand.Execute(null); } else if (e.ButtonIndex == shareButton) { AlertDialogService.Share( repoModel.FullName, repoModel.Description, repoModel.HtmlUrl, NavigationItem.RightBarButtonItem); } sheet.Dispose(); }; sheet.ShowFrom(NavigationItem.RightBarButtonItem, true); }
/// <summary> /// Need another function because Xamarin generates an Invalid IL if used inline above /// </summary> private async Task CommitThis(EditSourceViewModel viewModel, LiteComposer composer, string content, string message) { try { await this.DoWorkAsync("Commiting...", () => viewModel.Commit(content, message)); NavigationController.DismissViewController(true, null); } catch (Exception ex) { AlertDialogService.ShowAlert("Error", ex.Message); composer.EnableSendButton = true; } }
protected GistFileModifyViewController() : base(UITableViewStyle.Plain) { SaveCommand = ReactiveCommand.CreateFromTask(t => { if (String.IsNullOrEmpty(Content)) { throw new Exception("You cannot save a file without content!"); } Save?.Invoke(Filename, Content); return(Task.FromResult(Unit.Default)); }); SaveCommand.ThrownExceptions.Subscribe(x => AlertDialogService.ShowAlert("Error", x.Message)); }
private void Share(UIBarButtonItem barButtonItem) { var url = Content?.HtmlUrl; if (url == null) { return; } AlertDialogService.Share( Title, url: Content?.HtmlUrl, barButtonItem: barButtonItem); }
private async Task Activate(Func <Task> activation) { try { BTProgressHUD.ShowContinuousProgress("Activating...", ProgressHUD.MaskType.Gradient); using (Disposable.Create(BTProgressHUD.Dismiss)) await activation(); Load().ToBackground(); } catch (Exception e) { AlertDialogService.ShowAlert("Error", e.Message); } }
private void ShowExtraMenu() { if (ViewModel.PullRequest == null) { return; } var sheet = new UIActionSheet(); var editButton = ViewModel.GoToEditCommand.CanExecute(null) ? sheet.AddButton("Edit") : -1; var openButton = ViewModel.IsCollaborator ? sheet.AddButton(ViewModel.PullRequest.State == "open" ? "Close" : "Open") : -1; var commentButton = sheet.AddButton("Comment"); var shareButton = !string.IsNullOrEmpty(ViewModel.PullRequest?.HtmlUrl) ? sheet.AddButton("Share") : -1; var showButton = sheet.AddButton("Show in GitHub"); var cancelButton = sheet.AddButton("Cancel"); sheet.CancelButtonIndex = cancelButton; sheet.Dismissed += (s, e) => { BeginInvokeOnMainThread(() => { if (e.ButtonIndex == editButton) { ViewModel.GoToEditCommand.Execute(null); } else if (e.ButtonIndex == openButton) { ViewModel.ToggleStateCommand.Execute(null); } else if (e.ButtonIndex == shareButton) { AlertDialogService.ShareUrl(ViewModel.PullRequest?.HtmlUrl, NavigationItem.RightBarButtonItem); } else if (e.ButtonIndex == showButton) { ViewModel.GoToUrlCommand.Execute(ViewModel.PullRequest.HtmlUrl); } else if (e.ButtonIndex == commentButton) { AddCommentTapped(); } }); sheet.Dispose(); }; sheet.ShowInView(View); }
private void ShowCommentComposer(int line) { var composer = new MarkdownComposerViewController(); composer.NewComment(this, async(text) => { try { await composer.DoWorkAsync("Commenting...", () => ViewModel.PostComment(text, line)); composer.CloseComposer(); } catch (Exception e) { AlertDialogService.ShowAlert("Unable to Comment", e.Message); composer.EnableSendButton = true; } }); }
public override void ViewDidLoad() { base.ViewDidLoad(); try { var vm = (WebBrowserViewModel)ViewModel; if (!string.IsNullOrEmpty(vm.Url)) { Web.LoadRequest(new Foundation.NSUrlRequest(new Foundation.NSUrl(vm.Url))); } } catch (Exception e) { AlertDialogService.ShowAlert("Unable to process request!", e.Message); } }
/// <summary> /// Need another function because Xamarin generates an Invalid IL if used inline above /// </summary> private async Task CommitThis(string content, string message) { try { UIApplication.SharedApplication.BeginIgnoringInteractionEvents(); await this.DoWorkAsync("Commiting...", () => ViewModel.Commit(content, message)); this.PresentingViewController?.DismissViewController(true, null); } catch (Exception ex) { AlertDialogService.ShowAlert("Error", ex.Message); } finally { UIApplication.SharedApplication.EndIgnoringInteractionEvents(); } }
protected async override void Refresh() { var page = ViewModel.CurrentWikiPage(Web.Url.AbsoluteString); if (page != null) { try { await ViewModel.GetData(page); } catch (Exception e) { AlertDialogService.ShowAlert("Error", e.Message); } } base.Refresh(); }
public override void ViewDidLoad() { base.ViewDidLoad(); var vm = ViewModel as WebBrowserViewModel; System.Uri uri; if (!System.Uri.TryCreate(vm.Url, System.UriKind.Absolute, out uri)) { AlertDialogService.ShowAlert("Error", "Unable to display webpage as the provided link (" + vm.Url + ") was invalid"); } else { var safariBrowser = new SafariServices.SFSafariViewController(new NSUrl(vm.Url)); safariBrowser.View.Frame = View.Bounds; safariBrowser.View.AutoresizingMask = UIViewAutoresizing.All; AddChildViewController(safariBrowser); Add(safariBrowser.View); } }
private async Task CommitThis(string message) { var content = _descriptionElement.Value; var name = _titleElement.Value; var path = string.IsNullOrEmpty(_path) ? name : $"{_path.TrimEnd('/')}/{name}"; var hud = this.CreateHud(); try { hud.Show("Committing..."); UIApplication.SharedApplication.BeginIgnoringInteractionEvents(); NetworkActivity.PushNetworkActive(); var encodedPath = path == null ? null : System.Net.WebUtility.UrlEncode(path); var result = await _applicationService.GitHubClient.Repository.Content.CreateFile( _username, _repository, encodedPath, new Octokit.CreateFileRequest(message, content, _branch)); this.PresentingViewController?.DismissViewController(true, null); _successSubject.OnNext(result); } catch (Octokit.ApiException ex) { var errorMessage = ex.Message; if (ex.ApiError?.DocumentationUrl == "https://developer.github.com/v3/repos/contents/#update-a-file") { errorMessage = "A file with that name already exists!"; } AlertDialogService.ShowAlert("Error", errorMessage); } catch (Exception ex) { AlertDialogService.ShowAlert("Error", ex.Message); } finally { UIApplication.SharedApplication.EndIgnoringInteractionEvents(); NetworkActivity.PopNetworkActive(); hud.Hide(); } }
protected override bool ShouldStartLoad(WKWebView webView, WKNavigationAction navigationAction) { // F*****g BitBucket and their horrible user interface. if (ForbiddenRoutes.Any(navigationAction.Request.Url.AbsoluteString.StartsWith)) { AlertDialogService.ShowAlert("Invalid Request", "Sorry, due to restrictions you can not sign-up for a new account in CodeBucket."); return(false); } //We're being redirected to our redirect URL so we must have been successful if (navigationAction.Request.Url.Host == "codebucket") { ViewModel.Code = navigationAction.Request.Url.Query.Split('=')[1]; ViewModel.LoginCommand.ExecuteIfCan(); return(false); } return(base.ShouldStartLoad(webView, navigationAction)); }
private static ICollection <Section> RenderSections(IEnumerable <Section> sections, Action moreAction) { var weakAction = new WeakReference <Action>(moreAction); ICollection <Section> newSections = new LinkedList <Section>(sections); if (moreAction != null) { var loadMore = new PaginateElement("Load More", "Loading...") { AutoLoadOnVisible = true }; newSections.Add(new Section { loadMore }); loadMore.Tapped += async(obj) => { try { NetworkActivity.PushNetworkActive(); var a = weakAction.Get(); if (a != null) { await Task.Run(a); } var root = loadMore.GetRootElement(); root?.Remove(loadMore.Section, UITableViewRowAnimation.Fade); } catch (Exception e) { AlertDialogService.ShowAlert("Unable to load more!", e.Message); } finally { NetworkActivity.PopNetworkActive(); } }; } return(newSections); }
void AddCommentTapped() { var composer = new Composer(); composer.NewComment(this, async(text) => { try { await composer.DoWorkAsync("Commenting...", () => ViewModel.AddComment(text)); composer.CloseComposer(); } catch (Exception e) { AlertDialogService.ShowAlert("Unable to post comment!", e.Message); } finally { composer.EnableSendButton = true; } }); }