removed the old config activity (for now)

This commit is contained in:
mgroves 2011-02-26 11:06:43 -05:00
parent 30c95afa97
commit 0eeae1cfba
8 changed files with 65 additions and 149 deletions

View file

@ -28,6 +28,9 @@ namespace MonoStockPortfolio.Core.StockData
string url = "http://finance.yahoo.com/d/quotes.csv?s="; string url = "http://finance.yahoo.com/d/quotes.csv?s=";
url += string.Join("+", tickers.ToArray()); url += string.Join("+", tickers.ToArray());
url += "&f="; url += "&f=";
// the ordering is important, if it's changed here, it should be changed
// in the ParseCsvIntoStockQuotes method too
url += TICKER_SYMBOL; url += TICKER_SYMBOL;
url += LAST_TRADE_PRICE_ONLY; url += LAST_TRADE_PRICE_ONLY;
url += NAME; url += NAME;

View file

@ -3,69 +3,68 @@ using System.Linq;
using Android.App; using Android.App;
using Android.Content; using Android.Content;
using Android.OS; using Android.OS;
using Android.Preferences; using Android.Widget;
using MonoStockPortfolio.Core;
using MonoStockPortfolio.Core.Config; using MonoStockPortfolio.Core.Config;
using MonoStockPortfolio.Entities; using MonoStockPortfolio.Entities;
using MonoStockPortfolio.Framework; using MonoStockPortfolio.Framework;
using MonoStockPortfolio.Core;
namespace MonoStockPortfolio.Activites namespace MonoStockPortfolio.Activites
{ {
[Activity(Label = "Config")] [Activity(Label = "Config", Name = "monostockportfolio.activites.ConfigActivity")]
public class ConfigActivity : PreferenceActivity public class ConfigActivity : Activity
{ {
[IoC] private IConfigRepository _repo; [IoC] private IConfigRepository _repo;
private StockItemPreference[] _stockItemsConfig;
[LazyView(Resource.Id.configList)] private ListView ConfigList;
[LazyView(Resource.Id.btnSaveConfig)] private Button SaveConfigButton;
protected override void OnCreate(Bundle bundle) protected override void OnCreate(Bundle bundle)
{ {
base.OnCreate(bundle); base.OnCreate(bundle);
AddPreferencesFromResource(Resource.Layout.config); SetContentView(Resource.Layout.config);
_stockItemsConfig = StockItemPreference.BuildList(_repo.GetStockItems()).ToArray(); var allitems = StockDataItem.Volume.GetValues<StockDataItem>().ToList();
var allitemsLabels = allitems.Select(i => i.GetStringValue()).ToList();
var checkeditems = _repo.GetStockItems();
var customPref = FindPreference("customStockItems"); var configAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItemMultipleChoice, allitemsLabels);
customPref.PreferenceClick = customPref_PreferenceClick; ConfigList.Adapter = configAdapter;
ConfigList.ChoiceMode = ChoiceMode.Multiple;
for(int i=0;i<ConfigList.Count;i++)
{
if (checkeditems.Contains(allitems[i]))
{
ConfigList.SetItemChecked(i, true);
}
} }
private bool customPref_PreferenceClick(Preference preference) SaveConfigButton.Click += SaveConfigButton_Click;
{
string[] stockItemsDisplay = _stockItemsConfig.OrderBy(i => i.StockDataItem).Select(i => i.StockDataItem.GetStringValue()).ToArray();
bool[] allitemschecked = _stockItemsConfig.OrderBy(i => i.StockDataItem).Select(i => i.IsChecked).ToArray();
var dialog = new AlertDialog.Builder(this);
dialog.SetMultiChoiceItems(stockItemsDisplay, allitemschecked, clickCallback);
dialog.SetTitle("Select columns");
dialog.SetPositiveButton("Save", saveCallback);
dialog.Create().Show();
return true;
} }
private void saveCallback(object sender, DialogClickEventArgs e) void SaveConfigButton_Click(object sender, System.EventArgs e)
{ {
var list = _stockItemsConfig.Where(i => i.IsChecked).Select(i => i.StockDataItem).ToList(); var allitems = StockDataItem.Volume.GetValues<StockDataItem>().ToList();
_repo.UpdateStockItems(list); var newConfig = new List<StockDataItem>();
for (int i = 0; i < ConfigList.Count; i++)
{
if(ConfigList.IsItemChecked(i))
{
newConfig.Add(allitems[i]);
}
}
_repo.UpdateStockItems(newConfig);
this.LongToast("Configuration updated!");
} }
private void clickCallback(object sender, DialogMultiChoiceClickEventArgs e) public static Intent GotoIntent(Context context)
{ {
var which = int.Parse(e.Which.ToString()); var intent = new Intent();
_stockItemsConfig[which].IsChecked = e.IsChecked; intent.SetClassName(context, ManifestNames.GetName<ConfigActivity>());
} return intent;
public static string ClassName { get { return "monostockportfolio.activites.ConfigActivity"; } }
private class StockItemPreference
{
public static IEnumerable<StockItemPreference> BuildList(IEnumerable<StockDataItem> checkedItems)
{
var allitems = StockDataItem.Change.GetValues<StockDataItem>();
return allitems.Select(item => new StockItemPreference {StockDataItem = item, IsChecked = checkedItems.Contains(item)});
}
public StockDataItem StockDataItem { get; private set; }
public bool IsChecked { get; set; }
} }
} }
} }

