mirror of
https://github.com/mgroves/MonodroidStockPortfolio.git
synced 2024-12-28 03:00:17 +00:00
removed the old config activity (for now)
This commit is contained in:
parent
30c95afa97
commit
0eeae1cfba
8 changed files with 65 additions and 149 deletions
|
@ -28,6 +28,9 @@ namespace MonoStockPortfolio.Core.StockData
|
|||
string url = "http://finance.yahoo.com/d/quotes.csv?s=";
|
||||
url += string.Join("+", tickers.ToArray());
|
||||
url += "&f=";
|
||||
|
||||
// the ordering is important, if it's changed here, it should be changed
|
||||
// in the ParseCsvIntoStockQuotes method too
|
||||
url += TICKER_SYMBOL;
|
||||
url += LAST_TRADE_PRICE_ONLY;
|
||||
url += NAME;
|
||||
|
|
|
@ -3,69 +3,68 @@ using System.Linq;
|
|||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Preferences;
|
||||
using MonoStockPortfolio.Core;
|
||||
using Android.Widget;
|
||||
using MonoStockPortfolio.Core.Config;
|
||||
using MonoStockPortfolio.Entities;
|
||||
using MonoStockPortfolio.Framework;
|
||||
using MonoStockPortfolio.Core;
|
||||
|
||||
namespace MonoStockPortfolio.Activites
|
||||
{
|
||||
[Activity(Label = "Config")]
|
||||
public class ConfigActivity : PreferenceActivity
|
||||
[Activity(Label = "Config", Name = "monostockportfolio.activites.ConfigActivity")]
|
||||
public class ConfigActivity : Activity
|
||||
{
|
||||
[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)
|
||||
{
|
||||
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");
|
||||
customPref.PreferenceClick = customPref_PreferenceClick;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private bool customPref_PreferenceClick(Preference preference)
|
||||
{
|
||||
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;
|
||||
SaveConfigButton.Click += SaveConfigButton_Click;
|
||||
}
|
||||
|
||||
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();
|
||||
_repo.UpdateStockItems(list);
|
||||
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!");
|
||||
}
|
||||
|
||||
private void clickCallback(object sender, DialogMultiChoiceClickEventArgs e)
|
||||
public static Intent GotoIntent(Context context)
|
||||
{
|
||||
var which = int.Parse(e.Which.ToString());
|
||||
_stockItemsConfig[which].IsChecked = e.IsChecked;
|
||||
}
|
||||
|
||||
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; }
|
||||
var intent = new Intent();
|
||||
intent.SetClassName(context, ManifestNames.GetName<ConfigActivity>());
|
||||
return intent;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -95,7 +95,7 @@ namespace MonoStockPortfolio.Activites
|
|||
switch (item.TitleFormatted.ToS())
|
||||
{
|
||||
case "Config":
|
||||
var intent = ConfigActivity2.GotoIntent(this);
|
||||
var intent = ConfigActivity.GotoIntent(this);
|
||||
// var intent = new Intent();
|
||||
// intent.SetClassName(this, ConfigActivity.ClassName);
|
||||
StartActivityForResult(intent, 0);
|
||||
|
|
|
@ -49,7 +49,6 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Activites\ConfigActivity.cs" />
|
||||
<Compile Include="Activites\ConfigActivity2.cs" />
|
||||
<Compile Include="Activites\EditPortfolioActivity.cs" />
|
||||
<Compile Include="Framework\ActivityExtensions.cs" />
|
||||
<Compile Include="Framework\ContextExtensions.cs" />
|
||||
|
@ -72,7 +71,7 @@
|
|||
<ItemGroup>
|
||||
<None Include="PostSharp.Custom.targets" />
|
||||
<None Include="Resources\AboutResources.txt" />
|
||||
<AndroidResource Include="Resources\layout\config2.xml">
|
||||
<AndroidResource Include="Resources\layout\config.xml">
|
||||
<SubType>AndroidResource</SubType>
|
||||
</AndroidResource>
|
||||
</ItemGroup>
|
||||
|
@ -112,9 +111,6 @@
|
|||
<SubType>Designer</SubType>
|
||||
</AndroidResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AndroidResource Include="Resources\layout\config.xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<AndroidResource Include="Resources\drawable-hdpi\ic_menu_refresh.png" />
|
||||
|
|
|
@ -97,13 +97,10 @@ namespace MonoStockPortfolio
|
|||
public const int config = 2130903042;
|
||||
|
||||
// aapt resource value: 0x7f030003
|
||||
public const int config2 = 2130903043;
|
||||
public const int main = 2130903043;
|
||||
|
||||
// aapt resource value: 0x7f030004
|
||||
public const int main = 2130903044;
|
||||
|
||||
// aapt resource value: 0x7f030005
|
||||
public const int portfolio = 2130903045;
|
||||
public const int portfolio = 2130903044;
|
||||
|
||||
private Layout()
|
||||
{
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<PreferenceCategory android:title="General Settings">
|
||||
<Preference
|
||||
android:title="Stock Items"
|
||||
android:summary="Which columns do you want to see?"
|
||||
android:key="customStockItems" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
<?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>
|
||||
|
|
|
@ -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>
|
Loading…
Reference in a new issue