mirror of
https://github.com/mgroves/MonodroidStockPortfolio.git
synced 2024-12-29 11:17:07 +00:00
70 lines
No EOL
2.4 KiB
C#
70 lines
No EOL
2.4 KiB
C#
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.ConfigActivity")]
|
|
public class ConfigActivity : 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.config);
|
|
|
|
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<ConfigActivity>());
|
|
return intent;
|
|
}
|
|
}
|
|
} |