public Skaters()
        {
            try
            {
                InitializeComponent();
                LoggerMobile.Instance.logMessage("Opening Skaters", Portable.Util.Log.Enums.LoggerEnum.message);
                _viewModel = (SkatersViewModel)Resources["viewModel"];
                resultListBox.ItemRealized += resultListBox_ItemRealized;
                this.Loaded += new RoutedEventHandler(MainPage_Loaded);
                initialArray = new SkatersJson();

                ApplicationBar = new ApplicationBar();

                ApplicationBar.Mode = ApplicationBarMode.Default;
                ApplicationBar.Opacity = 1.0;
                ApplicationBar.IsVisible = true;
                ApplicationBar.IsMenuEnabled = true;

                ApplicationBarIconButton searchBtn = new ApplicationBarIconButton();
                searchBtn.IconUri = new Uri("/Assets/Icons/feature.search.png", UriKind.Relative);
                searchBtn.Text = "Search";
                searchBtn.Click += searchBtn_Click;
                ApplicationBar.Buttons.Add(searchBtn);
            }
            catch (Exception exception)
            {
                ErrorHandler.Save(exception, MobileTypeEnum.WP8);
            }
        }
        private void UpdateAdapter(SkatersJson obj)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
for (int i = 0; i < obj.Skaters.Count; i++)
                    this.SkatersCollection.Add(obj.Skaters[i]);
                IsLoading = false;
            });

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="p">page</param>
        /// <param name="c">count</param>
        /// <param name="s">ALpha Character to search by.</param>
        /// <returns></returns>
        public JsonResult GetAllSkatersMobile(int p, int c, string s, string sw)
        {
            List<SkaterJson> names = new List<SkaterJson>();
            SkatersJson skaters = new SkatersJson();
            try
            {
                if (!String.IsNullOrEmpty(s))
                    names = SiteCache.SearchAllPublicMembers(p, c, s);
                else
                    names = SiteCache.GetAllPublicMembers(p, c, sw);

                skaters.Count = names.Count;
                skaters.Page = p;
                skaters.StartsWith = s;


                for (int i = 0; i < names.Count; i++)
                {
                    skaters.Skaters.Add(new SkaterJson()
                    {
                        LeagueId = names[i].LeagueId,
                        MemberId = names[i].MemberId,
                        DerbyName = names[i].DerbyName,
                        DerbyNameUrl = names[i].DerbyNameUrl,
                        DerbyNumber = names[i].DerbyNumber,
                        Gender = names[i].Gender,
                        LeagueName = names[i].LeagueName,
                        LeagueUrl = names[i].LeagueUrl,
                        photoUrl = names[i].photoUrl,
                        ThumbUrl = names[i].ThumbUrl,
                        DOB = names[i].DOB,

                    });
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }

            return Json(skaters, JsonRequestBehavior.AllowGet);
        }
        protected override void OnCreate(Bundle bundle)
        {
            try
            {
                RequestWindowFeature(WindowFeatures.NoTitle);

                base.OnCreate(bundle);
                LoggerMobile.Instance.logMessage("Opening SkatersActivity", LoggerEnum.message);
                SetContentView(Resource.Layout.PublicSkaters);
                LegacyBar = FindViewById<LegacyBar.Library.Bar.LegacyBar>(Resource.Id.actionbar);
                LegacyBar.SetHomeLogo(Resource.Drawable.icon);
                LegacyBar.SeparatorColor = Color.Purple;

                LegacyBarAction signUpAction = new MenuAction(this, null, Resource.Drawable.a_z);
                LegacyBar.AddAction(signUpAction);

                LegacyBar = FindViewById<LegacyBar.Library.Bar.LegacyBar>(Resource.Id.actionbar);
                AddHomeAction(typeof(Main), Resource.Drawable.icon);
                // Get our button from the layout resource,
                // and attach an event to it

                Action<SkatersJson> skaters = new Action<SkatersJson>(UpdateAdapter);
                LegacyBar.ProgressBarVisibility = ViewStates.Visible;
                Skater.PullSkaters(lastPagePulled, PAGE_COUNT, lastLetterPulled, (Context)this, skaters);


                skaterList = FindViewById<ListView>(Resource.Id.skaterList);
                initialArray = new SkatersJson();
                Action pullMoreSkaters = new Action(PullMoreSkaters);
                ListAdapter = new SkaterAdapter(this, initialArray.Skaters, pullMoreSkaters);
                skaterList.Adapter = ListAdapter;
                skaterList.FastScrollEnabled = true;


                skaterList.ItemClick += skaterList_ItemClick;
                var myString = new SpannableStringBuilder("lol");
                Selection.SelectAll(myString); // needs selection or Index Out of bounds
                _dialog = new MyCharacterPickerDialog(this, new View(this), myString, options, false);
                _dialog.Clicked += (sender, args) =>
                {
                    lastPagePulled = 0;
                    lastLetterPulled = args.Text;
                    LegacyBar.ProgressBarVisibility = ViewStates.Visible;
                    Skater.PullSkaters(0, PAGE_COUNT, lastLetterPulled, (Context)this, skaters);
                    initialArray.Skaters.Clear();
                };
                search_skaters = FindViewById<EditText>(Resource.Id.search_skaters);
                search_skaters.TextChanged += search_skaters_TextChanged;
                var searchMenuItemAction = new SearchAction(this, null, Resource.Drawable.ic_action_search, search_skaters);
                LegacyBar.AddAction(searchMenuItemAction);

                LegacyBarAction infoAction = new DefaultLegacyBarAction(this, CreateInfoIntent(), Resource.Drawable.action_about);
                LegacyBar.AddAction(infoAction);

                m_AdView = FindViewById(Resource.Id.adView);
                if (SettingsMobile.Instance.User != null && SettingsMobile.Instance.User.IsValidSub)
                {
                }
            }
            catch (Exception exception)
            {
                ErrorHandler.Save(exception, MobileTypeEnum.Android, (Context)this);
            }
        }
 void UpdateAdapter(SkatersJson skaters)
 {
     initialArray.Skaters.AddRange(skaters.Skaters);
     RunOnUiThread(() =>
     {
         try
         {
             int firstPosition = skaterList.ScrollY;
             ListAdapter.NotifyDataSetChanged();
             LegacyBar.ProgressBarVisibility = ViewStates.Gone;
             skaterList.ScrollTo(0, firstPosition);
             _dialog.Dismiss();
         }
         catch (Exception exception)
         {
             ErrorHandler.Save(exception, MobileTypeEnum.Android, (Context)this);
         }
     });
 }
        void UpdateSkatersAdapter(SkatersJson skaters)
        {
            TableLayout leagueMemberTable = FindViewById<TableLayout>(Resource.Id.leagueMemberTable);
            RunOnUiThread(() =>
            {
                try
                {
                    LegacyBar.ProgressBarVisibility = ViewStates.Gone;
                    // Go through each item in the array
                    for (int current = 0; current < skaters.Skaters.Count; current++)
                    {
                        // Create a TableRow and give it an ID
                        View memberTableRow = LayoutInflater.Inflate(Resource.Layout.PublicLeagueMemberRow, null, false);


                        var publicLeagueRowMemberNumber = memberTableRow.FindViewById<TextView>(Resource.Id.publicLeagueRowMemberNumber);
                        publicLeagueRowMemberNumber.Text = skaters.Skaters[current].DerbyNumber;
                        var publicLeagueRowMemberName = memberTableRow.FindViewById<TextView>(Resource.Id.publicLeagueRowMemberName);
                        publicLeagueRowMemberName.Text = skaters.Skaters[current].DerbyName;
                        var publicLeagueRowId = memberTableRow.FindViewById<TextView>(Resource.Id.publicLeagueRowId);
                        publicLeagueRowId.Text = skaters.Skaters[current].MemberId;
                        publicLeagueRowMemberNumber.PaintFlags = PaintFlags.UnderlineText;
                        publicLeagueRowMemberName.PaintFlags = PaintFlags.UnderlineText;
                        var publicLeagueRowMemberImage = memberTableRow.FindViewById<ImageView>(Resource.Id.publicLeagueRowMemberImage);
                        SetProfileImage(skaters.Skaters[current].ThumbUrl, publicLeagueRowMemberImage);

                        if (current % 2 == 0)
                        {
                            memberTableRow.SetBackgroundResource(Resource.Color.gray);
                        }

                        memberTableRow.Clickable = true;
                        memberTableRow.Click += memberTableRow_Click;
                        leagueMemberTable.AddView(memberTableRow); //not working, obviously im missing something

                    }
                }
                catch (Exception exception)
                {
                    ErrorHandler.Save(exception, MobileTypeEnum.Android, (Context)this);
                }
            });
        }
        private void UpdateAdapterSkaters(SkatersJson obj)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                this.Skaters = new Collection<SkaterJson>();
                for (int i = 0; i < obj.Skaters.Count; i++)
                {
                    this.Skaters.Add(obj.Skaters[i]);
                }
                IsLoading = false;
            });

        }
        public override void ViewDidLoad()
        {
            try
            {
                //View = new UniversalView();

                base.ViewDidLoad();

                this.Title = _league.LeagueName;


                View.Frame = UIScreen.MainScreen.Bounds;
                View.BackgroundColor = UIColor.White;
                View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;

                //UIScrollView scroll = new UIScrollView(new RectangleF(0, 10, View.Bounds.Width, View.Bounds.Height));
                //scroll.ContentSize = new SizeF(View.Bounds.Width, 1000);

                //View.AddSubview(scroll);

                image = new UIImageView();
                if (!String.IsNullOrEmpty(_league.LogoUrlThumb))
                {
                    NSUrl nsUrl = new NSUrl(_league.LogoUrlThumb);
                    NSData data = NSData.FromUrl(nsUrl);
                    image.Frame = new RectangleF(0, 70, 100, 100);
                    image.Image = new UIImage(data);
                }
                View.AddSubview(image);

                Action<LeagueJsonDataTable> leaguePull = new Action<LeagueJsonDataTable>(UpdateAdapter);
                RDN.iOS.Classes.Public.League.PullLeague(_league.LeagueId, leaguePull);

                Action<SkatersJson> skaters = new Action<SkatersJson>(UpdateAdapterSkaters);
                Skater.PullSkaters(_league.LeagueId, skaters);

                Action<EventsJson> events = new Action<EventsJson>(UpdateAdapterEvents);
                RDN.iOS.Classes.Public.League.PullLeagueEvents(_league.LeagueId, events);

                cityState = new UILabel(new RectangleF(110, 70, View.Bounds.Width, 20));
                cityState.Text = _league.City + ", " + _league.State;
                View.AddSubview(cityState);

                membersCount = new UILabel(new RectangleF(110, 90, 200, 20));
                membersCount.Text = "";
                View.AddSubview(membersCount);


                tabs = new UITabBarController();
                tabs.View.Frame = new RectangleF(0, 190, View.Bounds.Width, 380);
                tabs.View.Bounds = new RectangleF(0, 0, View.Bounds.Width, 380);
                tab1 = new UIViewController();

                tab1.Title = "Roster";
                //tab1.View.Bounds = new RectangleF(0, 100, View.Bounds.Width, tabs.View.Bounds.Height);
                skatersArray = new SkatersJson();
                skaterTable = new UITableView(new RectangleF(0, 0, tabs.View.Bounds.Width, tabs.View.Bounds.Height - tabs.TabBar.Bounds.Height));
                skaterTable.Source = new SkatersTableView(skatersArray.Skaters, this.NavigationController);
                tab1.View.AddSubview(skaterTable);
                tab1.TabBarItem.SetTitleTextAttributes(new UITextAttributes() { Font = UIFont.FromName(membersCount.Font.Name, membersCount.Font.PointSize + 5) }, UIControlState.Normal);


                tab2 = new UIViewController();
                eventsArray = new EventsJson();
                eventTable = new UITableView(new RectangleF(0, 0, tabs.View.Bounds.Width, tabs.View.Bounds.Height - tabs.TabBar.Bounds.Height));
                eventTable.Source = new EventsTableView(eventsArray.Events, this.NavigationController);
                eventTable.RowHeight = 80;
                tab2.View.AddSubview(eventTable);
                tab2.Title = "Schedule";
                tab2.View.BackgroundColor = UIColor.Orange;
                //tab2.TabBarItem.Image = UIImage.FromFile("second.png");
                tab2.TabBarItem.SetTitleTextAttributes(new UITextAttributes() { Font = UIFont.FromName(membersCount.Font.Name, membersCount.Font.PointSize + 5) }, UIControlState.Normal);

                var tabsContainer = new UIViewController[] {
                                tab1, tab2
                        };

                tabs.ViewControllers = tabsContainer;
                //tabs.TabBar.Bounds = new RectangleF(0, 0, View.Bounds.Width, 50);

                View.AddSubview(tabs.View);
            }
            catch (Exception exception)
            {
                ErrorHandler.Save(exception, MobileTypeEnum.iPhone);
            }

        }
        void UpdateAdapterSkaters(SkatersJson skater)
        {
            InvokeOnMainThread(() =>
            {
                try
                {
                    membersCount.Text = "Members: " + skater.Skaters.Count;

                    skatersArray.Skaters.AddRange(skater.Skaters);

                    skaterTable.Source = new SkatersTableView(skatersArray.Skaters, this.NavigationController);
                    skaterTable.ReloadData();
                    //loading.Hide();

                }
                catch (Exception exception)
                {
                    ErrorHandler.Save(exception, MobileTypeEnum.iPhone);
                }
            });
        }
 public SkatersViewController()
 {
     initialArray = new SkatersJson();
 }
        void UpdateAdapter(SkatersJson skaters)
        {
            if (IsSearching)
                initialArray.Skaters.Clear();
            initialArray.Skaters.AddRange(skaters.Skaters);
            InvokeOnMainThread(() =>
            {
                try
                {
                    //table.InsertRows(indexPaths.ToArray(), UITableViewRowAnimation.Fade);

                    table.ReloadData();
                    loading.Hide();
                }
                catch (Exception exception)
                {
                    ErrorHandler.Save(exception, MobileTypeEnum.iPhone);
                }
            });



        }
        public JsonResult GetAllSkatersForLeague(string lId)
        {
            List<SkaterJson> names = new List<SkaterJson>();
            SkatersJson skaters = new SkatersJson();
            try
            {
                names = SiteCache.GetAllPublicMembersInLeague(lId);
                skaters.Count = names.Count;
                for (int i = 0; i < names.Count; i++)
                {
                    skaters.Skaters.Add(new SkaterJson()
                    {
                        LeagueId = names[i].LeagueId,
                        MemberId = names[i].MemberId,
                        DerbyName = names[i].DerbyName,
                        DerbyNameUrl = names[i].DerbyNameUrl,
                        DerbyNumber = names[i].DerbyNumber,
                        Gender = names[i].Gender,
                        LeagueName = names[i].LeagueName,
                        LeagueUrl = names[i].LeagueUrl,
                        photoUrl = names[i].photoUrl,
                        ThumbUrl = names[i].ThumbUrl,
                        DOB = names[i].DOB
                    });
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }

            return Json(skaters, JsonRequestBehavior.AllowGet);
        }