Пример #1
0
        private async Task <int> LoadTeamsAsync(int season)
        {
            try
            {
                if (season > 1900 && season <= DateTime.UtcNow.Year)
                {
                    if (season != _model.Year || _spnTeam.Adapter == null)
                    {
                        _teams = await _client.GetTeamsAsync(_model.Year).ConfigureAwait(true);

                        var teamNames = _teams.Select(t => t.Nickname ?? "???").ToArray();
                        var adapter   = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerItem, teamNames);
                        adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
                        _spnTeam.Adapter = adapter;

                        return(season);
                    }
                }
            }
            catch (Exception ex) when
            (
                ex is HttpRequestException ||
                ex is System.OperationCanceledException
            )
            {
                AlertHelper.ShowException(this, ex);
            }

            return(_model.Year);
        }
Пример #2
0
        private async Task LoadBoxScoresAsync()
        {
            try
            {
                var filter = _model.Filter;

                if (!int.TryParse(FindViewById <EditText>(Resource.Id.ed_week).Text, out var week))
                {
                    week = 0;
                }

                filter.Week = week;
                filter.Away = filter.Home = filter.Team = null;

                switch (FindViewById <RadioGroup>(Resource.Id.rg_team_slot).CheckedRadioButtonId)
                {
                case Resource.Id.rb_away:
                    filter.Away = _model.SelectedTeam;
                    break;

                case Resource.Id.rb_home:
                    filter.Home = _model.SelectedTeam;
                    break;

                case Resource.Id.rb_both:
                    filter.Team = _model.SelectedTeam;
                    break;

                default:
                    throw new InvalidOperationException("Unexpected team slot.");
                }

                _boxScoreUrls = await _client.GetBoxScoreUrlsAsync(_model);

                var displayUrls = _boxScoreUrls.Select(b => $"{b.Date:MM/dd}: {b.AwayCode} @ {b.HomeCode}").ToArray();
                var adapter     = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSelectableListItem, displayUrls);
                adapter.SetDropDownViewResource(Android.Resource.Layout.ListContent);
                _lstBoxScores.Adapter = adapter;
            }
            catch (Exception ex) when
            (
                ex is HttpRequestException ||
                ex is System.OperationCanceledException
            )
            {
                AlertHelper.ShowException(this, ex);
            }
        }
Пример #3
0
        private async void BoxScoreList_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            if (e.Position >= 0 && e.Position < _boxScoreUrls?.Length)
            {
                var boxScore = _boxScoreUrls[e.Position];

                try
                {
                    var reddit = await _client.GetRedditAsync(new PlayRequest
                    {
                        Season   = _model.Year,
                        Week     = _model.Filter.Week,
                        AwayCode = boxScore.AwayCode,
                        HomeCode = boxScore.HomeCode,
                        GameId   = boxScore.GetGameId()
                    }).ConfigureAwait(true);

                    var returnIntent = new Intent();
                    returnIntent.PutExtra(ResultData, reddit);

                    if (reddit?.Length > 0)
                    {
                        returnIntent.PutExtra(ResultName, FileNameBuilder.GetFileName(reddit[0], _model.Year, _model.Filter.Week));
                    }
                    SetResult(Result.Ok, returnIntent);

                    Finish();
                }
                catch (Exception ex) when
                (
                    ex is HttpRequestException ||
                    ex is System.OperationCanceledException
                )
                {
                    AlertHelper.ShowException(this, ex);
                }
            }
        }