Added Remove App feature in TrayApplication. 58/279758/1 accepted/tizen/unified/20220822.123817 submit/tizen/20220819.055231
authorshivamv <shivam.v2@samsung.com>
Wed, 17 Aug 2022 08:17:05 +0000 (13:47 +0530)
committershivamv <shivam.v2@samsung.com>
Wed, 17 Aug 2022 08:17:05 +0000 (13:47 +0530)
Change-Id: Ia58108cbf7f5eb2e183de3de853a405173896bf5
Signed-off-by: shivamv <shivam.v2@samsung.com>
12 files changed:
TrayApplication/Core/AppScoreDataBase.cs
TrayApplication/TrayApplication.csproj
TrayApplication/ViewModels/ApplicationViewModel.cs
TrayApplication/Views/AppItemView.cs
TrayApplication/Views/ApplicationsView.cs
TrayApplication/Views/MainView.cs
TrayApplication/Views/QuickAccessView.cs
TrayApplication/res/images/dark/cancel_button.png [new file with mode: 0755]
TrayApplication/res/images/light/cancel_button.png [new file with mode: 0755]
TrayApplication/res/themes/dark.xaml
TrayApplication/res/themes/light.xaml
packaging/org.tizen.TrayApplication-1.0.0.tpk

index b54ea09273615e23601222d2296f589c8261456d..07428db5bffc634de96f73fc772190f0df5e764b 100644 (file)
@@ -11,6 +11,7 @@ namespace TrayApplication.Core
         private const string CREATE_TABLE_QUERY = "CREATE TABLE APP_INFO(NAME VARCHAR(30), SCORE FLOAT(10));";
         private const string INSERT_VALUES_QUERY = "INSERT INTO APP_INFO(NAME, SCORE) VALUES('";
         private const string SELECT_MAX_SCORE_QUERY = "SELECT MAX(SCORE) FROM APP_INFO;";
+        private const string SELECT_MIN_SCORE_QUERY = "SELECT MIN(SCORE) FROM APP_INFO;";
         private const string UPDATE_LAUNCHED_APP_QUERY = "UPDATE APP_INFO SET SCORE = SCORE + 50.00 WHERE NAME = '";
         private const string UPDATE_OTHER_APPS_QUERY = "UPDATE APP_INFO SET SCORE = SCORE * 0.90 WHERE NAME !='";
         private const string DELETE_APP_QUERY = "DELETE FROM APP_INFO WHERE NAME = '";
