private void UpdateAdapter(EventsJson obj)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                for (int i = 0; i < obj.Events.Count; i++)
                    this.EventsCollection.Add(obj.Events[i]);
                IsLoading = false;
            });

        }
        protected override void OnCreate(Bundle bundle)
        {
            try
            {
                RequestWindowFeature(WindowFeatures.NoTitle);

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

                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<EventsJson> evs = new Action<EventsJson>(UpdateAdapter);
                LegacyBar.ProgressBarVisibility = ViewStates.Visible;

                eventsList = FindViewById<ListView>(Resource.Id.eventsList);
                initialArray = new EventsJson();
                Action pullMore = new Action(PullMore);
                RDNation.Droid.Classes.Public.Calendar.PullEvents(lastPagePulled, PAGE_COUNT, (Context)this, evs);
                ListAdapter = new EventsAdapter(this, initialArray.Events, pullMore);
                eventsList.Adapter = ListAdapter;
                eventsList.FastScrollEnabled = true;


                eventsList.ItemClick += skaterList_ItemClick;
                var myString = new SpannableStringBuilder("lol");
                Selection.SelectAll(myString); // needs selection or Index Out of bounds

                search_events = FindViewById<EditText>(Resource.Id.search_events);
                search_events.TextChanged += search_skaters_TextChanged;
                var searchMenuItemAction = new SearchAction(this, null, Resource.Drawable.ic_action_search, search_events);
                LegacyBar.AddAction(searchMenuItemAction);


                InitializeLocationManager();

                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);
            }
        }
        public JsonResult CalendarEvents(string lId)
        {
            var now = DateTime.UtcNow;

            EventsJson leagues = new EventsJson();
            try
            {
                Guid leagueId = new Guid(lId);
                var events = SiteCache.GetCalendarEvents(leagueId, PULL_COUNT, now);

                leagues.Count = events.Events.Count;
                foreach (var e in events.Events)
                {
                    EventJson j = new EventJson();
                    j.Address = e.Address;
                    j.LeagueId = lId;
                    j.CalendarItemId = e.CalendarItemId.ToString().Replace("-", "");
                    j.EndDate = e.EndDate;
                    j.Name = e.Name;
                    j.NameUrl = e.NameUrl;
                    j.StartDate = e.StartDate;
                    j.Description = e.Notes;
                    j.EventUrl = e.Link;
                    j.TicketUrl = e.TicketUrl;
                    j.RDNUrl = ServerConfig.WEBSITE_DEFAULT_LOCATION + "/roller-derby-event/" + RDN.Utilities.Strings.StringExt.ToSearchEngineFriendly(e.Name) + "/" + j.CalendarItemId;
                    if (e.Location != null)
                        j.Location = e.Location.LocationName;
                    j.LeagueId = e.OrganizersId.ToString().Replace("-", "");
                    j.LogoUrl = e.ImageUrl;
                    j.OrganizersId = e.OrganizersId.ToString().Replace("-", "");
                    j.OrganizersName = e.OrganizersName;
                    leagues.Events.Add(j);

                }

                return Json(leagues, JsonRequestBehavior.AllowGet);

            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return Json(leagues, JsonRequestBehavior.AllowGet);
        }
        public Events()
        {
            try
            {
                InitializeComponent();
                LoggerMobile.Instance.logMessage("Opening Events", Portable.Util.Log.Enums.LoggerEnum.message);
                _viewModel = (EventsViewModel)Resources["viewModel"];
                resultListBox.ItemRealized += resultListBox_ItemRealized;
                this.Loaded += new RoutedEventHandler(MainPage_Loaded);
                initialArray = new EventsJson();

                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);

                ApplicationBarIconButton mapBtn = new ApplicationBarIconButton();
                mapBtn.IconUri = new Uri("/Assets/Icons/appbar.crosshair.png", UriKind.Relative);
                mapBtn.Text = "locate";

                mapBtn.Click += searchByLocation_Click;
                ApplicationBar.Buttons.Add(mapBtn);
            }
            catch (Exception exception)
            {
                ErrorHandler.Save(exception, MobileTypeEnum.WP8);
            }
        }
 void UpdateAdapter(EventsJson events)
 {
     initialArray.Events.AddRange(events.Events);
     RunOnUiThread(() =>
     {
         try
         {
             int firstPosition = eventsList.ScrollY;
             ListAdapter.NotifyDataSetChanged();
             LegacyBar.ProgressBarVisibility = ViewStates.Gone;
             eventsList.ScrollTo(0, firstPosition);
             //_dialog.Dismiss();
         }
         catch (Exception exception)
         {
             ErrorHandler.Save(exception, MobileTypeEnum.Android, (Context)this);
         }
     });
 }
