-
Notifications
You must be signed in to change notification settings - Fork 0
/
DashboardAdapter.cs
82 lines (76 loc) · 3.16 KB
/
DashboardAdapter.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
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.Graphics;
using Android.OS;
using Android.Runtime;
using Android.Support.V4.Content;
using Android.Support.V7.Widget;
using Android.Views;
using Android.Views.Animations;
using Android.Widget;
namespace ImageSlider
{
class DashboardAdapter : RecyclerView.Adapter
{
String[] name = { };
int[] colorcode = { };
int[] imagename = { };
int lastPosition = -1;
public event EventHandler<int> ItemClick;
Activity ac;
View itemView;
RecyclerView mRecyclerView;
public DashboardAdapter(String[] name,int [] colorcode,int [] imagename,Activity ac,RecyclerView mRecyclerView)
{
this.name = name;
this.ac = ac;
this.colorcode = colorcode;
this.imagename = imagename;
this.mRecyclerView = mRecyclerView;
}
public override int ItemCount
{
get { return name.Length; }
}
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
PhotoViewHolder photoViewHolder = holder as PhotoViewHolder;
photoViewHolder.Caption.Text = name[position];
//int color = Resource.Color.abc_background_cache_hint_selector_material_dark;
var color = new Color(ContextCompat.GetColor(ac, colorcode[position]));
photoViewHolder.cardview.SetBackgroundColor(color);
photoViewHolder.Image.SetBackgroundResource(imagename[position]);
Animation animation = AnimationUtils.LoadAnimation(ac, (position > lastPosition) ? Resource.Animation.slide_up : Resource.Animation.slide_up);
photoViewHolder.ItemView.StartAnimation(animation);
lastPosition = position;
}
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
{
itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.dashboard_row, parent, false);
PhotoViewHolder vh = new PhotoViewHolder(itemView, OnClick,mRecyclerView);
return vh;
}
private void OnClick(int obj)
{
ItemClick?.Invoke(this, obj);
}
}
public class PhotoViewHolder : RecyclerView.ViewHolder
{
public ImageView Image { get; set; }
public TextView Caption { get; set; }
public LinearLayout cardview { get; set; }
public PhotoViewHolder(View itemview, Action<int> listener,RecyclerView mRecyclerView) : base(itemview)
{
//Image = itemview.FindViewById<ImageView>(Resource.Id.imageView);
Caption = itemview.FindViewById<TextView>(Resource.Id.imagename);
cardview = itemview.FindViewById<LinearLayout>(Resource.Id.cardviewfordashboard);
Image = itemview.FindViewById<ImageView>(Resource.Id.dashobardimage);
itemview.Click += (sender, e) => listener(mRecyclerView.GetChildAdapterPosition((View)sender));
}
}
}