@@ -48,7 +49,7 @@ namespace TrayApplication.Core
 
         private static void OnUninstallProgressChanged(object sender, PackageManagerEventArgs e)
         {
-            if (e.Progress ==0)
+            if (e.Progress == 0)
             {
                 Package package = PackageManager.GetPackage(e.PackageId);
                 foreach (ApplicationInfo appInfo in package.GetApplications())
@@ -158,6 +159,21 @@ namespace TrayApplication.Core
             Tizen.Log.Info(Resources.LogTag, "Score Updated of App: " + appId);
         }
 
+        public static void DecreaseScore(string appId)
+        {
+            SqliteCommand sqliteCmd = sqliteConn.CreateCommand();
+            sqliteCmd.CommandText = SELECT_MIN_SCORE_QUERY;
+            SqliteDataReader sqliteDatareader = sqliteCmd.ExecuteReader();
+            sqliteDatareader.Read();
+            float score = sqliteDatareader.GetFloat(0) * 0.90f;
+            sqliteCmd.Dispose();
+            sqliteCmd = sqliteConn.CreateCommand();
+            sqliteCmd.CommandText = "UPDATE APP_INFO SET SCORE = " + score + " WHERE NAME = '" + appId + "';";
+            sqliteCmd.ExecuteNonQuery();
+            OnDatabaseUpdate.Invoke(null, new EventArgs());
+            Tizen.Log.Info(Resources.LogTag, "App Score Decreased: " + appId);
+        }
+
         private static void RemoveAppScore(string appId)
         {
             SqliteCommand sqliteCmd = sqliteConn.CreateCommand();
@@ -166,7 +182,7 @@ namespace TrayApplication.Core
             Tizen.Log.Info(Resources.LogTag, "App Removed from DB: " + appId);
         }
 
-        public static Dictionary<string,int> ReadData(int count)
+        public static Dictionary<string, int> ReadData(int count)
         {
             SqliteDataReader sqliteDatareader;
             SqliteCommand sqliteCmd = sqliteConn.CreateCommand();
index b827d0e7e0b362a5e9d8f48ed2c5a3ba774f5b7b..5e96be5984b4c75349ed77a9ad2c952d6e3b7863 100644 (file)
@@ -3,8 +3,8 @@
   <PropertyGroup>
     <OutputType>Exe</OutputType>
     <TargetFramework>netcoreapp3.1</TargetFramework>
-      <TargetFrameworkIdentifier>Tizen</TargetFrameworkIdentifier>
-    <AssemblyName>TrayApplication</AssemblyName>
+    <LangVersion>8.0</LangVersion>
+    <TargetFrameworkIdentifier>Tizen</TargetFrameworkIdentifier>
   </PropertyGroup>
 
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -20,7 +20,7 @@
 
   <ItemGroup>
     <PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.7" />
-    <PackageReference Include="Tizen.NET" Version="10.0.0.17305" />
+    <PackageReference Include="Tizen.NET" Version="10.0.0.17357" />
     <PackageReference Include="Tizen.NET.Sdk" Version="1.1.8" />
   </ItemGroup>
 
index 3b242795aa052ee881827b9f5176cf69a626fc79..085efaec4df03ea2bd58783c91850dd0feba7b1c 100644 (file)
@@ -1,7 +1,9 @@
 using System.Collections;
 using System.Collections.Generic;
+using System.Windows.Input;
 using Tizen.Applications;
 using Tizen.NUI;
+using Tizen.NUI.Binding;
 using TrayApplication.Common;
 using TrayApplication.Core;
 using TrayApplication.Models;
@@ -18,6 +20,7 @@ namespace TrayApplication.ViewModels
             appScoreData = AppScoreDataBase.ReadData(appsCount - 1);
             BackgroundColor = ThemeManager.PlatformThemeId == Resources.DarkPlatformThemeId ? Resources.DarkApplicationsBackground : Resources.LightApplicationsBackground;
             AddButtonsInfo();
+            AppRemoveCommand = new Command(OnAppRemove);
             AppScoreDataBase.OnDatabaseUpdate += OnDatabaseUpdate;
             ThemeManager.ThemeChanged += (object sender, ThemeChangedEventArgs e) =>
             {
@@ -77,5 +80,18 @@ namespace TrayApplication.ViewModels
             get => buttonsInfo;
             set => SetProperty(ref buttonsInfo, value);
         }
+
+        private ICommand appRemoveCommand;
+        public ICommand AppRemoveCommand
+        {
+            get => appRemoveCommand;
+            set => SetProperty(ref appRemoveCommand, value);
+        }
+
+        private void OnAppRemove(object removedItem)
+        {
+            AppInfoModel app = (AppInfoModel)removedItem;
+            AppScoreDataBase.DecreaseScore(app.ApplicationId);
+        }
     }
 }
