예제 #1
0
        public static Task<IEnumerable<TabPlace>> GetPlacesByLocation(Tuple<double, double> latLng, double radius = 10)
        {
            var tcs = new TaskCompletionSource<IEnumerable<TabPlace>> ();
            var query = new ParseQuery ("Place");
            query.WhereWithinKilometers ("latLng", new ParseGeoPoint (latLng.Item1, latLng.Item2), radius);
            query.Include ("person");
            query.Limit = 10;

            query.FindInBackground (new TabFindCallback ((os, e) => {
                if (e != null)
                    tcs.SetException (e);
                else
                    tcs.SetResult (os.Select (FromParse).ToList ());
            }));

            return tcs.Task;
        }
예제 #2
0
        internal void LaunchApp(Activity ctx, ParseUser withUser, Action uiCallback)
        {
            // Fetch the person corresponding to the user
            Task.Factory.StartNew (() => {
                var query = new ParseQuery ("Person");
                query.SetCachePolicy (ParseQuery.CachePolicy.CacheElseNetwork);
                query.WhereEqualTo ("parseUser", withUser);
                query.Include ("parseUser");
                ParseObject self = null;
                try {
                    self = query.First;
                } catch (ParseException ex) {
                    // We may have a stall result from a previous registration
                    if (query.HasCachedResult) {
                        query.ClearCachedResult ();
                        try {
                            self = query.First;
                        } catch {
                            Android.Util.Log.Error ("Landing", "Error when trying to retrieve user 2. Normal if empty. {0}", ex.ToString ());
                        }
                    }
                    Android.Util.Log.Error ("Landing", "Error when trying to retrieve user. Normal if empty. {0}", ex.ToString ());
                }
                // First time ever, fill the info
                if (self == null) {
                    TabPerson person = null;
                    // Check if our TabPerson wasn't created indirectly by another user
                    query = new ParseQuery ("Person");
                    query.WhereEqualTo ("emails", TabPerson.MD5Hash (withUser.Email));
                    try {
                        person = TabPerson.FromParse (query.First);
                        person.AssociatedUser = withUser;
                    } catch {
                        // We use the main address email we got by parseUser
                        // and we will fill the rest lazily later from profile
                        // idem for the display name
                        person = new TabPerson {
                            AssociatedUser = withUser,
                            Emails = new string[] { withUser.Email }
                        };
                    }
                    return person;
                } else {
                    TabPerson.CurrentPerson = TabPerson.FromParse (self);
                    return null;
                }
            }).ContinueWith (t => {
                ctx.RunOnUiThread (() => {
                    // If the user was created, we setup a CursorLoader to query the information we need
                    if (t.Result != null) {
                        var person = t.Result;
                        person.DisplayName = profile.DisplayName;
                        person.Emails = profile.Emails.Union (person.Emails);
                        person.ToParse ().SaveEventually ();
                        TabPerson.CurrentPerson = person;
                    }

                    if (uiCallback != null)
                        uiCallback ();
                    ctx.Finish ();
                    ctx.StartActivity (typeof (MainActivity));
                });
            });
        }