Implement VI for Apps menu options
[profile/tv/apps/dotnet/home.git] / TVApps / TVApps / Controls / AppItemCell.xaml.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 LibTVRefCommonPortable.DataModels;
18 using LibTVRefCommonPortable.Utils;
19 using System;
20 using System.ComponentModel;
21 using System.Threading.Tasks;
22 using System.Windows.Input;
23 using Xamarin.Forms;
24
25 namespace TVApps.Controls
26 {
27     /// <summary>
28     /// hahaha
29     /// </summary>
30     public partial class AppItemCell : ViewCell
31     {        
32         public ICommand OnClickedCommand { get; set; }
33
34         public ICommand OnFocusedCommand { get; set; }
35
36         public static readonly BindableProperty IsPinnedProperty = BindableProperty.Create("IsPinned", typeof(bool), typeof(AppItemCell), default(bool));
37         public bool IsPinned
38         {
39             get { return (bool)GetValue(IsPinnedProperty); }
40             set { SetValue(IsPinnedProperty, value); }
41         }
42
43         public static readonly BindableProperty IsCheckedProperty = BindableProperty.Create("IsChecked", typeof(bool), typeof(AppItemCell), default(bool));
44         public bool IsChecked
45         {
46             get { return (bool)GetValue(IsCheckedProperty); }
47             set { SetValue(IsCheckedProperty, value); }
48         }
49
50         public static readonly BindableProperty IsShowOptionsProperty = BindableProperty.Create("IsShowOptions", typeof(bool), typeof(AppItemCell), default(bool));
51         public bool IsShowOptions
52         {
53             get { return (bool)GetValue(IsShowOptionsProperty); }
54             set { SetValue(IsShowOptionsProperty, value); }
55         }
56
57         public static readonly BindableProperty IsDimProperty = BindableProperty.Create("IsDim", typeof(bool), typeof(AppItemCell), default(bool));
58         public bool IsDim
59         {
60             get { return (bool)GetValue(IsDimProperty); }
61             set { SetValue(IsDimProperty, value); }
62         }
63
64         public AppItemCell()
65         {
66             InitializeComponent();
67             PropertyChanged += AppItemCell_PropertyChanged;
68             ButtonTitle.PropertyChanged += ButtonTitle_PropertyChanged;
69         }
70
71         private void AppItemCell_PropertyChanged(object sender, PropertyChangedEventArgs e)
72         {
73             if (e.PropertyName.CompareTo("IsPinned") == 0)
74             {
75                 if (IsPinned)
76                 {
77                     PinnedIcon.FadeTo(0.99, 300);
78                 }
79                 else
80                 {
81                     PinnedIcon.FadeTo(0.0, 300);
82                 }
83
84                 return;
85             }
86             else if (e.PropertyName.CompareTo("IsChecked") == 0)
87             {
88                 if (IsChecked)
89                 {
90                     CheckImage.FadeTo(0.99, 300);
91                     DimImage.FadeTo(0.99, 300);
92                     DimImage.TranslateTo(0.0, 2.0, 300);
93                     DimImage.ScaleTo(1.32, 300);
94                 }
95                 else
96                 {
97                     // TODO : Change Animation (Add Pin Contents Item : Unselected)
98                     CheckImage.FadeTo(0.0, 300);
99                     DimImage.FadeTo(0.0, 300);
100                     DimImage.TranslateTo(0.0, 0.0, 300);
101                     DimImage.ScaleTo(0.0, 300);
102                 }
103
104                 return;
105             }
106             else if (e.PropertyName.CompareTo("IsShowOptions") == 0)
107             {
108
109                 // Set the icon status to default
110                 ButtonImage.ScaleTo(1.0, 50);
111                 ButtonImage.TranslateTo(0.0, 0.0, 100);
112                 TextArea.TranslateTo(0.0, 0.0, 50);
113
114                 if (IsShowOptions)
115                 {
116                     ButtonImage.TranslateTo(0, -80, 100);
117                     TextArea.TranslateTo(0, -80, 100);
118                     TextArea.FadeTo(0.0, 100);
119                     OptionMenuArea.TranslateTo(0, -144, 100);
120                 }
121                 else
122                 {
123                     ButtonImage.TranslateTo(0, 0, 100);
124                     TextArea.TranslateTo(0, 0, 100);
125                     TextArea.FadeTo(0.99, 100);
126                     OptionMenuArea.TranslateTo(0, 0, 100);
127                 }
128             }
129             else if (e.PropertyName.CompareTo("IsDim") == 0)
130             {
131                 if (IsDim)
132                 {
133                     ItemDim.FadeTo(0.5, 100);
134                 }
135                 else
136                 {
137                     ItemDim.FadeTo(0.0, 100);
138                 }
139             }
140         }
141
142         private void ButtonTitle_PropertyChanged(object sender, PropertyChangedEventArgs e)
143         {
144             if (e.PropertyName == "Width")
145             {
146                 TextArea.ForceLayout();
147             }
148         }
149
150         private void OnClicked(object sender, EventArgs e)
151         {
152             OnClickedCommand?.Execute("");
153         }
154
155         private void OnFocused(object sender, EventArgs e)
156         {
157             OnFocusedCommand?.Execute("");
158             ButtonImage.ScaleTo(1.32, 300);
159             ButtonImage.TranslateTo(0.0, 2.0, 300);
160             TextArea.TranslateTo(0.0, 26.0, 300);
161
162             if (IsChecked)
163             {
164                 DimImage.ScaleTo(1.32, 300);
165                 DimImage.TranslateTo(0.0, 2.0, 300);
166                 CheckImage.TranslateTo(0.0, 2.0, 300);
167             }
168         }
169
170         private void OnUnFocused(object sender, EventArgs e)
171         {
172             ButtonImage.ScaleTo(1.0, 300);
173             ButtonImage.TranslateTo(0.0, 0.0, 300);
174             TextArea.TranslateTo(0.0, 0.0, 300);
175
176             if (IsChecked)
177             {
178                 DimImage.ScaleTo(1.0, 300);
179                 DimImage.TranslateTo(0.0, 0.0, 300);
180                 CheckImage.TranslateTo(0.0, 0.0, 300);
181             }
182         }
183     }
184 }