From 52ccea68c26c10bee2b2294e18abad2c13d6ace0 Mon Sep 17 00:00:00 2001 From: "aman.jeph" Date: Fri, 20 Aug 2021 11:50:55 +0530 Subject: [PATCH] Adding light/dark theme support part 2 Change-Id: Idbfd80c32b4c3a5a9c9393e239528c6cd8d2ac9f Signed-off-by: aman.jeph --- ViewModels/ListViewModel.cs | 12 + ViewModels/PlayerViewModel.cs | 50 +++- ViewModels/PlayingListViewModel.cs | 16 +- Views/BaseContentView.cs | 27 +- Views/BaseView.cs | 10 +- Views/ListItemLayout.cs | 19 +- Views/PlayerView.cs | 416 ++++++++++++++++++----------- Views/TrackView.cs | 42 ++- 8 files changed, 398 insertions(+), 194 deletions(-) diff --git a/ViewModels/ListViewModel.cs b/ViewModels/ListViewModel.cs index cb70383..24ea54e 100755 --- a/ViewModels/ListViewModel.cs +++ b/ViewModels/ListViewModel.cs @@ -5,6 +5,7 @@ using MusicPlayer.Models; using Tizen.Content.MediaContent; using MusicPlayer.Common; using System; +using System.Collections.Generic; namespace MusicPlayer.ViewModels { @@ -22,5 +23,16 @@ namespace MusicPlayer.ViewModels } Tizen.Log.Debug(AppConstants.LogTag, "Observable list item count: " + this.Count); } + + public void CreateData(List list) + { + foreach (var item in list) + { + Add((T)Activator.CreateInstance(typeof(T), new object[] { (U)item })); + } + Tizen.Log.Debug(AppConstants.LogTag, "Observable list item count: " + this.Count); + } + + } } diff --git a/ViewModels/PlayerViewModel.cs b/ViewModels/PlayerViewModel.cs index 6ccc60c..0b53d16 100755 --- a/ViewModels/PlayerViewModel.cs +++ b/ViewModels/PlayerViewModel.cs @@ -12,6 +12,8 @@ namespace MusicPlayer.ViewModels { class PlayerViewModel : PropertyNotifier { + public const string PlayState = "Play"; + public const string PauseState = "Pause"; private const int PlaybackTimerDuration = 1000; private const int MinPaletteColorCount = 2; @@ -26,7 +28,7 @@ namespace MusicPlayer.ViewModels playingListViewModel = new PlayingListViewModel(); playerModel = new PlayerModel(); playerModel.ElapsedTime = 0.0f; - PlayPauseUrl = Resources.GetImagePath() + "play.png"; + PlayingStatus = PlayingStatus.None; PlayerController.Instance.PlayerEventOccurred += OnPlayerEventOccurred; playbackTimer = new Timer(PlaybackTimerDuration); playbackTimer.Tick += OnPlaybackTimerTick; @@ -44,12 +46,12 @@ namespace MusicPlayer.ViewModels get => playingListViewModel; } - private string playPauseUrl; + private string playButtonState; - public string PlayPauseUrl + public string PlayButtonState { - get => playPauseUrl; - set => SetProperty(ref playPauseUrl, value); + get => playButtonState; + set => SetProperty(ref playButtonState, value); } private float volumeLevel; @@ -84,6 +86,14 @@ namespace MusicPlayer.ViewModels set => SetProperty(ref playerBackground, value); } + private PlayingStatus playingStatus; + + public PlayingStatus PlayingStatus + { + get => playingStatus; + set => UpdatePlayingStatus(value); + } + public void SetPlayingList(ListViewModel trackListVM) { playingListViewModel.SetTrackListViewModel(trackListVM); @@ -170,17 +180,15 @@ namespace MusicPlayer.ViewModels public void PlayingStatusChanged() { - if (playerModel.PlayingStatus == PlayingStatus.Playing) + if (PlayingStatus == PlayingStatus.Playing) { - playerModel.PlayingStatus = PlayingStatus.Paused; - PlayPauseUrl = Resources.GetImagePath() + "play.png"; + PlayingStatus = PlayingStatus.Paused; Pause(); playbackTimer.Stop(); } else { - playerModel.PlayingStatus = PlayingStatus.Playing; - PlayPauseUrl = Resources.GetImagePath() + "pause.png"; + PlayingStatus = PlayingStatus.Playing; Resume(); playbackTimer.Start(); } @@ -220,6 +228,22 @@ namespace MusicPlayer.ViewModels AudioManager.VolumeController.Level[AudioVolumeType.Media] = value; } + private void UpdatePlayingStatus(PlayingStatus status) + { + playingStatus = status; + switch (status) + { + case PlayingStatus.Playing: + PlayButtonState = PauseState; + break; + case PlayingStatus.Paused: // Fall Through + case PlayingStatus.Stopped: // Fall Through + case PlayingStatus.None: + PlayButtonState = PlayState; + break; + } + } + private bool OnPlaybackTimerTick(object source, Timer.TickEventArgs e) { UpdatePlayingTime(); @@ -258,16 +282,14 @@ namespace MusicPlayer.ViewModels private void StartPlayback() { - playerModel.PlayingStatus = PlayingStatus.Playing; - PlayPauseUrl = Resources.GetImagePath() + "pause.png"; + PlayingStatus = PlayingStatus.Playing; Play(); playbackTimer.Start(); } private void StopPlayback() { - playerModel.PlayingStatus = PlayingStatus.Stopped; - PlayPauseUrl = Resources.GetImagePath() + "play.png"; + PlayingStatus = PlayingStatus.Stopped; Stop(); playbackTimer.Stop(); } diff --git a/ViewModels/PlayingListViewModel.cs b/ViewModels/PlayingListViewModel.cs index 6358715..d84e547 100755 --- a/ViewModels/PlayingListViewModel.cs +++ b/ViewModels/PlayingListViewModel.cs @@ -83,7 +83,7 @@ namespace MusicPlayer.ViewModels get => tracklistViewModel; } - public string ShuffleUrl + public string ShuffleButtonState { get => shuffleButtonUrl; set => SetProperty(ref shuffleButtonUrl, value); @@ -106,14 +106,11 @@ namespace MusicPlayer.ViewModels UpdateShuffleList(tracklistViewModel.Count); } } - if (shuffleMode == ShuffleMode.On) - ShuffleUrl = Resources.GetImagePath() + "shuffle_on.png"; - else - ShuffleUrl = Resources.GetImagePath() + "shuffle_off.png"; + ShuffleButtonState = shuffleMode.ToString(); } } - public string RepeatUrl + public string RepeatButtonState { get => repeatButtonUrl; set => SetProperty(ref repeatButtonUrl, value); @@ -125,12 +122,7 @@ namespace MusicPlayer.ViewModels set { repeatMode = value; - if (repeatMode == RepeatMode.Off) - RepeatUrl = Resources.GetImagePath() + "repeat_off.png"; - else if (repeatMode == RepeatMode.RepeatOne) - RepeatUrl = Resources.GetImagePath() + "repeat_one.png"; - else - RepeatUrl = Resources.GetImagePath() + "repeat_all.png"; + RepeatButtonState = repeatMode.ToString(); } } diff --git a/Views/BaseContentView.cs b/Views/BaseContentView.cs index 1de2b3c..5aa5c44 100755 --- a/Views/BaseContentView.cs +++ b/Views/BaseContentView.cs @@ -11,6 +11,7 @@ namespace MusicPlayer.Views protected CollectionView collectionView; public BaseContentView() : base() { + ThemeChangeSensitive = true; WidthResizePolicy = ResizePolicyType.FillToParent; HeightResizePolicy = ResizePolicyType.FillToParent; Layout = new FlexLayout() @@ -20,13 +21,13 @@ namespace MusicPlayer.Views }; titleView = new View() { + ThemeChangeSensitive = true, WidthSpecification = LayoutParamPolicies.MatchParent, HeightSpecification = 60, Layout = new RelativeLayout() { Padding = new Extents(0, 0, 13, 13), }, - IsCreateByXaml = true, }; base.Add(titleView); FlexLayout.SetFlexGrow(titleView, 0); @@ -34,9 +35,10 @@ namespace MusicPlayer.Views collectionView = new CollectionView() { + ThemeChangeSensitive = true, Size2D = new Size2D(1792, 108), Margin = new Extents(0, 0, 0, 2), - BackgroundImage = Resources.GetImagePath() + "list_view_bg.png", + BackgroundImage = GetBackgroundImagePath(ThemeManager.PlatformThemeId), ItemsLayouter = new LinearLayouter(), ScrollingDirection = ScrollableBase.Direction.Vertical, WidthSpecification = LayoutParamPolicies.MatchParent, @@ -48,6 +50,27 @@ namespace MusicPlayer.Views FlexLayout.SetFlexShrink(collectionView, 1); } + private string GetBackgroundImagePath(string platformThemeId) + { + if(platformThemeId.Equals(AppConstants.DarkPlatformThemeId)) + { + return Resources.GetImagePath() + "dark/list_view_bg.png"; + } + else + { + return Resources.GetImagePath() + "light/list_view_bg.png"; + } + } + + protected override void OnThemeChanged(object sender, ThemeChangedEventArgs e) + { + base.OnThemeChanged(sender, e); + if(e.IsPlatformThemeChanged) + { + collectionView.BackgroundImage = GetBackgroundImagePath(e.PlatformThemeId); + } + } + protected override void Dispose(DisposeTypes type) { if (type == DisposeTypes.Explicit) diff --git a/Views/BaseView.cs b/Views/BaseView.cs index ffc4396..1cddb26 100755 --- a/Views/BaseView.cs +++ b/Views/BaseView.cs @@ -29,6 +29,7 @@ namespace MusicPlayer.Views }; public BaseView() : base() { + ThemeChangeSensitive = true; WidthSpecification = LayoutParamPolicies.MatchParent; HeightSpecification = LayoutParamPolicies.MatchParent; Layout = new FlexLayout() @@ -39,6 +40,7 @@ namespace MusicPlayer.Views }; topView = new View() { + ThemeChangeSensitive = true, WidthSpecification = LayoutParamPolicies.MatchParent, HeightSpecification = 120, Layout = new RelativeLayout() @@ -51,6 +53,7 @@ namespace MusicPlayer.Views FlexLayout.SetFlexShrink(topView, 0); titleLabel = new TextLabel() { + ThemeChangeSensitive = true, Text = "Music", PixelSize = 40, FontFamily = "BreezeSans", @@ -69,6 +72,7 @@ namespace MusicPlayer.Views contentView = new View() { + ThemeChangeSensitive = true, WidthSpecification = LayoutParamPolicies.MatchParent, HeightSpecification = 876, }; @@ -78,6 +82,7 @@ namespace MusicPlayer.Views tabs = new Tab() { + ThemeChangeSensitive = true, Size2D = new Size2D(Window.Instance.Size.Width, 84), WidthSpecification = LayoutParamPolicies.MatchParent, HeightSpecification = 84, @@ -134,6 +139,7 @@ namespace MusicPlayer.Views backButton = new Button(buttonStyle) { + ThemeChangeSensitive = true, Size2D = new Size2D(48, 48), Margin = new Extents(0, 24, 6, 6), }; @@ -159,13 +165,14 @@ namespace MusicPlayer.Views { Icon = new ImageViewStyle() { - ResourceUrl = Resources.GetImagePath() + "more_button.png", + ResourceUrl = Resources.GetImagePath() + "more.png", }, IsSelectable = false, IsEnabled = true, }; moreButton = new Button(buttonStyle) { + ThemeChangeSensitive = true, Size2D = new Size2D(48, 48), Margin = new Extents(32, 0, 6, 6), }; @@ -197,6 +204,7 @@ namespace MusicPlayer.Views }; 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), diff --git a/Views/ListItemLayout.cs b/Views/ListItemLayout.cs index 1c070d1..071523f 100755 --- a/Views/ListItemLayout.cs +++ b/Views/ListItemLayout.cs @@ -53,30 +53,41 @@ namespace MusicPlayer.Views }; base.Add(itemSeperator); - titleLabel = new TextLabel() + titleLabel = new TextLabel("ItemLabel") { + ThemeChangeSensitive = true, WidthSpecification = (Width - (2 * LeftPadding) - IconSize - LayoutPadding), HeightSpecification = 40, - TextColor = Color.Blue, PixelSize = 32, FontFamily = "BreezeSans", VerticalAlignment = VerticalAlignment.Center, IsCreateByXaml = true, Position2D = new Position2D((x + IconSize + LayoutPadding), LayoutMargin), }; + // ToDo need to make this a readonly const + PropertyMap titleFontStyle = new PropertyMap(); + titleFontStyle.Add("width", new PropertyValue("normal")); + titleFontStyle.Add("weight", new PropertyValue("light")); + titleLabel.FontStyle = titleFontStyle; base.Add(titleLabel); - subtitleLabel = new TextLabel() + subtitleLabel = new TextLabel("ItemLabel") { + ThemeChangeSensitive = true, WidthSpecification = (Width - (2 * LeftPadding) - IconSize - LayoutPadding), HeightSpecification = 36, - TextColor = Color.Black, PixelSize = 28, FontFamily = "BreezeSans", VerticalAlignment = VerticalAlignment.Center, IsCreateByXaml = true, Position2D = new Position2D((x + IconSize + LayoutPadding), LayoutMargin + 40) }; + // ToDo need to make this a readonly const + PropertyMap subtitleFontStyle = new PropertyMap(); + subtitleFontStyle.Add("width", new PropertyValue("normal")); + subtitleFontStyle.Add("weight", new PropertyValue("normal")); + subtitleFontStyle.Add("slant", new PropertyValue("normal")); + subtitleLabel.FontStyle = subtitleFontStyle; base.Add(subtitleLabel); IsCreateByXaml = true; } diff --git a/Views/PlayerView.cs b/Views/PlayerView.cs index 06ee773..b0a5883 100755 --- a/Views/PlayerView.cs +++ b/Views/PlayerView.cs @@ -5,6 +5,8 @@ using Tizen.NUI.BaseComponents; using Tizen.NUI.Binding; using MusicPlayer.Common; using MusicPlayer.ViewModels; +using MusicPlayer.Views.Utils; +using System.Collections.Generic; namespace MusicPlayer.Views { @@ -34,11 +36,11 @@ namespace MusicPlayer.Views private View controlsView; private View sliderView; - private Button playButton; + private MultiStateButton playButton; private Button prevButton; private Button nextButton; - private Button shuffleButton; - private Button repeatButton; + private MultiStateButton shuffleButton; + private MultiStateButton repeatButton; private Slider volumeSlider; private Slider playbackSlider; private TextLabel titleLabel; @@ -51,7 +53,7 @@ namespace MusicPlayer.Views private ImageView thumb; private Button listButton; private Button playlistButton; - private Button favouriteButton; + private MultiStateButton favouriteButton; private PlayingListView currentListView; private LyricsView lyricsView; @@ -63,7 +65,7 @@ namespace MusicPlayer.Views { this.viewModel = viewModel; BindingContext = viewModel.playerModel; - BackgroundColor = Color.White; + StyleName = "AppBackground"; WidthResizePolicy = ResizePolicyType.FillToParent; HeightResizePolicy = ResizePolicyType.FillToParent; @@ -96,42 +98,6 @@ namespace MusicPlayer.Views playerBackgroundView.SetBinding(BackgroundProperty, "PlayerBackground"); } - private Button CreateButton(ImageViewStyle style, int x, int y) - { - ButtonStyle buttonStyle = new ButtonStyle() - { - Icon = style, - IsSelectable = false, - IsEnabled = true, - }; - Button button = new Button(buttonStyle) - { - Size2D = new Size2D(IconSize, IconSize), - Position2D = new Position2D(x, y), - }; - return button; - } - - private Button CreateButton(string url, int x, int y) - { - ButtonStyle buttonStyle = new ButtonStyle() - { - Icon = new ImageViewStyle() - { - ResourceUrl = url, - }, - IsSelectable = false, - IsEnabled = true, - }; - - Button button = new Button(buttonStyle) - { - Size2D = new Size2D(IconSize, IconSize), - Position2D = new Position2D(x, y), - }; - return button; - } - private View CreateLeftView() { View leftView = new View() @@ -188,10 +154,14 @@ namespace MusicPlayer.Views private void AddTopButtons() { - backButton = CreateButton(Resources.GetImagePath() + "back_button.png", LayoutPadding, TopBarButtonsY); + backButton = new Button("BackButton"); + backButton.ThemeChangeSensitive = true; + backButton.Position2D = new Position2D(LayoutPadding, TopBarButtonsY); leftView.Add(backButton); - moreButton = CreateButton(Resources.GetImagePath() + "more_button.png", Window.Instance.WindowSize.Width / 2 - LayoutPadding - IconSize, TopBarButtonsY); + moreButton = new Button("MoreButton"); + moreButton.ThemeChangeSensitive = true; + moreButton.Position2D = new Position2D(Window.Instance.WindowSize.Width / 2 - LayoutPadding - IconSize, TopBarButtonsY); rightView.Add(moreButton); } @@ -208,13 +178,13 @@ namespace MusicPlayer.Views private void AddTitleLabel() { - titleLabel = new TextLabel() + titleLabel = new TextLabel("LabelText") { + ThemeChangeSensitive = true, Size2D = new Size2D(ControlViewWidth, TitleLabelHeight), Position2D = new Position2D(0, 0), PixelSize = 36, FontFamily = "BreezeSans", - TextColor = UIColors.HEX001447, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Ellipsis = true, @@ -225,13 +195,13 @@ namespace MusicPlayer.Views private void AddArtistLabel() { - artistLabel = new TextLabel() + artistLabel = new TextLabel("LabelText") { + ThemeChangeSensitive = true, Size2D = new Size2D(ControlViewWidth, ArtistLabelHeight), Position2D = new Position2D(0, 62), PixelSize = 28, FontFamily = "BreezeSans", - TextColor = UIColors.HEX001447, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Ellipsis = true, @@ -248,9 +218,56 @@ namespace MusicPlayer.Views private void AddShuffleButton() { - shuffleButton = CreateButton(Resources.GetImagePath() + "shuffle.png", 0, 196); - shuffleButton.Icon.BindingContext = viewModel.playingListViewModel; - shuffleButton.Icon.SetBinding(ImageView.ResourceUrlProperty, "ShuffleUrl"); + shuffleButton = new MultiStateButton() + { + Size2D = new Size2D(IconSize, IconSize), + Position2D = new Position2D(0, 196), + IconResources = new Dictionary>() + { + { + ThemeType.Light, + new Dictionary() + { + { + ShuffleMode.Off.ToString(), + new StringSelector() + { + All = Resources.GetImagePath() + "light/shuffle_off.png", + } + }, + { + ShuffleMode.On.ToString(), + new StringSelector() + { + All = Resources.GetImagePath() + "light/shuffle_on.png", + } + }, + } + }, + { + ThemeType.Dark, + new Dictionary() + { + { + ShuffleMode.Off.ToString(), + new StringSelector() + { + All = Resources.GetImagePath() + "dark/shuffle_off.png", + } + }, + { + ShuffleMode.On.ToString(), + new StringSelector() + { + All = Resources.GetImagePath() + "dark/shuffle_on.png", + } + }, + } + } + }, + }; + shuffleButton.BindingContext = viewModel.playingListViewModel; + shuffleButton.SetBinding(MultiStateButton.CustomStateProperty, "ShuffleButtonState"); // TODO need to implement command instead shuffleButton.Clicked += (object sender, ClickedEventArgs e) => { @@ -261,15 +278,8 @@ namespace MusicPlayer.Views private void AddPreviousButton() { - ImageViewStyle prevIconStyle = new ImageViewStyle() - { - ResourceUrl = new Selector - { - Normal = Resources.GetImagePath() + "prev.png", - Disabled = Resources.GetImagePath() + "prev_disabled.png" - }, - }; - prevButton = CreateButton(prevIconStyle, 168, 196); + prevButton = new Button("PrevButton"); + prevButton.ThemeChangeSensitive = true; // TODO need to implement command instead prevButton.Clicked += (object sender, ClickedEventArgs e) => { @@ -282,9 +292,65 @@ namespace MusicPlayer.Views private void AddPlayButton() { - playButton = CreateButton(Resources.GetImagePath() + "play.png", 296, 196); - playButton.Icon.BindingContext = viewModel; - playButton.Icon.SetBinding(ImageView.ResourceUrlProperty, "PlayPauseUrl"); + playButton = new MultiStateButton() + { + Size2D = new Size2D(IconSize, IconSize), + Position2D = new Position2D(296, 196), + BackgroundColor = Color.Transparent, + IconResources = new Dictionary>() + { + { + ThemeType.Light, + new Dictionary() + { + { + "Play", + new StringSelector() + { + Normal = Resources.GetImagePath() + "light/play.png", + Pressed = Resources.GetImagePath() + "play_pressed.png", + Disabled = Resources.GetImagePath() + "play_disabled.png", + } + }, + { + "Pause", + new StringSelector() + { + Normal = Resources.GetImagePath() + "light/pause.png", + Pressed = Resources.GetImagePath() + "pause_pressed.png", + Disabled = Resources.GetImagePath() + "pause_disabled.png", + } + }, + } + }, + { + ThemeType.Dark, + new Dictionary() + { + { + "Play", + new StringSelector() + { + Normal = Resources.GetImagePath() + "dark/play.png", + Pressed = Resources.GetImagePath() + "play_pressed.png", + Disabled = Resources.GetImagePath() + "play_disabled.png", + } + }, + { + "Pause", + new StringSelector() + { + Normal = Resources.GetImagePath() + "dark/pause.png", + Pressed = Resources.GetImagePath() + "pause_pressed.png", + Disabled = Resources.GetImagePath() + "pause_disabled.png", + } + }, + } + } + }, + }; + playButton.BindingContext = viewModel; + playButton.SetBinding(MultiStateButton.CustomStateProperty, "PlayButtonState"); controlsView.Add(playButton); // TODO need to implement command instead playButton.Clicked += (object sender, ClickedEventArgs e) => @@ -295,16 +361,8 @@ namespace MusicPlayer.Views private void AddNextButton() { - ImageViewStyle nextIconStyle = new ImageViewStyle() - { - ResourceUrl = new Selector - { - Normal = Resources.GetImagePath() + "next.png", - Disabled = Resources.GetImagePath() + "next_disabled.png", - }, - }; - - nextButton = CreateButton(nextIconStyle, 424, 196); + nextButton = new Button("NextButton"); + nextButton.ThemeChangeSensitive = true; // TODO need to implement command instead nextButton.Clicked += (object sender, ClickedEventArgs e) => { @@ -317,9 +375,70 @@ namespace MusicPlayer.Views private void AddRepeatButton() { - repeatButton = CreateButton(Resources.GetImagePath() + "repeat.png", 592, 196); - repeatButton.Icon.BindingContext = viewModel.playingListViewModel; - repeatButton.Icon.SetBinding(ImageView.ResourceUrlProperty, "RepeatUrl"); + repeatButton = new MultiStateButton() + { + Size2D = new Size2D(IconSize, IconSize), + Position2D = new Position2D(592, 196), + IconResources = new Dictionary>() + { + { + ThemeType.Light, + new Dictionary() + { + { + RepeatMode.Off.ToString(), + new StringSelector() + { + All = Resources.GetImagePath() + "light/repeat_off.png", + } + }, + { + RepeatMode.RepeatOne.ToString(), + new StringSelector() + { + All = Resources.GetImagePath() + "light/repeat_one.png", + } + }, + { + RepeatMode.RepeatAll.ToString(), + new StringSelector() + { + All = Resources.GetImagePath() + "light/repeat_all.png", + } + }, + } + }, + { + ThemeType.Dark, + new Dictionary() + { + { + RepeatMode.Off.ToString(), + new StringSelector() + { + All = Resources.GetImagePath() + "dark/repeat_off.png", + } + }, + { + RepeatMode.RepeatOne.ToString(), + new StringSelector() + { + All = Resources.GetImagePath() + "dark/repeat_one.png", + } + }, + { + RepeatMode.RepeatAll.ToString(), + new StringSelector() + { + All = Resources.GetImagePath() + "dark/repeat_all.png", + } + }, + } + } + }, + }; + repeatButton.BindingContext = viewModel.playingListViewModel; + repeatButton.SetBinding(MultiStateButton.CustomStateProperty, "RepeatButtonState"); controlsView.Add(repeatButton); // TODO need to implement command instead repeatButton.Clicked += (object sender, ClickedEventArgs e) => @@ -339,48 +458,24 @@ namespace MusicPlayer.Views private void AddLeftVolumeIcon() { - leftVolumeIcon = new ImageView(Resources.GetImagePath() + "left_sound_icon.png") + leftVolumeIcon = new ImageView() { - Size2D = new Size2D(IconSize, IconSize), - Position2D = new Position2D(0, 336), + ThemeChangeSensitive = true, + StyleName = "LeftVolume", }; controlsView.Add(leftVolumeIcon); } private void AddRightVolumeIcon() { - rightVolumeIcon = new ImageView(Resources.GetImagePath() + "right_sound_icon.png") + rightVolumeIcon = new ImageView() { - Size2D = new Size2D(IconSize, IconSize), - Position2D = new Position2D(592, 336), + ThemeChangeSensitive = true, + StyleName = "RightVolume", }; controlsView.Add(rightVolumeIcon); } - private SliderStyle CreateVolumeSliderStyle() - { - SliderStyle volumeSliderStyle = new SliderStyle() - { - IndicatorType = Slider.IndicatorType.Image, - TrackThickness = 4, - Track = new ImageViewStyle - { - ResourceUrl = new Selector - { - All = Resources.GetImagePath() + "empty_track.png", - }, - }, - Progress = new ImageViewStyle - { - ResourceUrl = new Selector - { - All = Resources.GetImagePath() + "progress_track.png", - }, - }, - }; - return volumeSliderStyle; - } - private void AddVolumeSliderEventHandlers() { volumeSlider.SlidingStarted += (object sender, SliderSlidingStartedEventArgs e) => @@ -399,14 +494,8 @@ namespace MusicPlayer.Views private void AddVolumeSlider() { - volumeSlider = new Slider(CreateVolumeSliderStyle()); - volumeSlider.Indicator = Slider.IndicatorType.Text; - volumeSlider.TrackThickness = 4; - volumeSlider.ThumbImageURLSelector = new StringSelector - { - Normal = Resources.GetImagePath() + "nomal_slider_handler.png", - Pressed = Resources.GetImagePath() + "nomal_slider_handler.png" - }; + volumeSlider = new Slider("Slider"); + volumeSlider.ThemeChangeSensitive = true; volumeSlider.Size2D = new Size2D(496, 48); volumeSlider.Position2D = new Position2D(72, 336); volumeSlider.ThumbSize = new Tizen.NUI.Size(36, 36); @@ -434,30 +523,6 @@ namespace MusicPlayer.Views AddVolumeSliderElements(); } - private SliderStyle CreatePlaybackSliderStyle() - { - SliderStyle playbackSliderStyle = new SliderStyle() - { - IndicatorType = Slider.IndicatorType.Image, - TrackThickness = 4, - Track = new ImageViewStyle - { - ResourceUrl = new Selector - { - All = Resources.GetImagePath() + "empty_track.png", - }, - }, - Progress = new ImageViewStyle - { - ResourceUrl = new Selector - { - All = Resources.GetImagePath() + "progress_track.png", - }, - }, - }; - return playbackSliderStyle; - } - private void AddPlaybackSliderEventHandler() { playbackSlider.SlidingStarted += (object sender, SliderSlidingStartedEventArgs e) => @@ -476,20 +541,15 @@ namespace MusicPlayer.Views private void AddPlaybackSlider(View sliderView) { - playbackSlider = new Slider(CreatePlaybackSliderStyle()) + playbackSlider = new Slider("Slider") { - ThumbImageURLSelector = new StringSelector - { - Normal = Resources.GetImagePath() + "nomal_slider_handler.png", - Pressed = Resources.GetImagePath() + "nomal_slider_handler.png" - }, + ThemeChangeSensitive = true, MinValue = 0.0f, MaxValue = 1.0f, WidthResizePolicy = ResizePolicyType.FillToParent, SizeHeight = 44, ThumbSize = new Tizen.NUI.Size(36, 36), Direction = Slider.DirectionType.Horizontal, - IsCreateByXaml = true, }; playbackSlider.SetBinding(Slider.CurrentValueProperty, "ElapsedTime"); sliderView.Add(playbackSlider); @@ -498,11 +558,11 @@ namespace MusicPlayer.Views private void AddCurrentTimeLabel(View sliderView) { - currentTime = new TextLabel() + currentTime = new TextLabel("LabelText") { + ThemeChangeSensitive = true, Size2D = new Size2D(400, 32), Position2D = new Position2D(0, 48), - TextColor = UIColors.HEX001447, PixelSize = 24, FontFamily = "BreezeSans", Text = "00::00:00", @@ -514,11 +574,11 @@ namespace MusicPlayer.Views private void AddTotalTimeLabel(View sliderView) { - totalTime = new TextLabel() + totalTime = new TextLabel("LabelText") { + ThemeChangeSensitive = true, Size2D = new Size2D(400, 32), Position2D = new Position2D(1792 - 400, 48), - TextColor = UIColors.HEX001447, PixelSize = 24, FontFamily = "BreezeSans", HorizontalAlignment = HorizontalAlignment.End, @@ -576,7 +636,10 @@ namespace MusicPlayer.Views }; rightView.Add(actionButtonView); - listButton = CreateButton(Resources.GetImagePath() + "playing_queue.png", 0, 0); + listButton = new Button("ListButton") + { + ThemeChangeSensitive = true, + }; listButton.Clicked += (object sender, ClickedEventArgs e) => { if(viewState == PlayerViewState.AlbumArt) @@ -600,10 +663,61 @@ namespace MusicPlayer.Views }; actionButtonView.Add(listButton); - playlistButton = CreateButton(Resources.GetImagePath() + "addtoplaylist.png", 88, 0); + playlistButton = new Button("PlaylistButton") + { + ThemeChangeSensitive = true, + }; actionButtonView.Add(playlistButton); - favouriteButton = CreateButton(Resources.GetImagePath() + "favourite_off.png", 176, 0); + favouriteButton = new MultiStateButton() + { + Size2D = new Size2D(IconSize, IconSize), + Position2D = new Position2D(176, 0), + IconResources = new Dictionary>() + { + { + ThemeType.Light, + new Dictionary() + { + { + Favourite.Off.ToString(), + new StringSelector() + { + All = Resources.GetImagePath() + "light/favourite_off.png", + } + }, + { + Favourite.On.ToString(), + new StringSelector() + { + All = Resources.GetImagePath() + "light/favourite_on.png", + } + }, + } + }, + { + ThemeType.Dark, + new Dictionary() + { + { + Favourite.Off.ToString(), + new StringSelector() + { + All = Resources.GetImagePath() + "dark/favourite_off.png", + } + }, + { + Favourite.On.ToString(), + new StringSelector() + { + All = Resources.GetImagePath() + "dark/favourite_on.png", + } + }, + } + } + }, + }; + favouriteButton.CusotmState = Favourite.Off.ToString(); actionButtonView.Add(favouriteButton); } diff --git a/Views/TrackView.cs b/Views/TrackView.cs index 95467e5..daa7df1 100755 --- a/Views/TrackView.cs +++ b/Views/TrackView.cs @@ -16,9 +16,8 @@ namespace MusicPlayer.Views public TrackView(TrackViewModel viewModel) { this.viewModel = viewModel; - BindingContext = viewModel; collectionView.ItemsSource = viewModel.ListViewModel; - collectionView.ItemTemplate= new DataTemplate(()=> + collectionView.ItemTemplate = new DataTemplate(() => { ListItemLayout layout = new ListItemLayout(); layout.Icon.SetBinding(ImageView.ResourceUrlProperty, "ThumbnailPath"); @@ -31,21 +30,40 @@ namespace MusicPlayer.Views collectionView.SelectionMode = ItemSelectionMode.Single; collectionView.SelectionChanged += OnTrackSelection; - trackCountLabel = new TextLabel() + trackCountLabel = new TextLabel("LabelText") { + ThemeChangeSensitive = true, PixelSize = 28, Text = "TRACK COUNT", - TextColor = UIColors.HEX001447, VerticalAlignment = VerticalAlignment.Center, FontFamily = "BreezeSans", - IsCreateByXaml = true, }; + trackCountLabel.BindingContext = viewModel; titleView.Add(trackCountLabel); trackCountLabel.SetBinding(TextLabel.TextProperty, "TrackCount"); RelativeLayout.SetLeftTarget(trackCountLabel, titleView); RelativeLayout.SetLeftRelativeOffset(trackCountLabel, 1.0f); RelativeLayout.SetRightRelativeOffset(trackCountLabel, 0.0f); RelativeLayout.SetFillHorizontal(trackCountLabel, true); + + playAllIcon = new Button("PlayAll") + { + ThemeChangeSensitive = true, + }; + titleView.Add(playAllIcon); + RelativeLayout.SetLeftRelativeOffset(playAllIcon, 1.0f); + RelativeLayout.SetRightRelativeOffset(playAllIcon, 1.0f); + RelativeLayout.SetHorizontalAlignment(playAllIcon, RelativeLayout.Alignment.End); + + addToPlaylistIcon = new Button("PlaylistAdd") + { + ThemeChangeSensitive = true, + Margin = new Extents(32, 40, 0, 0), + }; + titleView.Add(addToPlaylistIcon); + RelativeLayout.SetRightTarget(addToPlaylistIcon, playAllIcon); + RelativeLayout.SetRightRelativeOffset(addToPlaylistIcon, 0.0f); + RelativeLayout.SetHorizontalAlignment(addToPlaylistIcon, RelativeLayout.Alignment.End); } private void OnTrackSelection(object sender, SelectionChangedEventArgs e) @@ -53,6 +71,10 @@ namespace MusicPlayer.Views //TODO } + protected override void OnThemeChanged(object sender, ThemeChangedEventArgs e) + { + base.OnThemeChanged(sender, e); + } protected override void Dispose(DisposeTypes type) { if(Disposed) @@ -66,13 +88,13 @@ namespace MusicPlayer.Views trackCountLabel = null; // TODO Uncomment after implementation is completed - //titleView.Remove(playAllIcon); - //playAllIcon.Dispose(); - //playAllIcon = null; + titleView.Remove(playAllIcon); + playAllIcon.Dispose(); + playAllIcon = null; //titleView.Remove(addToPlaylistIcon); - //addToPlaylistIcon.Dispose(); - //addToPlaylistIcon = null; + addToPlaylistIcon.Dispose(); + addToPlaylistIcon = null; } base.Dispose(type); } -- 2.34.1