Ejemplo n.º 1
0
        public override async void OnActivityCreated(Bundle savedInstanceState)
        {
            base.OnActivityCreated(savedInstanceState);
            _account = AccountStore
                       .Create(Context)
                       .FindAccountsForService(GetString(Resource.String.app_name))
                       .FirstOrDefault();
            HttpResponseMessage httpResponse = await RestManager.GetMemberInvitations(_account.Username);

            _header        = View.FindViewById <TextView>(Resource.Id.tv_invitations_header);
            _noInvitations = View.FindViewById <TextView>(Resource.Id.tv_invitations_noInvitations);
            if (_account.Properties["roles"].Contains(Role.Coach.ToString()))
            {
                _header.Text = Literals.InvitationsToPlayers;
            }
            else
            {
                _header.Text = Literals.InvitationsFromClubs;
            }

            if (httpResponse.IsSuccessStatusCode)
            {
                string response = await httpResponse.Content.ReadAsStringAsync();

                if (!string.IsNullOrWhiteSpace(response) && response != "null")
                {
                    _invitationResponses = JsonConvert.DeserializeObject <IEnumerable <InvitationResponse> >(response);
                    _adapter             = new InvitationAdapter(Activity, _invitationResponses.ToArray(), _account);
                    _recyclerView        = View.FindViewById <RecyclerView>(Resource.Id.rv_invitations_invitations);
                    _recyclerView.SetAdapter(_adapter);
                    _layoutManager = new LinearLayoutManager(Activity, LinearLayoutManager.Vertical, false);
                    _recyclerView.SetLayoutManager(_layoutManager);
                    if (!_invitationResponses.Any())
                    {
                        _noInvitations.Visibility = ViewStates.Visible;
                    }
                }
            }
        }