Exemple #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Web = new WKWebView(View.Bounds, new WKWebViewConfiguration());
            Web.NavigationDelegate = new NavigationDelegate(this);
            Add(Web);

            var loadableViewModel = ViewModel as LoadableViewModel;

            if (loadableViewModel != null)
            {
                loadableViewModel.Bind(x => x.IsLoading).Subscribe(x =>
                {
                    if (x)
                    {
                        NetworkActivity.PushNetworkActive();
                    }
                    else
                    {
                        NetworkActivity.PopNetworkActive();
                    }
                });
            }
        }
Exemple #2
0
        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();
            }
        }
Exemple #3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            NetworkActivity.PushNetworkActive();
            Load().ContinueWith(t => NetworkActivity.PopNetworkActive()).ToBackground();
        }
Exemple #4
0
        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();
            }
        }
Exemple #5
0
 private void DeactivateLoadingIndicator()
 {
     if (_networkActivity)
     {
         NetworkActivity.PopNetworkActive();
     }
     _networkActivity = false;
 }
Exemple #6
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            ViewDidLoadCalled.Raise(this);

            var loadableViewModel = ViewModel as LoadableViewModel;

            if (loadableViewModel != null)
            {
                RefreshControl = new UIRefreshControl();
                OnActivation(d =>
                {
                    d(loadableViewModel.Bind(x => x.IsLoading, true).Subscribe(x =>
                    {
                        if (x)
                        {
                            NetworkActivity.PushNetworkActive();
                            RefreshControl.BeginRefreshing();

                            if (!_manualRefreshRequested)
                            {
                                UIView.Animate(0.25, 0f, UIViewAnimationOptions.BeginFromCurrentState | UIViewAnimationOptions.CurveEaseOut,
                                               () => TableView.ContentOffset = new CoreGraphics.CGPoint(0, -RefreshControl.Frame.Height), null);
                            }

                            foreach (var t in (ToolbarItems ?? Enumerable.Empty <UIBarButtonItem>()))
                            {
                                t.Enabled = false;
                            }
                        }
                        else
                        {
                            NetworkActivity.PopNetworkActive();

                            if (RefreshControl.Refreshing)
                            {
                                // Stupid bug...
                                BeginInvokeOnMainThread(() =>
                                {
                                    UIView.Animate(0.25, 0.0, UIViewAnimationOptions.BeginFromCurrentState | UIViewAnimationOptions.CurveEaseOut,
                                                   () => TableView.ContentOffset = new CoreGraphics.CGPoint(0, 0), null);
                                    RefreshControl.EndRefreshing();
                                });
                            }

                            foreach (var t in (ToolbarItems ?? Enumerable.Empty <UIBarButtonItem>()))
                            {
                                t.Enabled = true;
                            }

                            _manualRefreshRequested = false;
                        }
                    }));
                });
            }
        }
Exemple #7
0
        protected virtual void OnLoadError(NSError error)
        {
            NetworkActivity.PopNetworkActive();

            if (BackButton != null)
            {
                BackButton.Enabled    = Web.CanGoBack;
                ForwardButton.Enabled = Web.CanGoForward;
                RefreshButton.Enabled = true;
            }
        }
        private async Task Load()
        {
            NetworkActivity.PushNetworkActive();

            try
            {
                await LoadLanguages();
            }
            finally
            {
                NetworkActivity.PopNetworkActive();
            }
        }
Exemple #9
0
        public async override void ViewDidLoad()
        {
            base.ViewDidLoad();

            try
            {
                NetworkActivity.PushNetworkActive();
                var app = MvvmCross.Platform.Mvx.Resolve <CodeHub.Core.Services.IApplicationService>();
                await _milestones.SimpleCollectionLoad(app.Client.Users[_username].Repositories[_repository].Milestones.GetAll(), false);
            }
            catch {
            }
            finally
            {
                NetworkActivity.PopNetworkActive();
            }
        }
Exemple #10
0
        protected virtual void OnLoadFinished(object sender, EventArgs e)
        {
            NetworkActivity.PopNetworkActive();

            if (BackButton != null)
            {
                BackButton.Enabled    = Web.CanGoBack;
                ForwardButton.Enabled = Web.CanGoForward;
                RefreshButton.Enabled = true;
            }

            if (_showPageAsTitle)
            {
                Web.EvaluateJavaScript("document.title", (o, _) => {
                    Title = o as NSString;
                });
            }
        }
Exemple #11
0
        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();
            }
        }
Exemple #12
0
        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);
        }
Exemple #13
0
 public void PopNetworkActive()
 {
     NetworkActivity.PopNetworkActive();
 }