예제 #1
0
        public void Execute(object parameter)
        {
            TwitterStatus tweet = parameter as TwitterStatus;
            _pendingCalls = 0;
            var credentials = Config.ReadLaterCredentials;

            if (tweet == null)
                return;

            if (credentials.Pocket != null)
            {
                var service = new PocketService();
                service.UserName = credentials.Pocket.User;
                service.Password = credentials.Pocket.Password;

                TwitterUrl link = tweet.Entities.FirstOrDefault(item => item != null && item.EntityType == TwitterEntityType.Url) as TwitterUrl;
                Dependency.Resolve<IMessageService>().SetLoadingBar(true, Resources.SavingForLater);
                _pendingCalls++;
                if (link != null)
                    service.AddUrl(link.ExpandedValue, tweet.Id, Callback);
                else
                {
                    string url = "http://twitter.com/" + tweet.Author.ScreenName + "/statuses/" + tweet.Id.ToString();
                    service.AddUrl(url, Callback);
                }
            }
            if (credentials.Instapaper != null)
            {
                var service = new InstapaperService();
                service.UserName = credentials.Instapaper.User;
                service.Password = credentials.Instapaper.Password;

                TwitterUrl link = tweet.Entities.FirstOrDefault(item => item != null && item.EntityType == TwitterEntityType.Url) as TwitterUrl;
                Dependency.Resolve<IMessageService>().SetLoadingBar(true, Resources.SavingForLater);
                _pendingCalls++;
                if (link != null)
                    service.AddUrl(link.ExpandedValue, tweet.Text, Callback);
                else
                {
                    string url = "http://twitter.com/" + tweet.Author.ScreenName + "/statuses/" + tweet.Id.ToString();
                    service.AddUrl(url, Callback);
                }
            }
        }
예제 #2
0
        void SetCommands()
        {
            setCustomBackground = new DelegateCommand((obj) =>
            {
                Navigate("/Pages/Settings/Backgrounds.xaml");
            });

            showPrivacyPolicy = new DelegateCommand((obj) =>
            {
                MessageService.ShowMessage(Resources.PrivacyPolicy);
            });

            pinComposeToStart = new DelegateCommand((obj) =>
                {
                    SecondaryTiles.CreateComposeTile();
                    pinComposeToStart.RaiseCanExecuteChanged();
                }, (obj) => !SecondaryTiles.ComposeTileIsCreated());

            addAccount = new DelegateCommand((obj) => {
                OAuth.Type = AuthType.Twitter;
                Navigate(Uris.LoginPage);
            });

            editFilters = new DelegateCommand((obj) =>
                {
                    DataTransfer.cFilter = Config.GlobalFilter;
                    DataTransfer.IsGlobalFilter = true;
                    Navigate(Uris.Filters);
                });

            saveCredentials = new DelegateCommand((obj) =>
                {
                    AuthPair PocketPair = null;
                    AuthPair InstapaperPair = null;

                    if (!string.IsNullOrWhiteSpace(PocketUser))
                    {
                        BarText = Resources.VerifyingCredentials;
                        IsLoading = true;
                        PocketPair = new AuthPair { User = PocketUser, Password = PocketPassword };
                        var service = new PocketService { UserName = PocketPair.User, Password = PocketPair.Password };
                        service.CheckCredentials((valid, response) =>
                        {
                            if (valid)
                            {
                                MessageService.ShowLightNotification(String.Format(Resources.CredentialsSaved, "Pocket"));
                                Config.ReadLaterCredentials.Pocket = PocketPair;
                                Config.ReadLaterCredentials = Config.ReadLaterCredentials;
                            }
                            else
                            {
                                IsLoading = false;
                                MessageService.ShowError(String.Format(Resources.InvalidCredentials, "Pocket"));
                            }
                        });
                    }
                    else
                    {
                        Config.ReadLaterCredentials.Pocket = null;
                        Config.ReadLaterCredentials = Config.ReadLaterCredentials;
                    }

                    if (!string.IsNullOrWhiteSpace(InstapaperUser))
                    {
                        BarText = Resources.VerifyingCredentials;
                        IsLoading = true;
                        InstapaperPair = new AuthPair { User = InstapaperUser, Password = InstapaperPassword };
                        var service = new InstapaperService { UserName = InstapaperPair.User, Password = InstapaperPair.Password };
                        service.CheckCredentials((valid, response) =>
                        {
                            if (valid)
                            {
                                MessageService.ShowLightNotification(String.Format(Resources.CredentialsSaved, "Instapaper"));
                                Config.ReadLaterCredentials.Instapaper = InstapaperPair;
                                Config.ReadLaterCredentials = Config.ReadLaterCredentials;
                            }
                            else
                            {
                                IsLoading = false;
                                MessageService.ShowError(String.Format(Resources.InvalidCredentials, "Instapaper"));
                            }
                        });
                    }
                    else
                    {
                        Config.ReadLaterCredentials.Pocket = null;
                        Config.ReadLaterCredentials = Config.ReadLaterCredentials;
                    }
                });
        }