Merge branch 'lazy_control_properties' into develop

This commit is contained in:
mgroves 2011-02-20 12:12:34 -05:00
commit 48a6e6a318
10 changed files with 51 additions and 30 deletions

View file

@ -1,6 +1,7 @@
using System;
using Android.App;
using Android.OS;
using Android.Widget;
using MonoStockPortfolio.Core.PortfolioRepositories;
using MonoStockPortfolio.Entities;
using MonoStockPortfolio.Framework;
@ -12,6 +13,9 @@ namespace MonoStockPortfolio.Activites
{
[IoC] private IPortfolioRepository _repo;
[LazyView(Resource.Id.btnSave)] protected Button SaveButton;
[LazyView(Resource.Id.portfolioName)] protected EditText PortfolioName;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);

View file

@ -7,8 +7,5 @@ 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); } }
}
}

View file

@ -1,6 +1,7 @@
using System;
using Android.App;
using Android.OS;
using Android.Widget;
using MonoStockPortfolio.Core.PortfolioRepositories;
using MonoStockPortfolio.Entities;
using MonoStockPortfolio.Framework;
@ -12,6 +13,11 @@ namespace MonoStockPortfolio.Activites
{
[IoC] private IPortfolioRepository _repo;
[LazyView(Resource.Id.addPositionTicker)] protected EditText TickerTextBox;
[LazyView(Resource.Id.addPositionPrice)] protected EditText PriceTextBox;
[LazyView(Resource.Id.addPositionShares)] protected EditText SharesTextBox;
[LazyView(Resource.Id.addPositionSaveButton)] protected Button SaveButton;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);

View file

@ -9,10 +9,5 @@ namespace MonoStockPortfolio.Activites
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); } }
protected EditText SharesTextBox { get { return FindViewById<EditText>(Resource.Id.addPositionShares); } }
protected Button SaveButton { get { return FindViewById<Button>(Resource.Id.addPositionSaveButton); } }
}
}

View file

@ -13,10 +13,13 @@ using MonoStockPortfolio.Framework;
namespace MonoStockPortfolio.Activites
{
[Activity(Label = "Stock Portfolio", MainLauncher = true, Icon = "@drawable/icon")]
public partial class MainActivity : Activity
public class MainActivity : Activity
{
[IoC] private IPortfolioRepository _repo;
[LazyView(Resource.Id.btnAddPortfolio)] protected Button AddPortfolioButton;
[LazyView(Resource.Id.portfolioList)] protected ListView PortfolioListView;
private IList<Portfolio> _portfolios;
protected override void OnCreate(Bundle bundle)
@ -45,7 +48,7 @@ namespace MonoStockPortfolio.Activites
RegisterForContextMenu(PortfolioListView);
}
public override void OnCreateContextMenu(Android.Views.IContextMenu menu, Android.Views.View v, Android.Views.IContextMenuContextMenuInfo menuInfo)
public override void OnCreateContextMenu(IContextMenu menu, View v, IContextMenuContextMenuInfo menuInfo)
{
base.OnCreateContextMenu(menu, v, menuInfo);
@ -59,7 +62,7 @@ namespace MonoStockPortfolio.Activites
menu.Add(0, id, 2, "Delete");
}
public override bool OnContextItemSelected(Android.Views.IMenuItem item)
public override bool OnContextItemSelected(IMenuItem item)
{
if (item.Title.ToS() == "Rename")
{

View file

@ -1,12 +0,0 @@
using Android.Widget;
namespace MonoStockPortfolio.Activites
{
public partial class MainActivity
{
public static string ClassName { get { return "monostockportfolio.activites.MainActivity"; } }
protected Button AddPortfolioButton { get { return FindViewById<Button>(Resource.Id.btnAddPortfolio); } }
protected ListView PortfolioListView { get { return FindViewById<ListView>(Resource.Id.portfolioList); } }
}
}

View file

@ -22,6 +22,10 @@ namespace MonoStockPortfolio.Activites
[IoC] private IPortfolioRepository _repo;
[IoC] private IConfigRepository _config;
[LazyView(Resource.Id.quoteListview)] protected ListView QuoteListview;
[LazyView(Resource.Id.btnAddPosition)] protected Button AddPositionButton;
[LazyView(Resource.Id.quoteHeaderLayout)] protected LinearLayout QuoteListviewHeader;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);

View file

@ -8,9 +8,5 @@ namespace MonoStockPortfolio.Activites
public static string Extra_PortfolioID { get { return "monoStockPortfolio.PortfolioActivity.PortfolioID"; } }
public long ThisPortofolioId { get { return Intent.GetLongExtra(Extra_PortfolioID, -1); } }
protected ListView QuoteListview { get { return FindViewById<ListView>(Resource.Id.quoteListview); } }
protected Button AddPositionButton { get { return FindViewById<Button>(Resource.Id.btnAddPosition); } }
protected LinearLayout QuoteListviewHeader { get { return FindViewById<LinearLayout>(Resource.Id.quoteHeaderLayout); } }
}
}

View file

@ -0,0 +1,30 @@
using System;
using Android.App;
using Android.Util;
using PostSharp.Aspects;
namespace MonoStockPortfolio.Framework
{
public class LazyViewAttribute : LocationInterceptionAspect
{
private readonly int _viewId;
public LazyViewAttribute(int viewId)
{
_viewId = viewId;
}
public override void OnGetValue(LocationInterceptionArgs args)
{
args.ProceedGetValue(); // this actually fetches the field and populates the args.Value
if (args.Value == null)
{
Log.Info("OnGetValue", "FindViewById called for " + args.LocationFullName);
var activity = args.Instance as Activity;
if (activity == null) throw new ArgumentException("LazyViewAttribute can only be used within Activities");
args.SetNewValue(activity.FindViewById(_viewId));
args.ProceedGetValue();
}
}
}
}

View file

@ -59,9 +59,6 @@
<Compile Include="Framework\ActivityExtensions.cs" />
<Compile Include="Framework\ContextExtensions.cs" />
<Compile Include="Framework\GenericArrayAdapter.cs" />
<Compile Include="Activites\MainActivity.designer.cs">
<DependentUpon>MainActivity.cs</DependentUpon>
</Compile>
<Compile Include="Activites\PortfolioActivity.cs" />
<Compile Include="Activites\MainActivity.cs" />
<Compile Include="Activites\EditPositionActivity.cs" />
@ -70,6 +67,7 @@
</Compile>
<Compile Include="Framework\IoCAttribute.cs" />
<Compile Include="Framework\IttyBittyIoC.cs" />
<Compile Include="Framework\LazyViewAttribute.cs" />
<Compile Include="Framework\OnGuiThreadAttribute.cs" />
<Compile Include="Framework\OnWorkerThreadAttribute.cs" />
<Compile Include="Framework\ServiceLocator.cs" />