mirror of
https://github.com/mgroves/MonodroidStockPortfolio.git
synced 2025-01-12 11:15:47 +00:00
refactored config repository stuff
This commit is contained in:
parent
e13925d949
commit
8de53824b0
7 changed files with 23 additions and 78 deletions
|
@ -1,17 +1,18 @@
|
||||||
using System;
|
using System.Collections.Generic;
|
||||||
|
using MonoStockPortfolio.Entities;
|
||||||
|
|
||||||
namespace MonoStockPortfolio.Core.Config
|
namespace MonoStockPortfolio.Core.Config
|
||||||
{
|
{
|
||||||
public class AndroidSqliteConfigRepository : IConfigRepository
|
public class AndroidSqliteConfigRepository : IConfigRepository
|
||||||
{
|
{
|
||||||
public ConfigManager.Config LoadOrCreateConfig()
|
public IEnumerable<StockDataItem> GetStockItems()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var items = new List<StockDataItem>();
|
||||||
}
|
items.Add(StockDataItem.Ticker);
|
||||||
|
items.Add(StockDataItem.LastTradePrice);
|
||||||
public void SaveConfig(ConfigManager.Config config)
|
items.Add(StockDataItem.GainLossRealTime);
|
||||||
{
|
items.Add(StockDataItem.Time);
|
||||||
throw new NotImplementedException();
|
return items;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,54 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using MonoStockPortfolio.Core.Services;
|
|
||||||
using MonoStockPortfolio.Core.Config;
|
|
||||||
using MonoStockPortfolio.Entities;
|
|
||||||
|
|
||||||
namespace MonoStockPortfolio.Core.Config
|
|
||||||
{
|
|
||||||
public class ConfigManager
|
|
||||||
{
|
|
||||||
public class Config
|
|
||||||
{
|
|
||||||
public Config()
|
|
||||||
{
|
|
||||||
StockDetailItems = new List<StockDataItem>();
|
|
||||||
}
|
|
||||||
public IList<StockDataItem> StockDetailItems { get; set; }
|
|
||||||
public bool AgreedToTermsOfService { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private IConfigRepository _repo;
|
|
||||||
private Config _config;
|
|
||||||
|
|
||||||
public ConfigManager() : this(new AndroidSqliteConfigRepository()) {}
|
|
||||||
|
|
||||||
public ConfigManager(IConfigRepository repository)
|
|
||||||
{
|
|
||||||
_repo = repository;
|
|
||||||
_config = _repo.LoadOrCreateConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool AgreedToTos
|
|
||||||
{
|
|
||||||
get {
|
|
||||||
return _config.AgreedToTermsOfService;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_config.AgreedToTermsOfService = value;
|
|
||||||
_repo.SaveConfig(_config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateStockDetailItems(IList<StockDataItem> newStockDetailItems)
|
|
||||||
{
|
|
||||||
_config.StockDetailItems = newStockDetailItems;
|
|
||||||
_repo.SaveConfig(_config);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<StockDataItem> GetStockDetailItems()
|
|
||||||
{
|
|
||||||
return _config.StockDetailItems;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,8 +1,10 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using MonoStockPortfolio.Entities;
|
||||||
|
|
||||||
namespace MonoStockPortfolio.Core.Config
|
namespace MonoStockPortfolio.Core.Config
|
||||||
{
|
{
|
||||||
public interface IConfigRepository
|
public interface IConfigRepository
|
||||||
{
|
{
|
||||||
ConfigManager.Config LoadOrCreateConfig();
|
IEnumerable<StockDataItem> GetStockItems();
|
||||||
void SaveConfig(ConfigManager.Config config);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -43,7 +43,6 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Config\AndroidSqliteConfigRepository.cs" />
|
<Compile Include="Config\AndroidSqliteConfigRepository.cs" />
|
||||||
<Compile Include="Config\ConfigManager.cs" />
|
|
||||||
<Compile Include="Config\IConfigRepository.cs" />
|
<Compile Include="Config\IConfigRepository.cs" />
|
||||||
<Compile Include="DictionaryExtensions.cs" />
|
<Compile Include="DictionaryExtensions.cs" />
|
||||||
<Compile Include="EnumExtensions.cs" />
|
<Compile Include="EnumExtensions.cs" />
|
||||||
|
|
|
@ -229,6 +229,4 @@ namespace MonoStockPortfolio.Core.PortfolioRepositories
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -8,6 +8,7 @@ using Android.OS;
|
||||||
using Android.Views;
|
using Android.Views;
|
||||||
using Android.Widget;
|
using Android.Widget;
|
||||||
using MonoStockPortfolio.Core;
|
using MonoStockPortfolio.Core;
|
||||||
|
using MonoStockPortfolio.Core.Config;
|
||||||
using MonoStockPortfolio.Core.PortfolioRepositories;
|
using MonoStockPortfolio.Core.PortfolioRepositories;
|
||||||
using MonoStockPortfolio.Core.Services;
|
using MonoStockPortfolio.Core.Services;
|
||||||
using MonoStockPortfolio.Entities;
|
using MonoStockPortfolio.Entities;
|
||||||
|
@ -20,6 +21,7 @@ namespace MonoStockPortfolio.Activites
|
||||||
{
|
{
|
||||||
[IoC] private IPortfolioService _svc;
|
[IoC] private IPortfolioService _svc;
|
||||||
[IoC] private IPortfolioRepository _repo;
|
[IoC] private IPortfolioRepository _repo;
|
||||||
|
[IoC] private IConfigRepository _config;
|
||||||
|
|
||||||
protected override void OnCreate(Bundle bundle)
|
protected override void OnCreate(Bundle bundle)
|
||||||
{
|
{
|
||||||
|
@ -123,10 +125,10 @@ namespace MonoStockPortfolio.Activites
|
||||||
QuoteListview.Adapter = listAdapter;
|
QuoteListview.Adapter = listAdapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateHeader(ICollection<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);
|
||||||
|
@ -157,7 +159,8 @@ namespace MonoStockPortfolio.Activites
|
||||||
|
|
||||||
var row = new LinearLayout(Context);
|
var row = new LinearLayout(Context);
|
||||||
row.Orientation = Orientation.Horizontal;
|
row.Orientation = Orientation.Horizontal;
|
||||||
foreach (var stockDataItem in GetStockItemsFromConfig())
|
var portfolioActivity = (PortfolioActivity) Context;
|
||||||
|
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];
|
||||||
|
@ -199,15 +202,9 @@ namespace MonoStockPortfolio.Activites
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static List<StockDataItem> GetStockItemsFromConfig()
|
public IEnumerable<StockDataItem> GetStockItemsFromConfig()
|
||||||
{
|
{
|
||||||
// TODO: load this from a config
|
return _config.GetStockItems();
|
||||||
var items = new List<StockDataItem>();
|
|
||||||
items.Add(StockDataItem.Ticker);
|
|
||||||
items.Add(StockDataItem.LastTradePrice);
|
|
||||||
items.Add(StockDataItem.GainLossRealTime);
|
|
||||||
items.Add(StockDataItem.Time);
|
|
||||||
return items;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
|
using MonoStockPortfolio.Core.Config;
|
||||||
using MonoStockPortfolio.Core.PortfolioRepositories;
|
using MonoStockPortfolio.Core.PortfolioRepositories;
|
||||||
using MonoStockPortfolio.Core.Services;
|
using MonoStockPortfolio.Core.Services;
|
||||||
using MonoStockPortfolio.Core.StockData;
|
using MonoStockPortfolio.Core.StockData;
|
||||||
|
@ -29,6 +30,7 @@ namespace MonoStockPortfolio.Framework
|
||||||
container.Register<IStockDataProvider, YahooStockDataProvider>().AsMultiInstance();
|
container.Register<IStockDataProvider, YahooStockDataProvider>().AsMultiInstance();
|
||||||
container.Register<IPortfolioService, PortfolioService>().AsMultiInstance();
|
container.Register<IPortfolioService, PortfolioService>().AsMultiInstance();
|
||||||
container.Register<IPortfolioRepository, AndroidSqlitePortfolioRepository>().AsMultiInstance();
|
container.Register<IPortfolioRepository, AndroidSqlitePortfolioRepository>().AsMultiInstance();
|
||||||
|
container.Register<IConfigRepository, AndroidSqliteConfigRepository>().AsMultiInstance();
|
||||||
|
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue