Esempio n. 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);
        }
Esempio n. 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);
            }
        }
Esempio n. 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);
                }
            }
        }
Esempio n. 4
0
        protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
        {
            switch (requestCode)
            {
            case Code_Download:
                if (resultCode == Result.Ok)
                {
                    var fileName = data.GetStringExtra(DownloadActivity.ResultName);
                    var reddit   = data.GetStringArrayExtra(DownloadActivity.ResultData);

                    if (!string.IsNullOrEmpty(fileName) && reddit?.Any() == true)
                    {
                        ResumeStatus(reddit);
                        _recentFile = SaveFile(fileName, reddit);
                    }
                    else
                    {
                        AlertHelper.ShowMessage(this, "No play data available.", "Download");
                    }
                }
                break;

            case Code_SelectFile:
                if (resultCode == Result.Ok)
                {
                    // The document selected by the user won't be returned in the intent.
                    // Instead, a URI to that document will be contained in the return intent
                    // provided to this method as a parameter.  Pull that uri using "resultData.getData()"
                    ResumeStatus(data.Data);
                }
                break;

            case Code_ShowSettings:

                break;
            }
        }