mirror of
https://github.com/mgroves/MonodroidStockPortfolio.git
synced 2024-12-24 12:03:02 +00:00
minor cleanup & refactoring
This commit is contained in:
parent
b9a30b6d62
commit
3709c553cb
13 changed files with 54 additions and 63 deletions
|
@ -1,7 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using MonoStockPortfolio.Entities;
|
||||
|
||||
namespace MonoStockPortfolio.Core
|
||||
|
@ -24,16 +21,5 @@ namespace MonoStockPortfolio.Core
|
|||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public static IEnumerable<T> GetValues<T>(this Enum value)
|
||||
{
|
||||
var enumerations = new List<Enum>();
|
||||
var fields = value.GetType().GetFields(BindingFlags.Static | BindingFlags.Public);
|
||||
foreach (var fieldInfo in fields)
|
||||
{
|
||||
enumerations.Add((Enum)fieldInfo.GetValue(value));
|
||||
}
|
||||
return enumerations.Cast<T>();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,10 +8,11 @@ namespace MonoStockPortfolio.Core.PortfolioRepositories
|
|||
IList<Portfolio> GetAllPortfolios();
|
||||
void SavePortfolio(Portfolio portfolio);
|
||||
void DeletePortfolioById(int portfolioId);
|
||||
IList<Position> GetAllPositions(long portfolioId);
|
||||
Portfolio GetPortfolioById(long portfolioId);
|
||||
void SavePosition(Position position);
|
||||
Portfolio GetPortfolioByName(string portfolioName);
|
||||
|
||||
IList<Position> GetAllPositions(long portfolioId);
|
||||
void SavePosition(Position position);
|
||||
void DeletePositionById(long positionId);
|
||||
Position GetPositionById(long positionId);
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@ namespace MonoStockPortfolio.Core.Services
|
|||
{
|
||||
public interface IPortfolioService
|
||||
{
|
||||
IList<Portfolio> GetAllPortfolios();
|
||||
IEnumerable<PositionResultsViewModel> GetDetailedItems(long portfolioID, IEnumerable<StockDataItem> items);
|
||||
Portfolio GetPortolioById(long portfolioId);
|
||||
}
|
||||
}
|
|
@ -13,11 +13,6 @@ namespace MonoStockPortfolio.Core.Services
|
|||
private readonly IPortfolioRepository _portRepo;
|
||||
private readonly IStockDataProvider _stockRepo;
|
||||
|
||||
// public PortfolioService(Context context) : this(new AndroidSqlitePortfolioRepository(context),
|
||||
// new YahooStockDataProvider())
|
||||
// {
|
||||
// }
|
||||
|
||||
public PortfolioService(IPortfolioRepository portfolioRepository, IStockDataProvider stockDataProvider)
|
||||
{
|
||||
_portRepo = portfolioRepository;
|
||||
|
@ -60,11 +55,6 @@ namespace MonoStockPortfolio.Core.Services
|
|||
}
|
||||
}
|
||||
|
||||
public Portfolio GetPortolioById(long portfolioId)
|
||||
{
|
||||
return _portRepo.GetPortfolioById(portfolioId);
|
||||
}
|
||||
|
||||
private IDictionary<StockDataItem, string> GetStockItems(IEnumerable<StockDataItem> items, StockQuote quote)
|
||||
{
|
||||
var dict = new Dictionary<StockDataItem, string>();
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using FileHelpers;
|
||||
|
||||
namespace MonoStockPortfolio.Core.StockData
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
using System;
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Widget;
|
||||
using MonoStockPortfolio.Core.PortfolioRepositories;
|
||||
using MonoStockPortfolio.Entities;
|
||||
using MonoStockPortfolio.Framework;
|
||||
|
@ -22,7 +20,7 @@ namespace MonoStockPortfolio.Activites
|
|||
|
||||
WireUpEvents();
|
||||
|
||||
var portfolioId = Intent.GetLongExtra(Extra_PortfolioID, -1);
|
||||
var portfolioId = ThisPortfolioId;
|
||||
if(portfolioId != -1)
|
||||
{
|
||||
this.Title = "Edit Portfolio";
|
||||
|
@ -49,11 +47,9 @@ namespace MonoStockPortfolio.Activites
|
|||
{
|
||||
_repo.SavePortfolio(portfolioToSave);
|
||||
|
||||
Toast.MakeText(this, "You saved: " + PortfolioName.Text, ToastLength.Short).Show();
|
||||
this.LongToast("You saved: " + PortfolioName.Text);
|
||||
|
||||
var intent = new Intent();
|
||||
SetResult(Result.Ok, intent);
|
||||
Finish();
|
||||
this.EndActivity();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,7 +62,7 @@ namespace MonoStockPortfolio.Activites
|
|||
var result = validator.Apply();
|
||||
if(result != string.Empty)
|
||||
{
|
||||
Toast.MakeText(this, result, ToastLength.Long).Show();
|
||||
this.LongToast(result);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -85,7 +81,7 @@ namespace MonoStockPortfolio.Activites
|
|||
private Portfolio GetPortfolioToSave()
|
||||
{
|
||||
Portfolio portfolioToSave;
|
||||
var portfolioId = Intent.GetLongExtra(Extra_PortfolioID, -1);
|
||||
var portfolioId = ThisPortfolioId;
|
||||
if (portfolioId != -1)
|
||||
{
|
||||
portfolioToSave = new Portfolio(portfolioId);
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace MonoStockPortfolio.Activites
|
|||
{
|
||||
public static string ClassName { get { return "monostockportfolio.activites.EditPortfolioActivity"; } }
|
||||
public static string Extra_PortfolioID { get { return "monoStockPortfolio.EditPortfolioActivity.PortfolioID"; } }
|
||||
public long ThisPortfolioId { get { return Intent.GetLongExtra(Extra_PortfolioID, -1); } }
|
||||
|
||||
protected Button SaveButton { get { return FindViewById<Button>(Resource.id.btnSave); } }
|
||||
protected EditText PortfolioName { get { return FindViewById<EditText>(Resource.id.portfolioName); } }
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
using System;
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Widget;
|
||||
using MonoStockPortfolio.Core.PortfolioRepositories;
|
||||
using MonoStockPortfolio.Entities;
|
||||
using MonoStockPortfolio.Framework;
|
||||
|
@ -20,7 +18,7 @@ namespace MonoStockPortfolio.Activites
|
|||
|
||||
SetContentView(Resource.layout.addposition);
|
||||
|
||||
var positionId = Intent.GetLongExtra(Extra_PositionID, -1);
|
||||
var positionId = ThisPositionId;
|
||||
if (positionId != -1)
|
||||
{
|
||||
this.Title = "Edit Position";
|
||||
|
@ -50,9 +48,7 @@ namespace MonoStockPortfolio.Activites
|
|||
var positionToSave = GetPositionToSave();
|
||||
_repo.SavePosition(positionToSave);
|
||||
|
||||
var intent = new Intent();
|
||||
SetResult(Result.Ok, intent);
|
||||
Finish();
|
||||
this.EndActivity();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,7 +61,7 @@ namespace MonoStockPortfolio.Activites
|
|||
return true;
|
||||
}
|
||||
|
||||
Toast.MakeText(this, result, ToastLength.Long).Show();
|
||||
this.LongToast(result);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -84,7 +80,7 @@ namespace MonoStockPortfolio.Activites
|
|||
private Position GetPositionToSave()
|
||||
{
|
||||
Position positionToSave;
|
||||
var positionId = Intent.GetLongExtra(Extra_PortfolioID, -1);
|
||||
var positionId = ThisPositionId;
|
||||
if (positionId != -1)
|
||||
{
|
||||
positionToSave = new Position(positionId);
|
||||
|
@ -97,7 +93,7 @@ namespace MonoStockPortfolio.Activites
|
|||
positionToSave.Shares = decimal.Parse(SharesTextBox.Text.ToString());
|
||||
positionToSave.PricePerShare = decimal.Parse(PriceTextBox.Text.ToString());
|
||||
positionToSave.Ticker = TickerTextBox.Text.ToString();
|
||||
positionToSave.ContainingPortfolioID = Intent.GetLongExtra(Extra_PortfolioID, -1);
|
||||
positionToSave.ContainingPortfolioID = ThisPortfolioId;
|
||||
return positionToSave;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,9 @@ namespace MonoStockPortfolio.Activites
|
|||
{
|
||||
public static string ClassName { get { return "monostockportfolio.activites.EditPositionActivity"; } }
|
||||
public static string Extra_PortfolioID { get { return "monoStockPortfolio.EditPositionActivity.PortfolioID"; } }
|
||||
public long ThisPortfolioId { get { return Intent.GetLongExtra(Extra_PortfolioID, -1); } }
|
||||
public static string Extra_PositionID { get { return "monoStockPortfolio.EditPositionActivity.PositionID"; } }
|
||||
public long ThisPositionId { get { return Intent.GetLongExtra(Extra_PositionID, -1); } }
|
||||
|
||||
protected EditText TickerTextBox { get { return FindViewById<EditText>(Resource.id.addPositionTicker); } }
|
||||
protected EditText PriceTextBox { get { return FindViewById<EditText>(Resource.id.addPositionPrice); } }
|
||||
|
|
|
@ -6,7 +6,6 @@ using Android.Content;
|
|||
using Android.OS;
|
||||
using Android.Widget;
|
||||
using MonoStockPortfolio.Core.PortfolioRepositories;
|
||||
using MonoStockPortfolio.Core.Services;
|
||||
using MonoStockPortfolio.Entities;
|
||||
using MonoStockPortfolio.Framework;
|
||||
|
||||
|
@ -15,7 +14,6 @@ namespace MonoStockPortfolio.Activites
|
|||
[Activity(Label = "Stock Portfolio", MainLauncher = true, Icon = "@drawable/icon")]
|
||||
public partial class MainActivity : Activity
|
||||
{
|
||||
[IoC] private IPortfolioService _svc;
|
||||
[IoC] private IPortfolioRepository _repo;
|
||||
|
||||
private IList<Portfolio> _portfolios;
|
||||
|
@ -33,7 +31,7 @@ namespace MonoStockPortfolio.Activites
|
|||
|
||||
private void RefreshList()
|
||||
{
|
||||
_portfolios = _svc.GetAllPortfolios();
|
||||
_portfolios = _repo.GetAllPortfolios();
|
||||
|
||||
var listAdapter = new ArrayAdapter<string>(this, Android.R.Layout.SimpleListItem1, _portfolios.Select(p => p.Name).ToList());
|
||||
PortfolioListView.Adapter = listAdapter;
|
||||
|
|
|
@ -12,7 +12,6 @@ using MonoStockPortfolio.Core.PortfolioRepositories;
|
|||
using MonoStockPortfolio.Core.Services;
|
||||
using MonoStockPortfolio.Entities;
|
||||
using MonoStockPortfolio.Framework;
|
||||
using Orientation = Android.Widget.Orientation;
|
||||
|
||||
namespace MonoStockPortfolio.Activites
|
||||
{
|
||||
|
@ -178,21 +177,10 @@ namespace MonoStockPortfolio.Activites
|
|||
|
||||
private void SetTitle()
|
||||
{
|
||||
var portfolio = _svc.GetPortolioById(ThisPortofolioId);
|
||||
var portfolio = _repo.GetPortfolioById(ThisPortofolioId);
|
||||
this.Title = "Portfolio: " + portfolio.Name;
|
||||
}
|
||||
|
||||
public static List<StockDataItem> GetStockItemsFromConfig()
|
||||
{
|
||||
// TODO: load this from a config
|
||||
var items = new List<StockDataItem>();
|
||||
items.Add(StockDataItem.Ticker);
|
||||
items.Add(StockDataItem.LastTradePrice);
|
||||
items.Add(StockDataItem.GainLossRealTime);
|
||||
items.Add(StockDataItem.Time);
|
||||
return items;
|
||||
}
|
||||
|
||||
void addPositionButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var intent = new Intent();
|
||||
|
@ -207,5 +195,19 @@ namespace MonoStockPortfolio.Activites
|
|||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static List<StockDataItem> GetStockItemsFromConfig()
|
||||
{
|
||||
// TODO: load this from a config
|
||||
var items = new List<StockDataItem>();
|
||||
items.Add(StockDataItem.Ticker);
|
||||
items.Add(StockDataItem.LastTradePrice);
|
||||
items.Add(StockDataItem.GainLossRealTime);
|
||||
items.Add(StockDataItem.Time);
|
||||
return items;
|
||||
}
|
||||
}
|
||||
}
|
21
MonoStockPortfolio/Framework/ActivityExtensions.cs
Normal file
21
MonoStockPortfolio/Framework/ActivityExtensions.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.Widget;
|
||||
|
||||
namespace MonoStockPortfolio.Framework
|
||||
{
|
||||
public static class ActivityExtensions
|
||||
{
|
||||
public static void EndActivity(this Activity @this)
|
||||
{
|
||||
var intent = new Intent();
|
||||
@this.SetResult(Result.Ok, intent);
|
||||
@this.Finish();
|
||||
}
|
||||
|
||||
public static void LongToast(this Activity @this, string message)
|
||||
{
|
||||
Toast.MakeText(@this, message, ToastLength.Long).Show();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -55,6 +55,7 @@
|
|||
<Compile Include="Activites\EditPortfolioActivity.designer.cs">
|
||||
<DependentUpon>EditPortfolioActivity.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Framework\ActivityExtensions.cs" />
|
||||
<Compile Include="Framework\ContextExtensions.cs" />
|
||||
<Compile Include="Framework\GenericArrayAdapter.cs" />
|
||||
<Compile Include="Framework\IoCAttribute.cs" />
|
||||
|
|
Loading…
Reference in a new issue