mirror of
https://github.com/mgroves/MonodroidStockPortfolio.git
synced 2024-12-24 12:03:02 +00:00
reorganized activity classes into partials, also changed how IoCAttribute handles a long-running static Context
This commit is contained in:
parent
f5520b1ad5
commit
86a9854c88
11 changed files with 131 additions and 93 deletions
|
@ -10,17 +10,9 @@ using MonoStockPortfolio.Validation;
|
|||
namespace MonoStockPortfolio
|
||||
{
|
||||
[Activity(Label = "Add Position", MainLauncher = false)]
|
||||
public class AddPositionActivity : Activity
|
||||
public partial class AddPositionActivity : Activity
|
||||
{
|
||||
public static string ClassName { get { return "monostockportfolio.AddPositionActivity"; } }
|
||||
public static string Extra_PortfolioID { get { return "monoStockPortfolio.AddPositionActivity.PortfolioID"; } }
|
||||
|
||||
private IPortfolioRepository _repo;
|
||||
|
||||
private EditText TickerTextBox { get { return FindViewById<EditText>(Resource.id.addPositionTicker); } }
|
||||
private EditText PriceTextBox { get { return FindViewById<EditText>(Resource.id.addPositionPrice); } }
|
||||
private EditText SharesTextBox { get { return FindViewById<EditText>(Resource.id.addPositionShares); } }
|
||||
private Button SaveButton { get { return FindViewById<Button>(Resource.id.addPositionSaveButton); } }
|
||||
[IoC] private IPortfolioRepository _repo;
|
||||
|
||||
protected override void OnCreate(Bundle bundle)
|
||||
{
|
||||
|
@ -28,8 +20,6 @@ namespace MonoStockPortfolio
|
|||
|
||||
SetContentView(Resource.layout.addposition);
|
||||
|
||||
_repo = new AndroidSqlitePortfolioRepository(this);
|
||||
|
||||
SaveButton.Click += saveButton_Click;
|
||||
}
|
||||
|
||||
|
|
15
MonoStockPortfolio/AddPositionActivity.designer.cs
generated
Normal file
15
MonoStockPortfolio/AddPositionActivity.designer.cs
generated
Normal file
|
@ -0,0 +1,15 @@
|
|||
using Android.Widget;
|
||||
|
||||
namespace MonoStockPortfolio
|
||||
{
|
||||
public partial class AddPositionActivity
|
||||
{
|
||||
public static string ClassName { get { return "monostockportfolio.AddPositionActivity"; } }
|
||||
public static string Extra_PortfolioID { get { return "monoStockPortfolio.AddPositionActivity.PortfolioID"; } }
|
||||
|
||||
protected EditText TickerTextBox { get { return FindViewById<EditText>(Resource.id.addPositionTicker); } }
|
||||
protected EditText PriceTextBox { get { return FindViewById<EditText>(Resource.id.addPositionPrice); } }
|
||||
protected EditText SharesTextBox { get { return FindViewById<EditText>(Resource.id.addPositionShares); } }
|
||||
protected Button SaveButton { get { return FindViewById<Button>(Resource.id.addPositionSaveButton); } }
|
||||
}
|
||||
}
|
|
@ -10,22 +10,14 @@ using MonoStockPortfolio.Validation;
|
|||
namespace MonoStockPortfolio
|
||||
{
|
||||
[Activity(Label = "Add Portfolio", MainLauncher = false)]
|
||||
public class EditPortfolioActivity : Activity
|
||||
public partial class EditPortfolioActivity : Activity
|
||||
{
|
||||
public static string ClassName { get { return "monostockportfolio.EditPortfolioActivity"; } }
|
||||
public static string Extra_PortfolioID { get { return "monoStockPortfolio.EditPortfolioActivity.PortfolioID"; } }
|
||||
|
||||
private Button SaveButton { get { return FindViewById<Button>(Resource.id.btnSave); } }
|
||||
private EditText PortfolioName { get { return FindViewById<EditText>(Resource.id.portfolioName); } }
|
||||
|
||||
private IPortfolioRepository _repo;
|
||||
[IoC] private IPortfolioRepository _repo;
|
||||
|
||||
protected override void OnCreate(Bundle bundle)
|
||||
{
|
||||
base.OnCreate(bundle);
|
||||
|
||||
_repo = new AndroidSqlitePortfolioRepository(this);
|
||||
|
||||
SetContentView(Resource.layout.addportfolio);
|
||||
|
||||
WireUpEvents();
|
||||
|
|
13
MonoStockPortfolio/EditPortfolioActivity.designer.cs
generated
Normal file
13
MonoStockPortfolio/EditPortfolioActivity.designer.cs
generated
Normal file
|
@ -0,0 +1,13 @@
|
|||
using Android.Widget;
|
||||
|
||||
namespace MonoStockPortfolio
|
||||
{
|
||||
public partial class EditPortfolioActivity
|
||||
{
|
||||
public static string ClassName { get { return "monostockportfolio.EditPortfolioActivity"; } }
|
||||
public static string Extra_PortfolioID { get { return "monoStockPortfolio.EditPortfolioActivity.PortfolioID"; } }
|
||||
|
||||
protected Button SaveButton { get { return FindViewById<Button>(Resource.id.btnSave); } }
|
||||
protected EditText PortfolioName { get { return FindViewById<EditText>(Resource.id.portfolioName); } }
|
||||
}
|
||||
}
|
|
@ -13,7 +13,11 @@ namespace MonoStockPortfolio
|
|||
|
||||
public override void OnGetValue(LocationInterceptionArgs args)
|
||||
{
|
||||
if(_context == null) _context = (Context)args.Instance;
|
||||
if(_context == null)
|
||||
{
|
||||
var activityContext= (Context)args.Instance;
|
||||
_context = activityContext.ApplicationContext.ApplicationContext;
|
||||
}
|
||||
|
||||
var locationType = args.Location.LocationType;
|
||||
var instantiation = GetInstance(locationType);
|
||||
|
@ -24,7 +28,7 @@ namespace MonoStockPortfolio
|
|||
args.ProceedGetValue();
|
||||
}
|
||||
|
||||
private static object GetInstance(Type locationType)
|
||||
private object GetInstance(Type locationType)
|
||||
{
|
||||
if (DependencyMap.ContainsKey(locationType))
|
||||
{
|
||||
|
@ -33,13 +37,13 @@ namespace MonoStockPortfolio
|
|||
return null;
|
||||
}
|
||||
|
||||
private static IDictionary<Type, Func<object>> DependencyMap
|
||||
private IDictionary<Type, Func<object>> DependencyMap
|
||||
{
|
||||
get { return _dependencyMap ?? (_dependencyMap = DefaultDependencies()); }
|
||||
}
|
||||
|
||||
private static IDictionary<Type, Func<object>> _dependencyMap;
|
||||
private static IDictionary<Type, Func<object>> DefaultDependencies()
|
||||
private IDictionary<Type, Func<object>> DefaultDependencies()
|
||||
{
|
||||
var map = new Dictionary<Type, Func<object>>();
|
||||
map.Add(typeof(IPortfolioService), () => new PortfolioService(_context));
|
||||
|
|
|
@ -12,10 +12,8 @@ using MonoStockPortfolio.Entities;
|
|||
namespace MonoStockPortfolio
|
||||
{
|
||||
[Activity(Label = "Stock Portfolio", MainLauncher = true, Icon = "@drawable/icon")]
|
||||
public class MainActivity : Activity
|
||||
public partial class MainActivity : Activity
|
||||
{
|
||||
public static string ClassName { get { return "monostockportfolio.MainActivity"; } }
|
||||
|
||||
[IoC] private IPortfolioService _svc;
|
||||
[IoC] private IPortfolioRepository _repo;
|
||||
|
||||
|
@ -33,9 +31,6 @@ namespace MonoStockPortfolio
|
|||
WireUpEvents();
|
||||
}
|
||||
|
||||
private Button AddPortfolioButton { get { return FindViewById<Button>(Resource.id.btnAddPortfolio); } }
|
||||
private ListView PortfolioListView { get { return FindViewById<ListView>(Resource.id.portfolioList); } }
|
||||
|
||||
private void RefreshList()
|
||||
{
|
||||
_portfolios = _svc.GetAllPortfolios();
|
||||
|
|
12
MonoStockPortfolio/MainActivity.designer.cs
generated
Normal file
12
MonoStockPortfolio/MainActivity.designer.cs
generated
Normal file
|
@ -0,0 +1,12 @@
|
|||
using Android.Widget;
|
||||
|
||||
namespace MonoStockPortfolio
|
||||
{
|
||||
public partial class MainActivity
|
||||
{
|
||||
public static string ClassName { get { return "monostockportfolio.MainActivity"; } }
|
||||
|
||||
protected Button AddPortfolioButton { get { return FindViewById<Button>(Resource.id.btnAddPortfolio); } }
|
||||
protected ListView PortfolioListView { get { return FindViewById<ListView>(Resource.id.portfolioList); } }
|
||||
}
|
||||
}
|
|
@ -48,11 +48,23 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AddPositionActivity.designer.cs">
|
||||
<DependentUpon>AddPositionActivity.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="EditPortfolioActivity.cs" />
|
||||
<Compile Include="EditPortfolioActivity.designer.cs">
|
||||
<DependentUpon>EditPortfolioActivity.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="IoCAttribute.cs" />
|
||||
<Compile Include="MainActivity.designer.cs">
|
||||
<DependentUpon>MainActivity.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="PortfolioActivity.cs" />
|
||||
<Compile Include="MainActivity.cs" />
|
||||
<Compile Include="AddPositionActivity.cs" />
|
||||
<Compile Include="PortfolioActivity.designer.cs">
|
||||
<DependentUpon>PortfolioActivity.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Resources\Resource.Designer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="StringExtensions.cs" />
|
||||
|
|
|
@ -13,23 +13,17 @@ using MonoStockPortfolio.Core.Services;
|
|||
namespace MonoStockPortfolio
|
||||
{
|
||||
[Activity(Label = "Portfolio")]
|
||||
public class PortfolioActivity : Activity
|
||||
public partial class PortfolioActivity : Activity
|
||||
{
|
||||
public static string ClassName { get { return "monostockportfolio.PortfolioActivity"; } }
|
||||
public static string Extra_PortfolioID { get { return "monoStockPortfolio.PortfolioActivity.PortfolioID"; } }
|
||||
private IPortfolioService _svc;
|
||||
[IoC] private IPortfolioService _svc;
|
||||
private IEnumerable<char>[] longClickOptions;
|
||||
|
||||
private long ThisPortofolioId { get { return Intent.GetLongExtra(Extra_PortfolioID, -1); } }
|
||||
|
||||
protected override void OnCreate(Bundle bundle)
|
||||
{
|
||||
base.OnCreate(bundle);
|
||||
|
||||
SetContentView(Resource.layout.portfolio);
|
||||
|
||||
_svc = new PortfolioService(this);
|
||||
|
||||
Refresh();
|
||||
|
||||
WireUpEvents();
|
||||
|
@ -53,8 +47,7 @@ namespace MonoStockPortfolio
|
|||
|
||||
private void RefreshUI(IEnumerable<IDictionary<StockDataItem, string>> tickers)
|
||||
{
|
||||
var tableLayout = FindViewById<TableLayout>(Resource.id.quoteTable);
|
||||
tableLayout.RemoveAllViews();
|
||||
QuoteTable.RemoveAllViews();
|
||||
|
||||
WriteTickerHeader(tickers.First());
|
||||
foreach (var ticker in tickers)
|
||||
|
@ -65,8 +58,7 @@ namespace MonoStockPortfolio
|
|||
|
||||
private void WireUpEvents()
|
||||
{
|
||||
var addPositionButton = FindViewById<Button>(Resource.id.btnAddPosition);
|
||||
addPositionButton.Click += addPositionButton_Click;
|
||||
AddPositionButton.Click += addPositionButton_Click;
|
||||
}
|
||||
|
||||
private void SetTitle()
|
||||
|
@ -119,8 +111,7 @@ namespace MonoStockPortfolio
|
|||
tr.AddView(column);
|
||||
}
|
||||
|
||||
var tableLayout = FindViewById<TableLayout>(Resource.id.quoteTable);
|
||||
tableLayout.AddView(tr, new TableRow.LayoutParams(TableRow.LayoutParams.FillParent, TableRow.LayoutParams.WrapContent));
|
||||
QuoteTable.AddView(tr, new TableRow.LayoutParams(TableRow.LayoutParams.FillParent, TableRow.LayoutParams.WrapContent));
|
||||
}
|
||||
|
||||
private void WriteTickerRow(IDictionary<StockDataItem, string> ticker)
|
||||
|
@ -140,8 +131,7 @@ namespace MonoStockPortfolio
|
|||
tr.AddView(column);
|
||||
}
|
||||
|
||||
var tableLayout = FindViewById<TableLayout>(Resource.id.quoteTable);
|
||||
tableLayout.AddView(tr, new TableRow.LayoutParams(TableRow.LayoutParams.FillParent, TableRow.LayoutParams.WrapContent));
|
||||
QuoteTable.AddView(tr, new TableRow.LayoutParams(TableRow.LayoutParams.FillParent, TableRow.LayoutParams.WrapContent));
|
||||
}
|
||||
|
||||
void tr_LongClick(object sender, Android.Views.View.LongClickEventArgs e)
|
||||
|
|
15
MonoStockPortfolio/PortfolioActivity.designer.cs
generated
Normal file
15
MonoStockPortfolio/PortfolioActivity.designer.cs
generated
Normal file
|
@ -0,0 +1,15 @@
|
|||
using Android.Widget;
|
||||
|
||||
namespace MonoStockPortfolio
|
||||
{
|
||||
public partial class PortfolioActivity
|
||||
{
|
||||
public static string ClassName { get { return "monostockportfolio.PortfolioActivity"; } }
|
||||
|
||||
public static string Extra_PortfolioID { get { return "monoStockPortfolio.PortfolioActivity.PortfolioID"; } }
|
||||
public long ThisPortofolioId { get { return Intent.GetLongExtra(Extra_PortfolioID, -1); } }
|
||||
|
||||
protected TableLayout QuoteTable { get { return FindViewById<TableLayout>(Resource.id.quoteTable); } }
|
||||
protected Button AddPositionButton { get { return FindViewById<Button>(Resource.id.btnAddPosition); } }
|
||||
}
|
||||
}
|
90
MonoStockPortfolio/Resources/Resource.Designer.cs
generated
90
MonoStockPortfolio/Resources/Resource.Designer.cs
generated
|
@ -15,7 +15,7 @@ namespace MonoStockPortfolio
|
|||
public partial class Resource
|
||||
{
|
||||
|
||||
public class attr
|
||||
public partial class attr
|
||||
{
|
||||
|
||||
private attr()
|
||||
|
@ -23,7 +23,7 @@ namespace MonoStockPortfolio
|
|||
}
|
||||
}
|
||||
|
||||
public class drawable
|
||||
public partial class drawable
|
||||
{
|
||||
|
||||
// aapt resource value: 0x7f020000
|
||||
|
@ -34,7 +34,45 @@ namespace MonoStockPortfolio
|
|||
}
|
||||
}
|
||||
|
||||
public class layout
|
||||
public partial class id
|
||||
{
|
||||
|
||||
// aapt resource value: 0x7f050004
|
||||
public const int addPositionPrice = 2131034116;
|
||||
|
||||
// aapt resource value: 0x7f050005
|
||||
public const int addPositionSaveButton = 2131034117;
|
||||
|
||||
// aapt resource value: 0x7f050003
|
||||
public const int addPositionShares = 2131034115;
|
||||
|
||||
// aapt resource value: 0x7f050002
|
||||
public const int addPositionTicker = 2131034114;
|
||||
|
||||
// aapt resource value: 0x7f050006
|
||||
public const int btnAddPortfolio = 2131034118;
|
||||
|
||||
// aapt resource value: 0x7f050008
|
||||
public const int btnAddPosition = 2131034120;
|
||||
|
||||
// aapt resource value: 0x7f050001
|
||||
public const int btnSave = 2131034113;
|
||||
|
||||
// aapt resource value: 0x7f050007
|
||||
public const int portfolioList = 2131034119;
|
||||
|
||||
// aapt resource value: 0x7f050000
|
||||
public const int portfolioName = 2131034112;
|
||||
|
||||
// aapt resource value: 0x7f050009
|
||||
public const int quoteTable = 2131034121;
|
||||
|
||||
private id()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public partial class layout
|
||||
{
|
||||
|
||||
// aapt resource value: 0x7f030000
|
||||
|
@ -54,56 +92,18 @@ namespace MonoStockPortfolio
|
|||
}
|
||||
}
|
||||
|
||||
public class @string
|
||||
public partial class @string
|
||||
{
|
||||
|
||||
// aapt resource value: 0x7f040000
|
||||
public const int hello = 2130968576;
|
||||
|
||||
// aapt resource value: 0x7f040001
|
||||
public const int app_name = 2130968577;
|
||||
|
||||
// aapt resource value: 0x7f040000
|
||||
public const int hello = 2130968576;
|
||||
|
||||
private @string()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class id
|
||||
{
|
||||
|
||||
// aapt resource value: 0x7f050000
|
||||
public const int portfolioName = 2131034112;
|
||||
|
||||
// aapt resource value: 0x7f050001
|
||||
public const int btnSave = 2131034113;
|
||||
|
||||
// aapt resource value: 0x7f050002
|
||||
public const int addPositionTicker = 2131034114;
|
||||
|
||||
// aapt resource value: 0x7f050003
|
||||
public const int addPositionShares = 2131034115;
|
||||
|
||||
// aapt resource value: 0x7f050004
|
||||
public const int addPositionPrice = 2131034116;
|
||||
|
||||
// aapt resource value: 0x7f050005
|
||||
public const int addPositionSaveButton = 2131034117;
|
||||
|
||||
// aapt resource value: 0x7f050006
|
||||
public const int btnAddPortfolio = 2131034118;
|
||||
|
||||
// aapt resource value: 0x7f050007
|
||||
public const int portfolioList = 2131034119;
|
||||
|
||||
// aapt resource value: 0x7f050008
|
||||
public const int btnAddPosition = 2131034120;
|
||||
|
||||
// aapt resource value: 0x7f050009
|
||||
public const int quoteTable = 2131034121;
|
||||
|
||||
private id()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue