Merge branch 'refresh_stocks_thread'

This commit is contained in:
mgroves 2010-12-08 21:04:19 -05:00
commit 8c749c667f
7 changed files with 29 additions and 33 deletions

View file

@ -3,7 +3,6 @@ using System.Collections.Generic;
using Android.Content; using Android.Content;
using Android.Database.Sqlite; using Android.Database.Sqlite;
using Android.Util; using Android.Util;
using Android.Widget;
using MonoStockPortfolio.Entities; using MonoStockPortfolio.Entities;
namespace MonoStockPortfolio.Core.PortfolioRepositories namespace MonoStockPortfolio.Core.PortfolioRepositories
@ -12,7 +11,6 @@ namespace MonoStockPortfolio.Core.PortfolioRepositories
{ {
private OpenHelper _dbHelper; private OpenHelper _dbHelper;
private SQLiteDatabase _db; private SQLiteDatabase _db;
private Context _context;
private const string PORTFOLIO_TABLE_NAME = "Portfolios"; private const string PORTFOLIO_TABLE_NAME = "Portfolios";
private const string DATABASE_NAME = "stockportfolio.db"; private const string DATABASE_NAME = "stockportfolio.db";
private const int DATABASE_VERSION = 1; private const int DATABASE_VERSION = 1;
@ -20,7 +18,6 @@ namespace MonoStockPortfolio.Core.PortfolioRepositories
public AndroidSqlitePortfolioRepository(Context context) public AndroidSqlitePortfolioRepository(Context context)
{ {
_context = context;
_dbHelper = new OpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION); _dbHelper = new OpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION);
_db = _dbHelper.WritableDatabase; _db = _dbHelper.WritableDatabase;
} }

View file

