summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core/TableModel.cs
blob: e570b22b96e9984bd7049d221ac1711b6b9b1215 (plain)
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;

namespace Xamarin.Forms
{
	internal abstract class TableModel: ITableModel
	{
		public virtual Cell GetCell(int section, int row)
		{
			object item = GetItem(section, row);
			var cell = item as Cell;
			if (cell != null)
				return cell;

			return new TextCell { Text = item.ToString() };
		}

		public virtual Cell GetHeaderCell(int section)
		{
			return null;
		}

		public abstract object GetItem(int section, int row);

		public abstract int GetRowCount(int section);

		public abstract int GetSectionCount();

		public virtual string[] GetSectionIndexTitles()
		{
			return null;
		}

		public virtual string GetSectionTitle(int section)
		{
			return null;
		}

		public event EventHandler<EventArg<object>> ItemLongPressed;

		public event EventHandler<EventArg<object>> ItemSelected;

		public void RowLongPressed(int section, int row)
		{
			RowLongPressed(GetItem(section, row));
		}

		public void RowLongPressed(object item)
		{
			if (ItemLongPressed != null)
				ItemLongPressed(this, new EventArg<object>(item));

			OnRowLongPressed(item);
		}

		public void RowSelected(int section, int row)
		{
			RowSelected(GetItem(section, row));
		}

		public void RowSelected(object item)
		{
			if (ItemSelected != null)
				ItemSelected(this, new EventArg<object>(item));

			OnRowSelected(item);
		}

		protected virtual void OnRowLongPressed(object item)
		{
		}

		protected virtual void OnRowSelected(object item)
		{
		}
	}
}