Added Clearing Notifications Feature and Notification Added/Deleted Events. 75/294875/1
authorShivam Varshney/Core S/W Group /SRI-Delhi/Engineer/Samsung Electronics <shivam.v2@samsung.com>
Wed, 28 Jun 2023 05:18:53 +0000 (10:48 +0530)
committerShivam Varshney/Core S/W Group /SRI-Delhi/Engineer/Samsung Electronics <shivam.v2@samsung.com>
Wed, 28 Jun 2023 05:18:53 +0000 (10:48 +0530)
Change-Id: Icd48156f7e9745276aa8260ec62253ff994105a6
Signed-off-by: Shivam Varshney/Core S/W Group /SRI-Delhi/Engineer/Samsung Electronics <shivam.v2@samsung.com>
Notifications/Common/AppConstants.cs
Notifications/CustomBorder.cs
Notifications/Models/NotificationsModel.cs
Notifications/Notifications.cs
Notifications/ViewModels/NotificationsListViewModel.cs
Notifications/ViewModels/NotificationsViewModel.cs
Notifications/Views/BaseView.cs
Notifications/res/images/light/clear.png [new file with mode: 0644]
packaging/org.tizen.Notifications-1.0.0.tpk

index a76428bc63ed4f5ec4c40692ef6fb591bd94b1f8..2fedf8f950d48a518d7a6b0dc6d4568296ef262f 100644 (file)
@@ -9,13 +9,19 @@ namespace Notifications.Common
         public const string DarkPlatformThemeId = "org.tizen.default-dark-theme";
 
         public static Size2D DefaultWindowSize = new Size2D(960, 540);
+        public static Size2D IconSize = new Size2D(48, 48);
+        public static Size2D SmallIconSize = new Size2D(32, 32);
+        public static Size2D TextButtonSize = new Size2D(150, 48);
+
         public static Position2D DefaultWindowPosition = new Position2D(480, 170);
+
         public const int BorderHeight = 52;
+        public const int HeaderHeight = 64;
+        public const int TitlePixelSize = 24;
 
         public static Vector4 BaseViewCornerRadius = new Vector4(24, 24, 24, 24);
-        public const int HeaderHeight = 64;
+
+        public static Extents BaseViewPadding = new Extents(0, 0, 20, 20);
         public static Extents HeaderPadding = new Extents(16, 16, 8, 8);
-        public static Size2D IconSize = new Size2D(48, 48);
-        public const int TitlePixelSize = 24;
     }
 }
index d03922aec3c6f01b721692c27518ee3f46d0d432..bd7b293a2870d005dcda5374a5761dc14371f06a 100644 (file)
@@ -19,7 +19,7 @@ namespace Notifications
         public override void CreateBorderView(View borderView)
         {
             this.borderView = borderView;
-            borderView.CornerRadius = new Vector4(0.03f, 0.03f, 0.03f, 0.03f);
+            borderView.CornerRadius = new Vector4(24, 24, 24, 24);
             borderView.CornerRadiusPolicy = VisualTransformPolicyType.Relative;
             borderView.BackgroundColor = new Color(1, 1, 1, 0.3f);
         }
index cb05755c79c020c02d4efc0b59079c9dc44a8a62..541d273d56690321935070f4afd03055b471c149 100644 (file)
@@ -1,14 +1,25 @@
-using System.ComponentModel;
+using System;
+using System.ComponentModel;
+using Tizen.Applications.NotificationEventListener;
+using Tizen.NUI.Binding;
+using Notifications.Common;
 
 namespace Notifications.Models
 {
     class NotificationsModel : INotifyPropertyChanged
     {
         public event PropertyChangedEventHandler PropertyChanged;
-        public NotificationsModel(string title, string content)
+
+        private readonly string appId;
+        private readonly int uniqueNumber;
+
+        public NotificationsModel(string appId, int uniqueNumber, string title, string content)
         {
+            this.appId = appId;
+            this.uniqueNumber = uniqueNumber;
             this.title = title ?? string.Empty;
             subTitle = content ?? string.Empty;
+            ClearNotificationCommand = new Command(OnNotificationCleared);
         }
 
         private void OnPropertyChanged(string propertyName)
@@ -37,5 +48,28 @@ namespace Notifications.Models
                 OnPropertyChanged("SubTitle");
             }
         }
