mirror of
https://github.com/mgroves/MonodroidStockPortfolio.git
synced 2024-12-24 12:03:02 +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
|
||||
{
|
||||
public class AndroidSqliteConfigRepository : IConfigRepository
|
||||
{
|
||||
public ConfigManager.Config LoadOrCreateConfig()
|
||||
public IEnumerable<StockDataItem> GetStockItems()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SaveConfig(ConfigManager.Config config)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var items = new List<StockDataItem>();
|
||||
items.Add(StockDataItem.Ticker);
|
||||
items.Add(StockDataItem.LastTradePrice);
|
||||
items.Add(StockDataItem.GainLossRealTime);
|
||||
items.Add(StockDataItem.Time);
|
||||
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
|
||||
{
|
||||
public interface IConfigRepository
|
||||
{
|
||||
ConfigManager.Config LoadOrCreateConfig();
|
||||
void SaveConfig(ConfigManager.Config config);
|
||||
IEnumerable<StockDataItem> GetStockItems();
|
||||
}
|
||||
}
|
|
@ -43,7 +43,6 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Config\AndroidSqliteConfigRepository.cs" />
|
||||
<Compile Include="Config\ConfigManager.cs" />
|
||||
<Compile Include="Config\IConfigRepository.cs" />
|
||||
<Compile Include="DictionaryExtensions.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.Widget;
|
||||
using MonoStockPortfolio.Core;
|
||||
using MonoStockPortfolio.Core.Config;
|
||||
using MonoStockPortfolio.Core.PortfolioRepositories;
|
||||
using MonoStockPortfolio.Core.Services;
|
||||
using MonoStockPortfolio.Entities;
|
||||
|
@ -20,6 +21,7 @@ namespace MonoStockPortfolio.Activites
|
|||
{
|
||||
[IoC] private IPortfolioService _svc;
|
||||
[IoC] private IPortfolioRepository _repo;
|
||||
[IoC] private IConfigRepository _config;
|
||||
|
||||
protected override void OnCreate(Bundle bundle)
|
||||
{
|
||||
|
@ -123,10 +125,10 @@ namespace MonoStockPortfolio.Activites
|
|||
QuoteListview.Adapter = listAdapter;
|
||||
}
|
||||
|
||||
private void UpdateHeader(ICollection<StockDataItem> items)
|
||||
private void UpdateHeader(IEnumerable<StockDataItem> items)
|
||||
{
|
||||
QuoteListviewHeader.RemoveAllViews();
|
||||
var cellwidth = this.GetScreenWidth()/items.Count;
|
||||
var cellwidth = this.GetScreenWidth()/items.Count();
|
||||
foreach (var stockDataItem in items)
|
||||
{
|
||||
var textItem = new TextView(this);
|
||||
|
@ -157,7 +159,8 @@ namespace MonoStockPortfolio.Activites
|
|||
|
||||
var row = new LinearLayout(Context);
|
||||
row.Orientation = Orientation.Horizontal;
|
||||
foreach (var stockDataItem in GetStockItemsFromConfig())
|
||||
var portfolioActivity = (PortfolioActivity) Context;
|
||||
foreach (var stockDataItem in portfolioActivity.GetStockItemsFromConfig())
|
||||
{
|
||||
var cell = new TextView(Context);
|
||||
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
|
||||
var items = new List<StockDataItem>();
|
||||
items.Add(StockDataItem.Ticker);
|
||||
items.Add(StockDataItem.LastTradePrice);
|
||||
items.Add(StockDataItem.GainLossRealTime);
|
||||
items.Add(StockDataItem.Time);
|
||||
return items;
|
||||
return _config.GetStockItems();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using Android.Content;
|
||||
using MonoStockPortfolio.Core.Config;
|
||||
using MonoStockPortfolio.Core.PortfolioRepositories;
|
||||
using MonoStockPortfolio.Core.Services;
|
||||
using MonoStockPortfolio.Core.StockData;
|
||||
|
@ -29,6 +30,7 @@ namespace MonoStockPortfolio.Framework
|
|||
container.Register<IStockDataProvider, YahooStockDataProvider>().AsMultiInstance();
|
||||
container.Register<IPortfolioService, PortfolioService>().AsMultiInstance();
|
||||
container.Register<IPortfolioRepository, AndroidSqlitePortfolioRepository>().AsMultiInstance();
|
||||
container.Register<IConfigRepository, AndroidSqliteConfigRepository>().AsMultiInstance();
|
||||
|
||||
return container;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue