Fix typo error
[profile/tv/apps/dotnet/home.git] / TVHome / TVHome / ViewModels / MainPageViewModel.cs
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 using System;
18 using System.Collections;
19 using System.Collections.Generic;
20 using System.ComponentModel;
21 using System.Windows.Input;
22 using System.Threading.Tasks;
23 using LibTVRefCommonPortable.DataModels;
24 using LibTVRefCommonPortable.Utils;
25 using Xamarin.Forms;
26
27 namespace TVHome.ViewModels
28 {
29     public class MainPageViewModel : INotifyPropertyChanged
30     {
31         public IEnumerable<ShortcutInfo> MainList { get; set; }
32         public IEnumerable<ShortcutInfo> RecentList { get; set; }
33         public IEnumerable<ShortcutInfo> AppList { get; set; }
34         public IEnumerable<ShortcutInfo> SettingsList { get; set; }
35
36         public event PropertyChangedEventHandler PropertyChanged;
37         protected void OnPropertyChanged(string name)
38         {
39             PropertyChangedEventHandler handler = PropertyChanged;
40             if (handler != null)
41             {
42                 handler(this, new PropertyChangedEventArgs(name));
43             }
44         }
45
46         public MainPageViewModel()
47         {
48             string[] AppName = { "Recent", "Apps", "Settings" };
49             // TODO : Revert this before release
50             //string[] AppControlID = { "org.tizen.settings", "org.tizen.apps", "org.tizen.settings" };
51             string[] AppControlID = { "org.tizen.settings", "org.tizen.example.TVApps.TizenTV", "org.tizen.settings" };
52             string[] AppIconPath = { "ic_tizen_home_menu_recent_normal.png", "ic_tizen_home_menu_apps_normal.png", "ic_tizen_home_menu_settings_normal.png" };
53
54             List<ShortcutInfo> TempList = new List<ShortcutInfo>();
55             for (int i = 0; i < 3; i++)
56             {
57                 ShortcutInfo shortcutInfo = new HomeMenuAppShortcutInfo()
58                 {
59                     StateDescriptions =
60                     {
61                         {
62                             "default",
63                             new StateDescription
64                             {
65                                 Label = AppName[i],
66                                 IconPath = AppIconPath[i],
67                                 Action = new AppControlAction()
68                                 {
69                                     AppID = AppControlID[i]
70                                 }
71                             }
72                         },
73                     }
74                 };
75                 shortcutInfo.UpdateState();
76                 TempList.Add(shortcutInfo);
77             }
78
79             MainList = TempList;
80             OnPropertyChanged("MainList");
81
82             MakeRecentButtons();
83
84             DebuggingUtils.Dbg("Reading Apps list");
85             AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsWithDefaultShortcuts();
86             OnPropertyChanged("AppList");
87
88             //SettingsList = TVHomeImpl.GetInstance.AppShortcutControllerInstnace.ReadFromFile();
89             SettingsList = TVHomeImpl.GetInstance.SettingShortcutControllerInstance.GetList();
90             OnPropertyChanged("SettingsList");
91
92             TVHomeImpl.GetInstance.AppShortcutControllerInstance.AddFileSystemChangedListener(TestFunction);
93         }
94
95
96         private void TestFunction(object sender, EventArgs e)
97         {
98             AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsWithDefaultShortcuts();
99             OnPropertyChanged("AppList");
100         }
101
102         private void MakeRecentButtons()
103         {
104             RecentList = TVHomeImpl.GetInstance.RecentShortcutControllerInstance.GetList();
105             if (RecentList != null)
106             {
107                 OnPropertyChanged("RecentList");
108             }
109         }
110
111     }
112 }