+
+        private Command clearNotificationCommand;
+        public Command ClearNotificationCommand
+        {
+            get => clearNotificationCommand;
+            set
+            {
+                clearNotificationCommand = value;
+                OnPropertyChanged("ClearNotificationCommand");
+            }
+        }
+
+        private void OnNotificationCleared()
+        {
+            try
+            {
+                NotificationListenerManager.Delete(appId, uniqueNumber);
+            }
+            catch (Exception ex)
+            {
+                Tizen.Log.Error(AppConstants.LogTag, "Exception: " + ex.Message);
+            }
+        }
     }
 }
index 70cedeff2b1e9d5eae4a69b23ac26e00753ed9ec..aabc806d20297bf08f84d01f09760101280bdfac 100644 (file)
@@ -2,6 +2,7 @@
 using Tizen.NUI;
 using Notifications.Common;
 using Notifications.Views;
+using Tizen.Applications;
 
 namespace Notifications
 {
@@ -93,6 +94,12 @@ namespace Notifications
             }
         }
 
+        protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
+        {
+            base.OnAppControlReceived(e);
+            Tizen.Log.Info(AppConstants.LogTag, "AppControl Received");
+        }
+
         protected override void OnTerminate()
         {
             Tizen.Log.Info(AppConstants.LogTag, "On App Terminate");
index 1d9aeaf189f512806e0c7eaab343a2b138089f47..8b42222887eb231195f3d2cfe3b37aad87d73365 100644 (file)
@@ -13,7 +13,7 @@ namespace Notifications.ViewModels
             CreateData();
         }
 
-        private void CreateData()
+        public void CreateData()
         {
             Clear();
             try
@@ -26,7 +26,7 @@ namespace Notifications.ViewModels
                 foreach (var item in notificationsList)
                 {
                     Tizen.Log.Info(AppConstants.LogTag, "Notifications Title:" + item.Title);
-                    Add(new NotificationsModel(item.Title, item.Content));
+                    Add(new NotificationsModel(item.AppID, item.UniqueNumber, item.Title, item.Content));
                 }
             }
             catch (Exception ex)
index 75c4ffdcd8b78f61c66688db25c2518bcc5d8849..5d7e0514d56a645cb29c00cff8ea3b9678688713 100644 (file)
-namespace Notifications.ViewModels
+using System;
+using System.ComponentModel;
+using Tizen.Applications.NotificationEventListener;
+using Tizen.NUI;
+using Tizen.NUI.Binding;
+
+namespace Notifications.ViewModels
 {
-    class NotificationsViewModel
+    class NotificationsViewModel : IDisposable, INotifyPropertyChanged
     {
+        public event PropertyChangedEventHandler PropertyChanged;
+
         public NotificationsViewModel()
         {
             NotificationsListSource = new NotificationsListViewModel();
+            IsNotificationsPresent = NotificationsListSource.Count > 0;
+
+            BackCommand = new Command(OnBackPressed);
+            ClearAllNotificationsCommand = new Command(OnAllNotificationsCleared);
+
+            NotificationListenerManager.Added += OnNotificationAdded;
+            NotificationListenerManager.Deleted += OnNotificationDeleted;
+            NotificationListenerManager.Updated += OnNotificationUpdated;
         }
+
         public NotificationsListViewModel NotificationsListSource { get; set; }
+
+        private bool isNotificationsPresent;
+        public bool IsNotificationsPresent
+        {
+            get => isNotificationsPresent;
+            set
+            {
+                isNotificationsPresent = value;
+                OnPropertyChanged("IsNotificationsPresent");
+            }
+        }
+
+        public void Dispose()
+        {
+            NotificationListenerManager.Added -= OnNotificationAdded;
+            NotificationListenerManager.Deleted -= OnNotificationDeleted;
+            NotificationListenerManager.Updated -= OnNotificationUpdated;
+            NotificationsListSource.Clear();
+            NotificationsListSource = null;
+        }
+
+        private void OnPropertyChanged(string propertyName)
+        {
+            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+        }
+
+        private void OnNotificationUpdated(object sender, NotificationEventArgs e)
+        {
+            NotificationsListSource.CreateData();
+            IsNotificationsPresent = NotificationsListSource.Count > 0;
+        }
+
+        private void OnNotificationDeleted(object sender, NotificationDeleteEventArgs e)
+        {
+            NotificationsListSource.CreateData();
+            IsNotificationsPresent = NotificationsListSource.Count > 0;
+        }
+
+        private void OnNotificationAdded(object sender, NotificationEventArgs e)
+        {
+            NotificationsListSource.CreateData();
+            IsNotificationsPresent = NotificationsListSource.Count > 0;
+        }
+
+        private Command backCommand;
+        public Command BackCommand
+        {
+            get => backCommand;
+            set
+            {
+                backCommand = value;
+                OnPropertyChanged("BackCommand");
+            }
+        }
+
+        private void OnBackPressed()
+        {
+            NUIApplication.Current.Exit();
+        }
+
+        private Command clearAllNotificationsCommand;
+        public Command ClearAllNotificationsCommand
+        {
+            get => clearAllNotificationsCommand;
+            set
+            {
+                clearAllNotificationsCommand = value;
+                OnPropertyChanged("ClearAllNotificationsCommand");
+            }
+        }
+
+        private void OnAllNotificationsCleared()
+        {
+            NotificationListenerManager.DeleteAll();
+        }
     }
 }
