MonodroidStockPortfolio/MonoStockPortfolio/Activites/ConfigActivity.cs

70 lines
2.4 KiB
C#
Raw Normal View History

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