Пример #1
0
        public void Loaded(string resource, string userName)
        {
            whatUserList = resource;
            user         = userName;

            if (whatUserList == "followers")
            {
                ServiceDispatcher.GetCurrentService().ListFollowers(new ListFollowersOptions {
                    ScreenName = user, IncludeUserEntities = true
                }, ReceiveUsers);
                BarText   = Resources.DownloadingFollowers;
                PageTitle = Resources.Followers;
            }
            else if (whatUserList == "following")
            {
                ServiceDispatcher.GetCurrentService().ListFriends(new ListFriendsOptions {
                    ScreenName = user, IncludeUserEntities = true
                }, ReceiveUsers);
                BarText   = Resources.DownloadingFollowing;
                PageTitle = Resources.Following;
            }
            else
            {
                MessageService.ShowError(Resources.NotValidResource);
                GoBack();
                return;
            }

            IsLoading = true;
        }
Пример #2
0
 private void GetTopics()
 {
     IsLoading = true;
     ServiceDispatcher.GetCurrentService().ListLocalTrendsFor(new ListLocalTrendsForOptions {
         Id = (int)currentLocation
     }, ReceiveTrends);
 }
Пример #3
0
        private void ReceiveUsers(TwitterCursorList <TwitterUser> users, TwitterResponse response)
        {
            if (response.StatusCode == HttpStatusCode.NotFound)
            {
                MessageService.ShowError(Resources.CouldntFindUser);
                GoBack();
                return;
            }
            else if (response.StatusCode != HttpStatusCode.OK || users == null)
            {
                MessageService.ShowError(Resources.ErrorMessage);
                GoBack();
                return;
            }

            foreach (var usr in users)
            {
                if (!list.Contains(usr))
                {
                    list.Add(usr);
                }
            }

            if (users.NextCursor != null && users.NextCursor != 0)
            {
                if (whatUserList == "followers")
                {
                    ServiceDispatcher.GetCurrentService().ListFollowers(new ListFollowersOptions {
                        ScreenName = user
                    }, ReceiveUsers);
                }
                else if (whatUserList == "following")
                {
                    ServiceDispatcher.GetCurrentService().ListFriends(new ListFriendsOptions {
                        ScreenName = user
                    }, ReceiveUsers);
                }
            }
            else
            {
                IsLoading = false;
            }
        }
Пример #4
0
        public TopicsModel()
            : base("TrendingTopics")
        {
            this.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == "ListSelection")
                {
                    OnSelectionChanged();
                }
                if (e.PropertyName == "SelectedLocation")
                {
                    UserChoseLocation();
                }
            };

            geoWatcher = new GeoCoordinateWatcher();
            if (Config.EnabledGeolocation == true)
            {
                geoWatcher.Start();
            }

            Locations     = new ObservableCollection <string>();
            LocationMap   = new Dictionary <string, long>();
            refresh       = new DelegateCommand((obj) => GetTopics());
            showGlobal    = new DelegateCommand((obj) => { currentLocation = 1; PlaceName = Localization.Resources.Global; GetTopics(); });
            showLocations = new DelegateCommand((obj) => RaiseShowLocations(), (obj) => Locations.Any());

            ServiceDispatcher.GetCurrentService().ListAvailableTrendsLocations(ReceiveLocations);

            IsLoading = true;
            if (Config.EnabledGeolocation == true && (Config.TopicPlaceId == -1 || Config.TopicPlaceId == null))
            {
                ServiceDispatcher.GetCurrentService().ListClosestTrendsLocations(new ListClosestTrendsLocationsOptions {
                    Lat = geoWatcher.Position.Location.Latitude, Long = geoWatcher.Position.Location.Longitude
                }, ReceiveMyLocation);
            }
            else
            {
                currentLocation = Config.TopicPlaceId.HasValue ? (long)Config.TopicPlaceId : 1;
                PlaceName       = Config.TopicPlace;
                GetTopics();
            }
        }
Пример #5
0
        private void GetRetweets()
        {
            var service = ServiceDispatcher.GetCurrentService();

            if (service != null && Tweet != null)
            {
                service.Retweets(new RetweetsOptions {
                    Id = Tweet.Id
                }, (statuses, response) =>
                {
                    if (statuses != null && statuses.Any())
                    {
                        HasRetweets = true;
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            foreach (var rt in statuses)
                            {
                                UsersWhoRetweeted.Add(rt.Author);
                            }
                        });
                    }
                });
            }
        }
Пример #6
0
        private void CreateCommands()
        {
            deleteTweet = new DelegateCommand((obj) =>
            {
                var user = Config.Accounts.FirstOrDefault(item => item != null && item.ScreenName == Tweet.Author.ScreenName);

                ServiceDispatcher.GetService(user).DeleteTweet(new DeleteTweetOptions {
                    Id = Tweet.Id
                }, (s, response) =>
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        MessageService.ShowMessage(Localization.Resources.TweetDeleted, "");
                    }
                    else
                    {
                        MessageService.ShowError(Localization.Resources.ErrorDeletingTweet);
                    }
                });
            }, (obj) => Tweet != null && Tweet.Author != null && Config.Accounts.Any(item => item != null && item.ScreenName == Tweet.Author.ScreenName));


            share = new DelegateCommand((obj) => Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                EmailComposeTask emailComposeTask = new EmailComposeTask();

                emailComposeTask.Subject = String.Format(Localization.Resources.TweetFrom, Tweet.Author.ScreenName);
                emailComposeTask.Body    = "@" + Tweet.Author.ScreenName + ": " + Tweet.Text +
                                           Environment.NewLine + Environment.NewLine + Tweet.CreatedDate.ToString();

                emailComposeTask.Show();
            }), obj => Tweet != null);

            quote = new DelegateCommand((obj) =>
            {
                DataTransfer.Text = "RT @" + Tweet.Author.ScreenName + ": " + Tweet.Text;
                Navigate(Uris.WriteTweet);
            }, obj => Config.Accounts.Any() && Tweet != null);

            favorite = new DelegateCommand((parameter) =>
            {
                TwitterStatus param = (TwitterStatus)parameter;
                if (IsFavorited)
                {
                    ServiceDispatcher.GetService(DataTransfer.CurrentAccount).UnfavoriteTweet(new UnfavoriteTweetOptions {
                        Id = param.Id
                    }, (sts, resp) =>
                    {
                        MessageService.ShowLightNotification(Localization.Resources.Unfavorited);
                        IsFavorited = false;
                    });
                }
                else
                {
                    ServiceDispatcher.GetService(DataTransfer.CurrentAccount).FavoriteTweet(new FavoriteTweetOptions {
                        Id = param.Id
                    }, (sts, resp) =>
                    {
                        MessageService.ShowLightNotification(Localization.Resources.Favorited);
                        IsFavorited = true;
                    });
                }
            }, parameter => (parameter is TwitterStatus) && Config.Accounts.Count > 0 && DataTransfer.CurrentAccount != null);

            sendTweet = new DelegateCommand((parameter) =>
            {
                IsLoading = true;
                BarText   = Resources.SendingTweet;
                ServiceDispatcher.GetCurrentService().SendTweet(new SendTweetOptions
                {
                    InReplyToStatusId = Tweet.Id,
                    Status            = ReplyText
                }, (status, response) =>
                {
                    IsLoading = false;
                    BarText   = "";
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        MessageService.ShowError(response.Error != null ? response.Error.Message : Resources.UnknownValue);
                    }
                    else if (TweetSent != null)
                    {
                        TweetSent(this, new EventArgs <ITweetable>(status));
                    }
                });
            });
        }