-
Notifications
You must be signed in to change notification settings - Fork 0
/
GistsAdapter.cs
76 lines (63 loc) · 2.4 KB
/
GistsAdapter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Support.V7.View.Menu;
using Android.Support.V7.Widget;
using Android.Views;
using Android.Views.Animations;
using Android.Widget;
namespace GistsNotes
{
public class GistsAdapter : RecyclerView.Adapter
{
private readonly List<DetailedGist> _gists;
private View _itemView;
public override int ItemCount => _gists.Count;
public event EventHandler<int> ItemClick;
public GistsAdapter(List<DetailedGist> gists)
{
_gists = gists;
}
public GistsAdapter() {}
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
var vh = holder as GistHolder;
vh.Avatar.SetImageBitmap(_gists[position].Img);
vh.Login.Text = _gists[position].History.First().User.Login;
vh.Description.Text = _gists[position].Description;
var llm = new LinearLayoutManager(_itemView.Context);
vh.Notes.SetLayoutManager(llm);
vh.Notes.SetAdapter(new NotesAdapter(_gists[position].Notes));
}
private void OnClick(int position)
{
ItemClick?.Invoke(this, position);
}
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
{
_itemView = LayoutInflater.From(parent.Context).
Inflate(Resource.Layout.CardViewGists, parent, false);
var vh = new GistHolder(_itemView, OnClick);
return vh;
}
private class GistHolder : RecyclerView.ViewHolder
{
public TextView Login { get; }
public TextView Description { get; }
public ImageView Avatar { get; }
public RecyclerView Notes { get; }
public GistHolder(View itemView, Action<int> listener) : base(itemView)
{
Login = itemView.FindViewById<TextView>(Resource.Id.login);
Description = itemView.FindViewById<TextView>(Resource.Id.desc);
Avatar = itemView.FindViewById<ImageView>(Resource.Id.avatar);
Notes = itemView.FindViewById<RecyclerView>(Resource.Id.rv);
itemView.Click += (sender, e) => listener(base.Position);
}
}
}
}