d2224042597d427dcf178dc7d62706da2721cd2c
[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, 50);
112                 TextArea.TranslateTo(0.0, 0.0, 50);
113
114                 if (IsShowOptions)
115                 {
116                     ButtonImage.TranslateTo(0, -50, 100);
117                     TextArea.TranslateTo(0, -50, 100);
118                     TextArea.FadeTo(0.0, 100);
119                 }
120                 else
121                 {
122                     ButtonImage.TranslateTo(0, 0, 100);
123                     TextArea.TranslateTo(0, 0, 100);
124                     TextArea.FadeTo(0.99, 100);
125                 }
126             }
127             else if (e.PropertyName.CompareTo("IsDim") == 0)
128             {
129                 if (IsDim)
130                 {
131                     ItemDim.FadeTo(0.5, 100);
132                 }
133                 else
134                 {
135                     ItemDim.FadeTo(0.0, 100);
136                 }
137             }
138         }
139
140         private void ButtonTitle_PropertyChanged(object sender, PropertyChangedEventArgs e)
141         {
142             if (e.PropertyName == "Width")
143             {
144                 TextArea.ForceLayout();
145             }
146         }
147
148         private void OnClicked(object sender, EventArgs e)
149         {
150             OnClickedCommand?.Execute("");
151         }
152
153         private void OnFocused(object sender, EventArgs e)
154         {
155             OnFocusedCommand?.Execute("");
156             ButtonImage.ScaleTo(1.32, 300);
157             ButtonImage.TranslateTo(0.0, 2.0, 300);
158             TextArea.TranslateTo(0.0, 26.0, 300);
159
160             if (IsChecked)
161             {
162                 DimImage.ScaleTo(1.32, 300);
163                 DimImage.TranslateTo(0.0, 2.0, 300);
164                 CheckImage.TranslateTo(0.0, 2.0, 300);
165             }
166         }
167
168         private void OnUnFocused(object sender, EventArgs e)
169         {
170             ButtonImage.ScaleTo(1.0, 300);
171             ButtonImage.TranslateTo(0.0, 0.0, 300);
172             TextArea.TranslateTo(0.0, 0.0, 300);
173
174             if (IsChecked)
175             {
176                 DimImage.ScaleTo(1.0, 300);
177                 DimImage.TranslateTo(0.0, 0.0, 300);
178                 CheckImage.TranslateTo(0.0, 0.0, 300);
179             }
180         }
181     }
182 }