diff --git a/MonoStockPortfolio.Entities/Portfolio.cs b/MonoStockPortfolio.Entities/Portfolio.cs index 1183cdc..dc31dbd 100644 --- a/MonoStockPortfolio.Entities/Portfolio.cs +++ b/MonoStockPortfolio.Entities/Portfolio.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; - namespace MonoStockPortfolio.Entities { public class Portfolio @@ -11,11 +7,5 @@ namespace MonoStockPortfolio.Entities public long? ID { get; private set; } public string Name { get; set; } - - public void GetObjectData(SerializationInfo info, StreamingContext context) - { - info.AddValue("ID", this.ID); - info.AddValue("Name", this.Name); - } } } \ No newline at end of file diff --git a/MonoStockPortfolio/Activites/MainScreen/IMainPresenter.cs b/MonoStockPortfolio/Activites/MainScreen/IMainPresenter.cs index 8781f28..36b07b0 100644 --- a/MonoStockPortfolio/Activites/MainScreen/IMainPresenter.cs +++ b/MonoStockPortfolio/Activites/MainScreen/IMainPresenter.cs @@ -10,6 +10,5 @@ void EditPortfolio(int itemId); void GotoConfig(); void ExitApplication(); - int GetPortfolioIdForContextMenu(string selectedPortfolioName); } } \ No newline at end of file diff --git a/MonoStockPortfolio/Activites/MainScreen/IMainView.cs b/MonoStockPortfolio/Activites/MainScreen/IMainView.cs index 965f04b..157ca96 100644 --- a/MonoStockPortfolio/Activites/MainScreen/IMainView.cs +++ b/MonoStockPortfolio/Activites/MainScreen/IMainView.cs @@ -1,10 +1,11 @@ using System.Collections.Generic; +using MonoStockPortfolio.Entities; namespace MonoStockPortfolio.Activites.MainScreen { public interface IMainView { - void RefreshList(IList<string> portfolioNames); + void RefreshList(IList<Portfolio> portfolios); void StartAddPortfolioActivity(); void StartViewPortfolioActivity(long portfolioId); void StartEditPortfolioActivity(int itemId); diff --git a/MonoStockPortfolio/Activites/MainScreen/MainActivity.cs b/MonoStockPortfolio/Activites/MainScreen/MainActivity.cs index 57d0622..b95ac56 100644 --- a/MonoStockPortfolio/Activites/MainScreen/MainActivity.cs +++ b/MonoStockPortfolio/Activites/MainScreen/MainActivity.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Android.App; using Android.Content; using Android.OS; @@ -8,6 +9,7 @@ using Android.Widget; using MonoStockPortfolio.Activites.ConfigScreen; using MonoStockPortfolio.Activites.EditPortfolioScreen; using MonoStockPortfolio.Activites.PortfolioScreen; +using MonoStockPortfolio.Entities; using MonoStockPortfolio.Framework; namespace MonoStockPortfolio.Activites.MainScreen @@ -33,9 +35,10 @@ namespace MonoStockPortfolio.Activites.MainScreen #region IMainView implementation - public void RefreshList(IList<string> portfolioNames) + public void RefreshList(IList<Portfolio> portfolios) { - var listAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, portfolioNames); + var portfolioLabels = portfolios.Select(p => p.Name).ToArray(); + var listAdapter = new PortfolioArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, portfolios, portfolioLabels); PortfolioListView.Adapter = listAdapter; } @@ -82,9 +85,7 @@ namespace MonoStockPortfolio.Activites.MainScreen base.OnCreateContextMenu(menu, v, menuInfo); var info = (AdapterView.AdapterContextMenuInfo)menuInfo; - var selectedPortfolioName = ((TextView)info.TargetView).Text.ToS(); - - var id = _presenter.GetPortfolioIdForContextMenu(selectedPortfolioName); + var id = (int)info.Id; menu.SetHeaderTitle("Options".ToJ()); menu.Add(0, id, 1, "Rename".ToJ()); diff --git a/MonoStockPortfolio/Activites/MainScreen/MainPresenter.cs b/MonoStockPortfolio/Activites/MainScreen/MainPresenter.cs index 008ae17..dbd0ff8 100644 --- a/MonoStockPortfolio/Activites/MainScreen/MainPresenter.cs +++ b/MonoStockPortfolio/Activites/MainScreen/MainPresenter.cs @@ -1,7 +1,5 @@ using System.Collections.Generic; -using Android.Runtime; using MonoStockPortfolio.Core.PortfolioRepositories; -using System.Linq; using MonoStockPortfolio.Entities; namespace MonoStockPortfolio.Activites.MainScreen @@ -35,8 +33,7 @@ namespace MonoStockPortfolio.Activites.MainScreen public void RefreshPortfolioList() { _portfolios = null; - var portfolioNames = Portfolios.Select(p => p.Name).ToList(); - _currentView.RefreshList(portfolioNames); + _currentView.RefreshList(Portfolios); } public void AddNewPortfolio() @@ -68,12 +65,5 @@ namespace MonoStockPortfolio.Activites.MainScreen { _currentView.ExitApplication(); } - - public int GetPortfolioIdForContextMenu(string selectedPortfolioName) - { - var selectedPortfolio = _repo.GetPortfolioByName(selectedPortfolioName); - var id = (int)(selectedPortfolio.ID ?? -1); - return id; - } } } \ No newline at end of file diff --git a/MonoStockPortfolio/Activites/MainScreen/PortfolioArrayAdapter.cs b/MonoStockPortfolio/Activites/MainScreen/PortfolioArrayAdapter.cs new file mode 100644 index 0000000..577dedf --- /dev/null +++ b/MonoStockPortfolio/Activites/MainScreen/PortfolioArrayAdapter.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; +using Android.Content; +using Android.Widget; +using MonoStockPortfolio.Entities; + +namespace MonoStockPortfolio.Activites.MainScreen +{ + public class PortfolioArrayAdapter : ArrayAdapter<string> + { + private readonly IList<Portfolio> _results; + + public PortfolioArrayAdapter(Context context, int resource, IList<Portfolio> results, IList<string> labels) + : base(context, resource, labels) + { + _results = results; + } + + public override long GetItemId(int position) + { + return _results[position].ID ?? -1; + } + } +} \ No newline at end of file diff --git a/MonoStockPortfolio/Activites/PortfolioScreen/PositionArrayAdapter.cs b/MonoStockPortfolio/Activites/PortfolioScreen/PositionArrayAdapter.cs index 725d9b5..640f9af 100644 --- a/MonoStockPortfolio/Activites/PortfolioScreen/PositionArrayAdapter.cs +++ b/MonoStockPortfolio/Activites/PortfolioScreen/PositionArrayAdapter.cs @@ -10,7 +10,7 @@ namespace MonoStockPortfolio.Activites.PortfolioScreen { public class PositionArrayAdapter : GenericArrayAdapter<PositionResultsViewModel> { - private IEnumerable<StockDataItem> _configItems; + private readonly IEnumerable<StockDataItem> _configItems; public PositionArrayAdapter(Context context, IEnumerable<PositionResultsViewModel> results, IEnumerable<StockDataItem> configItems) : base(context, results) diff --git a/MonoStockPortfolio/Framework/StringExtensions.cs b/MonoStockPortfolio/Framework/StringExtensions.cs index da04678..bcb9f4b 100644 --- a/MonoStockPortfolio/Framework/StringExtensions.cs +++ b/MonoStockPortfolio/Framework/StringExtensions.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using Java.Lang; -using StringBuilder = System.Text.StringBuilder; namespace MonoStockPortfolio.Framework { diff --git a/MonoStockPortfolio/MonoStockPortfolio.csproj b/MonoStockPortfolio/MonoStockPortfolio.csproj index d388253..d6fa555 100644 --- a/MonoStockPortfolio/MonoStockPortfolio.csproj +++ b/MonoStockPortfolio/MonoStockPortfolio.csproj @@ -66,6 +66,7 @@ <Compile Include="Activites\EditPositionScreen\IEditPositionPresenter.cs" /> <Compile Include="Activites\EditPositionScreen\IEditPositionView.cs" /> <Compile Include="Activites\EditPositionScreen\PositionInputModel.cs" /> + <Compile Include="Activites\MainScreen\PortfolioArrayAdapter.cs" /> <Compile Include="Framework\FormValidator.cs" /> <Compile Include="Activites\MainScreen\IMainPresenter.cs" /> <Compile Include="Activites\MainScreen\IMainView.cs" />