2 * Copyright (c) 2017 Samsung Electronics Co., Ltd
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
8 * http://floralicense.org/license/
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.
18 using Tizen.Xamarin.Forms.Extension;
19 using LibTVRefCommonPortable.Utils;
20 using System.Windows.Input;
22 using TVApps.Controls;
23 using System.Collections.Generic;
25 namespace TVApps.Views
28 /// A custom view for displaying footer when CurrentStatus of MainPage is AppsStatus.Default
30 public partial class FooterNormalStatus : RelativeLayout
32 private bool isPopupShowing = false;
34 private DropdownList SortButton;
35 private Button OptionButton;
38 /// A command will be executed if the Pin option is selected
40 public static readonly BindableProperty PinAppCommandProperty = BindableProperty.Create("PinAppCommand", typeof(Command), typeof(FooterNormalStatus), null);
41 public ICommand PinAppCommand
43 get { return (ICommand)GetValue(PinAppCommandProperty); }
44 set { SetValue(PinAppCommandProperty, value); }
48 /// A command will be executed if the Delete option is selected
50 public static readonly BindableProperty DeleteAppCommandProperty = BindableProperty.Create("DeleteAppCommand", typeof(Command), typeof(FooterNormalStatus), null);
51 public ICommand DeleteAppCommand
53 get { return (ICommand)GetValue(DeleteAppCommandProperty); }
54 set { SetValue(DeleteAppCommandProperty, value); }
57 public static readonly BindableProperty SortOptionIndexCommandProperty = BindableProperty.Create("SortOptionIndexCommand", typeof(Command), typeof(FooterNormalStatus), null);
58 public ICommand SortOptionIndexCommand
60 get { return (ICommand)GetValue(SortOptionIndexCommandProperty); }
61 set { SetValue(SortOptionIndexCommandProperty, value); }
67 public FooterNormalStatus()
69 InitializeComponent();
75 public DropdownList GetSortDropdownList()
80 private void CreateOptionButton()
82 OptionButton = new Button()
86 OptionButton.Clicked += OnOptionsClicked;
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)));
95 private void CreateSortButton()
97 List<string> SortList = new List<string> { "Newest", "A - Z", "Z - A" };
99 SortButton = new DropdownList();
100 SortButton.ItemsSource = SortList;
101 SortButton.SelectedItem = SortList[0];
103 SortButton.ItemSelected += (s, e) =>
105 if (SortList.Contains(e.SelectedItem.ToString()))
107 SortOptionIndexCommand?.Execute(SortList.IndexOf(e.SelectedItem.ToString()));
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)));
118 void OnOptionsClicked(object sender, EventArgs e)
125 ContextPopup popup = new ContextPopup
127 IsAutoHidingEnabled = true,
128 Orientation = ContextPopupOrientation.Vertical,
129 DirectionPriorities = new ContextPopupDirectionPriorities(ContextPopupDirection.Up, ContextPopupDirection.Right, ContextPopupDirection.Left, ContextPopupDirection.Down),
132 popup.Items.Add(new ContextPopupItem("PIN"));
133 popup.Items.Add(new ContextPopupItem(" DELETE "));
135 //TODO: need to change the event callback
136 popup.SelectedIndexChanged += (s, args) =>
138 var ctxPopup = s as ContextPopup;
140 DebuggingUtils.Dbg("selected item : " + (ctxPopup.SelectedItem as ContextPopupItem).Label + " (" + ctxPopup.SelectedIndex + ")");
141 switch (ctxPopup.SelectedIndex)
145 PinAppCommand?.Execute("");
149 DeleteAppCommand?.Execute("");
158 popup.Dismissed += (s, args) =>
160 isPopupShowing = false;
163 View anchor = sender as View;
165 popup.Show(anchor, anchor.Width/2, 0);
166 isPopupShowing = true;