Implement SetBinding differently in Setting-Wallpaper with XAML off to improve launch... 46/322846/6 tizen
authorMd. Shahrukh Islam <shahrukhi.i@samsung.com>
Wed, 16 Apr 2025 10:26:24 +0000 (16:26 +0600)
committerMd. Shahrukh Islam <shahrukhi.i@samsung.com>
Thu, 17 Apr 2025 03:44:18 +0000 (09:44 +0600)
[Cause & Measure]
1. Implemented SetBinding with creating new BindingSession
2. Set IsUsingXaml variable to false.

Change-Id: I82750c6c9962a8c52e8cdfa0217911bc274a3be7
Signed-off-by: Md. Shahrukh Islam <shahrukhi.i@samsung.com>
SettingWallpaper/SettingWallpaper/Core/ViewManager.cs
SettingWallpaper/SettingWallpaper/SettingWallpaper.csproj
SettingWallpaper/SettingWallpaper/Views/AlbumView.cs
SettingWallpaper/SettingWallpaper/Views/CustomTitleItem.cs
SettingWallpaper/SettingWallpaper/Views/MainPage.cs
SettingWallpaper/SettingWallpaper/Views/WallpaperView.cs
packaging/org.tizen.cssetting-wallpaper-1.0.2.rpk

index a64115f6eec77c3a8ceee73698a0e87dc62ea447..f2e6e252bba2c05277ad853fc572f56e65ec6429 100644 (file)
@@ -29,9 +29,27 @@ using SettingWallpaper.MediaContent;
 using SettingWallpaper.Models;
 using SettingWallpaper.Views;
 using SettingWallpaper.ViewModels;
