コード例 #1
0
        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");
            }
        }
コード例 #2
0
        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");
            }
        }