created LazyView aspect, removed the '.designer' file for MainActivity

This commit is contained in:
mgroves 2011-02-20 12:05:36 -05:00
parent cc72b84404
commit 0a68bf1518
4 changed files with 37 additions and 18 deletions

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

@ -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" />