private async Task FilterPlayers()
        {
            AndHUD.Shared.Show(this, "Търсене…");
            HttpResponseMessage getPlayersHttpResponse = await RestManager.GetAvailablePlayers(_searchPlayersCritera);

            string getPlayersResponse = await getPlayersHttpResponse.Content.ReadAsStringAsync();

            if (getPlayersHttpResponse.IsSuccessStatusCode &&
                !string.IsNullOrWhiteSpace(getPlayersResponse) &&
                getPlayersResponse != "null")
            {
                _memberDetails = JsonConvert.DeserializeObject <IEnumerable <MemberDetails> >(getPlayersResponse);
                _adapter       = new PlayerAdapter(this, _memberDetails.ToArray(), _clubDetails, _account);
                _recyclerView.SetAdapter(_adapter);
                AndHUD.Shared.Dismiss(this);
                if (_memberDetails.Any())
                {
                    _noPlayersFound.Visibility = ViewStates.Gone;
                }
                else
                {
                    _noPlayersFound.Visibility = ViewStates.Visible;
                }
            }
        }
        protected async override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.SearchPlayers);

            Typeface tf = Typeface.CreateFromAsset(Assets, "fonts/Font Awesome 5 Free-Solid-900.otf");

            _toolbar          = FindViewById <Toolbar>(Resource.Id.tbr_searchPlayers_toolbar);
            _name             = FindViewById <EditText>(Resource.Id.et_searchPlayers_name);
            _positionsSpinner = FindViewById <Spinner>(Resource.Id.spn_searchPlayers_preferedPosition);

            _heightRange = FindViewById <RangeSliderControl>(Resource.Id.sld_searchPlayers_heightRange);
            _heightRange.SetSelectedMinValue(0);
            _heightRange.SetSelectedMaxValue(300);

            _weightRange = FindViewById <RangeSliderControl>(Resource.Id.sld_searchPlayers_weightRange);
            _weightRange.SetSelectedMinValue(0);
            _weightRange.SetSelectedMaxValue(300);

            _ageRange = FindViewById <RangeSliderControl>(Resource.Id.sld_searchPlayers_ageRange);
            _ageRange.SetSelectedMinValue(_ageRange.AbsoluteMinValue);
            _ageRange.SetSelectedMaxValue(_ageRange.AbsoluteMaxValue);

            _search        = FindViewById <Button>(Resource.Id.btn_searchPlayers_searchPlayers);
            _search.Click += Search_Click;

            _recyclerView  = FindViewById <RecyclerView>(Resource.Id.rv_searchPlayers_players);
            _layoutManager = new LinearLayoutManager(this, LinearLayoutManager.Vertical, false);
            _recyclerView.SetLayoutManager(_layoutManager);

            _noPlayersFound = FindViewById <TextView>(Resource.Id.tv_searchPlayers_noPlayersFound);

            SetSupportActionBar(_toolbar);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetHomeButtonEnabled(true);

            _toggleFilters = FindViewById <TextView>(Resource.Id.tv_searchPlayers_toggleFilters);

            _toggleFilters.Click   += ToggleFilters_Click;
            _toggleFilters.Typeface = tf;

            _filters = FindViewById <TableLayout>(Resource.Id.tl_searchPlayers_filters);

            var positions = new List <string> {
                Literals.AllPositions
            };

            positions.AddRange(Enum
                               .GetNames(typeof(Position))
                               .Select(r => Literals.ResourceManager.GetString(r)));
            _positionsSpinner.Adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, positions.ToArray());

            _resetFilters        = FindViewById <Button>(Resource.Id.btn_searchPlayers_resetFilters);
            _resetFilters.Click += ResetFilters_Click;

            _account = AccountStore
                       .Create()
                       .FindAccountsForService(GetString(Resource.String.app_name))
                       .FirstOrDefault();

            HttpResponseMessage getPlayersHttpResponse = await RestManager.GetAvailablePlayers(_searchPlayersCritera);

            HttpResponseMessage getCoachClubHttpResponse = await RestManager.GetMemberClub(_account.Username);

            string getCoachClubResponse = await getCoachClubHttpResponse.Content.ReadAsStringAsync();

            string getPlayersResponse = await getPlayersHttpResponse.Content.ReadAsStringAsync();

            if (getPlayersHttpResponse.IsSuccessStatusCode &&
                !string.IsNullOrWhiteSpace(getPlayersResponse) &&
                getPlayersResponse != "null")
            {
                _clubDetails   = JsonConvert.DeserializeObject <ClubDetails>(getCoachClubResponse);
                _memberDetails = JsonConvert.DeserializeObject <IEnumerable <MemberDetails> >(getPlayersResponse);
                if (_memberDetails.Any())
                {
                    _adapter = new PlayerAdapter(this, _memberDetails.ToArray(), _clubDetails, _account);
                    _recyclerView.SetAdapter(_adapter);
                }
            }
        }
