2011-03-15 01:42:26 +00:00
|
|
|
using System.Collections.Generic;
|
2011-04-02 03:27:11 +00:00
|
|
|
using System.Linq;
|
2011-03-15 01:42:26 +00:00
|
|
|
using Android.Content;
|
|
|
|
using Android.Graphics;
|
|
|
|
using Android.Views;
|
|
|
|
using Android.Widget;
|
|
|
|
using MonoStockPortfolio.Entities;
|
|
|
|
using MonoStockPortfolio.Framework;
|
|
|
|
|
|
|
|
namespace MonoStockPortfolio.Activites.PortfolioScreen
|
|
|
|
{
|
2011-04-02 03:27:11 +00:00
|
|
|
public class PositionArrayAdapter : BaseAdapter<PositionResultsViewModel>
|
2011-03-15 01:42:26 +00:00
|
|
|
{
|
2011-03-31 03:42:00 +00:00
|
|
|
private readonly IEnumerable<StockDataItem> _configItems;
|
2011-04-02 03:27:11 +00:00
|
|
|
private readonly List<PositionResultsViewModel> _items;
|
|
|
|
private readonly Context _context;
|
2011-03-15 01:42:26 +00:00
|
|
|
|
|
|
|
public PositionArrayAdapter(Context context, IEnumerable<PositionResultsViewModel> results, IEnumerable<StockDataItem> configItems)
|
|
|
|
{
|
|
|
|
_configItems = configItems;
|
2011-04-02 03:27:11 +00:00
|
|
|
_items = results.ToList();
|
|
|
|
_context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override int Count
|
|
|
|
{
|
|
|
|
get { return _items.Count(); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public override PositionResultsViewModel this[int position]
|
|
|
|
{
|
|
|
|
get { return _items[position]; }
|
2011-03-15 01:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override long GetItemId(int position)
|
|
|
|
{
|
|
|
|
return this[position].PositionId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override View GetView(int position, View convertView, ViewGroup parent)
|
|
|
|
{
|
|
|
|
var item = this[position];
|
|
|
|
|
2011-04-02 03:27:11 +00:00
|
|
|
var width = _context.GetScreenWidth();
|
2011-03-15 01:42:26 +00:00
|
|
|
var columnWidth = width / item.Items.Count;
|
|
|
|
|
2011-04-02 03:27:11 +00:00
|
|
|
var row = new LinearLayout(_context);
|
2011-03-15 01:42:26 +00:00
|
|
|
row.Orientation = Orientation.Horizontal;
|
|
|
|
foreach (var stockDataItem in _configItems)
|
|
|
|
{
|
2011-04-02 03:27:11 +00:00
|
|
|
var cell = new TextView(_context);
|
2011-03-15 01:42:26 +00:00
|
|
|
cell.Text = item.Items[stockDataItem];
|
2011-08-16 01:31:57 +00:00
|
|
|
cell.TextSize = 16.55F;
|
2011-03-15 01:42:26 +00:00
|
|
|
cell.SetWidth(columnWidth);
|
|
|
|
RedGreenHighlighting(cell, item.Items);
|
|
|
|
row.Tag = item.PositionId;
|
|
|
|
row.AddView(cell);
|
|
|
|
}
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void RedGreenHighlighting(TextView cell, IDictionary<StockDataItem, string> items)
|
|
|
|
{
|
|
|
|
if (items.ContainsKey(StockDataItem.GainLoss))
|
|
|
|
{
|
2011-08-16 01:27:07 +00:00
|
|
|
cell.SetTextColor(decimal.Parse(items[StockDataItem.GainLoss]) < 0 ? Color.Red : Color.LightGreen);
|
2011-03-15 01:42:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|