You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
QuickPlay/QuickPlay/SongRecycler.cs

57 lines
2.0 KiB
C#

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Support.V7.Widget;
using Android.Views;
using Android.Widget;
using System;
using System.Collections.Generic;
namespace QuickPlay
{
class SongRecyclerAdapter : Android.Support.V7.Widget.RecyclerView.Adapter
{
public event EventHandler<IPlayable> SongClick;
IPlayer player;
ILayoutStrategy layoutStrategy;
public SongRecyclerAdapter(IPlayer player, ILayoutStrategy layoutStrategy)
{
this.player = player;
this.layoutStrategy = layoutStrategy;
}
public override int ItemCount
{
get
{
return player.Songs.Count;
}
}
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
{
// 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, OnItemClick);
}
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
SongRecyclerViewHolder vh = (SongRecyclerViewHolder)holder;
List<IPlayable> 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, Action<int> callback) : base(itemView)
{
SongName = itemView.FindViewById<TextView>(Resource.Id.songName);
itemView.Click += (sender, e) => callback(base.LayoutPosition);
}
}
}