Пример #1
0
        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));
        }
Пример #2
0
        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);
        }
Пример #3
0
        public FeedbackComposerViewModel(IApplicationService applicationService, IImgurService imgurService,
                                         IMediaPickerService mediaPicker, IStatusIndicatorService statusIndicatorService, IAlertDialogService alertDialogService)
        {
            this.WhenAnyValue(x => x.IsFeature).Subscribe(x => Title = x ? "New Feature" : "Bug Report");

            SubmitCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.Subject).Select(x => !string.IsNullOrEmpty(x)),
                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.Client.ExecuteAsync(applicationService.Client.Users[CodeHubOwner].Repositories[CodeHubName].Labels.GetAll());
                var createLabels = labels.Data.Where(x => string.Equals(x.Name, IsFeature ? "feature request" : "bug", StringComparison.OrdinalIgnoreCase)).Select(x => x.Name).Distinct();
                var request      = applicationService.Client.Users[CodeHubOwner].Repositories[CodeHubName].Issues.Create(Subject, Description, null, null, createLabels.ToArray());
                var createdIssue = await applicationService.Client.ExecuteAsync(request);
                _createdIssueSubject.OnNext(createdIssue.Data);
                DismissCommand.ExecuteIfCan();
            });

            PostToImgurCommand = ReactiveCommand.CreateAsyncTask(async _ =>
            {
                var photo        = await mediaPicker.PickPhoto();
                var memoryStream = new MemoryStream();
                await photo.Save(Splat.CompressedBitmapFormat.Jpeg, 0.8f, memoryStream);
                using (statusIndicatorService.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 => alertDialogService.Alert("Upload Error", x.Message));
        }
 public PurchaseProViewController(IStatusIndicatorService statusIndicatorService)
     : base("PurchaseProViewController", null)
 {
     _statusIndicatorService = statusIndicatorService;
 }
Пример #5
0
 public static IDisposable Activate(this IStatusIndicatorService @this, string text)
 {
     @this.Show(text);
     return(Disposable.Create(@this.Hide));
 }
Пример #6
0
 public GistView(IStatusIndicatorService statusIndicatorService, IApplicationService applicationService)
 {
     _statusIndicatorService = statusIndicatorService;
     _applicationService     = applicationService;
 }
Пример #7
0
 public AddAccountView(IStatusIndicatorService statusIndicatorService, IAlertDialogService alertDialogService)
     : base("AddAccountView", null)
 {
     _statusIndicatorService = statusIndicatorService;
     _alertDialogService     = alertDialogService;
 }
Пример #8
0
        public GistViewModel(IApplicationService applicationService, IShareService shareService,
                             IActionMenuService actionMenuService, IStatusIndicatorService statusIndicatorService)
        {
            Comments = new ReactiveList <GistCommentModel>();

            Title = "Gist";

            GoToUrlCommand = this.CreateUrlCommand();

            this.WhenAnyValue(x => x.Gist).Where(x => x != null && x.Files != null && x.Files.Count > 0)
            .Select(x => x.Files.First().Key).Subscribe(x =>
                                                        Title = x);

            ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null));
            ShareCommand.Subscribe(_ => shareService.ShareUrl(Gist.HtmlUrl));

            ToggleStarCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.IsStarred).Select(x => x.HasValue),
                async t =>
            {
                try
                {
                    if (!IsStarred.HasValue)
                    {
                        return;
                    }
                    var request = IsStarred.Value ? applicationService.Client.Gists[Id].Unstar() : applicationService.Client.Gists[Id].Star();
                    await applicationService.Client.ExecuteAsync(request);
                    IsStarred = !IsStarred.Value;
                }
                catch (Exception e)
                {
                    throw new Exception("Unable to start gist. Please try again.", e);
                }
            });

            ForkCommand = ReactiveCommand.CreateAsyncTask(async t =>
            {
                var data       = await applicationService.Client.ExecuteAsync(applicationService.Client.Gists[Id].ForkGist());
                var forkedGist = data.Data;
                var vm         = CreateViewModel <GistViewModel>();
                vm.Id          = forkedGist.Id;
                vm.Gist        = forkedGist;
                ShowViewModel(vm);
            });

            ForkCommand.IsExecuting.Subscribe(x =>
            {
                if (x)
                {
                    statusIndicatorService.Show("Forking...");
                }
                else
                {
                    statusIndicatorService.Hide();
                }
            });

            GoToEditCommand = ReactiveCommand.Create();

            GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null && !string.IsNullOrEmpty(x.HtmlUrl)));
            GoToHtmlUrlCommand.Select(_ => Gist.HtmlUrl).Subscribe(this.ShowWebBrowser);

            GoToFileSourceCommand = ReactiveCommand.Create();
            GoToFileSourceCommand.OfType <GistFileModel>().Subscribe(x =>
            {
                var vm      = CreateViewModel <GistFileViewModel>();
                vm.Id       = Id;
                vm.GistFile = x;
                vm.Filename = x.Filename;
                ShowViewModel(vm);
            });

            GoToUserCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null && x.Owner != null));
            GoToUserCommand.Subscribe(x =>
            {
                var vm      = CreateViewModel <UserViewModel>();
                vm.Username = Gist.Owner.Login;
                ShowViewModel(vm);
            });

            AddCommentCommand = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm = CreateViewModel <GistCommentViewModel>();
                vm.Id  = Id;
                vm.CommentAdded.Subscribe(Comments.Add);
                ShowViewModel(vm);
            });

            ShowMenuCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.Gist).Select(x => x != null),
                _ =>
            {
                var menu = actionMenuService.Create(Title);
                if (Gist.Owner != null && string.Equals(applicationService.Account.Username, Gist.Owner.Login, StringComparison.OrdinalIgnoreCase))
                {
                    menu.AddButton("Edit", GoToEditCommand);
                }
                else
                {
                    menu.AddButton("Fork", ForkCommand);
                }
                menu.AddButton("Share", ShareCommand);
                menu.AddButton("Show in GitHub", GoToHtmlUrlCommand);
                return(menu.Show());
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
            {
                var forceCacheInvalidation = t as bool?;
                var t1 = this.RequestModel(applicationService.Client.Gists[Id].Get(), forceCacheInvalidation, response => Gist = response.Data);
                this.RequestModel(applicationService.Client.Gists[Id].IsGistStarred(), forceCacheInvalidation, response => IsStarred = response.Data).FireAndForget();
                Comments.SimpleCollectionLoad(applicationService.Client.Gists[Id].GetComments(), forceCacheInvalidation).FireAndForget();
                return(t1);
            });
        }
