Implement song clicking

develop
LEdoian 3 years ago
parent a8d9d7504d
commit 130e6d9573

@ -64,6 +64,7 @@ namespace QuickPlay
// Since this is rather complicated, it is in a separate method // Since this is rather complicated, it is in a separate method
InitializeRecyclerView(); InitializeRecyclerView();
// FIXME: This should be in OnResume...
// Refresh player info // Refresh player info
OnPlayerUpdate(); OnPlayerUpdate();
} }
@ -73,6 +74,7 @@ namespace QuickPlay
recyclerView = FindViewById<Android.Support.V7.Widget.RecyclerView>(Resource.Id.recyclerView1); recyclerView = FindViewById<Android.Support.V7.Widget.RecyclerView>(Resource.Id.recyclerView1);
var layoutStrategy = new LexicographicLayoutStrategy(); var layoutStrategy = new LexicographicLayoutStrategy();
var adapter = new SongRecyclerAdapter(currentPlayer, layoutStrategy); var adapter = new SongRecyclerAdapter(currentPlayer, layoutStrategy);
adapter.SongClick += OnSongClick;
recyclerView.SetAdapter(adapter); recyclerView.SetAdapter(adapter);
var layoutManager = new GridLayoutManager(this, 2, GridLayoutManager.Vertical, false); var layoutManager = new GridLayoutManager(this, 2, GridLayoutManager.Vertical, false);
recyclerView.SetLayoutManager(layoutManager); recyclerView.SetLayoutManager(layoutManager);
@ -141,5 +143,10 @@ namespace QuickPlay
) )
); );
} }
public void OnSongClick(object sender, IPlayable song)
{
throw new NotImplementedException("Song click.");
}
} }
} }

@ -13,6 +13,7 @@ namespace QuickPlay
{ {
class SongRecyclerAdapter : Android.Support.V7.Widget.RecyclerView.Adapter class SongRecyclerAdapter : Android.Support.V7.Widget.RecyclerView.Adapter
{ {
public event EventHandler<IPlayable> SongClick;
IPlayer player; IPlayer player;
ILayoutStrategy layoutStrategy; ILayoutStrategy layoutStrategy;
public SongRecyclerAdapter(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. // I admit I have little idea what I am doing.
View itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.songLayout, parent, false); 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) public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{ {
@ -39,13 +40,19 @@ namespace QuickPlay
List<IPlayable> layout = layoutStrategy.LayOut(player.Songs.Values); List<IPlayable> layout = layoutStrategy.LayOut(player.Songs.Values);
vh.SongName.Text = layout[position].Identifier; 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 class SongRecyclerViewHolder : Android.Support.V7.Widget.RecyclerView.ViewHolder
{ {
public TextView SongName { get; private set; } public TextView SongName { get; private set; }
public SongRecyclerViewHolder(View itemView) : base(itemView) public SongRecyclerViewHolder(View itemView, Action<int> callback) : base(itemView)
{ {
SongName = itemView.FindViewById<TextView>(Resource.Id.songName); SongName = itemView.FindViewById<TextView>(Resource.Id.songName);
itemView.Click += (sender, e) => callback(base.LayoutPosition);
} }
} }
} }
Loading…
Cancel
Save