示例#1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);


            // Create your application here

            SetTheme(Resource.Style.Theme_Normal);

            SetContentView(Resource.Layout.Events);
            SetTitle(Resource.String.findevent);

            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);

            SupportActionBar.SetDisplayHomeAsUpEnabled(true);

            _pager = FindViewById <ViewPager>(Resource.Id.tabpager);
            var _adapter = new MyPagerAdapter(SupportFragmentManager);

            _pager.Adapter = _adapter;

            if (bundle == null)
            {
                mainlist = new EventListFragment();
                sublist  = new EventListFragment();
            }
            else
            {
                mainlist = SupportFragmentManager.FindFragmentByTag("android:switcher:" + Resource.Id.tabpager + ":0") as EventListFragment;
                sublist  = SupportFragmentManager.FindFragmentByTag("android:switcher:" + Resource.Id.tabpager + ":1") as EventListFragment;
            }

            mainlist.OnConnect += Mainlist_OnConnect;
            mainlist.OnSub     += Mainlist_OnSub;
            sublist.OnConnect  += Mainlist_OnConnect;

            _adapter.AddTab("Shoot List", mainlist);
            _adapter.AddTab("Sub Events", sublist);

            var listtype = Intent.Extras.GetString("listtype", "all");

            switch (listtype)
            {
            case "featured":
                EventListFragment.EventUpdateDelegate del1 = Bootlegger.BootleggerClient.UpdateFeatured;
                mainlist.SetEvents("FeaturedEvents", del1, cancel.Token, EventAdapter.EventViewType.FEATURED_LIST);
                Title = "Featured Shoots";
                break;

            case "nearby":
                EventListFragment.EventUpdateDelegate del2 = Bootlegger.BootleggerClient.UpdateFeatured;
                mainlist.SetEvents("Nearby", del2, cancel.Token, EventAdapter.EventViewType.NEARBY);
                Title = "Nearby Shoots";
                break;

            case "all":
            default:
                EventListFragment.EventUpdateDelegate del3 = Bootlegger.BootleggerClient.ListMyEvents;
                mainlist.SetEvents("MyEvents", del3, cancel.Token, EventAdapter.EventViewType.LIST);
                break;
            }
        }
        public async override void OnResume()
        {
            base.OnResume();
            Plugin.Geolocator.Abstractions.Position pos;

            try
            {
                if (WhiteLabelConfig.LOCATION_SHOOTS_ENABLED)
                {
                    var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);

                    if (status != PermissionStatus.Denied)
                    {
                        if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location))
                        {
                            await LoginFuncs.ShowSnackbar(this.Activity, this.Activity.FindViewById(Resource.Id.main_content), "Location required to locate nearby shoots");
                        }

                        var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location);

                        //Best practice to always check that the key exists
                        if (results.ContainsKey(Permission.Location))
                        {
                            status = results[Permission.Location];
                        }
                    }

                    if (status == PermissionStatus.Granted)
                    {
                        //var results = await CrossGeolocator.Current.GetPositionAsync(10000);
                        //LabelGeolocation.Text = "Lat: " + results.Latitude + " Long: " + results.Longitude;
                        hasposition = true;
                        pos         = await CrossGeolocator.Current.GetLastKnownLocationAsync();

                        if (pos != null)
                        {
                            Bootlegger.BootleggerClient.UserLocation = new Tuple <double, double>(pos.Latitude, pos.Longitude);
                        }
                    }
                    else if (status != PermissionStatus.Unknown && status != PermissionStatus.Denied)
                    {
                        //no permissions
                        //await DisplayAlert("Location Denied", "Can not continue, try again.", "OK");
                        UI.LoginFuncs.ShowError(this.Activity, new Exception("Enable location to find local shoots"));
                    }
                }
            }
            catch (Exception)
            {
                //LabelGeolocation.Text = "Error: " + ex;
            }


            //await CalculateNearby(new CancellationTokenSource().Token);

            EventListFragment.EventUpdateDelegate del2 = Bootlegger.BootleggerClient.UpdateFeatured;
            nearby.SetEvents("FeaturedEvents", del2, new CancellationTokenSource().Token, EventAdapter.EventViewType.FEATURED);

            // try to get live position:
            if (hasposition)
            {
                try
                {
                    pos = await CrossGeolocator.Current.GetPositionAsync(TimeSpan.FromSeconds(10));

                    if (pos != null)
                    {
                        Bootlegger.BootleggerClient.UserLocation = new Tuple <double, double>(pos.Latitude, pos.Longitude);
                    }
                    //await CalculateNearby(new CancellationTokenSource().Token);
                    EventListFragment.EventUpdateDelegate del = Bootlegger.BootleggerClient.UpdateFeatured;
                    nearby.SetEvents("FeaturedEvents", del, new CancellationTokenSource().Token, EventAdapter.EventViewType.FEATURED);
                }
                catch
                {
                    //do nothing, cannot get location
                }
            }

            await nearby.RefreshMe(true);
        }