index b62c0a7af901a65009b297b096a0ff9bbaa6c0c4..bb44e71a5e8bc04a3089fccd7ead930025300280 100644 (file)
@@ -8,10 +8,28 @@ namespace Notifications.Views
 {
     class BaseView : View
     {
+        public static BindableProperty IsContentAvailableProperty = BindableProperty.Create(nameof(IsContentAvailable), typeof(bool), typeof(BaseView), false, propertyChanged: (bindable, oldValue, newValue) =>
+        {
+            BaseView instance = bindable as BaseView;
+            if (instance == null)
+            {
+                return;
+            }
+            if (newValue != oldValue)
+            {
+                instance.isContentAvailable = (bool)newValue;
+                instance.UpdateContent();
+            }
+        }, defaultValueCreator: (bindable) => (bindable as BaseView).isContentAvailable);
+
         private View topView;
         private Button backButton;
         private TextLabel titleText;
         private CollectionView notificationsView;
+        private View bottomView;
+        private Button clearAllButton;
+        private TextLabel noNotificationsText;
+
         public BaseView() : base()
         {
             Size2D = new Size2D(Window.Instance.WindowSize.Width, Window.Instance.WindowSize.Height);
@@ -22,10 +40,11 @@ namespace Notifications.Views
                 LinearOrientation = LinearLayout.Orientation.Vertical,
                 HorizontalAlignment = HorizontalAlignment.Begin,
                 VerticalAlignment = VerticalAlignment.Top,
+                Padding = AppConstants.BaseViewPadding,
             };
             AddTopView();
-            AddNotificationsView();
-
+            UpdateContent();
+            this.SetBinding(IsContentAvailableProperty, "IsNotificationsPresent");
         }
 
         private void AddTopView()
@@ -54,6 +73,7 @@ namespace Notifications.Views
             backButton.Icon.Size2D = AppConstants.IconSize.SpToPx();
             RelativeLayout.SetVerticalAlignment(backButton, RelativeLayout.Alignment.Center);
             RelativeLayout.SetHorizontalAlignment(backButton, RelativeLayout.Alignment.Start);
+            backButton.SetBinding(Control.CommandProperty, "BackCommand");
             topView.Add(backButton);
 
             titleText = new TextLabel()
@@ -70,30 +90,122 @@ namespace Notifications.Views
             topView.Add(titleText);
         }
 
