added red/green highlighting

This commit is contained in:
mgroves 2011-02-26 11:58:22 -05:00
parent bd57f2f665
commit 9ef1c04920

View file

@ -1,8 +1,10 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Android.App; using Android.App;
using Android.Content; using Android.Content;
using Android.Graphics;
using Android.OS; using Android.OS;
using Android.Views; using Android.Views;
using Android.Widget; using Android.Widget;
@ -12,19 +14,26 @@ using MonoStockPortfolio.Core.PortfolioRepositories;
using MonoStockPortfolio.Core.Services; using MonoStockPortfolio.Core.Services;
using MonoStockPortfolio.Entities; using MonoStockPortfolio.Entities;
using MonoStockPortfolio.Framework; using MonoStockPortfolio.Framework;
using Orientation = Android.Widget.Orientation;
namespace MonoStockPortfolio.Activites namespace MonoStockPortfolio.Activites
{ {
[Activity(Label = "Portfolio", Name = "monostockportfolio.activites.PortfolioActivity")] [Activity(Label = "Portfolio", Name = "monostockportfolio.activites.PortfolioActivity")]
public class PortfolioActivity : Activity public class PortfolioActivity : Activity
{ {
[IoC] private IPortfolioService _svc; [IoC]
[IoC] private IPortfolioRepository _repo; private IPortfolioService _svc;
[IoC] private IConfigRepository _config; [IoC]
private IPortfolioRepository _repo;
[IoC]
private IConfigRepository _config;
[LazyView(Resource.Id.quoteListview)] protected ListView QuoteListview; [LazyView(Resource.Id.quoteListview)]
[LazyView(Resource.Id.btnAddPosition)] protected Button AddPositionButton; protected ListView QuoteListview;
[LazyView(Resource.Id.quoteHeaderLayout)] protected LinearLayout QuoteListviewHeader; [LazyView(Resource.Id.btnAddPosition)]
protected Button AddPositionButton;
[LazyView(Resource.Id.quoteHeaderLayout)]
protected LinearLayout QuoteListviewHeader;
private const string PORTFOLIOIDEXTRA = "monoStockPortfolio.PortfolioActivity.PortfolioID"; private const string PORTFOLIOIDEXTRA = "monoStockPortfolio.PortfolioActivity.PortfolioID";
@ -52,7 +61,7 @@ namespace MonoStockPortfolio.Activites
public override bool OnCreateOptionsMenu(IMenu menu) public override bool OnCreateOptionsMenu(IMenu menu)
{ {
var item = menu.Add(0,1,1, "Refresh".ToJ()); var item = menu.Add(0, 1, 1, "Refresh".ToJ());
item.SetIcon(Resource.Drawable.ic_menu_refresh); item.SetIcon(Resource.Drawable.ic_menu_refresh);
return true; return true;
} }
@ -138,7 +147,7 @@ namespace MonoStockPortfolio.Activites
private void UpdateHeader(IEnumerable<StockDataItem> items) private void UpdateHeader(IEnumerable<StockDataItem> items)
{ {
QuoteListviewHeader.RemoveAllViews(); QuoteListviewHeader.RemoveAllViews();
var cellwidth = this.GetScreenWidth()/items.Count(); var cellwidth = this.GetScreenWidth() / items.Count();
foreach (var stockDataItem in items) foreach (var stockDataItem in items)
{ {
var textItem = new TextView(this); var textItem = new TextView(this);
@ -169,17 +178,26 @@ namespace MonoStockPortfolio.Activites
var row = new LinearLayout(Context); var row = new LinearLayout(Context);
row.Orientation = Orientation.Horizontal; row.Orientation = Orientation.Horizontal;
var portfolioActivity = (PortfolioActivity) Context; var portfolioActivity = (PortfolioActivity)Context;
foreach (var stockDataItem in portfolioActivity.GetStockItemsFromConfig()) foreach (var stockDataItem in portfolioActivity.GetStockItemsFromConfig())
{ {
var cell = new TextView(Context); var cell = new TextView(Context);
cell.Text = item.Items[stockDataItem]; cell.Text = item.Items[stockDataItem];
cell.SetWidth(columnWidth); cell.SetWidth(columnWidth);
RedGreenHighlighting(cell, item.Items);
row.Tag = item.PositionId; row.Tag = item.PositionId;
row.AddView(cell); row.AddView(cell);
} }
return row; return row;
} }
private static void RedGreenHighlighting(TextView cell, IDictionary<StockDataItem, string> items)
{
if(items.ContainsKey(StockDataItem.GainLoss))
{
cell.SetTextColor(decimal.Parse(items[StockDataItem.GainLoss]) < 0 ? Color.Red : Color.Green);
}
}
} }
private void WireUpEvents() private void WireUpEvents()
@ -212,4 +230,4 @@ namespace MonoStockPortfolio.Activites
return _config.GetStockItems(); return _config.GetStockItems();
} }
} }
} }