Example #1
0
        /// <summary>
        /// Update UI with profile results
        /// </summary>
        public void loadProfile()
        {
            if (null != host.profile.user_Result)  // cache may be incomplete
            {
                User user = host.profile.user_Result;
                GeoCoordinate loc = new GeoCoordinate();
                loc.Latitude = user.latitude;
                loc.Longitude = user.longitude;
                GreatCircle gc = new GreatCircle();

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    App.ViewModelHost.aboutItems.Clear();
                    App.ViewModelHost.aboutItems.Add(new AboutItemViewModel()
                    {
                        Line2 = WebResources.MemberFor + " " + gc.TimeSince(user.created),
                        Line3 = WebResources.LastAccess + " " + gc.TimeSince(user.access) + WebResources.ago,
                        Line4 = gc.Distance(loc) + " " + WebResources.FromCurrentLocation,
                        Type = AboutItemViewModel.AboutType.general
                    });
                });

                loadProfileCommon(user.latitude, user.longitude, user.street, user.additional, user.city, user.province, user.country, user.postal_code);

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    if (!string.IsNullOrEmpty(user.mobilephone))
                    {
                        App.ViewModelHost.aboutItems.Add(new AboutItemViewModel() { Line1 = WebResources.AboutPhone, Line2 = user.mobilephone, Type = AboutItemViewModel.AboutType.phone });
                        App.ViewModelHost.aboutItems.Add(new AboutItemViewModel() { Line1 = WebResources.AboutSMS, Line2 = user.mobilephone, Type = AboutItemViewModel.AboutType.sms });
                    }
                    if (!string.IsNullOrEmpty(user.homephone) && user.homephone != user.mobilephone)
                    {
                        App.ViewModelHost.aboutItems.Add(new AboutItemViewModel() { Line1 = WebResources.AboutHomePhone, Line2 = user.homephone, Type = AboutItemViewModel.AboutType.phone });
                    }
                    if (!string.IsNullOrEmpty(user.workphone) && user.workphone != user.mobilephone && user.workphone != user.homephone)
                    {
                        App.ViewModelHost.aboutItems.Add(new AboutItemViewModel() { Line1 = WebResources.AboutWorkPhone, Line2 = user.workphone, Type = AboutItemViewModel.AboutType.phone });
                    }
                    if (!string.IsNullOrEmpty(user.URL))
                    {
                        App.ViewModelHost.aboutItems.Add(new AboutItemViewModel() { Line1 = WebResources.AboutURL, Line2 = user.URL, Type = AboutItemViewModel.AboutType.web });
                    }
                    if (!string.IsNullOrEmpty(user.picture))
                    {
                        App.ViewModelHost.aboutItems.Add(new AboutItemViewModel() { Picture = user.profile_image_mobile_photo_456, Type = AboutItemViewModel.AboutType.picture });

                    }
                    App.ViewModelHost.aboutItems.Add(new AboutItemViewModel() { Line1 = WebResources.AboutComments, Line2 = user.comments, Type = AboutItemViewModel.AboutType.comments });

                    App.ViewModelHost.hostingItems.Clear();
                    if (!string.IsNullOrEmpty(user.languagesspoken))
                    {
                        App.ViewModelHost.hostingItems.Add(new HostingItemViewModel() { Line1 = WebResources.HostingHeaderLanguagesSpoken, Line2 = user.languagesspoken });
                    }
                    if (!string.IsNullOrEmpty(user.preferred_notice))
                    {
                        App.ViewModelHost.hostingItems.Add(new HostingItemViewModel() { Line1 = WebResources.HostingHeaderPreferred_notice, Line2 = user.preferred_notice });
                    }
                    if (!string.IsNullOrEmpty(user.maxcyclists))
                    {
                        App.ViewModelHost.hostingItems.Add(new HostingItemViewModel() { Line1 = WebResources.HostingHeaderMaxCyclists, Line2 = user.maxcyclists });
                    }
                    if (!string.IsNullOrEmpty(user.bikeshop))
                    {
                        App.ViewModelHost.hostingItems.Add(new HostingItemViewModel() { Line1 = WebResources.HostingHeaderBikeShop, Line2 = user.bikeshop });
                    }
                    if (!string.IsNullOrEmpty(user.campground))
                    {
                        App.ViewModelHost.hostingItems.Add(new HostingItemViewModel() { Line1 = WebResources.HostingHeaderCampground, Line2 = user.campground });
                    }
                    if (!string.IsNullOrEmpty(user.motel))
                    {
                        App.ViewModelHost.hostingItems.Add(new HostingItemViewModel() { Line1 = WebResources.HostingHeaderMotel, Line2 = user.motel });
                    }
                    string offer = getHostMayOffer();
                    if (!string.IsNullOrEmpty(offer))
                    {
                        App.ViewModelHost.hostingItems.Add(new HostingItemViewModel() { Line1 = WebResources.HostingHeaderHostMayOffer, Line2 = offer });
                    }
                    // Handle hosting list being empty
                    if (App.ViewModelHost.hostingItems.Count < 1)
                    {
                        App.ViewModelHost.hostingItems.Add(new HostingItemViewModel() { Line1 = WebResources.none });
                    }
                });
            }
        }
