diff --git a/MonoStockPortfolio.Core/StockData/YahooStockDataProvider.cs b/MonoStockPortfolio.Core/StockData/YahooStockDataProvider.cs index bc89f62..40917d7 100644 --- a/MonoStockPortfolio.Core/StockData/YahooStockDataProvider.cs +++ b/MonoStockPortfolio.Core/StockData/YahooStockDataProvider.cs @@ -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; diff --git a/MonoStockPortfolio/Activites/ConfigActivity.cs b/MonoStockPortfolio/Activites/ConfigActivity.cs index 258e018..1c961a2 100644 --- a/MonoStockPortfolio/Activites/ConfigActivity.cs +++ b/MonoStockPortfolio/Activites/ConfigActivity.cs @@ -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().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(this, Android.Resource.Layout.SimpleListItemMultipleChoice, allitemsLabels); + ConfigList.Adapter = configAdapter; + ConfigList.ChoiceMode = ChoiceMode.Multiple; - 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; - } - - private void saveCallback(object sender, DialogClickEventArgs e) - { - var list = _stockItemsConfig.Where(i => i.IsChecked).Select(i => i.StockDataItem).ToList(); - _repo.UpdateStockItems(list); - } - - private void clickCallback(object sender, DialogMultiChoiceClickEventArgs e) - { - 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 BuildList(IEnumerable checkedItems) + for(int i=0;i(); - - return allitems.Select(item => new StockItemPreference {StockDataItem = item, IsChecked = checkedItems.Contains(item)}); + if (checkeditems.Contains(allitems[i])) + { + ConfigList.SetItemChecked(i, true); + } } - public StockDataItem StockDataItem { get; private set; } - public bool IsChecked { get; set; } + + SaveConfigButton.Click += SaveConfigButton_Click; + } + + void SaveConfigButton_Click(object sender, System.EventArgs e) + { + var allitems = StockDataItem.Volume.GetValues().ToList(); + var newConfig = new List(); + 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()); + return intent; } } } \ No newline at end of file diff --git a/MonoStockPortfolio/Activites/ConfigActivity2.cs b/MonoStockPortfolio/Activites/ConfigActivity2.cs deleted file mode 100644 index 670cd43..0000000 --- a/MonoStockPortfolio/Activites/ConfigActivity2.cs +++ /dev/null @@ -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().ToList(); - var allitemsLabels = allitems.Select(i => i.GetStringValue()).ToList(); - var checkeditems = _repo.GetStockItems(); - - var configAdapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItemMultipleChoice, allitemsLabels); - ConfigList.Adapter = configAdapter; - ConfigList.ChoiceMode = ChoiceMode.Multiple; - - for(int i=0;i().ToList(); - var newConfig = new List(); - 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()); - return intent; - } - } -} \ No newline at end of file diff --git a/MonoStockPortfolio/Activites/MainActivity.cs b/MonoStockPortfolio/Activites/MainActivity.cs index 801e289..f99baa5 100644 --- a/MonoStockPortfolio/Activites/MainActivity.cs +++ b/MonoStockPortfolio/Activites/MainActivity.cs @@ -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); diff --git a/MonoStockPortfolio/MonoStockPortfolio.csproj b/MonoStockPortfolio/MonoStockPortfolio.csproj index c2605b2..50eb85b 100644 --- a/MonoStockPortfolio/MonoStockPortfolio.csproj +++ b/MonoStockPortfolio/MonoStockPortfolio.csproj @@ -49,7 +49,6 @@ - @@ -72,7 +71,7 @@ - + AndroidResource @@ -112,9 +111,6 @@ Designer - - - diff --git a/MonoStockPortfolio/Resources/Resource.Designer.cs b/MonoStockPortfolio/Resources/Resource.Designer.cs index 3d58126..a1cafbf 100644 --- a/MonoStockPortfolio/Resources/Resource.Designer.cs +++ b/MonoStockPortfolio/Resources/Resource.Designer.cs @@ -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() { diff --git a/MonoStockPortfolio/Resources/layout/config.xml b/MonoStockPortfolio/Resources/layout/config.xml index 1962c28..33c4210 100644 --- a/MonoStockPortfolio/Resources/layout/config.xml +++ b/MonoStockPortfolio/Resources/layout/config.xml @@ -1,9 +1,14 @@ - - - - - - \ No newline at end of file + + + +