+using System.Windows.Input;
+using System.Collections;
 
 namespace SettingWallpaper.Core
 {
+    static class WallpaperViewBindings
+    {
+        public static BindingProperty<WallpaperView, IEnumerable> WallpaperListProperty { get; } = new BindingProperty<WallpaperView, IEnumerable>
+        {
+            Setter = (v, value) => v.WallpaperList = value,
+        };
+    }
+
+    static class CollectionViewBindings
+    {
+        public static BindingProperty<CollectionView, ICommand> SelectionChangedCommandProperty { get; } = new BindingProperty<CollectionView, ICommand>
+        {
+            Setter = (v, value) => v.SelectionChangedCommand = value,
+        };
+    }
+
     class ViewManager : IDisposable
     {
         private WallpaperView wallpaperView;
@@ -56,8 +74,18 @@ namespace SettingWallpaper.Core
             wallpaperViewModel.WallpaperChanged += OnWallpaperChanged;
 
             wallpaperView = new WallpaperView();
+
+            var session = new BindingSession<WallpaperViewModel>();
+            wallpaperView.BindingContextChanged += (sender, e) =>
+            {
+                if (wallpaperView.BindingContext is WallpaperViewModel model)
+                {
+                    session.ViewModel = model;
+                }
+            };
+            wallpaperView.SetBinding(session, WallpaperViewBindings.WallpaperListProperty, "WallpaperListSource");
             wallpaperView.BindingContext = wallpaperViewModel;
-            wallpaperView.SetBinding(WallpaperView.WallpaperListProperty, "WallpaperListSource");
+
             wallpaperView.TouchEvent += (object source, View.TouchEventArgs e) =>
             {
                 if (e.Touch.GetState(0) == PointStateType.Down)
@@ -234,10 +262,21 @@ namespace SettingWallpaper.Core
         {
             if (albumView == null)
             {
+                var session = new BindingSession<AlbumViewModel>();
+
                 albumView = new AlbumView(customWindow);
+
+                albumView.BindingContextChanged += (sender, e) =>
+                {
+                    if (albumView.BindingContext is AlbumViewModel model)
+                    {
+                        session.ViewModel = model;
+                    }
+                };
+
+                albumView.SetBinding(session, CollectionViewBindings.SelectionChangedCommandProperty, "SelectionChangedCommand");
                 albumView.BindingContext = albumViewModel;
                 albumViewModel.AlbumSelected += OnAlbumSelected;
-                albumView.SetBinding(CollectionView.SelectionChangedCommandProperty, "SelectionChangedCommand");
             }
             return albumView;
         }
@@ -246,8 +285,19 @@ namespace SettingWallpaper.Core
         {
             if (albumDetailView == null)
             {
+                var session = new BindingSession<AlbumDetailViewModel>();
+
                 albumDetailView = new AlbumDetailView(customWindow);
-                albumDetailView.SetBinding(CollectionView.SelectionChangedCommandProperty, "SelectionChangedCommand");
+
+                albumDetailView.BindingContextChanged += (sender, e) =>
+                {
+                    if (albumDetailView.BindingContext is AlbumDetailViewModel model)
+                    {
+                        session.ViewModel = model;
+                    }
+                };
+                albumDetailView.SetBinding(session, CollectionViewBindings.SelectionChangedCommandProperty, "SelectionChangedCommand");
+
             }
             albumDetailView.BindingContext = albumDetailViewModel;
 
index b1bf0c02c3d5d0c98c7549e4cd4da88e55a8a6bb..9ee2694cf1dbd2e42e7f5f908e9ec59348d85bce 100644 (file)
@@ -14,7 +14,7 @@
        </PropertyGroup>
        <ItemGroup>
                <PackageReference Include="SettingCore" Version="2.0.0" />
-               <PackageReference Include="Tizen.NET" Version="12.0.0.18518" />
+               <PackageReference Include="Tizen.NET.API13" Version="13.0.0.18710" />
        </ItemGroup>
 
        <ItemGroup>
index 2a5cd68e5d90e8c219b64527a9db9ddda34199bf..75c68b89146daaea85d17c7f6a03701f167dcad7 100644 (file)
@@ -19,9 +19,18 @@ using Tizen.NUI.BaseComponents;
 using Tizen.NUI.Binding;
 using Tizen.NUI.Components;
 using SettingWallpaper.Common;
+using SettingWallpaper.ViewModels;
+using System.Collections;
 
 namespace SettingWallpaper.Views
 {
+    static class RecyclerViewBindings
+    {
+        public static BindingProperty<RecyclerView, IEnumerable> ItemsSourceProperty { get; } = new BindingProperty<RecyclerView, IEnumerable>
+        {
+            Setter = (v, value) => v.ItemsSource = value,
+        };
+    }
     class AlbumView : CollectionView
     {
         private CustomAlbumTitle albumTitleItem;
@@ -40,15 +49,34 @@ namespace SettingWallpaper.Views
             albumTitleItem = new CustomAlbumTitle();
             Header = albumTitleItem;
             UpdateItemTemplate();
-            this.SetBinding(ItemsSourceProperty, "AlbumListSource");
+
+            var session = new BindingSession<AlbumViewModel>();
+            this.BindingContextChanged += (sender, e) =>
+            {
+                if (this.BindingContext is AlbumViewModel model)
+                {
+                    session.ViewModel = model;
+                }
+            };
+            this.SetBinding(session, RecyclerViewBindings.ItemsSourceProperty, "AlbumListSource");
         }
 
         public void UpdateItemTemplate()
         {
             ItemTemplate = new DataTemplate(() =>
             {
+                var itemSession = new BindingSession<AlbumDetailViewModel>();
+
                 AlbumItemLayout item = new AlbumItemLayout();
-                item.AlbumLabel.SetBinding(TextLabel.TextProperty, "AlbumName");
+
+                item.BindingContextChanged += (sender, e) =>
+                {
+                    if (item.BindingContext is AlbumDetailViewModel model)
+                    {
+                        itemSession.ViewModel = model;
+                    }
+                };
+                item.AlbumLabel.SetBinding(itemSession, TextLabelBindings.TextProperty, "AlbumName");
                 return item;
             });
         }
index 87b7c7477c7d5dfcd788f000db36b45045812243..4f8bbe43f17b24a7c4f1d0b7328fd2ab28d3d60e 100644 (file)
@@ -19,6 +19,7 @@ using Tizen.NUI.BaseComponents;
 using Tizen.NUI.Binding;
 using Tizen.NUI.Components;
 using SettingWallpaper.Common;
+using SettingWallpaper.ViewModels;
 
 namespace SettingWallpaper.Views
 {
@@ -40,6 +41,9 @@ namespace SettingWallpaper.Views
             {
                 StyleName = "BackIcon",
             };
+
+            var session = new BindingSession<AlbumDetailViewModel>();
+
             backButton = new Button()
             {
                 Size2D = AppCommon.buttonSize,
@@ -50,8 +54,17 @@ namespace SettingWallpaper.Views
                 BackgroundColor = Color.Transparent,
             };
             backButton.Add(icon);
-            backButton.SetBinding(Control.CommandProperty, "BackButtonCommand");
+
+            backButton.BindingContextChanged += (sender, e) =>
+            {
+                if (backButton.BindingContext is AlbumDetailViewModel model)
+                {
+                    session.ViewModel = model;
+                }
+            };
+            backButton.SetBinding(session, ButtonBindings.CommandProperty, "BackButtonCommand");
             RelativeLayout.SetVerticalAlignment(backButton, RelativeLayout.Alignment.Center);
+
             albumTitle = new TextLabel()
             {
                 StyleName = "ItemText",
@@ -59,7 +72,16 @@ namespace SettingWallpaper.Views
                 HorizontalAlignment = HorizontalAlignment.Begin,
                 BackgroundColor = Color.Transparent,
             };
-            albumTitle.SetBinding(TextLabel.TextProperty, "AlbumName");
+
+            albumTitle.BindingContextChanged += (sender, e) =>
+            {
+                if (albumTitle.BindingContext is AlbumDetailViewModel model)
+                {
+                    session.ViewModel = model;
+                }
+            };
+
+            albumTitle.SetBinding(session, TextLabelBindings.TextProperty, "AlbumName");
             RelativeLayout.SetLeftTarget(albumTitle, backButton);
             RelativeLayout.SetLeftRelativeOffset(albumTitle, 1.0f);
             RelativeLayout.SetVerticalAlignment(albumTitle, RelativeLayout.Alignment.Center);
index 0c8b595d765f9281447430e589cb979ecdf49831..77dda1913e185d21f9fab49747429e4fa894f6b3 100644 (file)
@@ -44,6 +44,7 @@ namespace SettingWallpaper
 
         protected override View OnCreate()
         {
+            NUIApplication.IsUsingXaml = false;
             Tizen.Log.Info(Resources.LogTag, "OnCreate");
             base.OnCreate();
             gadgetResourceManager = NUIGadgetResourceManager;
index 067bd2763bfc17d757356f7bbd77bae33584124e..0ba758af513d7cb289802672dc449a29b13813cd 100644 (file)
@@ -25,9 +25,47 @@ using SettingWallpaper.Common;
 using SettingWallpaper.LanguageResources;
 using SettingCore;
 using System.Text;
-
+using System;
+using System.Windows.Input;
+using SettingWallpaper.ViewModels;
+using SettingWallpaper.Models;
+using Tizen.Maps;
 namespace SettingWallpaper.Views
 {
+    static class ButtonBindings
+    {
+        public static BindingProperty<Button, bool> IsSelectedProperty { get; } = new BindingProperty<Button, bool>
+        {
+            Setter = (v, value) => v.IsSelected = value,
+        };
+
+        public static BindingProperty<Button, ICommand> CommandProperty { get; } = new BindingProperty<Button, ICommand>
+        {
+            Setter = (v, value) => v.Command = value,
+        };
+
+        public static BindingProperty<Button, bool> IsEnabledProperty { get; } = new BindingProperty<Button, bool>
+        {
+            Setter = (v, value) => v.IsEnabled = value,
+        };
+    }
+
+    static class ImageViewBindings
+    {
+        public static BindingProperty<ImageView, string> ResourceUrlProperty { get; } = new BindingProperty<ImageView, string>
+        {
+            Setter = (v, value) => v.ResourceUrl = value,
+        };
+    }
+
+    static class SaveButtonBindings
+    {
+        public static BindingProperty<Button, ICommand> CommandProperty { get; } = new BindingProperty<Button, ICommand>
+        {
+            Setter = (v, value) => v.Command = value,
+        };
+    }
+
     class WallpaperView : ImageView
     {
         private View bottomView;
@@ -161,8 +199,26 @@ namespace SettingWallpaper.Views
                 BackgroundColor = Color.Transparent,
             };
             previousButton.Add(icon);
-            previousButton.SetBinding(IsEnabledProperty, "IsPreviousImageAvailable");
-            previousButton.SetBinding(Control.CommandProperty, "PreviousButtonCommand");
+            try
+            {
+                var session = new BindingSession<WallpaperViewModel>();
+
+                previousButton.BindingContextChanged += (sender, e) =>
+                {
+                    if (previousButton.BindingContext is WallpaperViewModel model)
+                    {
+                        session.ViewModel = model;
+                    }
+                };
+
+                previousButton.SetBinding(session, ButtonBindings.IsEnabledProperty, "IsPreviousImageAvailable");
+                previousButton.SetBinding(session, ButtonBindings.CommandProperty, "PreviousButtonCommand");
+            }
+            catch (Exception ex)
+            {
+                Tizen.Log.Debug("SRK", "First Vul "+ex.Message);
+            }
+
             bottomView.Add(previousButton);
         }
 
@@ -180,7 +236,16 @@ namespace SettingWallpaper.Views
             };
 
             albumFolder.Add(folderIconNormal);
-            albumFolder.SetBinding(Control.CommandProperty, "AlbumFolderCommand");
+
+            var session = new BindingSession<WallpaperViewModel>();
+            albumFolder.BindingContextChanged += (sender, e) =>
+            {
+                if (albumFolder.BindingContext is WallpaperViewModel model)
+                {
+                    session.ViewModel = model;
+                }
+            };
+            albumFolder.SetBinding(session, ButtonBindings.CommandProperty, "AlbumFolderCommand");
             bottomView.Add(albumFolder);
         }
 
@@ -232,9 +297,28 @@ namespace SettingWallpaper.Views
                     wallpaperListView.Add(wallpaper);
                     Tizen.Log.Info(Resources.LogTag, "Buttons Added");
 
+                    var session = new BindingSession<ImageDataModel>();
+                    icon.BindingContextChanged += (sender, e) =>
+                    {
+                        if (icon.BindingContext is ImageDataModel model)
+                        {
+                            session.ViewModel = model;
+                        }
+                    };
+
+                    icon.SetBinding(session, ImageViewBindings.ResourceUrlProperty, "ThumbnailUrl");
+
+                    wallpaper.BindingContextChanged += (sender, e) =>
+                    {
+                        if (wallpaper.BindingContext is ImageDataModel model)
+                        {
+                            session.ViewModel = model;
+                        }
+                    };
+                    wallpaper.SetBinding(session, ButtonBindings.CommandProperty, "WallpaperSelectCommand");
+
                     wallpaper.BindingContext = item;
-                    icon.SetBinding(ResourceUrlProperty, "ThumbnailUrl");
-                    wallpaper.SetBinding(Control.CommandProperty, "WallpaperSelectCommand");
+
                 }
                 index++;
             }
@@ -275,6 +359,7 @@ namespace SettingWallpaper.Views
 
         private void AddNextButton()
         {
+            var session = new BindingSession<WallpaperViewModel>();
             ImageView icon = new ImageView
             {
                 StyleName = "NextIcon",
@@ -285,8 +370,16 @@ namespace SettingWallpaper.Views
                 BackgroundColor = Color.Transparent,
             };
             nextButton.Add(icon);
-            nextButton.SetBinding(IsEnabledProperty, "IsNextImageAvailable");
-            nextButton.SetBinding(Control.CommandProperty, "NextButtonCommand");
+
+            nextButton.BindingContextChanged += (sender, e) =>
+            {
+                if (nextButton.BindingContext is WallpaperViewModel model)
+                {
+                    session.ViewModel = model;
+                }
+            };
+            nextButton.SetBinding(session, ButtonBindings.IsEnabledProperty, "IsNextImageAvailable");
+            nextButton.SetBinding(session, ButtonBindings.CommandProperty, "NextButtonCommand");
             bottomView.Add(nextButton);
         }
 
@@ -322,7 +415,17 @@ namespace SettingWallpaper.Views
                 Text = MainPage.gadgetResourceManager.GetString(nameof(LanguageResource.IDS_SAVE)),
                 Margin = AppCommon.saveButtonMargin,
             };
-            SaveButton.SetBinding(Control.CommandProperty, "SetWallpaperCommand");
+
+            var session = new BindingSession<WallpaperViewModel>();
+
+            SaveButton.BindingContextChanged += (sender, e) =>
+            {
+                if (SaveButton.BindingContext is WallpaperViewModel model)
+                {
+                    session.ViewModel = model;
+                }
+            };
+            SaveButton.SetBinding(session, SaveButtonBindings.CommandProperty, "SetWallpaperCommand");
             SaveButton.Hide();
 
             appBar = new AppBar()
index 666273f2762649f87f36647bc66e7bfcaa22d56c..b021ff4ef0bb963651e31bbe4c536bc1c577a867 100644 (file)
Binary files a/packaging/org.tizen.cssetting-wallpaper-1.0.2.rpk and b/packaging/org.tizen.cssetting-wallpaper-1.0.2.rpk differ