[NUI] Revive View constructor with style working again in TV
authorJiyun Yang <ji.yang@samsung.com>
Wed, 1 Feb 2023 23:33:03 +0000 (08:33 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Thu, 2 Feb 2023 06:16:49 +0000 (15:16 +0900)
And hide PROFILE_TV flags to make clear code

Signed-off-by: Jiyun Yang <ji.yang@samsung.com>
src/Tizen.NUI.Components/Theme/DefaultTheme.cs
src/Tizen.NUI/src/public/Application/NUIApplication.cs
src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs
src/Tizen.NUI/src/public/Theme/DefaultTheme.cs
src/Tizen.NUI/src/public/Theme/DefaultThemeCommon.cs
src/Tizen.NUI/src/public/Theme/DefaultThemeTV.cs [deleted file]
src/Tizen.NUI/src/public/Theme/ThemeManager.cs

index b75cf4a..332d9a9 100755 (executable)
  *
  */
 
-#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
         }
     }
 }
index b8fac90..525bbb2 100755 (executable)
@@ -14,9 +14,6 @@
  * limitations under the License.
  *
  */
-#if !PROFILE_TV
-#define ExternalThemeEnabled
-#endif
 
 using System;
 using System.ComponentModel;
@@ -601,9 +598,7 @@ namespace Tizen.NUI
         static public void Preload()
         {
             Interop.Application.PreInitialize();
-#if ExternalThemeEnabled
             ThemeManager.Preload();
-#endif
             IsPreload = true;
         }
 
index 2bf18e4..0b053d6 100755 (executable)
@@ -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)
             {
index 6a87fd7..b8392d4 100644 (file)
@@ -14,7 +14,6 @@
  * limitations under the License.
  *
  */
-#if !PROFILE_TV
 
 using System.Diagnostics.CodeAnalysis;
 using Tizen.NUI.BaseComponents;
@@ -124,4 +123,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 (file)
index 89646fb..0000000
+++ /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
index 615edbe..2f8d678 100755 (executable)
  * 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
         }
 
         /// <summary>
@@ -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);
         }
 
         /// <summary>
@@ -105,7 +100,15 @@ namespace Tizen.NUI
         /// </summary>
         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
+
         /// <summary>
         /// Apply custom theme to the NUI.
         /// This will change the appearance of the existing components with property <seealso cref="View.ThemeChangeSensitive"/> on.
@@ -314,8 +323,7 @@ namespace Tizen.NUI
         /// <param name="version">The external theme version.</param>
         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));