From 27432b80fe720d9eec8f81353f7e2001e56fa34a Mon Sep 17 00:00:00 2001 From: Jiyun Yang Date: Thu, 2 Feb 2023 08:33:03 +0900 Subject: [PATCH] [NUI] Revive View constructor with style working again in TV And hide PROFILE_TV flags to make clear code Signed-off-by: Jiyun Yang --- src/Tizen.NUI.Components/Theme/DefaultTheme.cs | 8 +--- .../src/public/Application/NUIApplication.cs | 5 -- .../src/public/BaseComponents/ViewInternal.cs | 10 ++-- src/Tizen.NUI/src/public/Theme/DefaultTheme.cs | 1 - .../src/public/Theme/DefaultThemeCommon.cs | 2 - src/Tizen.NUI/src/public/Theme/DefaultThemeTV.cs | 37 --------------- src/Tizen.NUI/src/public/Theme/ThemeManager.cs | 54 ++++++++++------------ 7 files changed, 33 insertions(+), 84 deletions(-) delete mode 100644 src/Tizen.NUI/src/public/Theme/DefaultThemeTV.cs diff --git a/src/Tizen.NUI.Components/Theme/DefaultTheme.cs b/src/Tizen.NUI.Components/Theme/DefaultTheme.cs index b75cf4a..332d9a9 100755 --- a/src/Tizen.NUI.Components/Theme/DefaultTheme.cs +++ b/src/Tizen.NUI.Components/Theme/DefaultTheme.cs @@ -15,10 +15,6 @@ * */ -#if !PROFILE_TV -#define ExternalThemeEnabled -#endif - namespace Tizen.NUI.Components { internal partial class DefaultThemeCreator @@ -29,13 +25,13 @@ namespace Tizen.NUI.Components public static void Preload() { -#if ExternalThemeEnabled + if (ThemeManager.InitialThemeDisabled) return; + ThemeManager.AddPackageTheme(Instance); if (string.IsNullOrEmpty(ExternalThemeManager.CurrentThemeId)) return; ThemeManager.LoadPlatformTheme(ExternalThemeManager.CurrentThemeId); -#endif } } } diff --git a/src/Tizen.NUI/src/public/Application/NUIApplication.cs b/src/Tizen.NUI/src/public/Application/NUIApplication.cs index 3d635d2..57af84a 100755 --- a/src/Tizen.NUI/src/public/Application/NUIApplication.cs +++ b/src/Tizen.NUI/src/public/Application/NUIApplication.cs @@ -14,9 +14,6 @@ * limitations under the License. * */ -#if !PROFILE_TV -#define ExternalThemeEnabled -#endif using System; using System.ComponentModel; @@ -613,9 +610,7 @@ namespace Tizen.NUI static public void Preload() { Interop.Application.PreInitialize(); -#if ExternalThemeEnabled ThemeManager.Preload(); -#endif IsPreload = true; } diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs index 2bf18e4..0b053d6 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs @@ -1560,10 +1560,12 @@ namespace Tizen.NUI.BaseComponents [EditorBrowsable(EditorBrowsableState.Never)] protected virtual void InitializeStyle(ViewStyle style = null) { -#if PROFILE_TV - // tv profile doesn't use NUI Style, so do nothing and just return here! - return; -#endif + if (style == null && ThemeManager.InitialThemeDisabled) + { + // Fast return in most TV cases. + return; + } + var initialStyle = ThemeManager.GetInitialStyleWithoutClone(GetType()); if (style == null) { diff --git a/src/Tizen.NUI/src/public/Theme/DefaultTheme.cs b/src/Tizen.NUI/src/public/Theme/DefaultTheme.cs index dca88a0..7467200 100644 --- a/src/Tizen.NUI/src/public/Theme/DefaultTheme.cs +++ b/src/Tizen.NUI/src/public/Theme/DefaultTheme.cs @@ -15,7 +15,6 @@ * */ -using System.Collections.Generic; namespace Tizen.NUI { diff --git a/src/Tizen.NUI/src/public/Theme/DefaultThemeCommon.cs b/src/Tizen.NUI/src/public/Theme/DefaultThemeCommon.cs index 188ae87..50987c8 100644 --- a/src/Tizen.NUI/src/public/Theme/DefaultThemeCommon.cs +++ b/src/Tizen.NUI/src/public/Theme/DefaultThemeCommon.cs @@ -14,7 +14,6 @@ * limitations under the License. * */ -#if !PROFILE_TV using System.Diagnostics.CodeAnalysis; using Tizen.NUI.BaseComponents; @@ -130,4 +129,3 @@ namespace Tizen.NUI } } -#endif // !PROFILE_TV diff --git a/src/Tizen.NUI/src/public/Theme/DefaultThemeTV.cs b/src/Tizen.NUI/src/public/Theme/DefaultThemeTV.cs deleted file mode 100644 index 89646fb..0000000 --- a/src/Tizen.NUI/src/public/Theme/DefaultThemeTV.cs +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright(c) 2021 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#if PROFILE_TV -using System.Collections.Generic; - -namespace Tizen.NUI -{ - internal partial class DefaultThemeCreator - { - public Theme Create() - { - Tizen.Log.Info("NUI", $"PROFILE_TV DefaultThemeCreator.Create()"); - - Theme theme = new Theme() - { - Id = DefaultId, - Version = DefaultVersion, - }; - return theme; - } - } -} -#endif diff --git a/src/Tizen.NUI/src/public/Theme/ThemeManager.cs b/src/Tizen.NUI/src/public/Theme/ThemeManager.cs index f41263c..6132515 100755 --- a/src/Tizen.NUI/src/public/Theme/ThemeManager.cs +++ b/src/Tizen.NUI/src/public/Theme/ThemeManager.cs @@ -14,11 +14,6 @@ * limitations under the License. * */ - -#if !PROFILE_TV -#define ExternalThemeEnabled -#endif - using System; using System.Collections.Generic; using System.ComponentModel; @@ -53,10 +48,10 @@ namespace Tizen.NUI static ThemeManager() { -#if ExternalThemeEnabled + if (InitialThemeDisabled) return; + ExternalThemeManager.Initialize(); AddPackageTheme(DefaultThemeCreator.Instance); -#endif } /// @@ -96,7 +91,7 @@ namespace Tizen.NUI [EditorBrowsable(EditorBrowsableState.Never)] public static string PlatformThemeId { - get => platformTheme?.Id ?? (platformThemeEnabled ? baseTheme.Id : null); + get => platformTheme?.Id ?? (platformThemeEnabled ? baseTheme?.Id : null); } /// @@ -105,7 +100,15 @@ namespace Tizen.NUI /// internal static Theme BaseTheme { - get => baseTheme; + get + { + if (baseTheme == null) + { + baseTheme = new Theme(); + UpdateThemeForInitialize(); + } + return baseTheme; + } set { baseTheme = value; @@ -146,6 +149,12 @@ namespace Tizen.NUI internal static bool ApplicationThemeChangeSensitive { get; set; } = false; +#if PROFILE_TV + internal const bool InitialThemeDisabled = true; +#else + internal const bool InitialThemeDisabled = false; +#endif + /// /// Apply custom theme to the NUI. /// This will change the appearance of the existing components with property on. @@ -314,8 +323,7 @@ namespace Tizen.NUI /// The external theme version. internal static void ApplyExternalPlatformTheme(string id, string version) { -#if ExternalThemeEnabled - Debug.Assert(baseTheme != null); + if (InitialThemeDisabled) return; // If the given theme is invalid, do nothing. if (string.IsNullOrEmpty(id)) @@ -324,7 +332,7 @@ namespace Tizen.NUI } // If no platform theme has been applied and the base theme can cover the given one, do nothing. - if (platformTheme == null && baseTheme.HasSameIdAndVersion(id, version)) + if (platformTheme == null && baseTheme != null && baseTheme.HasSameIdAndVersion(id, version)) { Tizen.Log.Info("NUI", "The base theme can cover platform theme: Skip loading."); return; @@ -347,23 +355,16 @@ namespace Tizen.NUI UpdateThemeForUpdate(); NotifyThemeChanged(true); } -#endif } internal static void AddPackageTheme(IThemeCreator themeCreator) { -#if PROFILE_TV - // for tv profile, set empty theme and just return here! - userTheme = null; - baseTheme = themeCreator.Create(); - return; -#endif - if (packages.Contains(themeCreator)) + if (InitialThemeDisabled || packages.Contains(themeCreator)) { return; } - Tizen.Log.Info("NUI", $"AddPackageTheme({themeCreator.GetType().Assembly.GetName().Name})"); + Tizen.Log.Debug("NUI", $"AddPackageTheme({themeCreator.GetType().Assembly.GetName().Name})"); packages.Add(themeCreator); // Base theme @@ -374,7 +375,6 @@ namespace Tizen.NUI else baseTheme.MergeWithoutClone(packageBaseTheme); baseTheme.PackageCount++; -#if ExternalThemeEnabled if (platformThemeEnabled) { Tizen.Log.Info("NUI", $"Platform theme is enabled"); @@ -395,19 +395,16 @@ namespace Tizen.NUI } UpdateThemeForUpdate(); } -#endif UpdateThemeForInitialize(); } internal static void Preload() { -#if ExternalThemeEnabled - Debug.Assert(baseTheme != null); + if (InitialThemeDisabled) return; if (string.IsNullOrEmpty(ExternalThemeManager.CurrentThemeId)) return; LoadPlatformTheme(ExternalThemeManager.CurrentThemeId); -#endif } // TODO Please make it private after removing Tizen.NUI.Components.StyleManager. @@ -440,7 +437,8 @@ namespace Tizen.NUI } themeForInitialize = new Theme(); - themeForInitialize.Merge(baseTheme); + + if (baseTheme != null) themeForInitialize.Merge(baseTheme); if (userTheme == null) { @@ -529,8 +527,6 @@ namespace Tizen.NUI private static void NotifyThemeChanged(bool platformThemeUpdated = false) { - Debug.Assert(baseTheme != null); - var platformThemeId = PlatformThemeId; var userThemeId = userTheme?.Id; ThemeChangedInternal.Invoke(null, new ThemeChangedEventArgs(userThemeId, platformThemeId, platformThemeUpdated)); -- 2.7.4