Пример #9
0
 public LoginViewController(IStatusIndicatorService statusIndicator)
 {
     Title            = "Login";
     _statusIndicator = statusIndicator;
 }
Пример #10
0
        public LoginViewModel(ILoginService loginFactory,
                              IAccountsService accountsService,
                              IActionMenuService actionMenuService,
                              IStatusIndicatorService statusIndicatorService,
                              IAlertDialogService alertDialogService)
        {
            _loginFactory = loginFactory;

            Title = "Login";

            GoToOldLoginWaysCommand = ReactiveCommand.Create();
            GoToOldLoginWaysCommand.Subscribe(_ => ShowViewModel(CreateViewModel <AddAccountViewModel>()));

            var loginCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.Code).Select(x => !string.IsNullOrEmpty(x)), _ => Login(Code));

            loginCommand.Subscribe(x => accountsService.ActiveAccount = x);
            loginCommand.Subscribe(x => MessageBus.Current.SendMessage(new LogoutMessage()));
            LoginCommand = loginCommand;

            ShowLoginOptionsCommand = ReactiveCommand.CreateAsyncTask(t =>
            {
                var actionMenu = actionMenuService.Create(Title);
                actionMenu.AddButton("Login via BASIC", GoToOldLoginWaysCommand);
                return(actionMenu.Show());
            });

            LoginCommand.IsExecuting.Skip(1).Subscribe(x =>
            {
                if (x)
                {
                    statusIndicatorService.Show("Logging in...");
                }
                else
                {
                    statusIndicatorService.Hide();
                }
            });

            _loginUrl = this.WhenAnyValue(x => x.WebDomain)
                        .IsNotNull()
                        .Select(x => x.TrimEnd('/'))
                        .Select(x =>
                                string.Format(x + "/login/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}",
                                              ClientId, Uri.EscapeDataString(RedirectUri), Uri.EscapeDataString("user,repo,notifications,gist")))
                        .ToProperty(this, x => x.LoginUrl);

            LoadCommand = ReactiveCommand.CreateAsyncTask(async t =>
            {
                if (IsEnterprise && string.IsNullOrEmpty(WebDomain))
                {
                    var response = await alertDialogService.PromptTextBox("Enterprise URL",
                                                                          "Please enter the webpage address for the GitHub Enterprise installation",
                                                                          DefaultWebDomain, "Ok");
                    WebDomain = response;
                }
                else
                {
                    WebDomain = DefaultWebDomain;
                }
            });

            LoadCommand.ThrownExceptions.Take(1).Subscribe(x => DismissCommand.ExecuteIfCan());
        }
Пример #11
0
 public EnableEnterpriseViewController(IStatusIndicatorService statusIndicatorService, IFeaturesService featuresService)
     : base("EnableEnterpriseViewController", null)
 {
     _statusIndicatorService = statusIndicatorService;
     _featuresService        = featuresService;
 }
Пример #12
0
 public IssueEditView(IStatusIndicatorService statusIndicatorService)
 {
     _statusIndicatorService = statusIndicatorService;
 }
 public EnablePushNotificationsViewController(IStatusIndicatorService statusIndicatorService, IFeaturesService featuresService) 
     : base("EnablePushNotificationsViewController", null)
 {
     _statusIndicatorService = statusIndicatorService;
     _featuresService = featuresService;
 }
Пример #14
0
 public GistCommentViewModel(IStatusIndicatorService status, IAlertDialogService alert, IJsonHttpClientService jsonClient, IApplicationService applicationService)
     : base(status, alert, jsonClient)
 {
     _applicationService = applicationService;
 }
Пример #15
0
 public LoginView(IAlertDialogService alertDialogService, IStatusIndicatorService statusIndicatorService)
 {
     _alertDialogService     = alertDialogService;
     _statusIndicatorService = statusIndicatorService;
 }
 public EnableEnterpriseViewController(IStatusIndicatorService statusIndicatorService, IFeaturesService featuresService) 
     : base("EnableEnterpriseViewController", null)
 {
     _statusIndicatorService = statusIndicatorService;
     _featuresService = featuresService;
 }
 public EnablePushNotificationsViewController(IStatusIndicatorService statusIndicatorService, IFeaturesService featuresService)
     : base("EnablePushNotificationsViewController", null)
 {
     _statusIndicatorService = statusIndicatorService;
     _featuresService        = featuresService;
 }