adjusted onworkerthread--I may not even need all this multithreaded malarkey, but I'll look into that later

This commit is contained in:
mgroves 2011-02-21 23:02:28 -05:00
parent 132655170b
commit 3164d4a3c7
5 changed files with 27 additions and 22 deletions

View file

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Android.Content;
using MonoStockPortfolio.Entities;

View file

@ -57,6 +57,7 @@
<Compile Include="CsvParserTests.cs" />
<Compile Include="GoogleStockQuoteTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="YahooStockDataProviderTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MonoStockPortfolio.Core\MonoStockPortfolio.Core.csproj">

View file

@ -0,0 +1,17 @@
using System.Linq;
using MonoStockPortfolio.Core.StockData;
using Xunit;
namespace MonoStockPortfolio.Tests
{
public class YahooStockDataProviderTests
{
[Fact]
public void Can_get_volume()
{
var svc = new YahooStockDataProvider();
var quote = svc.GetStockQuotes(new[] {"XIN"}).Single();
Assert.True(!string.IsNullOrEmpty(quote.Volume));
}
}
}

View file

@ -1,6 +1,5 @@
using System;
using Android.App;
using Android.Util;
using PostSharp.Aspects;
namespace MonoStockPortfolio.Framework
@ -19,7 +18,6 @@ namespace MonoStockPortfolio.Framework
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));

View file

@ -7,36 +7,26 @@ namespace MonoStockPortfolio.Framework
{
public class OnWorkerThreadAttribute : MethodInterceptionAspect
{
private ProgressDialog _progressDialog;
public override void OnInvoke(MethodInterceptionArgs args)
{
var activity = args.Instance as Activity;
if(activity == null) throw new Exception("OnWorkerThread can only be used on methods in Activity classes");
ShowProgressDialog(activity);
var pd = ShowProgressDialog(activity);
pd.Show();
ThreadPool.QueueUserWorkItem(delegate
{
args.Proceed();
activity.RunOnUiThread(DismissProgressDialog);
activity.RunOnUiThread(pd.Dismiss);
});
}
private void ShowProgressDialog(Activity activity)
private static ProgressDialog ShowProgressDialog(Activity activity)
{
if (_progressDialog == null)
{
var pd = new ProgressDialog(activity);
pd.SetMessage("Loading...Please wait...");
pd.SetProgressStyle(ProgressDialogStyle.Spinner);
_progressDialog = pd;
}
_progressDialog.Show();
}
private void DismissProgressDialog()
{
_progressDialog.Dismiss();
var pd = new ProgressDialog(activity);
pd.SetMessage("Loading...Please wait...");
pd.SetProgressStyle(ProgressDialogStyle.Spinner);
return pd;
}
}
}