diff --git a/QuickPlay/MainActivity.cs b/QuickPlay/MainActivity.cs index fd86f36..be7b912 100644 --- a/QuickPlay/MainActivity.cs +++ b/QuickPlay/MainActivity.cs @@ -64,6 +64,7 @@ namespace QuickPlay // Since this is rather complicated, it is in a separate method InitializeRecyclerView(); + // FIXME: This should be in OnResume... // Refresh player info OnPlayerUpdate(); } @@ -73,6 +74,7 @@ namespace QuickPlay recyclerView = FindViewById(Resource.Id.recyclerView1); var layoutStrategy = new LexicographicLayoutStrategy(); var adapter = new SongRecyclerAdapter(currentPlayer, layoutStrategy); + adapter.SongClick += OnSongClick; recyclerView.SetAdapter(adapter); var layoutManager = new GridLayoutManager(this, 2, GridLayoutManager.Vertical, false); recyclerView.SetLayoutManager(layoutManager); @@ -141,5 +143,10 @@ namespace QuickPlay ) ); } + + public void OnSongClick(object sender, IPlayable song) + { + throw new NotImplementedException("Song click."); + } } } diff --git a/QuickPlay/SongRecycler.cs b/QuickPlay/SongRecycler.cs index 39fbd88..16adad4 100644 --- a/QuickPlay/SongRecycler.cs +++ b/QuickPlay/SongRecycler.cs @@ -13,6 +13,7 @@ namespace QuickPlay { class SongRecyclerAdapter : Android.Support.V7.Widget.RecyclerView.Adapter { + public event EventHandler SongClick; IPlayer player; ILayoutStrategy layoutStrategy; public SongRecyclerAdapter(IPlayer player, ILayoutStrategy layoutStrategy) @@ -31,7 +32,7 @@ namespace QuickPlay { // I admit I have little idea what I am doing. View itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.songLayout, parent, false); - return new SongRecyclerViewHolder(itemView); + return new SongRecyclerViewHolder(itemView, OnItemClick); } public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position) { @@ -39,13 +40,19 @@ namespace QuickPlay List layout = layoutStrategy.LayOut(player.Songs.Values); vh.SongName.Text = layout[position].Identifier; } + void OnItemClick(int position) + { + IPlayable playable = layoutStrategy.LayOut(player.Songs.Values)[position]; + if (SongClick != null) SongClick.Invoke(this, playable); + } } class SongRecyclerViewHolder : Android.Support.V7.Widget.RecyclerView.ViewHolder { public TextView SongName { get; private set; } - public SongRecyclerViewHolder(View itemView) : base(itemView) + public SongRecyclerViewHolder(View itemView, Action callback) : base(itemView) { SongName = itemView.FindViewById(Resource.Id.songName); + itemView.Click += (sender, e) => callback(base.LayoutPosition); } } } \ No newline at end of file