From: Md. Shahrukh Islam Date: Wed, 16 Apr 2025 10:26:24 +0000 (+0600) Subject: Implement SetBinding differently in Setting-Wallpaper with XAML off to improve launch... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen;p=profile%2Fiot%2Fapps%2Fdotnet%2Fsetting-wallpaper.git Implement SetBinding differently in Setting-Wallpaper with XAML off to improve launch time and memory management. [Cause & Measure] 1. Implemented SetBinding with creating new BindingSession 2. Set IsUsingXaml variable to false. Change-Id: I82750c6c9962a8c52e8cdfa0217911bc274a3be7 Signed-off-by: Md. Shahrukh Islam --- diff --git a/SettingWallpaper/SettingWallpaper/Core/ViewManager.cs b/SettingWallpaper/SettingWallpaper/Core/ViewManager.cs index a64115f..f2e6e25 100644 --- a/SettingWallpaper/SettingWallpaper/Core/ViewManager.cs +++ b/SettingWallpaper/SettingWallpaper/Core/ViewManager.cs @@ -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 WallpaperListProperty { get; } = new BindingProperty + { + Setter = (v, value) => v.WallpaperList = value, + }; + } + + static class CollectionViewBindings + { + public static BindingProperty SelectionChangedCommandProperty { get; } = new BindingProperty + { + 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(); + 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(); + 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(); + 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; diff --git a/SettingWallpaper/SettingWallpaper/SettingWallpaper.csproj b/SettingWallpaper/SettingWallpaper/SettingWallpaper.csproj index b1bf0c0..9ee2694 100644 --- a/SettingWallpaper/SettingWallpaper/SettingWallpaper.csproj +++ b/SettingWallpaper/SettingWallpaper/SettingWallpaper.csproj @@ -14,7 +14,7 @@ - + diff --git a/SettingWallpaper/SettingWallpaper/Views/AlbumView.cs b/SettingWallpaper/SettingWallpaper/Views/AlbumView.cs index 2a5cd68..75c68b8 100644 --- a/SettingWallpaper/SettingWallpaper/Views/AlbumView.cs +++ b/SettingWallpaper/SettingWallpaper/Views/AlbumView.cs @@ -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 ItemsSourceProperty { get; } = new BindingProperty + { + 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(); + 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(); + 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; }); } diff --git a/SettingWallpaper/SettingWallpaper/Views/CustomTitleItem.cs b/SettingWallpaper/SettingWallpaper/Views/CustomTitleItem.cs index 87b7c74..4f8bbe4 100644 --- a/SettingWallpaper/SettingWallpaper/Views/CustomTitleItem.cs +++ b/SettingWallpaper/SettingWallpaper/Views/CustomTitleItem.cs @@ -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(); + 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); diff --git a/SettingWallpaper/SettingWallpaper/Views/MainPage.cs b/SettingWallpaper/SettingWallpaper/Views/MainPage.cs index 0c8b595..77dda19 100644 --- a/SettingWallpaper/SettingWallpaper/Views/MainPage.cs +++ b/SettingWallpaper/SettingWallpaper/Views/MainPage.cs @@ -44,6 +44,7 @@ namespace SettingWallpaper protected override View OnCreate() { + NUIApplication.IsUsingXaml = false; Tizen.Log.Info(Resources.LogTag, "OnCreate"); base.OnCreate(); gadgetResourceManager = NUIGadgetResourceManager; diff --git a/SettingWallpaper/SettingWallpaper/Views/WallpaperView.cs b/SettingWallpaper/SettingWallpaper/Views/WallpaperView.cs index 067bd27..0ba758a 100644 --- a/SettingWallpaper/SettingWallpaper/Views/WallpaperView.cs +++ b/SettingWallpaper/SettingWallpaper/Views/WallpaperView.cs @@ -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 IsSelectedProperty { get; } = new BindingProperty + { + Setter = (v, value) => v.IsSelected = value, + }; + + public static BindingProperty CommandProperty { get; } = new BindingProperty + { + Setter = (v, value) => v.Command = value, + }; + + public static BindingProperty IsEnabledProperty { get; } = new BindingProperty + { + Setter = (v, value) => v.IsEnabled = value, + }; + } + + static class ImageViewBindings + { + public static BindingProperty ResourceUrlProperty { get; } = new BindingProperty + { + Setter = (v, value) => v.ResourceUrl = value, + }; + } + + static class SaveButtonBindings + { + public static BindingProperty CommandProperty { get; } = new BindingProperty + { + 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(); + + 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(); + 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(); + 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(); 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(); + + SaveButton.BindingContextChanged += (sender, e) => + { + if (SaveButton.BindingContext is WallpaperViewModel model) + { + session.ViewModel = model; + } + }; + SaveButton.SetBinding(session, SaveButtonBindings.CommandProperty, "SetWallpaperCommand"); SaveButton.Hide(); appBar = new AppBar() diff --git a/packaging/org.tizen.cssetting-wallpaper-1.0.2.rpk b/packaging/org.tizen.cssetting-wallpaper-1.0.2.rpk index 666273f..b021ff4 100644 Binary files a/packaging/org.tizen.cssetting-wallpaper-1.0.2.rpk and b/packaging/org.tizen.cssetting-wallpaper-1.0.2.rpk differ