+        private void UpdateContent()
+        {
+            RemoveContent();
+
+            if (IsContentAvailable == true)
+            {
+                AddNotificationsView();
+                AddBottomView();
+            }
+            else
+            {
+                AddNoNotificationsText();
+            }
+        }
+
+        private void RemoveContent()
+        {
+            Remove(noNotificationsText);
+            Remove(notificationsView);
+            Remove(bottomView);
+        }
+
         private void AddNotificationsView()
         {
-            notificationsView = new CollectionView()
+            if (notificationsView == null)
             {
-                ItemsLayouter = new LinearLayouter(),
-                ItemTemplate = new DataTemplate(() =>
+                notificationsView = new CollectionView()
                 {
-                    DefaultLinearItem item = new DefaultLinearItem();
-                    item.WidthSpecification = LayoutParamPolicies.MatchParent;
-                    item.Label.SetBinding(TextLabel.TextProperty, "Title");
-                    item.Label.HorizontalAlignment = HorizontalAlignment.Begin;
-                    item.Label.FontFamily = "BreezeSans";
-                    item.SubLabel.SetBinding(TextLabel.TextProperty, "SubTitle");
-                    item.SubLabel.HorizontalAlignment = HorizontalAlignment.Begin;
-                    item.SubLabel.FontFamily = "BreezeSans";
-                    return item;
-                }),
-                ScrollingDirection = ScrollableBase.Direction.Vertical,
-                WidthSpecification = LayoutParamPolicies.MatchParent,
-                HeightSpecification = LayoutParamPolicies.MatchParent,
-                SelectionMode = ItemSelectionMode.Single,
-            };
-            notificationsView.SetBinding(RecyclerView.ItemsSourceProperty, "NotificationsListSource");
+                    ItemsLayouter = new LinearLayouter(),
+                    ItemTemplate = new DataTemplate(() =>
+                    {
+                        DefaultLinearItem item = new DefaultLinearItem();
+                        item.WidthSpecification = LayoutParamPolicies.MatchParent;
+                        item.Label.SetBinding(TextLabel.TextProperty, "Title");
+                        item.Label.HorizontalAlignment = HorizontalAlignment.Begin;
+                        item.Label.FontFamily = "BreezeSans";
+                        item.SubLabel.SetBinding(TextLabel.TextProperty, "SubTitle");
+                        item.SubLabel.HorizontalAlignment = HorizontalAlignment.Begin;
+                        item.SubLabel.FontFamily = "BreezeSans";
+                        item.Extra = new Button()
+                        {
+                            Size2D = AppConstants.SmallIconSize.SpToPx().SpToPx(),
+                            IconURL = Resources.GetImagePath() + "/light/clear.png",
+                            BackgroundColor = Color.Transparent,
+                        };
+                        (item.Extra as Button).Icon.Size2D = AppConstants.SmallIconSize.SpToPx().SpToPx();
+                        item.Extra.SetBinding(Control.CommandProperty, "ClearNotificationCommand");
+                        return item;
+                    }),
+                    ScrollingDirection = ScrollableBase.Direction.Vertical,
+                    WidthSpecification = LayoutParamPolicies.MatchParent,
+                    HeightSpecification = LayoutParamPolicies.MatchParent,
+                    SelectionMode = ItemSelectionMode.Single,
+                };
+                notificationsView.SetBinding(RecyclerView.ItemsSourceProperty, "NotificationsListSource");
+            }
             Add(notificationsView);
         }
+
+        private void AddBottomView()
+        {
+            if (bottomView == null)
+            {
+                bottomView = new View()
+                {
+                    WidthSpecification = LayoutParamPolicies.MatchParent,
+                    HeightSpecification = AppConstants.HeaderHeight.SpToPx(),
+                    Layout = new RelativeLayout()
+                    {
+                        Padding = AppConstants.HeaderPadding.SpToPx(),
+                    },
+                };
+            }
+            if (clearAllButton == null)
+            {
+                clearAllButton = new Button()
+                {
+                    Size2D = AppConstants.TextButtonSize.SpToPx(),
+                    Text = "Clear All",
+                    TextColor = new Color("#FF6200"),
+                    FontFamily = "BreezeSans",
+                    BackgroundColor = Color.Transparent,
+                    TextAlignment = HorizontalAlignment.Center,
+                };
+                RelativeLayout.SetVerticalAlignment(clearAllButton, RelativeLayout.Alignment.Center);
+                RelativeLayout.SetHorizontalAlignment(clearAllButton, RelativeLayout.Alignment.End);
+                clearAllButton.SetBinding(Control.CommandProperty, "ClearAllNotificationsCommand");
+                bottomView.Add(clearAllButton);
+            }
+            Add(bottomView);
+        }
+
+        private void AddNoNotificationsText()
+        {
+            if (noNotificationsText == null)
+            {
+                noNotificationsText = new TextLabel()
+                {
+                    Text = "You don't have notifications",
+                    HorizontalAlignment = HorizontalAlignment.Center,
+                    VerticalAlignment = VerticalAlignment.Center,
+                    FontFamily = "BreezeSans",
+                    PixelSize = AppConstants.TitlePixelSize.SpToPx(),
+                    TextColor = new Color("#090E21"),
+                    WidthSpecification = LayoutParamPolicies.MatchParent,
+                    HeightSpecification = LayoutParamPolicies.MatchParent,
+                };
+            }
+            Add(noNotificationsText);
+        }
+
+        private bool isContentAvailable;
+        public bool IsContentAvailable
+        {
+            get => (bool)GetValue(IsContentAvailableProperty);
+            set => SetValue(IsContentAvailableProperty, value);
+        }
     }
 }
diff --git a/Notifications/res/images/light/clear.png b/Notifications/res/images/light/clear.png
new file mode 100644 (file)
index 0000000..7240e82
Binary files /dev/null and b/Notifications/res/images/light/clear.png differ
index 7507a3e6fc295acaf4c8f17aa555089b2dde6255..c58b8f2a9b01f5f78e98a150b2cbc834aceff510 100644 (file)
Binary files a/packaging/org.tizen.Notifications-1.0.0.tpk and b/packaging/org.tizen.Notifications-1.0.0.tpk differ