@ -11,18 +11,15 @@ namespace MonoStockPortfolio
[Activity(Label = "Add Portfolio", MainLauncher = false)] [Activity(Label = "Add Portfolio", MainLauncher = false)]
public class AddPortfolioActivity : Activity public class AddPortfolioActivity : Activity
{ {
public AddPortfolioActivity(IntPtr handle) : base(handle) public static string ClassName { get { return "monostockportfolio.AddPortfolioActivity"; } }
{
_repo = new AndroidSqlitePortfolioRepository(this);
}
public static string ClassName { get { return "monoStockPortfolio.AddPortfolioActivity"; } }
private IPortfolioRepository _repo; private IPortfolioRepository _repo;
protected override void OnCreate(Bundle bundle) protected override void OnCreate(Bundle bundle)
{ {
base.OnCreate(bundle); base.OnCreate(bundle);
_repo = new AndroidSqlitePortfolioRepository(this);
SetContentView(Resource.layout.addportfolio); SetContentView(Resource.layout.addportfolio);
WireUpEvents(); WireUpEvents();

View file

@ -12,12 +12,7 @@ namespace MonoStockPortfolio
[Activity(Label = "Add Position", MainLauncher = false)] [Activity(Label = "Add Position", MainLauncher = false)]
public class AddPositionActivity : Activity public class AddPositionActivity : Activity
{ {
public AddPositionActivity(IntPtr handle) : base(handle) public static string ClassName { get { return "monostockportfolio.AddPositionActivity"; } }
{
_repo = new AndroidSqlitePortfolioRepository(this);
}
public static string ClassName { get { return "monoStockPortfolio.AddPositionActivity"; } }
public static string Extra_PortfolioID { get { return "monoStockPortfolio.AddPositionActivity.PortfolioID"; } } public static string Extra_PortfolioID { get { return "monoStockPortfolio.AddPositionActivity.PortfolioID"; } }
private IPortfolioRepository _repo; private IPortfolioRepository _repo;
@ -33,6 +28,8 @@ namespace MonoStockPortfolio
SetContentView(Resource.layout.addposition); SetContentView(Resource.layout.addposition);
_repo = new AndroidSqlitePortfolioRepository(this);
SaveButton.Click += saveButton_Click; SaveButton.Click += saveButton_Click;
} }

View file

@ -13,11 +13,7 @@ namespace MonoStockPortfolio
[Activity(Label = "Stock Portfolio", MainLauncher = true, Icon = "@drawable/icon")] [Activity(Label = "Stock Portfolio", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity public class MainActivity : Activity
{ {
public static string ClassName { get { return "monoStockPortfolio.MainActivity"; } } public static string ClassName { get { return "monostockportfolio.MainActivity"; } }
public MainActivity(IntPtr handle) : base(handle)
{
_svc = new PortfolioService(this);
}
private IPortfolioService _svc; private IPortfolioService _svc;
private IList<Portfolio> _portfolios; private IList<Portfolio> _portfolios;
@ -26,6 +22,8 @@ namespace MonoStockPortfolio
{ {
base.OnCreate(bundle); base.OnCreate(bundle);
_svc = new PortfolioService(this);
SetContentView(Resource.layout.main); SetContentView(Resource.layout.main);
RefreshList(); RefreshList();

View file

@ -14,6 +14,9 @@
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest> <AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile> <AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
<AndroidUseSharedRuntime>True</AndroidUseSharedRuntime>
<AndroidSupportedAbis>armeabi</AndroidSupportedAbis>
<AndroidApplication>true</AndroidApplication>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>

View file

@ -5,6 +5,7 @@ using Android.App;
using Android.Content; using Android.Content;
using Android.Graphics; using Android.Graphics;
using Android.OS; using Android.OS;
using Android.Util;
using Android.Widget; using Android.Widget;
using MonoStockPortfolio.Core; using MonoStockPortfolio.Core;
using MonoStockPortfolio.Core.Services; using MonoStockPortfolio.Core.Services;
@ -14,12 +15,7 @@ namespace MonoStockPortfolio
[Activity(Label = "Portfolio")] [Activity(Label = "Portfolio")]
public class PortfolioActivity : Activity public class PortfolioActivity : Activity
{ {
public PortfolioActivity(IntPtr handle) : base(handle) public static string ClassName { get { return "monostockportfolio.PortfolioActivity"; } }
{
_svc = new PortfolioService(this);
}
public static string ClassName { get { return "monoStockPortfolio.PortfolioActivity"; } }
public static string Extra_PortfolioID { get { return "monoStockPortfolio.PortfolioActivity.PortfolioID"; } } public static string Extra_PortfolioID { get { return "monoStockPortfolio.PortfolioActivity.PortfolioID"; } }
private IPortfolioService _svc; private IPortfolioService _svc;
private IEnumerable<char>[] longClickOptions; private IEnumerable<char>[] longClickOptions;
@ -30,20 +26,28 @@ namespace MonoStockPortfolio
{ {
base.OnCreate(bundle); base.OnCreate(bundle);
try
{
SetContentView(Resource.layout.portfolio); SetContentView(Resource.layout.portfolio);
_svc = new PortfolioService(this);
Refresh(); Refresh();
WireUpEvents(); WireUpEvents();
SetTitle(); SetTitle();
} }
catch (Exception ex)
{
Log.E("EXCEPTION", ex.ToString());
Toast.MakeText(this, ex.ToString(), ToastLength.Long);
}
}
private void Refresh() private void Refresh()
{ {
// TODO: put this in another thread or something, perhaps?
var tickers = _svc.GetDetailedItems(ThisPortofolioId, GetStockItemsFromConfig()); var tickers = _svc.GetDetailedItems(ThisPortofolioId, GetStockItemsFromConfig());
if (tickers.Any()) if (tickers.Any())
{ {
var tableLayout = FindViewById<TableLayout>(Resource.id.quoteTable); var tableLayout = FindViewById<TableLayout>(Resource.id.quoteTable);

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="MonoStockPortfolio.MonoStockPortfolio" android:versionCode="1" android:versionName="1.0"> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.monostockportfolio" android:versionCode="1" android:versionName="1.0">
<application android:label="MonoStockPortfolio"> <application android:label="MonoStockPortfolio">
</application> </application>
<uses-sdk android:minSdkVersion="8" /> <uses-sdk android:minSdkVersion="8" />