-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListAdapter.cs
104 lines (92 loc) · 3.17 KB
/
ListAdapter.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using AndroidX.RecyclerView.Widget;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Docutain_SDK_Example_Xamarin_Android
{
public class ListItem
{
public int Title { get; set; }
public int Subtitle { get; set; }
public int Icon { get; set; }
public ItemType Type { get; set; }
}
public enum ItemType
{
NONE,
DOCUMENT_SCAN,
DATA_EXTRACTION,
TEXT_RECOGNITION,
PDF_GENERATING,
SETTINGS
}
internal class ListAdapter : RecyclerView.Adapter
{
Context context;
private readonly Action<ListItem> onItemClicked;
private List<ListItem> items = new List<ListItem>
{
new ListItem
{
Title = Resource.String.title_document_scan,
Subtitle = Resource.String.subtitle_document_scan,
Icon = Resource.Drawable.document_scanner,
Type = ItemType.DOCUMENT_SCAN
},
new ListItem
{
Title = Resource.String.title_data_extraction,
Subtitle = Resource.String.subtitle_data_extraction,
Icon = Resource.Drawable.data_extraction,
Type = ItemType.DATA_EXTRACTION
},
new ListItem
{
Title = Resource.String.title_text_recognition,
Subtitle = Resource.String.subtitle_text_recognition,
Icon = Resource.Drawable.ocr,
Type = ItemType.TEXT_RECOGNITION
},
new ListItem
{
Title = Resource.String.title_PDF_generating,
Subtitle = Resource.String.subtitle_PDF_generating,
Icon = Resource.Drawable.pdf,
Type = ItemType.PDF_GENERATING
},
new ListItem {
Title = Resource.String.title_settings,
Subtitle = Resource.String.subtitle_settings,
Icon = Resource.Drawable.settings,
Type = ItemType.SETTINGS
}
};
public ListAdapter(Action<ListItem> onItemClicked)
{
this.onItemClicked = onItemClicked;
}
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
{
View view = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.list_item, parent, false);
return new ListItemViewHolder(view);
}
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
ListItemViewHolder itemViewHolder = (ListItemViewHolder)holder;
ListItem item = items[position];
itemViewHolder.Title.SetText(item.Title);
itemViewHolder.Secondary.SetText(item.Subtitle);
itemViewHolder.Icon.SetImageResource(item.Icon);
holder.ItemView.Click += (sender, e) => onItemClicked(item);
}
public override int ItemCount => items.Count;
}
}