[NUI] Introduce CollectionView and related classes. (#2525)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / CollectionViewDemo / Gallery.cs
1 using System;
2 using System.ComponentModel;
3 using System.Collections.Generic;
4 using System.Collections.ObjectModel;
5 using Tizen.NUI.BaseComponents;
6 using Tizen.NUI.Components;
7 using Tizen.NUI.Binding;
8
9
10
11 class Gallery : INotifyPropertyChanged
12 {
13     string sourceDir = Tizen.NUI.Samples.CommonResource.GetDaliResourcePath()+"ItemViewDemo/gallery/gallery-medium-";
14     private int index;
15     private string name;
16     private bool selected;
17
18     public event PropertyChangedEventHandler PropertyChanged;
19
20     private void OnPropertyyChanged(string propertyName)
21     {
22
23         PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
24     }
25
26     public Gallery(int galleryIndex, string galleryName)
27     {
28         index = galleryIndex;
29         name = galleryName;
30     }
31
32     public string Name {
33         get
34         {
35             return name;
36         }
37         set
38         {
39             name = value;
40             OnPropertyyChanged("Name");
41             OnPropertyyChanged("ViewLabel");
42         }
43     }
44     public string ViewLabel
45     {
46         get
47         {
48             return "[" + index + "] : " + name;
49         }
50     }
51
52     public string ImageUrl
53     {
54         get
55         {
56             return sourceDir+(index%20)+".jpg";
57         }
58     }
59
60     public bool Selected {
61         get
62         {
63             return selected;
64         }
65         set
66         {
67             selected = value;
68             OnPropertyyChanged("Selected");
69         }
70     }
71 }
72
73 class Album : ObservableCollection<Gallery>
74 {
75     private int index;
76     private string name;
77     private DateTime date;
78
79     public Album(int albumIndex, string albumName, DateTime albumDate)
80     {
81         index = albumIndex;
82         name = albumName;
83         date = albumDate;
84     }
85
86     public string Title
87     {
88         get
89         {
90             return "[" + index + "] " + name;
91         }
92     }
93
94     public string Date
95     {
96         get
97         {
98             return date.ToLongDateString();
99         }
100     }
101 }
102
103 class GalleryViewModel : ObservableCollection<Gallery>
104 {
105     string[] namePool = {
106         "Cat",
107         "Boy",
108         "Arm muscle",
109         "Girl",
110         "House",
111         "Cafe",
112         "Statue",
113         "Sea",
114         "hosepipe",
115         "Police",
116         "Rainbow",
117         "Icicle",
118         "Tower with the Moon",
119         "Giraffe",
120         "Camel",
121         "Zebra",
122         "Red Light",
123         "Banana",
124         "Lion",
125         "Espresso",
126     };
127     public GalleryViewModel(int count)
128     {
129         CreateData(this, count);
130     }
131
132     public ObservableCollection<Gallery> CreateData(ObservableCollection<Gallery> result , int count)
133     {
134         for (int i = 0; i < count; i++)
135         {
136             result.Add(new Gallery(i, namePool[i%20]));
137         }
138         return result;
139     }
140 }
141
142 class AlbumViewModel : ObservableCollection<Album>
143 {
144     string[] namePool = {
145         "Cat",
146         "Boy",
147         "Arm muscle",
148         "Girl",
149         "House",
150         "Cafe",
151         "Statue",
152         "Sea",
153         "hosepipe",
154         "Police",
155         "Rainbow",
156         "Icicle",
157         "Tower with the Moon",
158         "Giraffe",
159         "Camel",
160         "Zebra",
161         "Red Light",
162         "Banana",
163         "Lion",
164         "Espresso",
165     };
166
167     (string name, DateTime date)[] titlePool = {
168         ("House Move", new DateTime(2021, 2, 26)),
169         ("Covid 19", new DateTime(2020, 1, 20)),
170         ("Porto Trip", new DateTime(2019, 11, 23)),
171         ("Granada Trip", new DateTime(2019, 11, 20)),
172         ("Barcelona Trip", new DateTime(2019, 11, 17)),
173         ("Developer's Day", new DateTime(2019, 11, 16)),
174         ("Tokyo Trip", new DateTime(2019, 7, 5)),
175         ("Otaru Trip", new DateTime(2019, 3, 2)),
176         ("Sapporo Trip", new DateTime(2019, 2, 28)),
177         ("Hakodate Trip", new DateTime(2019, 2, 26)),
178         ("Friend's Wedding", new DateTime(2018, 11, 23)),
179         ("Grandpa Birthday", new DateTime(2018, 9, 14)),
180         ("Family Jeju Trip", new DateTime(2018, 7, 15)),
181         ("HongKong Trip", new DateTime(2018, 3, 30)),
182         ("Mom's Birthday", new DateTime(2017, 12, 21)),
183         ("Buy new Car", new DateTime(2017, 10, 18)),
184         ("Graduation", new DateTime(2017, 6, 30)),
185     };
186
187
188     public AlbumViewModel()
189     {
190         CreateData(this);
191     }
192
193     public ObservableCollection<Album> CreateData(ObservableCollection<Album> result)
194     {
195         for (int i = 0; i < titlePool.Length; i++)
196         {
197             (string name, DateTime date) = titlePool[i];
198             Album cur = new Album(i, name, date);
199             for (int j = 0; j < 20; j++)
200             {
201                 cur.Add(new Gallery(j, namePool[j]));
202             }
203             result.Add(cur);
204         }
205         return result;
206     }
207
208 }