From: aman.jeph Date: Fri, 30 Jul 2021 09:18:48 +0000 (+0530) Subject: Adding dark/light theme support part-1 X-Git-Tag: submit/tizen/20210915.141722~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d073538da1e4708f314870d87ebedc2eb2854e3f;p=profile%2Fiot%2Fapps%2Fdotnet%2Fmusic-player.git Adding dark/light theme support part-1 Change-Id: I62bba67864778f1a551b58c89da4dc5b7eb5ae15 Signed-off-by: aman.jeph --- diff --git a/Common/AppConstants.cs b/Common/AppConstants.cs index 3dfb522..104322b 100755 --- a/Common/AppConstants.cs +++ b/Common/AppConstants.cs @@ -10,5 +10,7 @@ // string literals public const string TimeFormat = @"mm\:ss"; + public const string LightPlatformThemeId = "org.tizen.default-light-theme"; + public const string DarkPlatformThemeId = "org.tizen.default-dark-theme"; } } diff --git a/Common/PlayerCommon.cs b/Common/PlayerCommon.cs index 2d51a56..04ba5a2 100755 --- a/Common/PlayerCommon.cs +++ b/Common/PlayerCommon.cs @@ -4,6 +4,11 @@ using System.Text; namespace MusicPlayer.Common { + public enum ThemeType + { + Light, + Dark + }; public enum RepeatMode { Off, @@ -25,6 +30,12 @@ namespace MusicPlayer.Common Off, } + public enum Favourite + { + On, + Off, + } + public enum EventType { Error, diff --git a/Common/Resources.cs b/Common/Resources.cs index 865883c..361c2da 100644 --- a/Common/Resources.cs +++ b/Common/Resources.cs @@ -10,5 +10,10 @@ namespace MusicPlayer.Common { return Tizen.Applications.Application.Current.DirectoryInfo.Resource + "images/"; } + + public static string GetThemePath() + { + return Tizen.Applications.Application.Current.DirectoryInfo.Resource + "themes/"; + } } } diff --git a/Models/PlayerModel.cs b/Models/PlayerModel.cs index f5335a0..1bc59db 100755 --- a/Models/PlayerModel.cs +++ b/Models/PlayerModel.cs @@ -22,7 +22,6 @@ namespace MusicPlayer.Models TrackLength = currentTrack.Duration; PlayingTime = TimeSpan.FromMilliseconds(0).ToString(AppConstants.TimeFormat); ThumbnailPath = currentTrack.ThumbnailPath; - PlayingStatus = PlayingStatus.None; } } @@ -58,14 +57,6 @@ namespace MusicPlayer.Models set => SetProperty(ref thumbnailPath, value); } - private PlayingStatus playingStatus; - - public PlayingStatus PlayingStatus - { - get => playingStatus; - set { playingStatus = value; } - } - private string playingTime; public string PlayingTime diff --git a/MusicPlayer.cs b/MusicPlayer.cs index 1a0a01e..cb65d24 100755 --- a/MusicPlayer.cs +++ b/MusicPlayer.cs @@ -7,6 +7,10 @@ namespace MusicPlayer { public class Application : NUIApplication { + public Application() : base(ThemeOptions.PlatformThemeEnabled) + { + + } protected override void OnCreate() { Tizen.Log.Info(AppConstants.LogTag, "OnCreate statrted"); diff --git a/Views/Utils/MultiStateButton.cs b/Views/Utils/MultiStateButton.cs new file mode 100644 index 0000000..e605dc0 --- /dev/null +++ b/Views/Utils/MultiStateButton.cs @@ -0,0 +1,93 @@ +using System.Collections.Generic; +using Tizen.NUI; +using Tizen.NUI.Binding; +using Tizen.NUI.Components; +using MusicPlayer.Common; + +namespace MusicPlayer.Views.Utils +{ + class MultiStateButton: Button + { + public static readonly BindableProperty CustomStateProperty = BindableProperty.Create(nameof(CusotmState), typeof(string), typeof(MultiStateButton), null, propertyChanged: (bindable, oldValue, newValue) => + { + var instance = (MultiStateButton)bindable; + if (newValue != null) + { + string newCustomState = (string)newValue; + instance.UpdateCustomState(newCustomState); + } + }, + defaultValueCreator: (bindable) => + { + var instance = (MultiStateButton)bindable; + return instance.customState; + }); + + public MultiStateButton() : base() + { + ThemeChangeSensitive = true; + EnableControlState = true; + BackgroundColor = Color.Transparent; + } + + private Dictionary> iconResources; + + public Dictionary> IconResources + { + get => iconResources; + set => iconResources = value; + } + + private string customState; + public string CusotmState + { + get => (string)GetValue(CustomStateProperty); + set => SetValue(CustomStateProperty, value); + } + + private void UpdateCustomState(string customStatevalue) + { + if (IconResources == null) + { + Tizen.Log.Error(AppConstants.LogTag, "ThemesIconState needs to be set first"); + return; + } + ThemeType type = GetCurrentThemeType(); + if (iconResources.ContainsKey(type) == false) + { + Tizen.Log.Error(AppConstants.LogTag, "Theme state doesn't exists: " + type.ToString()); + return; + } + Dictionary stateResource = iconResources[type]; + if (stateResource.ContainsKey(customStatevalue) == false) + { + Tizen.Log.Error(AppConstants.LogTag, "Invalid state: " + customStatevalue); + return; + } + IconURLSelector = stateResource[customStatevalue]; + customState = customStatevalue; + } + + private ThemeType GetCurrentThemeType() + { + ThemeType type; + string id = ThemeManager.PlatformThemeId; + if (id.Equals(AppConstants.LightPlatformThemeId)) + { + type = ThemeType.Light; + } + else + { + type = ThemeType.Dark; + } + return type; + } + + protected override void OnThemeChanged(object sender, ThemeChangedEventArgs e) + { + base.OnThemeChanged(sender, e); + UpdateCustomState(CusotmState); + } + } +} + diff --git a/res/themes/dark.xaml b/res/themes/dark.xaml new file mode 100644 index 0000000..1ad5b52 --- /dev/null +++ b/res/themes/dark.xaml @@ -0,0 +1,154 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + *Resource*/images/empty_track.png + + + + + *Resource*/images/dark/progress_track.png + + + + + *Resource*/images/dark/nomal_slider_handler.png + + + + + + + + + + + + + + + + + + + + + + + + + + *Resource*/images/dark/left_sound_icon.png + + + + *Resource*/images/dark/right_sound_icon.png + + + + + + + + + + + \ No newline at end of file diff --git a/res/themes/light.xaml b/res/themes/light.xaml new file mode 100644 index 0000000..552ec81 --- /dev/null +++ b/res/themes/light.xaml @@ -0,0 +1,154 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + *Resource*/images/empty_track.png + + + + + *Resource*/images/light/progress_track.png + + + + + *Resource*/images/light/nomal_slider_handler.png + + + + + + + + + + + + + + + + + + + + + + + + + + *Resource*/images/light/left_sound_icon.png + + + + *Resource*/images/light/right_sound_icon.png + + + + + + + + + + + \ No newline at end of file