index 745916ee9a4022bfd0f309101e266aa92ca44d28..2da31d348a1a9530ec7a2ec00db2478c954c6e42 100644 (file)
@@ -11,6 +11,7 @@ namespace TrayApplication.Views
     internal class AppItemView : View
     {
         public event EventHandler<EventArgs> LongPressed;
+        public event EventHandler<EventArgs> RemoveClicked;
 
         private bool isMoved;
         private bool isLongPressed;
@@ -110,7 +111,14 @@ namespace TrayApplication.Views
                 {
                     if (isLongPressed == false && isMoved == false)
                     {
-                        AppSelectCommand.Execute(BindingContext);
+                        if (RemoveMode == false)
+                        {
+                            AppSelectCommand.Execute(BindingContext);
+                        }
+                        else
+                        {
+                            RemoveClicked.Invoke(this, new EventArgs());
+                        }
                         Tizen.Log.Debug(Resources.LogTag, "Clicked");
                     }
                     isLongPressed = false;
@@ -131,6 +139,8 @@ namespace TrayApplication.Views
 
         public Button CrossButton { get; internal set; }
 
+        public bool RemoveMode { get; set; }
+
         private ICommand appSelectCommand;
 
         public ICommand AppSelectCommand
@@ -150,9 +160,37 @@ namespace TrayApplication.Views
                 Add(CrossButton);
                 RelativeLayout.SetHorizontalAlignment(CrossButton, RelativeLayout.Alignment.End);
                 RelativeLayout.SetVerticalAlignment(CrossButton, RelativeLayout.Alignment.Start);
+                RemoveMode = true;
+                CrossButton.Clicked += (object sender, ClickedEventArgs e) =>
+                {
+                    if (RemoveMode == true)
+                    {
+                        RemoveClicked.Invoke(this, new EventArgs());
+                    }
+                };
+            }
+        }
+
+        public void AddTouchEvent()
+        {
+            TouchEvent += OnTouched;
+        }
+
+        public void RemoveCrossButton()
+        {
+            if(CrossButton != null)
+            {
+                Remove(CrossButton);
+                CrossButton = null;
+                RemoveMode = false;
             }
         }
 