Esempio n. 6
0
        public static void PullLeagueEvents(string leagueId, Context context, Action<EventsJson> callback)
        {
            Task<bool>.Factory.StartNew(
                                   () =>
                                   {
                                       try
                                       {
                                           var profile = new SqlFactory().GetCalendarEvents(leagueId);
                                           if (profile != null && profile.Count >= 5)
                                           {

                                               var evs = new EventsJson();

                                               evs.Events.AddRange(profile);

                                               callback(evs);
                                               return true;
                                           }
                                           var connectivityManager = (ConnectivityManager)context.GetSystemService(Context.ConnectivityService);
                                           var activeConnection = connectivityManager.ActiveNetworkInfo;
                                           if ((activeConnection != null) && activeConnection.IsConnected)
                                           {
                                               try
                                               {
                                                   LeaguesMobile.PullPublicLeagueEvents(leagueId, callback);
                                               }
                                               catch (Exception ex)
                                               {
                                                   ErrorHandler.Save(ex, MobileTypeEnum.Android, context);
                                               }
                                           }
                                       }
                                       catch (Exception exception)
                                       {
                                           ErrorHandler.Save(exception, MobileTypeEnum.Android, context);
                                       }
                                       return true;
                                   });

        }
        public JsonResult SearchEventsAllByLL(string p, string c, string lat, string lon)
        {
            var now = DateTime.UtcNow;

            EventsJson evs = new EventsJson();
            try
            {
                lat = lat.Replace(",", ".");
                lon = lon.Replace(",", ".");
                var latitude = Convert.ToDouble(lat);
                var longitude = Convert.ToDouble(lon);
                GeoCoordinate geo = new GeoCoordinate(latitude, longitude);
                var events = SiteCache.SearchCalendarEvents(now, longitude, latitude, Convert.ToInt32(p), Convert.ToInt32(c));

                evs.Count = events.Count;
                foreach (var e in events)
                {
                    EventJson j = new EventJson();
                    j.Address = e.Address;
                    j.LeagueId = e.OrganizersId.ToString().Replace("-", "");
                    j.CalendarItemId = e.CalendarItemId.ToString().Replace("-", "");
                    j.EndDate = e.EndDate;
                    j.Name = e.Name;
                    j.NameUrl = e.NameUrl;
                    j.StartDate = e.StartDate;
                    j.LogoUrl = e.ImageUrl;
                    j.OrganizersId = e.OrganizersId.ToString().Replace("-", "");
                    j.OrganizersName = e.OrganizersName;
                    j.Description = e.Notes;
                    j.EventUrl = e.Link;
                    j.TicketUrl = e.TicketUrl;
                    j.Latitude = e.Location.Contact.Addresses.FirstOrDefault().Coords.Latitude;
                    j.Longitude = e.Location.Contact.Addresses.FirstOrDefault().Coords.Longitude;
                    j.Miles = Conversion.ConvertMetersToMiles(geo.GetDistanceTo(new GeoCoordinate(j.Latitude, j.Longitude)));
                    j.RDNUrl = ServerConfig.WEBSITE_DEFAULT_LOCATION + "/roller-derby-event/" + RDN.Utilities.Strings.StringExt.ToSearchEngineFriendly(e.Name) + "/" + j.CalendarItemId;
                    if (e.Location != null)
                        j.Location = e.Location.LocationName;
                    evs.Events.Add(j);
                }

                return Json(evs, JsonRequestBehavior.AllowGet);

            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return Json(evs, JsonRequestBehavior.AllowGet);
        }
 public EventsViewController()
 {
     initialArray = new EventsJson();
 }
        void UpdateAdapter(EventsJson skaters)
        {
            if (IsSearching)
                initialArray.Events.Clear();
            initialArray.Events.AddRange(skaters.Events);
            InvokeOnMainThread(() =>
            {
                try
                {
                    //table.InsertRows(indexPaths.ToArray(), UITableViewRowAnimation.Fade);

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



        }
        void UpdateEventsAdapter(EventsJson events)
        {
            TableLayout leagueScheduleTable = FindViewById<TableLayout>(Resource.Id.leagueScheduleTable);
            RunOnUiThread(() =>
                        {
                            try
                            {
                                LegacyBar.ProgressBarVisibility = ViewStates.Gone;
                                // Go through each item in the array
                                for (int current = 0; current < events.Events.Count; current++)
                                {
                                    // Create a TableRow and give it an ID
                                    View scheduleTableRow = LayoutInflater.Inflate(Resource.Layout.PublicLeagueEventRow, null, false);

                                    DateTime iKnowThisIsUtc = events.Events[current].StartDate;
                                    DateTime runtimeKnowsThisIsUtc = DateTime.SpecifyKind(iKnowThisIsUtc, DateTimeKind.Utc);
                                    DateTime localVersion = runtimeKnowsThisIsUtc.ToLocalTime();
                                    var publicLeagueRowDate = scheduleTableRow.FindViewById<TextView>(Resource.Id.publicLeagueRowDate);
                                    publicLeagueRowDate.Text = localVersion.ToShortDateString();
                                    var publicLeagueRowTime = scheduleTableRow.FindViewById<TextView>(Resource.Id.publicLeagueRowTime);
                                    publicLeagueRowTime.Text = localVersion.ToShortTimeString();
                                    var publicLeagueRowEventName = scheduleTableRow.FindViewById<TextView>(Resource.Id.publicLeagueRowEventName);
                                    publicLeagueRowEventName.Text = events.Events[current].Name;
                                    var publicLeagueRowId = scheduleTableRow.FindViewById<TextView>(Resource.Id.publicLeagueRowId);
                                    publicLeagueRowId.Text = events.Events[current].CalendarItemId;
                                    publicLeagueRowDate.PaintFlags = PaintFlags.UnderlineText;
                                    publicLeagueRowEventName.PaintFlags = PaintFlags.UnderlineText;
                                    publicLeagueRowTime.PaintFlags = PaintFlags.UnderlineText;

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

                                    scheduleTableRow.Clickable = true;
                                    scheduleTableRow.Click += scheduleTableRow_Click;
                                    leagueScheduleTable.AddView(scheduleTableRow); //not working, obviously im missing something

                                }
                            }
                            catch (Exception exception)
                            {
                                ErrorHandler.Save(exception, MobileTypeEnum.Android, (Context)this);
                            }
                        });
        }
        private void UpdateAdapterEvents(EventsJson obj)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                this.EventsCollection = new ObservableCollection<EventJson>();
                for (int i = 0; i < obj.Events.Count; i++)
                {
                    this.EventsCollection.Add(obj.Events[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 UpdateAdapterEvents(EventsJson skater)
 {
     InvokeOnMainThread(() =>
     {
         try
         {
             eventsArray.Events.AddRange(skater.Events);
             eventTable.Source = new EventsTableView(eventsArray.Events, this.NavigationController);
             eventTable.ReloadData();
         }
         catch (Exception exception)
         {
             ErrorHandler.Save(exception, MobileTypeEnum.iPhone);
         }
     });
 }