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 System.Collections.Generic;
21 using Xamarin.Forms.Xaml;
22 using Tizen.Xamarin.Forms.Extension;
23 using TVMediaHub.Tizen.Utils;
24 using TVMediaHub.Tizen.DataModels;
26 namespace TVMediaHub.Tizen.Views
29 /// A custom view for displaying footer when the status of page is normal
31 [XamlCompilation(XamlCompilationOptions.Compile)]
32 public partial class FooterNormalStatus : RelativeLayout
34 public static readonly BindableProperty IsFooterEnabledProperty = BindableProperty.Create("IsFooterEnabled", typeof(bool), typeof(FooterNormalStatus), true);
36 public bool IsFooterEnabled
38 get { return (bool)GetValue(IsFooterEnabledProperty); }
39 set { SetValue(IsFooterEnabledProperty, value); }
43 /// Identifies the SourceList bindable property
45 public static readonly BindableProperty SourceListProperty = BindableProperty.Create("SourceList", typeof(IEnumerable<string>), typeof(FooterNormalStatus), default(IEnumerable<string>));
48 /// Gets or sets list about source of contents
50 public IEnumerable<string> SourceList
52 get { return (IEnumerable<string>)GetValue(SourceListProperty); }
53 set { SetValue(SourceListProperty, value); }
57 /// Identifies the SortOptions bindable property
59 public static readonly BindableProperty SortOptionsProperty = BindableProperty.Create("SortOptions", typeof(IEnumerable<string>), typeof(FooterNormalStatus), default(IEnumerable<string>));
62 /// Gets or sets sort options
64 public IEnumerable<string> SortOptions
66 get { return (IEnumerable<string>)GetValue(SortOptionsProperty); }
67 set { SetValue(SortOptionsProperty, value); }
71 /// Identifies the OptionList bindable property
73 public static readonly BindableProperty OptionListProperty = BindableProperty.Create("OptionList", typeof(IEnumerable<string>), typeof(FooterNormalStatus), default(IEnumerable<string>));
76 /// Gets or sets list about options
78 public IEnumerable<string> OptionList
80 get { return (IEnumerable<string>)GetValue(OptionListProperty); }
81 set { SetValue(OptionListProperty, value); }
85 /// A EventHandler for DropdownSource ItemSelected event
87 public EventHandler<SelectedItemChangedEventArgs> OnDropdownSourceItemSelected;
90 /// A EventHandler for DropdownSort ItemSelected event
92 public EventHandler<SelectedItemChangedEventArgs> OnDropdownSortItemSelected;
95 /// A EventHandler for DropdownOption ItemSelected event
97 public EventHandler<ContextPopupSelectedEventArgs> OnSelectedOptionIndexChanged;
100 /// A DropdownList for displaying sources of contents
102 public DropdownList DropdownSource;
105 /// A DropdownList for displaying sort options
107 public DropdownList DropdownSort;
110 /// A Button for displaying page options
112 public Button ButtonOption;
113 private bool isPopupShowing;
118 public FooterNormalStatus()
120 InitializeComponent();
121 InitializeFooterItems();
122 PropertyChanged += FooterNormalStatusPropertyChanged;
126 /// This method is called when the properties is changed
128 /// <param name="sender">The source of the event</param>
129 /// <param name="e">A propertyChanged event argument</param>
130 private void FooterNormalStatusPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
132 if (e.PropertyName.Equals("SourceList"))
134 DropdownSource.ItemsSource = SourceList;
135 var list = SourceList as List<string>;
136 DropdownSource.SelectedItem = list[0];
138 else if (e.PropertyName.Equals("SortOptions"))
140 DropdownSort.ItemsSource = SortOptions;
141 var list = SortOptions as List<string>;
142 DropdownSort.SelectedItem = list[0];
144 else if (e.PropertyName.Equals("IsFooterEnabled"))
146 DropdownSource.IsEnabled = IsFooterEnabled;
147 DropdownSort.IsEnabled = IsFooterEnabled;
148 ButtonOption.IsEnabled = IsFooterEnabled;
149 if (!IsFooterEnabled)
151 ButtonOption.Text = "";
155 ButtonOption.Text = "OPTION";
161 /// A method for initializing footer items
163 private void InitializeFooterItems()
165 DropdownSource = new DropdownList();
166 DropdownSort = new DropdownList();
167 ButtonOption = new Button();
169 ButtonOption.Text = "OPTION";
171 DropdownSource.ItemsSource = SourceList;
172 DropdownSort.ItemsSource = SortOptions;
174 DropdownSource.ItemSelected += (s, e) =>
176 OnDropdownSourceItemSelected?.Invoke(s, e);
179 DropdownSort.ItemSelected += (s, e) =>
181 OnDropdownSortItemSelected?.Invoke(s, e);
184 ButtonOption.Command = new Command(() =>
189 // TODO : Change yConstraint.
192 Children.Add(DropdownSource,
193 heightConstraint: Constraint.Constant(SizeUtils.GetHeightSize(80)),
194 widthConstraint: Constraint.Constant(SizeUtils.GetWidthSize(300)),
195 yConstraint: Constraint.Constant(SizeUtils.GetHeightSize(752)),
196 xConstraint: Constraint.Constant(SizeUtils.GetWidthSize(96)));
198 Children.Add(DropdownSort,
199 heightConstraint: Constraint.Constant(SizeUtils.GetHeightSize(80)),
200 widthConstraint: Constraint.Constant(SizeUtils.GetWidthSize(300)),
201 yConstraint: Constraint.Constant(SizeUtils.GetHeightSize(752)),
202 xConstraint: Constraint.Constant(SizeUtils.GetWidthSize(1220)));
204 Children.Add(ButtonOption,
205 heightConstraint: Constraint.Constant(SizeUtils.GetHeightSize(80)),
206 widthConstraint: Constraint.Constant(SizeUtils.GetWidthSize(300)),
207 yConstraint: Constraint.Constant(SizeUtils.GetHeightSize(752)),
208 xConstraint: Constraint.Constant(SizeUtils.GetWidthSize(1524)));
210 ButtonOption.FontSize = SizeUtils.GetFontSize(28);
214 /// A method for showing context popup
216 private void ShowContextPopup()
223 ContextPopup popup = new ContextPopup
225 IsAutoHidingEnabled = true,
226 Orientation = ContextPopupOrientation.Vertical,
227 DirectionPriorities = new ContextPopupDirectionPriorities(ContextPopupDirection.Up, ContextPopupDirection.Right, ContextPopupDirection.Left, ContextPopupDirection.Down),
230 if (OptionList != null)
232 foreach (var item in OptionList)
234 popup.Items.Add(new ContextPopupItem(item));
238 //TODO: need to change the event callback
239 popup.SelectedIndexChanged += (s, args) =>
241 var index = popup.SelectedIndex;
242 var item = popup.SelectedItem as ContextPopupItem;
243 OnSelectedOptionIndexChanged.Invoke(s, new ContextPopupSelectedEventArgs(index, item));
247 popup.Dismissed += (s, args) =>
249 isPopupShowing = false;
252 popup.Show(ButtonOption, (ButtonOption.Width / 2), 0);
253 isPopupShowing = true;