using System; using System.Collections.Generic; using System.Linq; using System.Threading; using Android.App; using Android.Content; using Android.Graphics; using Android.OS; using Android.Widget; using MonoStockPortfolio.Core; using MonoStockPortfolio.Core.Services; namespace MonoStockPortfolio { [Activity(Label = "Portfolio")] public class PortfolioActivity : Activity { public static string ClassName { get { return "monostockportfolio.PortfolioActivity"; } } public static string Extra_PortfolioID { get { return "monoStockPortfolio.PortfolioActivity.PortfolioID"; } } private IPortfolioService _svc; private IEnumerable[] longClickOptions; private long ThisPortofolioId { get { return Intent.GetLongExtra(Extra_PortfolioID, -1); } } protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.layout.portfolio); _svc = new PortfolioService(this); Refresh(); WireUpEvents(); SetTitle(); } private void Refresh() { Action refresh = () => { var tickers = _svc.GetDetailedItems(ThisPortofolioId, GetStockItemsFromConfig()); if (tickers.Any()) { RunOnUiThread(() => RefreshUI(tickers)); } }; var background = new Thread(() => refresh()); background.Start(); } private void RefreshUI(IEnumerable> tickers) { var tableLayout = FindViewById(Resource.id.quoteTable); tableLayout.RemoveAllViews(); WriteTickerHeader(tickers.First()); foreach (var ticker in tickers) { WriteTickerRow(ticker); } } private void WireUpEvents() { var addPositionButton = FindViewById