-using System.Collections.Generic;\r
-using Tizen.NUI;\r
-using Tizen.NUI.BaseComponents;\r
-using Tizen.NUI.Components;\r
-using Tizen.NUI.Binding;\r
-using MusicPlayer.Common;\r
-\r
-namespace MusicPlayer.Views\r
-{\r
- class BaseView : View\r
- {\r
- private View topView;\r
- private View bottomView; // TODO Used this for MiniController UI\r
- private View contentView;\r
- private TextLabel titleLabel;\r
- private Button backButton;\r
- private Button moreButton;\r
- private Button searchButton;\r
- private Tab tabs;\r
- private BaseContentView baseContentView;\r
-\r
- // TODO these name strings are temporary...once the po files are added\r
- // need to use Translatable names.\r
- private static string[] TabNames = new string[]\r
- {\r
- "Playlists",\r
- "Tracks",\r
- "Albums",\r
- "Artists",\r
- };\r
- public BaseView() : base()\r
- {\r
- ThemeChangeSensitive = true;\r
- WidthSpecification = LayoutParamPolicies.MatchParent;\r
- HeightSpecification = LayoutParamPolicies.MatchParent;\r
- Layout = new FlexLayout()\r
- {\r
- Direction = FlexLayout.FlexDirection.Column,\r
- ItemsAlignment = FlexLayout.AlignmentType.FlexStart,\r
- Justification = FlexLayout.FlexJustification.FlexStart,\r
- };\r
- topView = new View()\r
- {\r
- ThemeChangeSensitive = true,\r
- WidthSpecification = LayoutParamPolicies.MatchParent,\r
- HeightSpecification = 120,\r
- Layout = new RelativeLayout()\r
- {\r
- Padding = new Extents(64, 64, 30, 30),\r
- },\r
- };\r
- base.Add(topView);\r
- FlexLayout.SetFlexGrow(topView, 0);\r
- FlexLayout.SetFlexShrink(topView, 0);\r
- titleLabel = new TextLabel()\r
- {\r
- StyleName = "PageLabel",\r
- ThemeChangeSensitive = true,\r
- Text = "Music",\r
- PixelSize = 40,\r
- FontFamily = "BreezeSans",\r
- HorizontalAlignment = HorizontalAlignment.Begin,\r
- VerticalAlignment = VerticalAlignment.Center,\r
- Ellipsis = true,\r
- FontStyle = UIFontStyles.NormalLight,\r
- };\r
- topView.Add(titleLabel);\r
- titleLabel.SetBinding(TextLabel.TextProperty, "Title");\r
- RelativeLayout.SetLeftTarget(titleLabel, topView);\r
- RelativeLayout.SetLeftRelativeOffset(titleLabel, 0.0f);\r
- RelativeLayout.SetRightTarget(titleLabel, topView);\r
- RelativeLayout.SetRightRelativeOffset(titleLabel, 1.0f);\r
- RelativeLayout.SetFillHorizontal(titleLabel, true);\r
-\r
- contentView = new View()\r
- {\r
- ThemeChangeSensitive = true,\r
- WidthSpecification = LayoutParamPolicies.MatchParent,\r
- HeightSpecification = 876,\r
- };\r
- base.Add(contentView);\r
- FlexLayout.SetFlexGrow(contentView, 1);\r
- FlexLayout.SetFlexShrink(contentView, 1);\r
-\r
- tabs = new Tab()\r
- {\r
- ThemeChangeSensitive = true,\r
- Size2D = new Size2D(Window.Instance.Size.Width, 84),\r
- WidthSpecification = LayoutParamPolicies.MatchParent,\r
- HeightSpecification = 84,\r
- UnderLineBackgroundColor = Color.Blue,\r
- UnderLineSize = new Size2D(1, 3),\r
- PointSize = 25,\r
- BackgroundColor = Color.White,\r
- };\r
- tabs.TextColorSelector = new ColorSelector\r
- {\r
- Normal = Color.Black,\r
- Selected = Color.Magenta,\r
- };\r
- base.Add(tabs);\r
- for(int i = 0; i<4; ++i)\r
- {\r
- Tab.TabItemData item = new Tab.TabItemData();\r
- item.Text = TabNames[i];\r
- tabs.AddItem(item);\r
- }\r
- tabs.SelectedItemIndex = 1;\r
-\r
- backButton = null;\r
- moreButton = null;\r
- searchButton = null;\r
- }\r
-\r
- public Tab Tabs\r
- {\r
- get => tabs;\r
- }\r
-\r
- public string Title\r
- {\r
- get => titleLabel.Text;\r
- set { titleLabel.Text = value;}\r
- }\r
-\r
- public bool BackButton\r
- {\r
- set\r
- {\r
- if (value)\r
- {\r
- if (backButton == null)\r
- {\r
- backButton = new Button("BackButton")\r
- {\r
- ThemeChangeSensitive = true,\r
- Size2D = new Size2D(48, 48),\r
- Margin = new Extents(0, 24, 6, 6),\r
- };\r
-\r
- backButton.Clicked += OnBackButtonClicked;\r
- }\r
- topView.Add(backButton);\r
- backButton.Show();\r
- RelativeLayout.SetLeftRelativeOffset(backButton, 0.0f);\r
- RelativeLayout.SetRightRelativeOffset(backButton, 0.0f);\r
- RelativeLayout.SetHorizontalAlignment(backButton, RelativeLayout.Alignment.Start);\r
-\r
- RelativeLayout.SetLeftTarget(titleLabel, backButton);\r
- RelativeLayout.SetLeftRelativeOffset(titleLabel, 1.0f);\r
- }\r
- else\r
- {\r
- if(backButton)\r
- {\r
- topView.Remove(backButton);\r
- backButton.Hide();\r
- RelativeLayout.SetLeftTarget(titleLabel, topView);\r
- RelativeLayout.SetLeftRelativeOffset(titleLabel, 0.0f);\r
- }\r
- }\r
- }\r
- }\r
-\r
- public bool MoreButton\r
- {\r
- set\r
- {\r
- moreButton = new Button("MoreButton")\r
- {\r
- ThemeChangeSensitive = true,\r
- Margin = new Extents(32, 0, 6, 6),\r
- };\r
- topView.Add(moreButton);\r
- RelativeLayout.SetLeftRelativeOffset(moreButton, 1.0f);\r
- RelativeLayout.SetRightRelativeOffset(moreButton, 1.0f);\r
- RelativeLayout.SetHorizontalAlignment(moreButton, RelativeLayout.Alignment.End);\r
-\r
- RelativeLayout.SetRightTarget(titleLabel, moreButton);\r
- RelativeLayout.SetRightRelativeOffset(titleLabel, 0.0f);\r
- moreButton.Clicked += OnMoreButtonClicked;\r
- }\r
- }\r
-\r
- public bool SearchButton\r
- {\r
- set\r
- {\r
- if (value)\r
- {\r
- ButtonStyle buttonStyle = new ButtonStyle()\r
- {\r
- Icon = new ImageViewStyle()\r
- {\r
- ResourceUrl = Resources.GetImagePath() + "search_icon.png",\r
- },\r
- IsSelectable = false,\r
- IsEnabled = true,\r
- };\r
- searchButton = new Button(buttonStyle)\r
- {\r
- ThemeChangeSensitive = true,\r
- Size2D = new Size2D(96, 60),\r
- BackgroundImage = Resources.GetImagePath() + "search_button_bg.png",\r
- Margin = new Extents(24, 0, 0, 0),\r
- };\r
- topView.Add(searchButton);\r
- RelativeLayout.SetRightTarget(searchButton, moreButton);\r
- RelativeLayout.SetRightRelativeOffset(searchButton, 0.0f);\r
- RelativeLayout.SetHorizontalAlignment(searchButton, RelativeLayout.Alignment.End);\r
-\r
- RelativeLayout.SetLeftTarget(titleLabel, RelativeLayout.GetLeftTarget(titleLabel));\r
- RelativeLayout.SetLeftRelativeOffset(titleLabel, RelativeLayout.GetLeftRelativeOffset(titleLabel));\r
- RelativeLayout.SetRightTarget(titleLabel, searchButton);\r
- RelativeLayout.SetRightRelativeOffset(titleLabel, 0.0f);\r
- }\r
- }\r
- }\r
-\r
- public Button GetSearchButton()\r
- {\r
- return searchButton;\r
- }\r
-\r
- public void SetContent(BaseContentView view)\r
- {\r
- if(view == null)\r
- {\r
- Tizen.Log.Error(AppConstants.LogTag, "BaseContentView is null, provide correct object");\r
- return;\r
- }\r
-\r
- if(baseContentView != null)\r
- {\r
- Tizen.Log.Error(AppConstants.LogTag, "ContentView is already added, remove it first");\r
- return;\r
- }\r
- if (view.IsSubViewAdded)\r
- {\r
- BackButton = true;\r
- Title = view.GetSubContentTitle();\r
- }\r
- else\r
- {\r
- BackButton = false;\r
- Title = "Music";\r
- }\r
- contentView.Add(view);\r
- baseContentView = view;\r
- }\r
-\r
- public void RemoveContent(BaseContentView view)\r
- {\r
- if(view == null)\r
- {\r
- Tizen.Log.Error(AppConstants.LogTag, "BaseContentView is null, provide correct object");\r
- return;\r
- }\r
- contentView.Remove(view);\r
- baseContentView = null;\r
- }\r
-\r
- public void AddSubViewContent(string titleText, BaseSubContentView subContentView)\r
- {\r
- if(baseContentView != null)\r
- {\r
- baseContentView.AddSubContentView(subContentView);\r
- BackButton = true;\r
- Title = titleText;\r
- }\r
- }\r
-\r
- protected override void Dispose(DisposeTypes type)\r
- {\r
- if (Disposed)\r
- {\r
- return;\r
- }\r
- if (type == DisposeTypes.Explicit)\r
- {\r
- if (topView != null)\r
- {\r
- List<View> children = topView.Children;\r
- foreach (View child in children)\r
- {\r
- topView.Remove(child);\r
- child?.Dispose();\r
- }\r
- base.Remove(topView);\r
- topView.Dispose();\r
- topView = null;\r
- }\r
-\r
- // Do not delete the children of contentview as they are not owned by BaseView\r
- base.Remove(contentView);\r
- contentView?.Dispose();\r
- contentView = null;\r
-\r
- base.Remove(tabs);\r
- tabs?.Dispose();\r
- tabs = null;\r
-\r
- base.Remove(bottomView);\r
- bottomView?.Dispose();\r
- bottomView = null;\r
- }\r
-\r
- base.Dispose(type);\r
- }\r
-\r
- private void RemoveSubViewContent()\r
- {\r
- if (baseContentView != null)\r
- {\r
- BackButton = false;\r
- Title = "Music";\r
- baseContentView.RemoveSubContentView();\r
- }\r
- }\r
-\r
- private void OnBackButtonClicked(object sender, ClickedEventArgs e)\r
- {\r
- RemoveSubViewContent();\r
- }\r
-\r
- private Menu CreateMenu()\r
- {\r
- Menu moreMenu = new Menu()\r
- {\r
- Anchor = moreButton,\r
- HorizontalPositionToAnchor = Menu.RelativePosition.End,\r
- VerticalPositionToAnchor = Menu.RelativePosition.End,\r
- };\r
- return moreMenu;\r
- }\r
-\r
- private void OnMoreButtonClicked(object sender, ClickedEventArgs e)\r
- {\r
- if(baseContentView != null)\r
- {\r
- Menu moreMenu = CreateMenu();\r
- baseContentView.UpdateButtonMoreItems(moreMenu);\r
- moreMenu.Post();\r
- }\r
- }\r
- }\r
+using System.Collections.Generic;
+using Tizen.NUI;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Components;
+using Tizen.NUI.Binding;
+using MusicPlayer.Common;
+
+namespace MusicPlayer.Views
+{
+ class BaseView : View
+ {
+ private View topView;
+ private View bottomView; // TODO Used this for MiniController UI
+ private View contentView;
+ private TextLabel titleLabel;
+ private Button backButton;
+ private Button moreButton;
+ private Button searchButton;
+ private Tab tabs;
+ private BaseContentView baseContentView;
+
+ // TODO these name strings are temporary...once the po files are added
+ // need to use Translatable names.
+ private static string[] TabNames = new string[]
+ {
+ "Playlists",
+ "Tracks",
+ "Albums",
+ "Artists",
+ };
+ public BaseView() : base()
+ {
+ ThemeChangeSensitive = true;
+ WidthSpecification = LayoutParamPolicies.MatchParent;
+ HeightSpecification = LayoutParamPolicies.MatchParent;
+ Layout = new FlexLayout()
+ {
+ Direction = FlexLayout.FlexDirection.Column,
+ ItemsAlignment = FlexLayout.AlignmentType.FlexStart,
+ Justification = FlexLayout.FlexJustification.FlexStart,
+ };
+ topView = new View()
+ {
+ ThemeChangeSensitive = true,
+ WidthSpecification = LayoutParamPolicies.MatchParent,
+ HeightSpecification = 120,
+ Layout = new RelativeLayout()
+ {
+ Padding = new Extents(64, 64, 30, 30),
+ },
+ };
+ base.Add(topView);
+ FlexLayout.SetFlexGrow(topView, 0);
+ FlexLayout.SetFlexShrink(topView, 0);
+ titleLabel = new TextLabel()
+ {
+ StyleName = "PageLabel",
+ ThemeChangeSensitive = true,
+ Text = "Music",
+ PixelSize = 40,
+ FontFamily = "BreezeSans",
+ HorizontalAlignment = HorizontalAlignment.Begin,
+ VerticalAlignment = VerticalAlignment.Center,
+ Ellipsis = true,
+ FontStyle = UIFontStyles.NormalLight,
+ };
+ topView.Add(titleLabel);
+ titleLabel.SetBinding(TextLabel.TextProperty, "Title");
+ RelativeLayout.SetLeftTarget(titleLabel, topView);
+ RelativeLayout.SetLeftRelativeOffset(titleLabel, 0.0f);
+ RelativeLayout.SetRightTarget(titleLabel, topView);
+ RelativeLayout.SetRightRelativeOffset(titleLabel, 1.0f);
+ RelativeLayout.SetFillHorizontal(titleLabel, true);
+
+ contentView = new View()
+ {
+ ThemeChangeSensitive = true,
+ WidthSpecification = LayoutParamPolicies.MatchParent,
+ HeightSpecification = 876,
+ };
+ base.Add(contentView);
+ FlexLayout.SetFlexGrow(contentView, 1);
+ FlexLayout.SetFlexShrink(contentView, 1);
+
+ tabs = new Tab()
+ {
+ ThemeChangeSensitive = true,
+ Size2D = new Size2D(Window.Instance.Size.Width, 84),
+ WidthSpecification = LayoutParamPolicies.MatchParent,
+ HeightSpecification = 84,
+ UnderLineBackgroundColor = Color.Blue,
+ UnderLineSize = new Size2D(1, 3),
+ PointSize = 25,
+ BackgroundColor = Color.White,
+ };
+ tabs.TextColorSelector = new ColorSelector
+ {
+ Normal = Color.Black,
+ Selected = Color.Magenta,
+ };
+ base.Add(tabs);
+ for(int i = 0; i<4; ++i)
+ {
+ Tab.TabItemData item = new Tab.TabItemData();
+ item.Text = TabNames[i];
+ tabs.AddItem(item);
+ }
+ tabs.SelectedItemIndex = 1;
+
+ backButton = null;
+ moreButton = null;
+ searchButton = null;
+ }
+
+ public Tab Tabs
+ {
+ get => tabs;
+ }
+
+ public string Title
+ {
+ get => titleLabel.Text;
+ set { titleLabel.Text = value;}
+ }
+
+ public bool BackButton
+ {
+ set
+ {
+ if (value)
+ {
+ if (backButton == null)
+ {
+ backButton = new Button("BackButton")
+ {
+ ThemeChangeSensitive = true,
+ Size2D = new Size2D(48, 48),
+ Margin = new Extents(0, 24, 6, 6),
+ };
+
+ backButton.Clicked += OnBackButtonClicked;
+ }
+ topView.Add(backButton);
+ backButton.Show();
+ RelativeLayout.SetLeftRelativeOffset(backButton, 0.0f);
+ RelativeLayout.SetRightRelativeOffset(backButton, 0.0f);
+ RelativeLayout.SetHorizontalAlignment(backButton, RelativeLayout.Alignment.Start);
+
+ RelativeLayout.SetLeftTarget(titleLabel, backButton);
+ RelativeLayout.SetLeftRelativeOffset(titleLabel, 1.0f);
+ }
+ else
+ {
+ if(backButton)
+ {
+ topView.Remove(backButton);
+ backButton.Hide();
+ RelativeLayout.SetLeftTarget(titleLabel, topView);
+ RelativeLayout.SetLeftRelativeOffset(titleLabel, 0.0f);
+ }
+ }
+ }
+ }
+
+ public bool MoreButton
+ {
+ set
+ {
+ moreButton = new Button("MoreButton")
+ {
+ ThemeChangeSensitive = true,
+ Margin = new Extents(32, 0, 6, 6),
+ };
+ topView.Add(moreButton);
+ RelativeLayout.SetLeftRelativeOffset(moreButton, 1.0f);
+ RelativeLayout.SetRightRelativeOffset(moreButton, 1.0f);
+ RelativeLayout.SetHorizontalAlignment(moreButton, RelativeLayout.Alignment.End);
+
+ RelativeLayout.SetRightTarget(titleLabel, moreButton);
+ RelativeLayout.SetRightRelativeOffset(titleLabel, 0.0f);
+ moreButton.Clicked += OnMoreButtonClicked;
+ }
+ }
+
+ public bool SearchButton
+ {
+ set
+ {
+ if (value)
+ {
+ ButtonStyle buttonStyle = new ButtonStyle()
+ {
+ Icon = new ImageViewStyle()
+ {
+ ResourceUrl = Resources.GetImagePath() + "search_icon.png",
+ },
+ IsSelectable = false,
+ IsEnabled = true,
+ };
+ searchButton = new Button(buttonStyle)
+ {
+ ThemeChangeSensitive = true,
+ Size2D = new Size2D(96, 60),
+ BackgroundImage = Resources.GetImagePath() + "search_button_bg.png",
+ Margin = new Extents(24, 0, 0, 0),
+ };
+ topView.Add(searchButton);
+ RelativeLayout.SetRightTarget(searchButton, moreButton);
+ RelativeLayout.SetRightRelativeOffset(searchButton, 0.0f);
+ RelativeLayout.SetHorizontalAlignment(searchButton, RelativeLayout.Alignment.End);
+
+ RelativeLayout.SetLeftTarget(titleLabel, RelativeLayout.GetLeftTarget(titleLabel));
+ RelativeLayout.SetLeftRelativeOffset(titleLabel, RelativeLayout.GetLeftRelativeOffset(titleLabel));
+ RelativeLayout.SetRightTarget(titleLabel, searchButton);
+ RelativeLayout.SetRightRelativeOffset(titleLabel, 0.0f);
+ }
+ }
+ }
+
+ public Button GetSearchButton()
+ {
+ return searchButton;
+ }
+
+ public void SetContent(BaseContentView view)
+ {
+ if(view == null)
+ {
+ Tizen.Log.Error(AppConstants.LogTag, "BaseContentView is null, provide correct object");
+ return;
+ }
+
+ if(baseContentView != null)
+ {
+ Tizen.Log.Error(AppConstants.LogTag, "ContentView is already added, remove it first");
+ return;
+ }
+ if (view.IsSubViewAdded)
+ {
+ BackButton = true;
+ Title = view.GetSubContentTitle();
+ }
+ else
+ {
+ BackButton = false;
+ Title = "Music";
+ }
+ contentView.Add(view);
+ baseContentView = view;
+ }
+
+ public void RemoveContent(BaseContentView view)
+ {
+ if(view == null)
+ {
+ Tizen.Log.Error(AppConstants.LogTag, "BaseContentView is null, provide correct object");
+ return;
+ }
+ contentView.Remove(view);
+ baseContentView = null;
+ }
+
+ public void AddSubViewContent(string titleText, BaseSubContentView subContentView)
+ {
+ if(baseContentView != null)
+ {
+ baseContentView.AddSubContentView(subContentView);
+ BackButton = true;
+ Title = titleText;
+ }
+ }
+
+ public bool BackKeyEventEmitted()
+ {
+ if (baseContentView != null && baseContentView.IsSubViewAdded)
+ {
+ OnBack();
+ return true;
+ }
+ return false;
+ }
+
+ protected override void Dispose(DisposeTypes type)
+ {
+ if (Disposed)
+ {
+ return;
+ }
+ if (type == DisposeTypes.Explicit)
+ {
+ if (topView != null)
+ {
+ List<View> children = topView.Children;
+ foreach (View child in children)
+ {
+ topView.Remove(child);
+ child?.Dispose();
+ }
+ base.Remove(topView);
+ topView.Dispose();
+ topView = null;
+ }
+
+ // Do not delete the children of contentview as they are not owned by BaseView
+ base.Remove(contentView);
+ contentView?.Dispose();
+ contentView = null;
+
+ base.Remove(tabs);
+ tabs?.Dispose();
+ tabs = null;
+
+ base.Remove(bottomView);
+ bottomView?.Dispose();
+ bottomView = null;
+ }
+
+ base.Dispose(type);
+ }
+
+ private void RemoveSubViewContent()
+ {
+ if (baseContentView != null)
+ {
+ BackButton = false;
+ Title = "Music";
+ baseContentView.RemoveSubContentView();
+ }
+ }
+
+ private void OnBack()
+ {
+ RemoveSubViewContent();
+ }
+
+ private void OnBackButtonClicked(object sender, ClickedEventArgs e)
+ {
+ OnBack();
+ }
+
+ private Menu CreateMenu()
+ {
+ Menu moreMenu = new Menu()
+ {
+ Anchor = moreButton,
+ HorizontalPositionToAnchor = Menu.RelativePosition.End,
+ VerticalPositionToAnchor = Menu.RelativePosition.End,
+ };
+ return moreMenu;
+ }
+
+ private void OnMoreButtonClicked(object sender, ClickedEventArgs e)
+ {
+ if(baseContentView != null)
+ {
+ Menu moreMenu = CreateMenu();
+ baseContentView.UpdateButtonMoreItems(moreMenu);
+ moreMenu.Post();
+ }
+ }
+ }
}
\ No newline at end of file