+        public void RemoveTouchEvent()
+        {
+            TouchEvent -= OnTouched;
+        }
+
         protected override void Dispose(DisposeTypes type)
         {
             if (Disposed)
index 630867fdd20bdce139f41370dfd5de93f9a6dd43..bcdd0c91e2c9d2d69374c13ce599db7e2fc07e20 100644 (file)
@@ -1,19 +1,25 @@
 using System;
 using System.Collections.Generic;
 using System.Collections;
+using System.Windows.Input;
 using Tizen.NUI;
 using Tizen.NUI.BaseComponents;
 using Tizen.NUI.Binding;
 using TrayApplication.Common;
+using Tizen.NUI.Components;
 
 namespace TrayApplication.Views
 {
     public class ApplicationsView : View
     {
+        public event EventHandler<EventArgs> RemoveModeToggled;
+
         private const int ApplicationViewHeight = 189;
         private List<AppItemView> appIcons;
         private readonly int maxAppsCount;
         private int currentAppsCount;
+        private AlertDialog removePopup;
+        private Window removePopupWindow;
 
         public static readonly BindableProperty AppListProperty = BindableProperty.Create(nameof(AppList), typeof(IEnumerable), typeof(ApplicationsView), null, propertyChanged: (bindable, oldValue, newValue) =>
         {
@@ -33,6 +39,16 @@ namespace TrayApplication.Views
         },
         defaultValueCreator: (bindable) => ((ApplicationsView)bindable).appList);
 
+        public static readonly BindableProperty AppRemoveCommandProperty = BindableProperty.Create(nameof(AppRemoveCommand), typeof(ICommand), typeof(ApplicationsView), null, propertyChanged: (bindable, oldValue, newValue) =>
+        {
+            var instance = (ApplicationsView)bindable;
+            if (oldValue != newValue)
+            {
+                instance.appRemoveCommand = (ICommand)newValue;
+            }
+        },
+        defaultValueCreator: (bindable) => ((ApplicationsView)bindable).appRemoveCommand);
+
         public ApplicationsView(int appsCount) : base()
         {
             Name = "ApplicationsView";
@@ -53,6 +69,22 @@ namespace TrayApplication.Views
             Tizen.Log.Info(Resources.LogTag, "ApplicationsView");
         }
 
+        public void OnRemoveModeToggled(bool removeMode)
+        {
+            if(removeMode == true)
+            {
+                AddDeleteOption();
+                appIcons[^1].RemoveTouchEvent();
+                appIcons[^1].Opacity = 0.4f;
+            }
+            else
+            {
+                RemoveDeleteOption();
+                appIcons[^1].AddTouchEvent();
+                appIcons[^1].Opacity = 1.0f;
+            }
+        }
+
         private void CreateDefaultAppItems()
         {
             appIcons = new List<AppItemView>();
@@ -62,7 +94,7 @@ namespace TrayApplication.Views
                 itemView.Hide();
                 itemView.LongPressed += (object sender, EventArgs e) =>
                 {
-                    AddDeleteOption();
+                    RemoveModeToggled.Invoke(this, new EventArgs());
                 };
                 appIcons.Add(itemView);
             }
@@ -70,12 +102,21 @@ namespace TrayApplication.Views
         }
 
         private IEnumerable appList;
+
         public IEnumerable AppList
         {
             get => (IEnumerable)GetValue(AppListProperty);
             set => SetValue(AppListProperty, value);
         }
 
+        private ICommand appRemoveCommand;
+
+        public ICommand AppRemoveCommand
+        {
+            get => (ICommand)GetValue(AppRemoveCommandProperty);
+            set => SetValue(AppRemoveCommandProperty, value);
+        }
+
         private void UpdateAppIcons()
         {
             List<object> appDataList = (List<object>)appList;
@@ -120,8 +161,75 @@ namespace TrayApplication.Views
             for(int i = 0; i < currentAppsCount - 1; i++)
             {
                 appIcons[i].AddCrossButton();
+                appIcons[i].RemoveClicked += (object sender, EventArgs e) =>
+                {
+                    AddConfirmationPopup(sender);
+                };
             }
         }
+        private void RemoveDeleteOption()
+        {
+            for (int i = 0; i < currentAppsCount - 1; i++)
+            {
+                appIcons[i].RemoveCrossButton();
+            }
+        }
+
+        private void AddConfirmationPopup(object appIcon)
+        {
+            Tizen.Log.Info(Resources.LogTag, "Popup Added");
+            if (removePopupWindow == null)
+            {
+                int popupWidth = (int)((DeviceInfo.IsPortrait ? DeviceInfo.DisplayHeight : DeviceInfo.DisplayWidth) * 0.36f);
+                int popupHeight = 256.SpToPx();
+                int windowPositionX = ((DeviceInfo.DisplayWidth - popupWidth) / 2) - 144.SpToPx();
+                int windowPositionY = ((DeviceInfo.DisplayHeight - popupHeight) / 2) - 32.SpToPx();
+                Button cancelButton = new Button("CancelButton");
+                Button deleteButton = new Button()
+                {
+                    Size2D = new Size2D(252, 48).SpToPx(),
+                    Text = "Delete",
+                };
+                if (removePopup == null)
+                {
+                    removePopup = new AlertDialog()
+                    {
+                        StyleName = "AlertDialogBackground",
+                        Size2D = new Size2D(popupWidth, popupHeight),
+                        Title = "Delete App from the Tray",
+                        Message = "Do you want to delete this app from the Tray? App won't be uninstalled from your device",
+                        Actions = new List<Button>() { cancelButton, deleteButton },
+                    };
+                }
+                removePopupWindow = new Window
+                {
+                    WindowPosition = new Position2D(windowPositionX, windowPositionY),
+                    WindowSize = new Size2D(popupWidth + 144.SpToPx(), popupHeight + 32.SpToPx()),
+                };
+                removePopupWindow.SetTransparency(true);
+                removePopupWindow.BackgroundColor = Color.Transparent;
+                removePopupWindow.Add(removePopup);
+                cancelButton.Clicked += (object sender, ClickedEventArgs e) =>
+                {
+                    RemoveConfirmationPopup();
+                };
+                deleteButton.Clicked += (object sender, ClickedEventArgs e) =>
+                {
+                    AppRemoveCommand.Execute(((AppItemView)appIcon).BindingContext);
+                    RemoveConfirmationPopup();
+                };
+            }
+        }
+
+        private void RemoveConfirmationPopup()
+        {
+            removePopupWindow.Remove(removePopup);
+            removePopup.Dispose();
+            removePopup = null;
+            removePopupWindow.Dispose();
+            removePopupWindow = null;
+            RemoveModeToggled.Invoke(this, new EventArgs());
+        }
 
         protected override void Dispose(DisposeTypes type)
         {
index 0576dcdcc44dee901bb5e93d6e778c532af13798..e2ea6defc4a676a8bbfafc52e930f023f1fa51d2 100644 (file)
@@ -14,6 +14,7 @@ namespace TrayApplication.Views
         private ApplicationsView applicationsView;
         private QuickAccessView quickAccessView;
         private Animation animation;
+        private bool removeMode;
 
         public MainView() : base()
         {
@@ -34,6 +35,7 @@ namespace TrayApplication.Views
             applicationsView.BindingContext = applicationViewModel;
             applicationsView.SetBinding(BackgroundColorProperty, "BackgroundColor");
             applicationsView.SetBinding(ApplicationsView.AppListProperty, "ButtonsInfo");
+            applicationsView.SetBinding(ApplicationsView.AppRemoveCommandProperty, "AppRemoveCommand");
             QuickAccessViewModel quickAccessViewModel = new QuickAccessViewModel();
             quickAccessView = new QuickAccessView();
             Add(quickAccessView);
@@ -41,6 +43,15 @@ namespace TrayApplication.Views
             quickAccessView.SetBinding(BackgroundColorProperty, "BackgroundColor");
             quickAccessView.SetBinding(QuickAccessView.AppListProperty, "ButtonsInfo");
             ThemeManager.ThemeChanged += OnThemeUpdated;
+            removeMode = false;
+            applicationsView.RemoveModeToggled += ApplicationsViewRemoveModeToggled;
+        }
+
+        private void ApplicationsViewRemoveModeToggled(object sender, EventArgs e)
+        {
+            removeMode = !removeMode;
+            applicationsView.OnRemoveModeToggled(removeMode);
+            quickAccessView.OnRemoveModeToggled(removeMode);
         }
 
         private void OnThemeUpdated(object sender, ThemeChangedEventArgs e)
index 4eb34196887e287f87385768c96d75f3b80fe732..dea4cc6fe3f400c4f460435e39af67599b69db10 100644 (file)
@@ -91,6 +91,38 @@ namespace TrayApplication.Views
             Tizen.Log.Info(Resources.LogTag, "Buttons Added");
         }
 
+        public void OnRemoveModeToggled(bool removeMode)
+        {
+            if (removeMode == true)
+            {
+                DisableButtons();
+                Opacity = 0.4f;
+            }
+            else
+            {
+                EnableButtons();
+                Opacity = 1.0f;
+            }
+        }
+
+        private void DisableButtons()
+        {
+            foreach(Button button in defaultButtons)
+            {
+                button.IsEnabled = false;
+                button.IsSelectable = false;
+            }
+        }
+
+        private void EnableButtons()
+        {
+            foreach (Button button in defaultButtons)
+            {
+                button.IsEnabled = true;
+                button.IsSelectable = true;
+            }
+        }
+
         protected override void Dispose(DisposeTypes type)
         {
             if (Disposed)
diff --git a/TrayApplication/res/images/dark/cancel_button.png b/TrayApplication/res/images/dark/cancel_button.png
new file mode 100755 (executable)
index 0000000..f5818fb
Binary files /dev/null and b/TrayApplication/res/images/dark/cancel_button.png differ
diff --git a/TrayApplication/res/images/light/cancel_button.png b/TrayApplication/res/images/light/cancel_button.png
new file mode 100755 (executable)
index 0000000..a575b04
Binary files /dev/null and b/TrayApplication/res/images/light/cancel_button.png differ
index 24ef708e5107bf1d407d01f7b6dd577eecfe0488..2c0341c109c040cec8853719d0953f638296b955 100644 (file)
@@ -6,7 +6,7 @@ xmlns:c="clr-namespace:Tizen.NUI.Components;assembly=Tizen.NUI.Components"
 Id="DarkTheme">
 
     <ViewStyle x:Key="AppItemBackGround" BackgroundColor="#16131A" />
-    <TextLabelStyle x:Key="AppItemLabel" TextColor="#FDFDFD" />
+    <TextLabelStyle x:Key="AppItemLabel" TextColor="#FDFDFD" FontFamily="BreezeSans" />
 
     <c:ButtonStyle x:Key="CrossButton" ThemeChangeSensitive="true" IsSelectable="false" IsEnabled="true" BackgroundColor="Transparent">
         <c:ButtonStyle.Icon>
@@ -18,4 +18,23 @@ Id="DarkTheme">
         </c:ButtonStyle.Icon>
     </c:ButtonStyle>
 
+    <c:AlertDialogStyle x:Key="AlertDialogBackground" ThemeChangeSensitive="true" BackgroundColor="#16131A">
+        <c:AlertDialogStyle.TitleTextLabel>
+            <TextLabelStyle TextColor="#FDFDFD" FontFamily="BreezeSans" PixelSize="24sp" />
+        </c:AlertDialogStyle.TitleTextLabel>
+        <c:AlertDialogStyle.MessageTextLabel>
+            <TextLabelStyle TextColor="#FDFDFD" FontFamily="BreezeSans" PixelSize="24sp" />
+        </c:AlertDialogStyle.MessageTextLabel>
+    </c:AlertDialogStyle>
+
+    <c:ButtonStyle x:Key="CancelButton" ThemeChangeSensitive="true" Size="252sp, 48sp" IsSelectable="false" IsEnabled="true" BackgroundColor="Transparent" >
+        <c:ButtonStyle.Icon>
+            <ImageViewStyle Size="252sp, 48sp">
+                <ImageViewStyle.ResourceUrl>
+                    <Selector x:TypeArguments="x:String" Normal="*Resource*/images/dark/cancel_button.png" />
+                </ImageViewStyle.ResourceUrl>
+            </ImageViewStyle>
+        </c:ButtonStyle.Icon>
+    </c:ButtonStyle>
+
 </Theme>
\ No newline at end of file
index 44ed7320046cc8dca1c1631b91cc4b1f1b04f300..ac84fac53c9dbaa24fb0d4430fd4fadc8f2d59c5 100644 (file)
@@ -6,7 +6,7 @@ xmlns:c="clr-namespace:Tizen.NUI.Components;assembly=Tizen.NUI.Components"
 Id="LightTheme">
 
     <ViewStyle x:Key="AppItemBackGround" BackgroundColor="#FAFAFA" />
-    <TextLabelStyle x:Key="AppItemLabel" TextColor="#090E21" />
+    <TextLabelStyle x:Key="AppItemLabel" TextColor="#090E21" FontFamily="BreezeSans" />
 
     <c:ButtonStyle x:Key="CrossButton" ThemeChangeSensitive="true" IsSelectable="false" IsEnabled="true" BackgroundColor="Transparent">
         <c:ButtonStyle.Icon>
@@ -18,4 +18,23 @@ Id="LightTheme">
         </c:ButtonStyle.Icon>
     </c:ButtonStyle>
 
+    <c:AlertDialogStyle x:Key="AlertDialogBackground" ThemeChangeSensitive="true" BackgroundColor="#FAFAFA">
+        <c:AlertDialogStyle.TitleTextLabel>
+            <TextLabelStyle TextColor="#090E21" FontFamily="BreezeSans" PixelSize="24sp" />
+        </c:AlertDialogStyle.TitleTextLabel>
+        <c:AlertDialogStyle.MessageTextLabel>
+            <TextLabelStyle TextColor="#090E21" FontFamily="BreezeSans" PixelSize="24sp" />
+        </c:AlertDialogStyle.MessageTextLabel>
+    </c:AlertDialogStyle>
+
+    <c:ButtonStyle x:Key="CancelButton" ThemeChangeSensitive="true" Size="252sp, 48sp" IsSelectable="false" IsEnabled="true" BackgroundColor="Transparent" >
+        <c:ButtonStyle.Icon>
+            <ImageViewStyle Size="252sp, 48sp">
+                <ImageViewStyle.ResourceUrl>
+                    <Selector x:TypeArguments="x:String" Normal="*Resource*/images/light/cancel_button.png" />
+                </ImageViewStyle.ResourceUrl>
+            </ImageViewStyle>
+        </c:ButtonStyle.Icon>
+    </c:ButtonStyle>
+
 </Theme>
\ No newline at end of file
index 29978dde366d6b8b2ef9b2e825958e48a1e51183..5942c1cc981ef42c47057a33ced0b133b4623e4c 100755 (executable)
Binary files a/packaging/org.tizen.TrayApplication-1.0.0.tpk and b/packaging/org.tizen.TrayApplication-1.0.0.tpk differ