async partial void ButtonQuote_TouchUpInside(UIButton sender)
        {
            if (string.IsNullOrWhiteSpace(TextSymbol.Text))
            {
                var alert = new UIAlertView("No symbol", string.Empty, null, "OK");
                alert.Show();

                return;
            }

            TextSymbol.ResignFirstResponder();
            ProgressBar.StartAnimating();

            var quoteTask   = viewModel.GetQuote(TextSymbol.Text);
            var historyTask = viewModel.GetHistory(
                TextSymbol.Text,
                DateTime.Today.AddDays(-14),
                DateTime.Today);

            await Task.WhenAll(quoteTask, historyTask);

            var quote = quoteTask.Result;

            if (quote == null)
            {
                LabelQuote.Text = "Invalid";
                ProgressBar.StopAnimating();

                return;
            }

            LabelQuote.Text      = quote.CurrentQuote + " | " + quote.Change;
            LabelQuote.TextColor = quote.StockIsUp ? UIColor.Green : UIColor.Red;

            var items = historyTask.Result;

            if (items != null)
            {
                barChart.ItemsSource = items.Select(
                    s => new BarChart.BarModel
                {
                    Value  = s.Value,
                    Legend = s.Date.Remove(0, 5)
                }).ToList();
            }

            ProgressBar.StopAnimating();
        }
Beispiel #2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById <Button>(Resource.Id.MyButton);

            var quoteLable  = FindViewById <TextView>(Resource.Id.textView1);
            var symbol      = FindViewById <EditText>(Resource.Id.editText1);
            var progressBar = FindViewById <ProgressBar>(Resource.Id.progressBar1);

            mainLayout = FindViewById <LinearLayout>(Resource.Id.main);

            progressBar.Visibility = ViewStates.Invisible;
            quoteLable.Text        = string.Empty;

            button.Click += async(sender, args) =>
            {
                progressBar.Visibility = ViewStates.Visible;

                if (string.IsNullOrWhiteSpace(symbol.Text))
                {
                    quoteLable.Text        = "Invalid";
                    progressBar.Visibility = ViewStates.Invisible;
                    return;
                }

                var quote = await viewModel.GetQuote(symbol.Text.Trim());

                if (quote != null)
                {
                    quoteLable.Text = quote.CurrentQuote + " | " + quote.Change;

                    quoteLable.SetTextColor(quote.StockIsUp ? Color.Green : Color.Red);
                }


                var items = await viewModel.GetHistory(
                    symbol.Text.Trim(),
                    DateTime.Today.AddDays(-14),
                    DateTime.Today);

                if (items != null)
                {
                    data = items.Select(
                        s => new BarChart.BarModel
                    {
                        Value  = s.Value,
                        Legend = s.Date.Remove(0, 5),
                        Color  = Android.Graphics.Color.Orange
                    });
                    RunOnUiThread(() =>
                    {
                        if (barChart != null)
                        {
                            mainLayout.RemoveView(barChart);
                        }

                        barChart                      = new BarChartView(this);
                        barChart.ItemsSource          = data;
                        barChart.BarOffset            = 30;
                        barChart.MinimumValue         = items.Min(i => i.Value);
                        barChart.LegendColor          = Android.Graphics.Color.Black;
                        barChart.BarCaptionOuterColor = Android.Graphics.Color.Black;
                        barChart.BarCaptionFontSize   = 28;
                        mainLayout.AddView(barChart, new ViewGroup.LayoutParams(
                                               ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent));
                    });
                }


                progressBar.Visibility = ViewStates.Invisible;
            };
        }