14e553ad757a7dfc95ccfb641055eafeac61c9f8
[platform/core/csapi/tizenfx.git] / test / NUITizenGallery / Examples / CollectionViewTest / Animals.cs
1 /*
2  * Copyright(c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using System;
19 using System.Collections.Generic;
20 using System.Collections.ObjectModel;
21 using System.ComponentModel;
22 using Tizen.NUI;
23 using Tizen.NUI.Binding;
24
25 public class Animal : INotifyPropertyChanged
26 {
27     private string _name;
28     private string _scientificName;
29     private string _imageUrl = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "/images/animals/";
30
31     public event PropertyChangedEventHandler PropertyChanged;
32     private void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); }
33
34
35     public Animal(string name, string scientificName)
36     {
37         _name = name;
38         _scientificName = scientificName;
39     }
40
41     public string Name
42     {
43         get => _name;
44         set
45         {
46             _name = value;
47             OnPropertyChanged("Name");
48         }
49     }
50
51     public string ScientificName
52     {
53         get => _scientificName;
54         set
55         {
56             _scientificName = value;
57             OnPropertyChanged("ScientificName");
58         }
59     }
60
61     public string ImagePath
62     {
63         get
64         {
65             string filename = _name.Replace(" ", "");
66             filename = filename.ToLower() + ".jpg";
67             return _imageUrl + filename;
68         }
69     }
70 }
71
72
73 public class Animals
74 {
75     (string Name,string ScientificName)[] namePool = {
76     ("Bald Eagle", "Haliaeetus leucocephalus"),
77     ("Bear", "Ursidae"),
78     ("Cat", "Felis catus"),
79     ("Chicken", "Gallus gallus domesticus"),
80     ("Cow", "Bos taurus"),
81     ("Deer", "Cervidae"),
82     ("Dog", "Canis lupus familiaris"),
83     ("Duck", "Anatidae"),
84     ("Elephant", "Elephantidae"),
85     ("Emperor Penguin", "Aptenodytes forsteri"),
86     ("Giraffe", "Giraffa"),
87     ("Horse", "Equus ferus"),
88     ("Leopard", "Panthera pardus"),
89     ("Lion", "Panthera leo"),
90     ("Panda", "Ailuropoda melanoleuca"),
91     ("Peacock", "Pavo cristatus"),
92     ("Pig", "Sus scrofa domesticus"),
93     ("Pigeon", "Columba livia"),
94     ("Red Fox", "Vulpes vulpes"),
95     ("Seagull", "Larus canus"),
96     ("Squirrel", "Sciurus vulgaris"),
97     ("Tiger", "Panthera tigris"),
98     ("Wolf", "Canis lupus"),
99     ("Zebra", "Hippotigris"),
100 };
101     public ObservableCollection<Animal> Source {get; private set; } = new ObservableCollection<Animal>();
102
103     public Animals()
104     {
105         for (int i = 0; i < namePool.Length; i++)
106             Source.Add(new Animal(namePool[i].Name, namePool[i].ScientificName));
107     }
108 }