Beispiel #3
0
        public override async void OnActivityCreated(Bundle OnActivityCreated)
        {
            base.OnActivityCreated(OnActivityCreated);

            _account = AccountStore
                       .Create(Context)
                       .FindAccountsForService(GetString(Resource.String.app_name))
                       .FirstOrDefault();
            HttpResponseMessage httpResponse = await RestManager.GetMemberClub(_account.Username);

            string response = await httpResponse.Content.ReadAsStringAsync();

            bool isCoach = _account.Properties["roles"].Contains(Role.Coach.ToString());

            if (string.IsNullOrWhiteSpace(response) || response == "null")
            {
                TextView noClubMessage = View.FindViewById <TextView>(Resource.Id.tv_club_noClubMessage);
                noClubMessage.Text       = Literals.NoClubMessage;
                noClubMessage.Visibility = ViewStates.Visible;

                if (isCoach)
                {
                    Button createClubButton = View.FindViewById <Button>(Resource.Id.btn_club_createClub);
                    createClubButton.Visibility = ViewStates.Visible;
                    createClubButton.Click     += CreateClubButton_Click;
                }
            }
            else
            {
                _clubDetails = JsonConvert.DeserializeObject <ClubDetails>(response);
                string imagePath = await RestManager.GetClubPhoto(_clubDetails.Id);

                _mainPhoto = View.FindViewById <ImageView>(Resource.Id.iv_club_mainPhoto);
                var bitmap = BitmapFactory.DecodeFile(imagePath);
                _mainPhoto.SetImageBitmap(bitmap);

                TextView clubNameText = View.FindViewById <TextView>(Resource.Id.tv_club_clubName);
                clubNameText.Text = _clubDetails.Name;
                LinearLayout clubDetailsLayout = View.FindViewById <LinearLayout>(Resource.Id.ll_club_clubDetails);
                clubDetailsLayout.Visibility = ViewStates.Visible;
                if (isCoach)
                {
                    Button searchPlayersButton = View.FindViewById <Button>(Resource.Id.btn_club_searchPlayers);
                    searchPlayersButton.Click += SearchPlayersButton_Click;

                    Button editClub = View.FindViewById <Button>(Resource.Id.btn_club_editClubDetails);
                    editClub.Click += EditClub_Click;

                    LinearLayout coachActions = View.FindViewById <LinearLayout>(Resource.Id.ll_club_coachActions);
                    coachActions.Visibility = ViewStates.Visible;
                }
                else
                {
                    Button leaveClub = View.FindViewById <Button>(Resource.Id.btn_club_leaveClub);
                    leaveClub.Click += LeaveClub_Click;
                    LinearLayout playerActions = View.FindViewById <LinearLayout>(Resource.Id.ll_club_playerActions);
                    playerActions.Visibility = ViewStates.Visible;
                }

                _searchPlayersCritera.ClubId = _clubDetails.Id;
                HttpResponseMessage getPlayersHttpResponse = await RestManager.GetClubPlayers(_searchPlayersCritera);

                string getPlayersResponse = await getPlayersHttpResponse.Content.ReadAsStringAsync();

                if (!string.IsNullOrWhiteSpace(getPlayersResponse) && getPlayersResponse != "null")
                {
                    _memberDetails = JsonConvert.DeserializeObject <IEnumerable <MemberDetails> >(getPlayersResponse);
                    if (_memberDetails.Any())
                    {
                        _adapter      = new PlayerAdapter(Activity, _memberDetails.ToArray(), _clubDetails, _account);
                        _recyclerView = View.FindViewById <RecyclerView>(Resource.Id.rv_club_clubPlayers);
                        _recyclerView.SetAdapter(_adapter);
                        _layoutManager = new LinearLayoutManager(Activity, LinearLayoutManager.Vertical, false);
                        _recyclerView.SetLayoutManager(_layoutManager);
                    }
                }
            }
        }