Modifies Apps Additional Information
[profile/tv/apps/dotnet/home.git] / TVApps / TVApps / Views / FooterNormalStatus.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 Xamarin.Forms;
18 using Tizen.Xamarin.Forms.Extension;
19 using LibTVRefCommonPortable.Utils;
20 using System.Windows.Input;
21 using System;
22 using TVApps.Controls;
23 using System.Collections.Generic;
24
25 namespace TVApps.Views
26 {
27     /// <summary>
28     /// A custom view for displaying footer when CurrentStatus of MainPage is AppsStatus.Default
29     /// </summary>
30     public partial class FooterNormalStatus : RelativeLayout
31     {
32         private bool isPopupShowing = false;
33
34         private DropdownList SortButton;
35         private Button OptionButton;
36
37         /// <summary>
38         /// A command will be executed if the Pin option is selected
39         /// </summary>
40         public static readonly BindableProperty PinAppCommandProperty = BindableProperty.Create("PinAppCommand", typeof(Command), typeof(FooterNormalStatus), null);
41         public ICommand PinAppCommand
42         {
43             get { return (ICommand)GetValue(PinAppCommandProperty); }
44             set { SetValue(PinAppCommandProperty, value); }
45         }
46
47         /// <summary>
48         /// A command will be executed if the Delete option is selected
49         /// </summary>
50         public static readonly BindableProperty DeleteAppCommandProperty = BindableProperty.Create("DeleteAppCommand", typeof(Command), typeof(FooterNormalStatus), null);
51         public ICommand DeleteAppCommand
52         {
53             get { return (ICommand)GetValue(DeleteAppCommandProperty); }
54             set { SetValue(DeleteAppCommandProperty, value); }
55         }
56
57         public static readonly BindableProperty SortOptionIndexCommandProperty = BindableProperty.Create("SortOptionIndexCommand", typeof(Command), typeof(FooterNormalStatus), null);
58         public ICommand SortOptionIndexCommand
59         {
60             get { return (ICommand)GetValue(SortOptionIndexCommandProperty); }
61             set { SetValue(SortOptionIndexCommandProperty, value); }
62         }
63
64         /// <summary>
65         /// A constructor
66         /// </summary>
67         public FooterNormalStatus()
68         {
69             InitializeComponent();
70
71             CreateSortButton();
72             CreateOptionButton();
73         }
74
75         public DropdownList GetSortDropdownList()
76         {
77             return SortButton;
78         }
79
80         private void CreateOptionButton()
81         {
82             OptionButton = new Button()
83             {
84                 Text = "OPTION",
85             };
86             OptionButton.Clicked += OnOptionsClicked;
87
88             this.Children.Add(OptionButton,
89                 heightConstraint: Constraint.Constant(SizeUtils.GetHeightSize(80)),
90                 widthConstraint: Constraint.Constant(SizeUtils.GetWidthSize(300)),
91                 yConstraint: Constraint.Constant(SizeUtils.GetHeightSize(762)),
92                 xConstraint: Constraint.Constant(SizeUtils.GetWidthSize(96 + 1130 + 300 + 2)));
93         }
94
95         private void CreateSortButton()
96         {
97             List<string> SortList = new List<string> { "Newest", "A - Z", "Z - A" };
98
99             SortButton = new DropdownList();
100             SortButton.ItemsSource = SortList;
101             SortButton.SelectedItem = SortList[0];
102
103             SortButton.ItemSelected += (s, e) =>
104             {
105                 if (SortList.Contains(e.SelectedItem.ToString()))
106                 {
107                     SortOptionIndexCommand?.Execute(SortList.IndexOf(e.SelectedItem.ToString()));
108                 }
109             };
110
111             this.Children.Add(SortButton,
112                 heightConstraint: Constraint.Constant(SizeUtils.GetHeightSize(80)),
113                 widthConstraint: Constraint.Constant(SizeUtils.GetWidthSize(300)),
114                 yConstraint: Constraint.Constant(SizeUtils.GetHeightSize(762)),
115                 xConstraint: Constraint.Constant(SizeUtils.GetWidthSize(96 + 1130)));
116         }
117
118         void OnOptionsClicked(object sender, EventArgs e)
119         {
120             if (isPopupShowing)
121             {
122                 return;
123             }
124
125             ContextPopup popup = new ContextPopup
126             {
127                 IsAutoHidingEnabled = true,
128                 Orientation = ContextPopupOrientation.Vertical,
129                 DirectionPriorities = new ContextPopupDirectionPriorities(ContextPopupDirection.Up, ContextPopupDirection.Right, ContextPopupDirection.Left, ContextPopupDirection.Down),
130             };
131
132             popup.Items.Add(new ContextPopupItem("PIN"));
133             popup.Items.Add(new ContextPopupItem("          DELETE          "));
134
135             //TODO: need to change the event callback
136             popup.SelectedIndexChanged += (s, args) =>
137             {
138                 var ctxPopup = s as ContextPopup;
139
140                 DebuggingUtils.Dbg("selected item : " + (ctxPopup.SelectedItem as ContextPopupItem).Label + " (" + ctxPopup.SelectedIndex + ")");
141                 switch (ctxPopup.SelectedIndex)
142                 {
143                     case 0:
144                         //PIN
145                         PinAppCommand?.Execute("");
146                         break;
147                     case 1:
148                         //DELETE
149                         DeleteAppCommand?.Execute("");
150                         break;
151                     default:
152                         break;
153                 }
154
155                 popup.Dismiss();
156             };
157
158             popup.Dismissed += (s, args) =>
159             {
160                 isPopupShowing = false;
161             };
162
163             View anchor = sender as View;
164
165             popup.Show(anchor, anchor.Width/2, 0);
166             isPopupShowing = true;
167         }
168     }
169 }