View file

@ -1,70 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Widget;
using MonoStockPortfolio.Core.Config;
using MonoStockPortfolio.Entities;
using MonoStockPortfolio.Framework;
using MonoStockPortfolio.Core;
namespace MonoStockPortfolio.Activites
{
[Activity(Label = "Config", Name = "monostockportfolio.activites.ConfigActivity2")]
public class ConfigActivity2 : Activity
{
[IoC] private IConfigRepository _repo;
[LazyView(Resource.Id.configList)] private ListView ConfigList;
[LazyView(Resource.Id.btnSaveConfig)] private Button SaveConfigButton;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.config2);
var allitems = StockDataItem.Volume.GetValues<StockDataItem>().ToList();
var allitemsLabels = allitems.Select(i => i.GetStringValue()).ToList();
var checkeditems = _repo.GetStockItems();
var configAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItemMultipleChoice, allitemsLabels);
ConfigList.Adapter = configAdapter;
ConfigList.ChoiceMode = ChoiceMode.Multiple;
for(int i=0;i<ConfigList.Count;i++)
{
if (checkeditems.Contains(allitems[i]))
{
ConfigList.SetItemChecked(i, true);
}
}
SaveConfigButton.Click += SaveConfigButton_Click;
}
void SaveConfigButton_Click(object sender, System.EventArgs e)
{
var allitems = StockDataItem.Volume.GetValues<StockDataItem>().ToList();
var newConfig = new List<StockDataItem>();
for (int i = 0; i < ConfigList.Count; i++)
{
if(ConfigList.IsItemChecked(i))
{
newConfig.Add(allitems[i]);
}
}
_repo.UpdateStockItems(newConfig);
this.LongToast("Configuration updated!");
}
public static Intent GotoIntent(Context context)
{
var intent = new Intent();
intent.SetClassName(context, ManifestNames.GetName<ConfigActivity2>());
return intent;
}
}
}

View file

@ -95,7 +95,7 @@ namespace MonoStockPortfolio.Activites
switch (item.TitleFormatted.ToS()) switch (item.TitleFormatted.ToS())
{ {
case "Config": case "Config":
var intent = ConfigActivity2.GotoIntent(this); var intent = ConfigActivity.GotoIntent(this);
// var intent = new Intent(); // var intent = new Intent();
// intent.SetClassName(this, ConfigActivity.ClassName); // intent.SetClassName(this, ConfigActivity.ClassName);
StartActivityForResult(intent, 0); StartActivityForResult(intent, 0);

View file

@ -49,7 +49,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Activites\ConfigActivity.cs" /> <Compile Include="Activites\ConfigActivity.cs" />
<Compile Include="Activites\ConfigActivity2.cs" />
<Compile Include="Activites\EditPortfolioActivity.cs" /> <Compile Include="Activites\EditPortfolioActivity.cs" />
<Compile Include="Framework\ActivityExtensions.cs" /> <Compile Include="Framework\ActivityExtensions.cs" />
<Compile Include="Framework\ContextExtensions.cs" /> <Compile Include="Framework\ContextExtensions.cs" />
@ -72,7 +71,7 @@
<ItemGroup> <ItemGroup>
<None Include="PostSharp.Custom.targets" /> <None Include="PostSharp.Custom.targets" />
<None Include="Resources\AboutResources.txt" /> <None Include="Resources\AboutResources.txt" />
<AndroidResource Include="Resources\layout\config2.xml"> <AndroidResource Include="Resources\layout\config.xml">
<SubType>AndroidResource</SubType> <SubType>AndroidResource</SubType>
</AndroidResource> </AndroidResource>
</ItemGroup> </ItemGroup>
@ -112,9 +111,6 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
</AndroidResource> </AndroidResource>
</ItemGroup> </ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\layout\config.xml" />
</ItemGroup>
<ItemGroup /> <ItemGroup />
<ItemGroup> <ItemGroup>
<AndroidResource Include="Resources\drawable-hdpi\ic_menu_refresh.png" /> <AndroidResource Include="Resources\drawable-hdpi\ic_menu_refresh.png" />

View file

@ -97,13 +97,10 @@ namespace MonoStockPortfolio
public const int config = 2130903042; public const int config = 2130903042;
// aapt resource value: 0x7f030003 // aapt resource value: 0x7f030003
public const int config2 = 2130903043; public const int main = 2130903043;
// aapt resource value: 0x7f030004 // aapt resource value: 0x7f030004
public const int main = 2130903044; public const int portfolio = 2130903044;
// aapt resource value: 0x7f030005
public const int portfolio = 2130903045;
private Layout() private Layout()
{ {

View file

@ -1,9 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<PreferenceCategory android:title="General Settings"> android:orientation="vertical"
<Preference android:layout_width="fill_parent"
android:title="Stock Items" android:layout_height="fill_parent">
android:summary="Which columns do you want to see?"
android:key="customStockItems" /> <Button android:text="Save" android:layout_height="wrap_content"
</PreferenceCategory> android:layout_width="fill_parent" android:id="@+id/btnSaveConfig" />
</PreferenceScreen>
<ListView android:id="@+id/configList"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>

View file

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:text="Save" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="@+id/btnSaveConfig" />
<ListView android:id="@+id/configList"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>