using System; using System.Collections.Generic; using System.Device.Location; using System.Linq; using System.Windows.Controls; using MahApps.FourSquare.Models; using MahTweets.Core; using MahTweets.Core.Interfaces; using MahTweets.Extensions.Foursquare.Models; using MahTweets.Extensions.Foursquare.ViewModels; using MahTweets.Extensions.Foursquare.Views; namespace MahTweets.Extensions.Foursquare { public class FourSquare : IKnowWhereYouAre { private readonly MahApps.FourSquare.FourSquare _client = new MahApps.FourSquare.FourSquare("U3GXDF3BLYOQUKRI3MNOYZZVIE1W25OLO5OGANFY1A3IMSKO", "QLY0N1RR3PK2GVNXRXNPSFKRRZJBGDT3HRP2TW13AE211MKP", "http://www.mahtweets.com", string.Empty); private readonly Func _setupViewModelFactory; public FourSquare(Func setupViewModelFactory) { _setupViewModelFactory = setupViewModelFactory; } public static Action OnSuccess { get; set; } public static Action OnFailure { get; set; } #region IKnowWhereYouAre Members public Credential Credentials { get; set; } public string Name { get { return "FourSquare"; } } public string Protocol { get { return "foursquare"; } } public Action ShowDialog { get; set; } public Uri DarkIcon { get { return new Uri("/MahTweets.Extensions.Foursquare;component/Resources/4sq.png", UriKind.RelativeOrAbsolute); } } public Uri LightIcon { get { return new Uri("/MahTweets.Extensions.Foursquare;component/Resources/4sq.png", UriKind.RelativeOrAbsolute); } } public void Setup(Action onSuccess, Action onError) { OnSuccess = onSuccess; OnFailure = onError; var setup = new FourSquareSetupView { DataContext = _setupViewModelFactory() }; ShowDialog(setup); } public void Connect() { _client.SetAccessToken(Credentials.Username); } public void Disconnect() { } public void NewLocationUpdate(string text, string id, GeoCoordinate location) { } public void BeginGetVenues(double phoneLatitude, double phoneLongitude, Action> action) { _client.Venue.BeginSearch(phoneLatitude, phoneLongitude, (venues) => { var results = new List(); foreach (Group v in venues.Groups) { foreach (Venue iv in v.Items) { var p = new Place { Id = iv.ID, City = iv.Location.City, Distance = iv.Location.Distance, Lat = iv.Location.Lat, Long = iv.Location.Lng, Name = iv.Name, State = iv.Location.State }; if (iv.Categories != null && iv.Categories.Any()) { p.PlaceType = new PlaceType { FullPathName = iv.Categories.First().Name, IconUrl = iv.Categories.First().Icon.Replace(".png", "_64.png"), ID = iv.Categories.First().ID, }; } else p.PlaceType = new PlaceType { IconUrl = "http://foursquare.com/img/categories/none_64.png" }; results.Add(p); } } action(results); }); } public void BeginGetFriends(Action> action) { _client.Friends.GetRecent((checkins) => { if (checkins == null || checkins.Count == 0) return; var updates = new List(); foreach (Checkin c in checkins) { var update = new FourSquareStatus { Text = c.Shout, Venue = c.Venue, Contact = new Contact { Name = c.User.FirstName + " " + c.User.LastName, ID = c.User.Id, ImageUrl = new Uri(c.User.Photo) }, }; updates.Add(update); } action(updates); }); } #endregion } }