Example #2
0
        /// <summary>
        /// Update UI with hosts results
        /// </summary>
        public void loadHosts()
        {
            if (null == App.nearby.hosts) return;
            else if (null == App.nearby.hosts.hosts_Result) return;
            Deployment.Current.Dispatcher.BeginInvoke(() => { App.ViewModelMain.nearbyItems.Clear(); });

            if (!App.settings.isLocationEnabled)
            {   // User deliberately disabled location service
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    App.ViewModelMain.nearbyItems.Add(new NearbyItemViewModel()
                    {
                        Name = WebResources.NearbyListLocationDisabledHeader,
                        Line2 = WebResources.NearbyListLocationDisabledBody
                    });
                });
                return;
            }

            int len = hosts.hosts_Result.accounts.Count;
            if (len < 1)
            {   // Display empty list message to user and return
                // Todo:  Filter feature
                //                if (App.ViewModelFilter.isFiltered())
                //                {   // With filter active message
                //                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                //                    {
                //                        App.ViewModelMain.nearbyItems.Add(new NearbyItemViewModel()
                //                        {
                //                            Name = WebResources.NearbyListEmptyHeader,
                //                            Line2 = WebResources.NearbyListEmptyBody1 + "\n\n" +
                //                                WebResources.NearbyListEmptyBody2 + "\n\n" + WebResources.NearbyListEmptyBody3
                //                        });
                //                    });
                //                }
                //                else
                {   // Without filter active message
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        App.ViewModelMain.nearbyItems.Add(new NearbyItemViewModel()
                        {
                            Name = WebResources.NearbyListEmptyHeader,
                            Line2 = WebResources.NearbyListEmptyBody1 + "\n\n" + WebResources.NearbyListEmptyBody3
                        });
                    });
                }
                return;
            }

            // Add hosts to main list
            List<MapCoord> mapCoords = new List<MapCoord>();
            GreatCircle gc = new GreatCircle();
            foreach (var account in hosts.hosts_Result.accounts)
            {
                MapCoord coord = new MapCoord();
                coord.geoCoord = new GeoCoordinate(account.latitude, account.longitude);
                coord.userName = account.fullname;
                coord.uId = account.uid;
                if (App.pinned.isPinned(coord.uId))
                {
                    coord.type = PushpinType.pinned;
                }
                else
                {
                    coord.type = PushpinType.unpinned;
                }
                mapCoords.Add(coord);

                App.nearby.viewportCache.hostLocation(coord.geoCoord);

                string distance = gc.Distance(coord.geoCoord);
                double d = gc.dDistance(coord.geoCoord);
                if (App.pinned.isPinned(account.uid))
                {
                    distance += " - " + WebResources.pinned;
                }

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                { App.ViewModelMain.nearbyItems.Add(new NearbyItemViewModel() { Name = account.fullname, Line2 = distance, userID = account.uid, Distance = d }); });
            }

            Deployment.Current.Dispatcher.BeginInvoke(() => { App.ViewModelMain.mapItems.Clear(); });

            // Add hosts to map
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                foreach (MapCoord coord in mapCoords)
                {
                    App.ViewModelMain.mapItems.Add(new MapItemViewModel() { location = coord.geoCoord, username = coord.userName, Type = coord.type, userID = coord.uId });
                }
            });
        }