public void FilterWithLocation(Tuple <double, double> location) { TabPlace.GetPlacesByLocation(location).ContinueWith(t => Activity.RunOnUiThread(() => { var progress = Dialog.FindViewById <ProgressBar> (Resource.Id.LocationProgress); progress.Visibility = ViewStates.Gone; if (!t.Result.Any()) { var noneText = Dialog.FindViewById <TextView> (Resource.Id.NoneText); noneText.Visibility = ViewStates.Visible; } else { var completion = Dialog.FindViewById <ListView> (Resource.Id.CompletionList); adapter = new ArrayAdapter <string> (Activity, Android.Resource.Layout.SimpleListItemActivated1, t.Result.Select(p => p.PlaceName).ToArray()); completion.Adapter = adapter; } })); }
public static void RegisterPlace(string placeName, Tuple <double, double> latLng) { if (string.IsNullOrWhiteSpace(placeName) || localLocations.Contains(placeName)) { return; } var queryChecker = new ParseQuery("Place"); queryChecker.SetCachePolicy(ParseQuery.CachePolicy.NetworkOnly); queryChecker.WhereEqualTo("placeName", placeName); queryChecker.CountInBackground(new TabCountCallback((c, e) => { if (e == null && c == 0 && localLocations.Add(placeName)) { var place = new TabPlace(null) { PlaceName = placeName, LatLng = latLng, Person = TabPerson.CurrentPerson }; place.ToParse().SaveInBackground(); } })); }
void RegisterNewTab(SelectedUserInfo originator, SelectedUserInfo recipient, string tabTypeName, string locationDesc = null) { var selectedPerson = (originator ?? recipient).ToPerson(); var tabType = TabTypes.GetTabTypes() .ContinueWith(ts => ts.Result.FirstOrDefault(t => t.Name.Equals(tabTypeName, StringComparison.OrdinalIgnoreCase))); var dialog = new AskLocationDialog(locator); if (!string.IsNullOrEmpty(locationDesc)) { dialog.FillInLocation(locationDesc); } Task.Factory.ContinueWhenAll(new Task[] { selectedPerson, tabType, dialog.LocationName }, _ => { if (dialog.LocationName.IsCanceled) { return; } var dir = originator == null ? TabDirection.Giving : TabDirection.Receiving; var location = locator.GetLocationAndStopActiveSearching(); locationDesc = dialog.LocationName.Result; locator.RefreshNamedLocation(locationDesc); TabPlace.RegisterPlace(locationDesc, Tuple.Create(location.Latitude, location.Longitude)); var tab = new TabObject { Originator = TabPerson.CurrentPerson, Recipient = selectedPerson.Result, Type = tabType.Result, Direction = dir, LatLng = Tuple.Create(location.Latitude, location.Longitude), LocationDesc = locationDesc, Time = DateTime.Now }; Action postSave = () => { UpdateTabStatistics(selectedPerson.Result, originator ?? recipient, true); Activity.RunOnUiThread(() => PostedNewTab(tab)); }; var po = tab.ToParse(); try { po.Save(); } catch (Exception e) { Log.Error("TabSaver", e.ToString()); Activity.RunOnUiThread(() => flashBarCtrl.ShowBarUntil(() => { po.Save(); postSave(); return(true); }, withMessageId: Resource.String.flashbar_tab_error)); return; } postSave(); }); if (locationDesc == null) { var lastLocation = locator.LastKnownLocation; if (lastLocation != null) { dialog.FilterWithLocation(Tuple.Create(lastLocation.Latitude, lastLocation.Longitude)); } dialog.Show(FragmentManager, "location-asker"); } }
public static void RegisterPlace(string placeName, Tuple<double, double> latLng) { if (string.IsNullOrWhiteSpace (placeName) || localLocations.Contains (placeName)) return; var queryChecker = new ParseQuery ("Place"); queryChecker.SetCachePolicy (ParseQuery.CachePolicy.NetworkOnly); queryChecker.WhereEqualTo ("placeName", placeName); queryChecker.CountInBackground (new TabCountCallback ((c, e) => { if (e == null && c == 0 && localLocations.Add (placeName)) { var place = new TabPlace (null) { PlaceName = placeName, LatLng = latLng, Person = TabPerson.CurrentPerson }; place.ToParse ().SaveInBackground (); } })); }