- Add Pin/Unpin function
authorcskim <charles0.kim@samsung.com>
Sat, 11 Mar 2017 07:41:49 +0000 (16:41 +0900)
committerChulSeung Kim <charles0.kim@samsung.com>
Thu, 8 Jun 2017 09:34:46 +0000 (18:34 +0900)
- Add Sorting function(Asc,desc)
- Fix AppShortcutStorage
- Modify Util classes

Change-Id: Ibefb5103c44c250a78dde174cf72dcadcec18068

32 files changed:
LibTVRefCommonPortable/DataModels/AppShortcutInfo.cs
LibTVRefCommonPortable/DataModels/CommandAction.cs
LibTVRefCommonPortable/DataModels/ShortcutInfo.cs
LibTVRefCommonPortable/DataModels/StateDescription.cs
LibTVRefCommonPortable/LibTVRefCommonPortable.csproj
LibTVRefCommonPortable/Models/AppShortcutController.cs
LibTVRefCommonPortable/Utils/AppControlUtils.cs
LibTVRefCommonPortable/Utils/AppShortcutStorage.cs
LibTVRefCommonPortable/Utils/IPackageManager.cs
LibTVRefCommonPortable/Utils/IPlatformNotification.cs [new file with mode: 0644]
LibTVRefCommonPortable/Utils/PackageManagerUtils.cs
LibTVRefCommonTizen/LibTVRefCommonTizen.cs [deleted file]
LibTVRefCommonTizen/LibTVRefCommonTizen.csproj
LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs
LibTVRefCommonTizen/Ports/PackageManagerPort.cs
TVApps/TVApps.TizenTV/TVApps.TizenTV.cs
TVApps/TVApps.TizenTV/TVApps.TizenTV.csproj
TVApps/TVApps/TVApps.cs
TVApps/TVApps/TVApps.csproj
TVApps/TVApps/ViewModels/AppsHolder.cs [new file with mode: 0644]
TVApps/TVApps/ViewModels/AppsListSorter.cs
TVApps/TVApps/ViewModels/IAppsViewModel.cs [new file with mode: 0644]
TVApps/TVApps/ViewModels/MainPageViewModel.cs
TVApps/TVApps/Views/FooterDeleteStatus.xaml
TVApps/TVApps/Views/FooterNormalStatus.xaml
TVApps/TVApps/Views/FooterPinStatus.xaml
TVApps/TVApps/Views/FooterPinStatus.xaml.cs
TVApps/TVApps/Views/MainPage.xaml
TVApps/TVApps/Views/MainPage.xaml.cs
TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk
TVHome/TVHome.TizenTV/tizen-manifest.xml
TVHome/TVHome/ViewModels/MainPageViewModel.cs

index 3814d7ecfd9eebf4e49c933b35a1308036494468..a0dc7a17af48f0080faab95e59cf14c289db675b 100644 (file)
@@ -33,8 +33,11 @@ namespace LibTVRefCommmonPortable.DataModels
 
         [XmlIgnore]
         public bool IsRemovable { get; set; }
+
+        [XmlIgnore]
         public DateTime Installed { get; set; }
 
+        [XmlIgnore]
         public DateTime LastUsed { get; set; }
 
         public override void UpdateState()
index d5dda8477f9ba0bc8a7f3f406d92f6fd43c30390..a46e12ac88f90187b60c83ebd256dcd41fe10a88 100644 (file)
@@ -21,12 +21,13 @@ namespace LibTVRefCommonPortable.DataModels
 {
     public class CommandAction : IAction
     {
+        public string NextStateDescription { get; set; }
         public ICommand Command { get; set; }
         public string CommandParameter { get; set; }
         public string Execute()
         {
             Command.Execute(CommandParameter);
-            return null;
+            return NextStateDescription;
         }
     }
 }
index c14ccbad5a3c2340363fe14fe943ed4ea9cf9177..cfb1b1121a40aa82cc4b6142c8d734adbed24cba 100644 (file)
@@ -62,6 +62,22 @@ namespace LibTVRefCommmonPortable.DataModels
                 return false;
             }
 
+            if (CurrentStateDescription != null &&
+                CurrentStateDescription == stateDescriptions[state])
+            {
+                return true;
+            }
+
+            // TODO : remove, for debugging purpose
+            foreach (var item in stateDescriptions)
+            {
+                if (item.Value.Equals(CurrentStateDescription))
+                {
+                    DebuggingUtils.Dbg("[" + item.Key + "] => [" + state + "]");
+                    break;
+                }
+            }
+
             CurrentStateDescription = stateDescriptions[state];
             OnPropertyChanged("CurrentStateDescription");
             return true;
index 0a68f3e602b4c54de136f0297775cdf3576a2235..0ffc05c3faba36fd8e40b00771278e60d1c10a51 100644 (file)
@@ -18,6 +18,12 @@ namespace LibTVRefCommmonPortable.DataModels
 {
     public class StateDescription
     {
+        public StateDescription()
+        {
+            Label = "";
+            IconPath = "";
+        }
+
         public string Label
         {
             get;
index 1744dc78f0a2cc2fa9bad56201b592ce5295deb1..05c8a62dec71a406a6a59da100550c4ab100f51b 100644 (file)
@@ -68,6 +68,7 @@
     <Compile Include="Utils\DebuggingUtils.cs" />
     <Compile Include="Utils\IAppControl.cs" />
     <Compile Include="Utils\IApplicationManagerAPIs.cs" />
+    <Compile Include="Utils\IPlatformNotification.cs" />
     <Compile Include="Utils\IBTAPIs.cs" />
     <Compile Include="Utils\IDBAPIs.cs" />
     <Compile Include="Utils\IDebuggingAPIs.cs" />
index f9759933e4c14e57308995e7c9f24f402def4b8e..8de24f391d1295c8ee2476f6e8cddb8cb12783ec 100755 (executable)
@@ -27,8 +27,6 @@ namespace LibTVRefCommmonPortable.Models
 {
     public class AppShortcutController
     {
-        private List<AppShortcutInfo> returnPinnedAppsInfo = new List<AppShortcutInfo>();
-
         public AppShortcutController()
         {
 
@@ -36,6 +34,7 @@ namespace LibTVRefCommmonPortable.Models
 
         public async Task<IEnumerable<AppShortcutInfo>> GetInstalledApps()
         {
+            DebuggingUtils.Dbg(">AppShortcutController, GetInstalledApps - start");
             IApplicationManagerAPIs applicationManagerPort = DependencyService.Get<IApplicationManagerAPIs>();
             List<AppShortcutInfo> appShortcutInfoList = new List<AppShortcutInfo>();
 
@@ -66,10 +65,11 @@ namespace LibTVRefCommmonPortable.Models
                 appShortcutInfoList.Add(appShortcutInfo);
             }
 
+            DebuggingUtils.Dbg("<AppShortcutController, GetInstalledApps - end");
             return appShortcutInfoList;
         }
 
-        private void AddAllAppsAndMediaHubShortcut()
+        private void AddAllAppsAndMediaHubShortcut(ref List<AppShortcutInfo> returnPinnedAppsInfo)
         {
             var allAppsStateDescription = new StateDescription()
             {
@@ -86,7 +86,7 @@ namespace LibTVRefCommmonPortable.Models
             allAppsShortcutInfo.StateDescriptions.Add("default", allAppsStateDescription);
             allAppsShortcutInfo.CurrentStateDescription = allAppsStateDescription;
 
-            returnPinnedAppsInfo.Add(allAppsShortcutInfo);
+            returnPinnedAppsInfo.Insert(0, allAppsShortcutInfo);
 
             var mediaHubStateDescription = new StateDescription()
             {
@@ -102,10 +102,10 @@ namespace LibTVRefCommmonPortable.Models
             mediaHubShortcutInfo.StateDescriptions.Add("default", mediaHubStateDescription);
             mediaHubShortcutInfo.CurrentStateDescription = mediaHubStateDescription;
 
-            returnPinnedAppsInfo.Add(mediaHubShortcutInfo);
+            returnPinnedAppsInfo.Insert(1, mediaHubShortcutInfo);
         }
 
-        private void AppendAddPinShortcut()
+        private void AppendAddPinShortcut(ref List<AppShortcutInfo> returnPinnedAppsInfo)
         {
             var addPinStateDescription = new StateDescription()
             {
@@ -125,54 +125,76 @@ namespace LibTVRefCommmonPortable.Models
             returnPinnedAppsInfo.Add(addPinShortcutInfo);
         }
 
-        public IEnumerable<AppShortcutInfo> GetPinnedApps()
+        private List<AppShortcutInfo> GetPinnedApps()
         {
             IApplicationManagerAPIs applicationManagerPort = DependencyService.Get<IApplicationManagerAPIs>();
             IEnumerable<AppShortcutInfo> pinned_apps_info = AppShortcutStorage.Read();
             string[] icons = { "ic_black.png", "ic_blue.png", "ic_green.png", "ic_red.png", "ic_yellow.png", "AppIcon.png" };
 
-            AddAllAppsAndMediaHubShortcut();
+            List<AppShortcutInfo> returnPinnedAppsInfo = new List<AppShortcutInfo>();
 
             foreach (AppShortcutInfo appShortcutInfo in pinned_apps_info)
             {
                 Dictionary<string, string> appInfo = applicationManagerPort.GetInstalledApplication(appShortcutInfo.AppID);
 
-                if (appInfo != null)
+                if (appInfo == null)
                 {
-                    string appLabel;
-                    string appIconPath;
+                    continue;
+                }
 
-                    appInfo.TryGetValue("Label", out appLabel);
-                    appInfo.TryGetValue("IconPath", out appIconPath);
+                string appLabel;
+                string appIconPath;
 
-                    DebuggingUtils.Dbg("AppID: " + appShortcutInfo.AppID + ", Label : " + appLabel + " IconPath : " + appIconPath);
-                    Random random = new Random();
-                    var defaultStateDescription = new StateDescription()
-                    {
-                        Label = appLabel,
-                        IconPath = appIconPath ?? icons[random.Next(0, 6)],
-                        Action = new AppControlAction
-                        {
-                            AppID = appShortcutInfo.AppID,
-                        }
-                    };
-
-                    appShortcutInfo.StateDescriptions.Add("default", defaultStateDescription);
-                    appShortcutInfo.CurrentStateDescription = defaultStateDescription;
-                    appShortcutInfo.IsPinned = true;
-                    returnPinnedAppsInfo.Add(appShortcutInfo);
-                }
-                else
+                appInfo.TryGetValue("Label", out appLabel);
+                appInfo.TryGetValue("IconPath", out appIconPath);
+
+                DebuggingUtils.Dbg("AppID: " + appShortcutInfo.AppID + ", Label : " + appLabel + " IconPath : " + appIconPath);
+                Random random = new Random();
+                var defaultStateDescription = new StateDescription()
                 {
-                    // TODO : Remove the broken appInfo from pinned_apps_info
-                }
+                    Label = appLabel,
+                    IconPath = appIconPath ?? icons[random.Next(0, 6)],
+                    Action = new AppControlAction
+                    {
+                        AppID = appShortcutInfo.AppID,
+                    }
+                };
+
+                appShortcutInfo.StateDescriptions.Add("default", defaultStateDescription);
+                appShortcutInfo.CurrentStateDescription = defaultStateDescription;
+                appShortcutInfo.IsPinned = true;
+                returnPinnedAppsInfo.Add(appShortcutInfo);
             }
 
-            AppendAddPinShortcut();
+            return returnPinnedAppsInfo;
+        }
+
+        public IEnumerable<AppShortcutInfo> GetPinnedAppsWithDefaultShortcuts()
+        {
+            List<AppShortcutInfo> returnPinnedAppsInfo = GetPinnedApps();
+
+            AddAllAppsAndMediaHubShortcut(ref returnPinnedAppsInfo);
+            AppendAddPinShortcut(ref returnPinnedAppsInfo);
 
             return returnPinnedAppsInfo;
         }
 
+        public Dictionary<string, string> GetPinnedAppsAppIDs()
+        {
+            IApplicationManagerAPIs applicationManagerPort = DependencyService.Get<IApplicationManagerAPIs>();
+            IEnumerable<AppShortcutInfo> pinned_apps_info = AppShortcutStorage.Read();
+            string[] icons = { "ic_black.png", "ic_blue.png", "ic_green.png", "ic_red.png", "ic_yellow.png", "AppIcon.png" };
+
+            Dictionary<string, string> pinnedAppsDictionary = new Dictionary<string, string>();
+
+            foreach (AppShortcutInfo appShortcutInfo in pinned_apps_info)
+            {
+                pinnedAppsDictionary.Add(appShortcutInfo.AppID, appShortcutInfo.AppID);
+            }
+
+            return pinnedAppsDictionary;
+        }
+
         public void UpdatePinnedApps(IEnumerable<AppShortcutInfo> pinnedAppsInfo)
         {
             AppShortcutStorage.Write(pinnedAppsInfo);
index 7d4a467723e7a345033dd5a579f90bf17f2b3e2f..304262f4188fe388c6462f296818520886bc0409 100644 (file)
@@ -26,36 +26,14 @@ namespace LibTVRefCommmonPortable.Utils
 {
     public sealed class AppControlUtils
     {
-        private static IAppControl iam;
-        private static readonly AppControlUtils instance = new AppControlUtils();
-
-        public static AppControlUtils Instance
-        {
-            get { return instance; }
-        }
-
-        private class DefaultAM : IAppControl
-        {
-            public void SendLaunchRequest(string PkgID)
-            {
-            }
-        }
-
-        private AppControlUtils()
+        public static void SendLaunchRequest(string PkgID)
         {
-            if (DependencyService.Get<IAppControl>() != null)
-            {
-                iam = DependencyService.Get<IAppControl>();
-            }
-            else
+            if (DependencyService.Get<IAppControl>() == null)
             {
-                iam = new DefaultAM();
+                return;
             }
-        }
 
-        public static void SendLaunchRequest(string PkgID)
-        {
-            iam.SendLaunchRequest(PkgID);
+            DependencyService.Get<IAppControl>().SendLaunchRequest(PkgID);
         }
     }
 }
index d691cf4fe4bfe32daf0b89e2846c42d342511504..6ef851e8760fcbfd234efe33bfed73467310c824 100644 (file)
@@ -104,36 +104,74 @@ namespace LibTVRefCommmonPortable.Utils
         {
             IFileSystemAPIs fileSystem = DependencyService.Get<IFileSystemAPIs>();
             XmlSerializer serializer = new XmlSerializer(typeof(List<AppShortcutInfo>));
-            Stream fileStream = fileSystem.OpenFile(storagePath, UtilFileMode.Open);
-            if (fileStream == null)
+            Stream fileStream = null;
+
+            try
+            {
+                fileStream = fileSystem.OpenFile(storagePath, UtilFileMode.Open);
+                if (fileStream == null)
+                {
+                    DebuggingUtils.Dbg("OpenFile failed : " + storagePath);
+                    // TODO : Remove later, below lines are sample apps for demonstration.
+                    List<AppShortcutInfo> result = GetSampleList();
+                    Write(result);
+                    return result;
+                }
+
+                StreamReader streamReader = new StreamReader(fileStream);
+                List<AppShortcutInfo> list = (List<AppShortcutInfo>)serializer.Deserialize(streamReader);
+
+                return list;
+            }
+            catch (Exception e)
             {
-                DebuggingUtils.Dbg("OpenFile failed : " + storagePath);
-                // TODO : Remove later, below lines are sample apps for demonstration.
+                // TODO : recover xml file here!
+                DebuggingUtils.Err("XML Desearialize is failed, " + storagePath + ", " + e.Message);
                 List<AppShortcutInfo> result = GetSampleList();
                 Write(result);
                 return result;
             }
-
-            StreamReader streamReader = new StreamReader(fileStream);
-            List<AppShortcutInfo> list = (List<AppShortcutInfo>)serializer.Deserialize(streamReader);
-            fileSystem.CloseFile(fileStream);
-            return list;
+            finally
+            {
+                if (fileStream != null)
+                {
+                    fileSystem.CloseFile(fileStream);
+                }
+            }
         }
 
         public static bool Write(IEnumerable<AppShortcutInfo> pinnedAppInfo)
         {
             IFileSystemAPIs fileSystem = DependencyService.Get<IFileSystemAPIs>();
             XmlSerializer serializer = new XmlSerializer(typeof(List<AppShortcutInfo>));
-            Stream fileStream = fileSystem.OpenFile(storagePath, UtilFileMode.OpenOrCreate);
-            if (fileStream == null)
+            Stream fileStream = null;
+
+            try
+            {
+                fileStream = fileSystem.OpenFile(storagePath, UtilFileMode.Create);
+                if (fileStream == null)
+                {
+                    return false;
+                }
+
+                StreamWriter streamWriter = new StreamWriter(fileStream);
+                serializer.Serialize(streamWriter, pinnedAppInfo);
+                streamWriter.Flush();
+            }
+            catch (Exception e)
             {
+                DebuggingUtils.Err("XML Searialize is failed, " + storagePath + ", " + e.Message);
                 return false;
             }
+            finally
+            {
+                if (fileStream != null)
+                {
+                    fileSystem.CloseFile(fileStream);
+                }
+
+            }
 
-            StreamWriter streamWriter = new StreamWriter(fileStream);
-            serializer.Serialize(streamWriter, pinnedAppInfo);
-            streamWriter.Flush();
-            fileSystem.CloseFile(fileStream);
             return true;
         }
 
index 073609a1bfdcd960990e149e935d81539fea2a52..a9bbff06822eee33892a98c1eff72f0a335bf57c 100644 (file)
@@ -36,5 +36,9 @@ namespace LibTVRefCommmonPortable.Utils
         Dictionary<string, string[]> GetPackageList();
 
         string GetPackage(string PkgID);
+
+        bool UninstallPackage(string pkgID);
+
+        bool UninstallPackageByAppID(string appID);
     }
 }
diff --git a/LibTVRefCommonPortable/Utils/IPlatformNotification.cs b/LibTVRefCommonPortable/Utils/IPlatformNotification.cs
new file mode 100644 (file)
index 0000000..3a8c2e1
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * 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.
+ */
+
+
+namespace LibTVRefCommonPortable.Utils
+{
+    public interface IPlatformNotification
+    {
+        void OnBackKeyPressed();
+
+        void OnAppInstalled(string pkgID);
+
+        void OnAppUninstalled(string pkgID);
+    }
+}
index 7ccaf4e8181a520598e6a9a744b3cb8c91ecfef9..dd18a18e47d6312904c7eade1016a785e716e561 100644 (file)
@@ -27,47 +27,44 @@ namespace LibTVRefCommmonPortable.Utils
 {
     public sealed class PackageManagerUtils
     {
-        private static IPackageManager ipm;
-        private static readonly PackageManagerUtils instance = new PackageManagerUtils();
-
-        public static PackageManagerUtils Instance
+        public static Dictionary<string, string[]> GetPackageList()
         {
-            get { return instance; }
+            if (DependencyService.Get<IPackageManager>() == null)
+            {
+                return new Dictionary<string, string[]>();
+            }
+
+            return DependencyService.Get<IPackageManager>().GetPackageList();
         }
 
-        private class DefaultPM : IPackageManager
+        public static string GetPackage(string PkgID)
         {
-            public Dictionary<string, string[]> GetPackageList()
+            if (DependencyService.Get<IPackageManager>() == null)
             {
-                return null;
+                return "";
             }
 
-            public string GetPackage(string PkgID)
-            {
-                return null;
-            }
+            return DependencyService.Get<IPackageManager>().GetPackage(PkgID);
         }
 
-        private PackageManagerUtils()
+        public static bool UninstallPackage(string pkgID)
         {
-            if (DependencyService.Get<IPackageManager>() != null)
+            if (DependencyService.Get<IPackageManager>() == null)
             {
-                ipm = DependencyService.Get<IPackageManager>();
+                return false;
             }
-            else
-            {
-                ipm = new DefaultPM();
-            }
-        }
 
-        public Dictionary<string, string[]> GetPackageList()
-        {
-            return ipm.GetPackageList();
+            return DependencyService.Get<IPackageManager>().UninstallPackage(pkgID);
         }
 
-        public string GetPackage(string PkgID)
+        public static bool UninstallPackageByAppID(string appID)
         {
-            return ipm.GetPackage(PkgID);
+            if (DependencyService.Get<IPackageManager>() == null)
+            {
+                return false;
+            }
+
+            return DependencyService.Get<IPackageManager>().UninstallPackageByAppID(appID);
         }
     }
 }
diff --git a/LibTVRefCommonTizen/LibTVRefCommonTizen.cs b/LibTVRefCommonTizen/LibTVRefCommonTizen.cs
deleted file mode 100644 (file)
index d53b4eb..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-using System;
-
-namespace LibTVRefCommonTizen
-{
-    public class MyLibrary
-    {
-        public string MyMethod()
-        {
-            return "Hello Tizen Library!!!";
-        }
-    }
-}
index 6df096fe1f8d340e9ce418d19cdda5d1e9a48ec3..565835ca81a6f65ebc5c4ff095f73b7332f63202 100644 (file)
@@ -45,7 +45,6 @@
     <None Include="LibTVRefCommonTizen.project.json" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="LibTVRefCommonTizen.cs" />
     <Compile Include="Ports\AppControlPort.cs" />
     <Compile Include="Ports\ApplicationManagerPort.cs" />
     <Compile Include="Ports\BTModulePort.cs" />
index c2e8b42d5624caadd1b2403a25fb35a82737800e..1b8e49d699b83879dd65cf6e7f169482b2e71c0a 100644 (file)
@@ -106,8 +106,6 @@ namespace LibTVRefCommonTizen.Ports
 
                 foreach (var appInfo in installedList)
                 {
-                    DebuggingPort.D("-------------------------------------");
-                    DebuggingPort.D("TRY" + appInfo.ToString());
                     if (appInfo.IsNoDisplay)
                     {
                         continue;
@@ -119,16 +117,11 @@ namespace LibTVRefCommonTizen.Ports
                         continue;
                     }
 
-                    DebuggingPort.D("TRY" + pkgInfo.ToString());
-
                     if (pkgInfo.IsSystemPackage)
                     {
                         continue;
                     }
 
-                    DebuggingPort.D("ADD" + appInfo.ToString());
-
-
                     result = new string[3];
 
                     result[0] = (appInfo.Label != null) ? appInfo.Label : null;
index 99d99c3491aa4642af208138b0107a698c9228d2..b0f61b0de3540f061f1279d61377c11161646c16 100644 (file)
@@ -24,30 +24,56 @@ using Tizen;
 using Tizen.Applications;
 
 using LibTVRefCommmonPortable.Utils;
+using LibTVRefCommonPortable.Utils;
 
 namespace LibTVRefCommonTizen.Ports
 {
     public class PackageManagerPort : IPackageManager
     {
+        private static IPlatformNotification Notification
+        {
+            get;
+            set;
+        }
+
         public PackageManagerPort()
         {
+
+        }
+
+        public static void RegisterCallbacks(IPlatformNotification app)
+        {
+            Notification = app;
             PackageManager.InstallProgressChanged += PackageManager_InstallProgressChanged;
             PackageManager.UninstallProgressChanged += PackageManager_UninstallProgressChanged;
         }
 
-        private void PackageManager_UninstallProgressChanged(object sender, PackageManagerEventArgs e)
+        public static void DeregisterCallbacks()
+        {
+            Notification = null;
+            PackageManager.InstallProgressChanged -= PackageManager_InstallProgressChanged;
+            PackageManager.UninstallProgressChanged -= PackageManager_UninstallProgressChanged;
+        }
+
+        private static void PackageManager_UninstallProgressChanged(object sender, PackageManagerEventArgs e)
         {
             if (e.State == PackageEventState.Completed)
             {
-                DebuggingUtils.Dbg("uninstall completed");
+                if (Notification != null)
+                {
+                    Notification.OnAppUninstalled(e.PackageId);
+                }
             }
         }
 
-        private void PackageManager_InstallProgressChanged(object sender, PackageManagerEventArgs e)
+        private static void PackageManager_InstallProgressChanged(object sender, PackageManagerEventArgs e)
         {
             if (e.State == PackageEventState.Completed)
             {
-                DebuggingUtils.Dbg("install completed");
+                if (Notification != null)
+                {
+                    Notification.OnAppInstalled(e.PackageId);
+                }
             }
         }
 
@@ -78,5 +104,28 @@ namespace LibTVRefCommonTizen.Ports
 
             return (tempItem != null) ? tempItem.Label : null;
         }
+
+        public bool UninstallPackage(string pkgID)
+        {
+            Package tempItem = PackageManager.GetPackage(pkgID);
+            if (tempItem == null)
+            {
+                return false;
+            }
+
+            return PackageManager.Uninstall(tempItem.Id, tempItem.PackageType);
+        }
+
+        public bool UninstallPackageByAppID(string appID)
+        {
+            string pkgID = PackageManager.GetPackageIdByApplicationId(appID);
+            if (pkgID == null ||
+                pkgID.Length == 0)
+            {
+                return false;
+            }
+
+            return UninstallPackage(pkgID);
+        }
     }
 }
\ No newline at end of file
index 44387bf622fb80c719091a7b0c87e79c1bf7c7ed..f34d5107caa79adc1f15314fc3435d131094e6a0 100644 (file)
@@ -1,29 +1,81 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * 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.
+ */
+
+using System;
+using LibTVRefCommonPortable.Utils;
 using LibTVRefCommonTizen.Ports;
+using LibTVRefCommonTizen;
 
 namespace TVApps.TizenTV
 {
-    class Program : Xamarin.Forms.Platform.Tizen.FormsApplication
+    public class Program : Xamarin.Forms.Platform.Tizen.FormsApplication
     {
+        IPlatformNotification notification;
+
         protected override void OnCreate()
         {
             base.OnCreate();
-            LoadApplication(new App());
+            var app = new App();
+            notification = app;
+            LoadApplication(app);
+
+            PackageManagerPort.RegisterCallbacks(notification);
+            MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformBackButtonName, true);
+            MainWindow.KeyUp += BackkeyListener;
+        }
+
+        private void BackkeyListener(object sender, ElmSharp.EvasKeyEventArgs e)
+        {
+            if (e.KeyName.CompareTo(ElmSharp.EvasKeyEventArgs.PlatformBackButtonName) == 0)
+            {
+                if (notification != null)
+                {
+                    notification.OnBackKeyPressed();
+                }
+            }
+        }
+
+        protected override void OnTerminate()
+        {
+            base.OnTerminate();
+
+            notification = null;
+            PackageManagerPort.DeregisterCallbacks();
+            MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformBackButtonName);
+            MainWindow.KeyUp -= BackkeyListener;
         }
 
         static void Main(string[] args)
         {
             var app = new Program();
-            global::Xamarin.Forms.DependencyService.Register<DebuggingPort>();
-            global::Xamarin.Forms.DependencyService.Register<DBPort>();
-            global::Xamarin.Forms.DependencyService.Register<AppControlPort>();
-            global::Xamarin.Forms.DependencyService.Register<PackageManagerPort>();
-            global::Xamarin.Forms.DependencyService.Register<WifiModulePort>();
-            global::Xamarin.Forms.DependencyService.Register<BTModulePort>();
-            global::Xamarin.Forms.DependencyService.Register<FileSystemWatcherPort>();
-            global::Xamarin.Forms.DependencyService.Register<ApplicationManagerPort>();
-            global::Xamarin.Forms.DependencyService.Register<FileSystemPort>();
+
+            Xamarin.Forms.DependencyService.Register<DebuggingPort>();
+            Xamarin.Forms.DependencyService.Register<DBPort>();
+            Xamarin.Forms.DependencyService.Register<AppControlPort>();
+            Xamarin.Forms.DependencyService.Register<PackageManagerPort>();
+            Xamarin.Forms.DependencyService.Register<WifiModulePort>();
+            Xamarin.Forms.DependencyService.Register<BTModulePort>();
+            Xamarin.Forms.DependencyService.Register<FileSystemWatcherPort>();
+            Xamarin.Forms.DependencyService.Register<ApplicationManagerPort>();
+            Xamarin.Forms.DependencyService.Register<FileSystemPort>();
             Xamarin.Forms.Platform.Tizen.Forms.Init(app);
+
             app.Run(args);
+
         }
+
     }
 }
index 283d6ef392d4155cc206766314df7869097d2c01..151e5a297bd68159a020df4734f7a3a3ffe06248 100644 (file)
@@ -68,6 +68,9 @@
       <Name>TVApps</Name>
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup>
+    <Reference Include="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" />
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
                Other similar extension points exist, see Microsoft.Common.targets.
index 345bef6143d2e039e72869a9f207836b1305efa1..a16b374431e22767bfb052df26548ead7bde37ef 100644 (file)
 
 using Xamarin.Forms;
 using TVApps.Views;
+using LibTVRefCommonPortable.Utils;
+using System;
+using LibTVRefCommmonPortable.Utils;
 
 namespace TVApps
 {
-    public class App : Application
+    public class TVAppsEventArgs : EventArgs
     {
+        public string arg;
+    }
+
+    public class App : Application, IPlatformNotification
+    {
+        private static EventHandler<TVAppsEventArgs> BackKeyListener;
+        private static EventHandler<TVAppsEventArgs> AppInstalledListener;
+        private static EventHandler<TVAppsEventArgs> AppUninstalledListener;
+
         public App()
         {
             MainPage = new MainPage();
@@ -41,5 +53,46 @@ namespace TVApps
         {
 
         }
+
+        public static void SetBackKeyListener(EventHandler<TVAppsEventArgs> listener)
+        {
+            BackKeyListener += listener;
+        }
+        public static void SetAppInstalledListener(EventHandler<TVAppsEventArgs> listener)
+        {
+            AppInstalledListener += listener;
+        }
+
+        public static void SetAppUninstalledListener(EventHandler<TVAppsEventArgs> listener)
+        {
+            AppUninstalledListener += listener;
+        }
+
+        public void OnBackKeyPressed()
+        {
+            DebuggingUtils.Dbg("[[[ Back Key ]]] ");
+            BackKeyListener.Invoke(this, new TVAppsEventArgs()
+            {
+                arg = "",
+            });
+        }
+
+        public void OnAppInstalled(string pkgID)
+        {
+            DebuggingUtils.Dbg("[[[ App Installed ]]] " + pkgID);
+            AppInstalledListener.Invoke(this, new TVAppsEventArgs()
+            {
+                arg = pkgID,
+            });
+        }
+
+        public void OnAppUninstalled(string pkgID)
+        {
+            DebuggingUtils.Dbg("[[[ App Uninstalled ]]] " + pkgID);
+            AppUninstalledListener.Invoke(this, new TVAppsEventArgs()
+            {
+                arg = pkgID,
+            });
+        }
     }
 }
index d4902a7877d5d0a1d46745e91472ea9c764e78ea..830f5638c2ba981048654bd5736a7f3dcb674413 100644 (file)
@@ -42,7 +42,9 @@
     </Compile>
     <Compile Include="TVApps.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="ViewModels\AppsHolder.cs" />
     <Compile Include="ViewModels\AppsListSorter.cs" />
+    <Compile Include="ViewModels\IAppsViewModel.cs" />
     <Compile Include="ViewModels\MainPageViewModel.cs" />
     <Compile Include="Views\FooterDeleteStatus.xaml.cs">
       <DependentUpon>FooterDeleteStatus.xaml</DependentUpon>
diff --git a/TVApps/TVApps/ViewModels/AppsHolder.cs b/TVApps/TVApps/ViewModels/AppsHolder.cs
new file mode 100644 (file)
index 0000000..669d600
--- /dev/null
@@ -0,0 +1,234 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * 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.
+ */
+
+using LibTVRefCommmonPortable.DataModels;
+using LibTVRefCommmonPortable.Utils;
+using LibTVRefCommonPortable.DataModels;
+using System.Collections.Generic;
+using System.Linq;
+using Xamarin.Forms;
+
+namespace TVApps.ViewModels
+{
+    internal class AppsHolder
+    {
+        IAppsViewModel ViewModel;
+
+        public SortingOptions SortingOption;
+
+        public List<AppShortcutInfo> InstalledApps;
+
+        public Dictionary<string, string> PinnedApps;
+
+
+        public AppsHolder(IAppsViewModel ViewModel)
+        {
+            this.ViewModel = ViewModel;
+
+            InstalledApps = new List<AppShortcutInfo>();
+            PinnedApps = new Dictionary<string, string>();
+
+            App.SetAppInstalledListener((s, e) =>
+            {
+                SetApps();
+            });
+
+            App.SetAppUninstalledListener((s, e) =>
+            {
+                // TODO : find apps by package id
+                // TODO : remove all apps from pinned app list
+
+                SetApps();
+            });
+
+            SetApps();
+        }
+
+        private async void SetApps()
+        {
+            DebuggingUtils.Dbg(">GetInstalledApps - Start");
+            PinnedApps = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsAppIDs();
+            var installedApps = await TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetInstalledApps();
+
+            foreach (AppShortcutInfo item in installedApps)
+            {
+                if (item.CurrentStateDescription == null)
+                {
+                    DebuggingUtils.Err("Invalid AppshortcutInfo, " + item.AppID);
+                    continue;
+                }
+
+                item.SetPinned(PinnedApps.ContainsKey(item.AppID));
+
+                var pinStateDescription = new StateDescription()
+                {
+                    Label = item.CurrentStateDescription.Label,
+                    IconPath = item.CurrentStateDescription.IconPath,
+                    Action = new CommandAction()
+                    {
+                        NextStateDescription = AppsStatus.Pin.ToString().ToLower(),
+                        Command = new Command<string>((key) =>
+                        {
+                            PinToggle(key);
+                        }),
+                        CommandParameter = item.AppID
+                    }
+                };
+
+                item.StateDescriptions.Add(AppsStatus.Pin.ToString().ToLower(), pinStateDescription);
+
+                var deleteStateDescription = new StateDescription()
+                {
+                    Label = item.CurrentStateDescription.Label,
+                    IconPath = item.CurrentStateDescription.IconPath,
+                    Action = new CommandAction()
+                    {
+                        NextStateDescription = AppsStatus.Delete.ToString().ToLower(),
+                        Command = new Command<string>((key) =>
+                        {
+                            DeleteApp(key);
+                        }),
+                        CommandParameter = item.AppID
+                    }
+                };
+
+                item.StateDescriptions.Add(AppsStatus.Delete.ToString().ToLower(), deleteStateDescription);
+            }
+
+            InstalledApps = installedApps.ToList();
+            SortApps(SortingOption);
+
+            DebuggingUtils.Dbg("<GetInstalledApps - End");
+        }
+
+        private void PinToggle(string key)
+        {
+            if (PinnedApps.ContainsKey(key))
+            {
+                DebuggingUtils.Dbg("UnPin!");
+                InstalledApps.FirstOrDefault(a => a.AppID == key).SetChecked(false);
+                PinnedApps.Remove(key);
+            }
+            else
+            {
+                DebuggingUtils.Dbg("Pin!");
+                InstalledApps.FirstOrDefault(a => a.AppID == key).SetChecked(true);
+                PinnedApps.Add(key, key);
+            }
+        }
+
+        private void DeleteApp(string AppID)
+        {
+            DebuggingUtils.Dbg("Delete, " + AppID);
+            // 1. Check the property of the app
+            // 1-1. If the app is pinned, call UnsetPinnedApp(AppId)
+            // 2. Show Popup(Delete message)
+            // 2-1. OK : Call the AppFW API to remove the app
+            // 2-2. Cancel : Change AppsStatus to Normal
+
+            // TODO : popup
+
+            RemovePinnedApp(AppID);
+
+            ViewModel.ChangeCurrentStatus(AppsStatus.Default);
+
+            if (PackageManagerUtils.UninstallPackageByAppID(AppID) == false)
+            {
+                DebuggingUtils.Err("App uninstall is failed!!!, " + AppID);
+            }
+            else
+            {
+                var removed = from app in InstalledApps
+                              where app.AppID == AppID
+                              select app;
+                InstalledApps.Remove(removed.First());
+                foreach (var item in InstalledApps)
+                {
+                    DebuggingUtils.Dbg("- " + item.AppID);
+                }
+
+                RefreshApps();
+            }
+        }
+
+        public void UpdateStateDescription(AppsStatus status)
+        {
+            string tag = status.ToString().ToLower();
+
+            DebuggingUtils.Dbg("AppsListStateUpdate, status = " + status.ToString() + ", tag = " + tag);
+            foreach (AppShortcutInfo item in InstalledApps)
+            {
+                item.CurrentStateDescription = item.StateDescriptions[tag];
+                switch (status)
+                {
+                    case AppsStatus.Pin:
+                        item.SetChecked(item.IsPinned);
+                        break;
+
+                    default:
+                        item.SetChecked(false);
+                        break;
+                }
+
+                item.SetPinned(PinnedApps.ContainsKey(item.AppID));
+            }
+
+            ViewModel.OnPropertyChanged("InstalledAppList");
+        }
+
+        // Just use to update list view which is binding
+        private void RefreshApps()
+        {
+            InstalledApps = new List<AppShortcutInfo>(InstalledApps);
+            ViewModel.OnPropertyChanged("InstalledAppList");
+        }
+
+        public void SortApps(SortingOptions sortOption)
+        {
+            AppsListSorter.GetSortedAppsList(sortOption, ref InstalledApps);
+            RefreshApps();
+        }
+
+        public void ResetPinnedApps()
+        {
+            PinnedApps = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsAppIDs();
+        }
+
+        public void UpdatePinnedApps()
+        {
+            List<AppShortcutInfo> pinnedAppList = new List<AppShortcutInfo>();
+            foreach (var item in PinnedApps)
+            {
+                DebuggingUtils.Dbg("Pinned App : " + item.Key);
+                pinnedAppList.Add(new AppShortcutInfo()
+                {
+                    AppID = item.Key,
+                });
+            }
+
+            TVHomeImpl.GetInstance.AppShortcutControllerInstance.UpdatePinnedApps(pinnedAppList);
+        }
+
+        public void RemovePinnedApp(string AppID)
+        {
+            if (PinnedApps.ContainsKey(AppID))
+            {
+                PinnedApps.Remove(AppID);
+                UpdatePinnedApps();
+            }
+        }
+    }
+}
index 9f00da62f6027732fee162bbcbd9fc4e0f929ba2..b04622fd12b6d0e362d50b952d210126c2e50754 100644 (file)
  */
 
 using LibTVRefCommmonPortable.DataModels;
+using LibTVRefCommmonPortable.Utils;
 using System.Collections.Generic;
 
 namespace TVApps.ViewModels
 {
-    public class AppsListSorter
+    internal class AppsListSorter
     {
 
         private static int SortByLabelAscending(AppShortcutInfo left, AppShortcutInfo right)
@@ -44,6 +45,7 @@ namespace TVApps.ViewModels
 
         public static void GetSortedAppsList(SortingOptions sortOption, ref List<AppShortcutInfo> list)
         {
+            DebuggingUtils.Dbg("GetSortedAppsList, option = " + sortOption.ToString());
             switch (sortOption)
             {
                 case SortingOptions.RecentlyInstalled:
@@ -52,12 +54,13 @@ namespace TVApps.ViewModels
                 case SortingOptions.RecentlyUsed:
                     list.Sort(SortByRecentlyUsed);
                     break;
-                case SortingOptions.Ascending:
-                    list.Sort(SortByLabelAscending);
-                    break;
                 case SortingOptions.Descending:
                     list.Sort(SortByLabelDescending);
                     break;
+                case SortingOptions.Ascending:
+                default:
+                    list.Sort(SortByLabelAscending);
+                    break;
             }
         }
     }
diff --git a/TVApps/TVApps/ViewModels/IAppsViewModel.cs b/TVApps/TVApps/ViewModels/IAppsViewModel.cs
new file mode 100644 (file)
index 0000000..088ae89
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * 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.
+ */
+
+namespace TVApps.ViewModels
+{
+    interface IAppsViewModel
+    {
+        void OnPropertyChanged(string name);
+        void ChangeCurrentStatus(AppsStatus newStatus);
+    }
+}
index cc96463494b661d9882c2769c49b1c81f68f33b8..a7f4f34934d63240ced5f474afa709e9e3da90aa 100644 (file)
 
 using LibTVRefCommmonPortable.DataModels;
 using LibTVRefCommmonPortable.Utils;
-using LibTVRefCommonPortable.DataModels;
 using System.Collections.Generic;
 using System.ComponentModel;
-using System.Linq;
 using Xamarin.Forms;
 using System;
 
@@ -27,18 +25,11 @@ namespace TVApps.ViewModels
 {
     public enum AppsStatus
     {
-        Launch,
+        Default = 0,
         Pin,
         Delete,
     };
 
-    public enum BackKeyInfo
-    {
-        Back,
-        Front,
-        Quit,
-    };
-
     public enum SortingOptions
     {
         RecentlyInstalled = 0,
@@ -47,26 +38,39 @@ namespace TVApps.ViewModels
         Descending,
     };
 
-    class MainPageViewModel : INotifyPropertyChanged
+    class MainPageViewModel : INotifyPropertyChanged, IAppsViewModel
     {
-        private List<AppShortcutInfo> installedAppList;
+        AppsHolder appsHolder;
+
         public List<AppShortcutInfo> InstalledAppList
         {
             get
             {
-                return installedAppList;
+                return appsHolder.InstalledApps;
             }
         }
 
-        public List<AppShortcutInfo> PinnedAppList { get; private set; }
-
         public Command OptionCommand { get; set; }
-        public Command ButtonDelCommand { get; set; }
-        public Command ButtonPinCommand { get; set; }
+        public Command ButtonDeleteCancelCommand { get; set; }
+        public Command ButtonPinAppCommand { get; set; }
+        public Command ButtonDeleteAppCommand { get; set; }
+        public Command ButtonPinOkCommand { get; set; }
+        public Command ButtonPinCancelCommand { get; set; }
 
         public AppsStatus CurrentStatus { get; private set; }
 
-        private SortingOptions SortingOption { get; set; }
+        private SortingOptions SortingOption
+        {
+            get
+            {
+                return appsHolder.SortingOption;
+            }
+
+            set
+            {
+                appsHolder.SortingOption = value;
+            }
+        }
 
         public int SortOptionIndex
         {
@@ -77,74 +81,82 @@ namespace TVApps.ViewModels
 
             set
             {
-                SortingOption = (SortingOptions)Enum.ToObject(typeof(SortingOptions), value);
-                if (installedAppList != null)
+                SortingOptions newSortingOption = (SortingOptions)Enum.ToObject(typeof(SortingOptions), value);
+                if (newSortingOption != SortingOption)
                 {
-                    AppsListSorter.GetSortedAppsList(SortingOption, ref installedAppList);
-                    OnPropertyChanged("AppList");
+                    SortingOption = newSortingOption;
+                    if (InstalledAppList != null)
+                    {
+                        appsHolder.SortApps(SortingOption);
+                    }
                 }
             }
         }
 
-        public BackKeyInfo BackKeyStatus { get; private set; }
-
         public ShortcutInfo FocusedItem { get; set; }
 
         public event PropertyChangedEventHandler PropertyChanged;
 
         public MainPageViewModel()
         {
+            DebuggingUtils.Dbg(">MainPageViewModel - Start");
+
             Init();
 
-            GetInstalledApps();
+            ButtonDeleteCancelCommand = new Command(() =>
+            {
+                ChangeCurrentStatus(AppsStatus.Default);
+            });
 
-            OptionCommand = new Command((optionType) =>
+            ButtonPinAppCommand = new Command(() =>
             {
-                // 1. Change current status by optionType
-                CurrentStatus = AppsStatus.Pin;
-                foreach (AppShortcutInfo item in installedAppList)
-                {
-                    item.CurrentStateDescription = item.StateDescriptions["pin"];
-                    item.SetChecked(item.IsPinned);
-                    item.SetPinned(false);
-                }
+                ChangeCurrentStatus(AppsStatus.Pin);
+            });
 
-                OnPropertyChanged("CurrentStatus");
+            ButtonDeleteAppCommand = new Command(() =>
+            {
+                ChangeCurrentStatus(AppsStatus.Delete);
             });
 
-            ButtonDelCommand = new Command(() =>
+            ButtonPinOkCommand = new Command(() =>
             {
-                CurrentStatus = AppsStatus.Launch;
-                foreach (AppShortcutInfo item in installedAppList)
-                {
-                    item.CurrentStateDescription = item.StateDescriptions["default"];
-                    item.SetPinned(item.IsChecked);
-                    item.SetChecked(false);
-                }
+                appsHolder.UpdatePinnedApps();
+
+                ChangeCurrentStatus(AppsStatus.Default);
+            });
 
-                OnPropertyChanged("CurrentStatus");
+            ButtonPinCancelCommand = new Command(() =>
+            {
+                appsHolder.ResetPinnedApps();
+                ChangeCurrentStatus(AppsStatus.Default);
             });
 
-            ButtonPinCommand = new Command(() =>
+            App.SetBackKeyListener((s, e) =>
             {
-                CurrentStatus = AppsStatus.Delete;
-                OnPropertyChanged("CurrentStatus");
+                // TODO : check concurrency
+                ChangeCurrentStatus(AppsStatus.Default);
             });
+
+            DebuggingUtils.Dbg("<MainPageViewModel - End");
         }
 
         private void Init()
         {
-            BackKeyStatus = BackKeyInfo.Back;
+            appsHolder = new AppsHolder(this);
+
             // TODO : set default value as RecentlyInstalled
             SortingOption = SortingOptions.Ascending;
-            SortOptionIndex = (int)SortingOption;
-            CurrentStatus = AppsStatus.Launch;
+            ChangeCurrentStatus(AppsStatus.Default);
+        }
 
-            installedAppList = new List<AppShortcutInfo>();
-            PinnedAppList = new List<AppShortcutInfo>();
+        public void ChangeCurrentStatus(AppsStatus newStatus)
+        {
+            CurrentStatus = newStatus;
+            appsHolder.UpdateStateDescription(CurrentStatus);
+            OnPropertyChanged("CurrentStatus");
         }
 
-        protected void OnPropertyChanged(string name)
+        public void OnPropertyChanged(string name)
         {
             PropertyChangedEventHandler handler = PropertyChanged;
             if (handler != null)
@@ -153,87 +165,5 @@ namespace TVApps.ViewModels
             }
         }
 
-        private async void GetInstalledApps()
-        {
-            var pinnedApps = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetInstalledApps();
-            var installedApps = await TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetInstalledApps();
-
-            foreach (AppShortcutInfo item in installedApps)
-            {
-                var pinStateDescription = new StateDescription()
-                {
-                    Label = item.CurrentStateDescription.Label,
-                    IconPath = item.CurrentStateDescription.IconPath,
-                    Action = new CommandAction()
-                    {
-                        Command = new Command<string>((key) =>
-                        {
-                            PinToggle(key);
-                        }),
-                        CommandParameter = item.AppID
-                    }
-                };
-
-                item.StateDescriptions.Add("pin", pinStateDescription);
-
-                var deleteStateDescription = new StateDescription()
-                {
-                    Label = item.CurrentStateDescription.Label,
-                    IconPath = item.CurrentStateDescription.IconPath,
-                    Action = new CommandAction()
-                    {
-                        Command = new Command<string>((key) =>
-                        {
-                            DeleteApp(key);
-                        }),
-                        CommandParameter = item.AppID
-                    }
-                };
-
-                item.StateDescriptions.Add("delete", deleteStateDescription);
-            }
-
-            foreach (AppShortcutInfo item in pinnedApps.Result)
-            {
-                var app = installedApps.First(a => a.AppID == item.AppID);
-                if (app != null)
-                {
-                    installedApps.First(a => a.AppID == item.AppID).SetPinned(true);
-                }
-            }
-
-            installedAppList = installedApps.ToList();
-            PinnedAppList = pinnedApps.Result.ToList();
-
-            if (installedAppList != null)
-            {
-                OnPropertyChanged("InstalledAppList");
-            }
-        }
-
-        private void PinToggle(string key)
-        {
-            if (PinnedAppList.Exists(a => a.AppID == key))
-            {
-                DebuggingUtils.Dbg("UnPin!");
-                installedAppList.FirstOrDefault(a => a.AppID == key).SetChecked(false);
-                PinnedAppList.Remove(PinnedAppList.FirstOrDefault(a => a.AppID == key));
-            }
-            else
-            {
-                DebuggingUtils.Dbg("Pin!");
-                installedAppList.FirstOrDefault(a => a.AppID == key).SetChecked(true);
-                PinnedAppList.Add(installedAppList.FirstOrDefault(a => a.AppID == key));
-            }
-        }
-
-        public void DeleteApp(string AppId)
-        {
-            // 1. Check the property of the app
-            // 1-1. If the app is pinned, call UnsetPinnedApp(AppId)
-            // 2. Show Popup(Delete message)
-            // 2-1. OK : Call the AppFW API to remove the app
-            // 2-2. Cancel : Change AppsStatus to Normal
-        }
     }
 }
index 22f9872e0850c54ae067d9cda926aa6b09d78467..3070f55f34a7ed6f08f000c0e9e6b244a82ac87a 100644 (file)
@@ -16,9 +16,8 @@
   </ContentView.Resources>
 
   <ContentView.Content>
-    <Button x:Name="ButtonDel"
-            Text="Del"
+    <Button Text="CANCEL"
             Style="{StaticResource button}"
-            Command="{Binding ButtonDelCommand}"/>
+            Command="{Binding ButtonDeleteCancelCommand}"/>
   </ContentView.Content>
 </ContentView>
index 9fb2f946c77e3fc176a2dafd1b7ab5159e882a4e..cd1c3a239d053def745c982b5c026bfc5c59244c 100644 (file)
     </Picker.Items>
   </Picker>
 
-  <Button x:Name="ButtonOption"
-      Style="{StaticResource button}"
-      Text="OPTION"
-      Command="{Binding OptionCommand}"/>
+  <Button  Text="PIN"
+           Style="{StaticResource button}"
+           Command="{Binding ButtonPinAppCommand}"/>
+  <Button  Text="DELETE"
+           Style="{StaticResource button}"
+           Command="{Binding ButtonDeleteAppCommand}"/>
 
 </StackLayout>
\ No newline at end of file
index 26fe29245ff37446dd6386a0c015e8d14a2ce6fc..73f39796111b5d565b4f566844ac7b206411d500 100644 (file)
@@ -1,9 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
+<StackLayout xmlns="http://xamarin.com/schemas/2014/forms"
              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
-             x:Class="TVApps.Views.FooterPinStatus">
+             x:Class="TVApps.Views.FooterPinStatus"
+             Orientation="Horizontal">
 
-  <ContentView.Resources>
+  <StackLayout.Resources>
     <ResourceDictionary>
       <Style x:Key="button" TargetType="Button">
         <Setter Property="BorderColor" Value="#FFFFFF"/>
         <Setter Property="BackgroundColor" Value="Transparent"/>
       </Style>
     </ResourceDictionary>
-  </ContentView.Resources>
+  </StackLayout.Resources>
 
-  <ContentView.Content>
-    <Button x:Name="ButtonPin"
-            Text="PIN"
-            Style="{StaticResource button}"
-            Command="{Binding ButtonPinCommand}"/>
-  </ContentView.Content>
-</ContentView>
+  <Button x:Name="ButtonPinOk"
+          Text="OK"
+          Style="{StaticResource button}"
+          Command="{Binding ButtonPinOkCommand}"/>
+
+  <Button x:Name="ButtonPinCancel"
+          Text="CANCEL"
+          Style="{StaticResource button}"
+          Command="{Binding ButtonPinCancelCommand}"/>
+</StackLayout>
index e751d9f551c742d89943429a7d2b34748f5e6b8b..6507473eb597adaacb032de2fdf970b1a48e8085 100644 (file)
@@ -21,7 +21,7 @@ namespace TVApps.Views
     /// <summary>
     /// hahaha
     /// </summary>
-    public partial class FooterPinStatus : ContentView
+    public partial class FooterPinStatus : StackLayout
     {
         public FooterPinStatus()
         {
index 8cd6ae63eb49d2d36fcb13b04a58bf19cefebf06..e90aa54d7b48f9c95ca1760a48a311201698a345 100755 (executable)
              x:Class="TVApps.Views.MainPage"
              BackgroundColor="#000000"
              CurrentStatus="{Binding CurrentStatus}">
-    <ContentPage.BindingContext>
-        <ViewModels:MainPageViewModel />
-    </ContentPage.BindingContext>
-
-    <ContentPage.Resources>
-        <ResourceDictionary>
-            <Style x:Key="titleText" TargetType="Label" >
-                <Setter Property="FontSize" Value="187" />
-                <Setter Property="TextColor" Value="#FFFFFF" />
-                <Setter Property="FontFamily" Value="Samsung sans" />
-            </Style>
-            <Style x:Key="buttonTextNormal" TargetType="Label" >
-                <Setter Property="FontSize" Value="62" />
-                <Setter Property="TextColor" Value="#F7F7F7" />
-                <Setter Property="FontFamily" Value="Breeze Sans Regular" />
-            </Style>
-            <Style x:Key="buttonTextPressed" TargetType="Label" >
-                <Setter Property="FontSize" Value="62" />
-                <Setter Property="TextColor" Value="#F7F7F708" />
-                <Setter Property="FontFamily" Value="Breeze Sans Regular" />
-            </Style>
-            <Style x:Key="pinnedText" TargetType="Label" >
-                <Setter Property="FontSize" Value="50" />
-                <Setter Property="TextColor" Value="#F7F7F7" />
-                <Setter Property="FontFamily" Value="Breeze Sans Regular" />
-            </Style>
-
-            <Style x:Key="button" TargetType="Button">
-                <Setter Property="BorderColor" Value="#FFFFFF"/>
-                <Setter Property="HeightRequest" Value="40"/>
-                <Setter Property="BorderWidth" Value="2" />
-                <Setter Property="HorizontalOptions" Value="Center"/>
-                <Setter Property="BackgroundColor" Value="Transparent"/>
-            </Style>
-        </ResourceDictionary>
-    </ContentPage.Resources>
-
-    <Grid>
+  <ContentPage.BindingContext>
+    <ViewModels:MainPageViewModel />
+  </ContentPage.BindingContext>
+
+  <ContentPage.Resources>
+    <ResourceDictionary>
+      <Style x:Key="titleText" TargetType="Label" >
+        <Setter Property="FontSize" Value="187" />
+        <Setter Property="TextColor" Value="#FFFFFF" />
+        <Setter Property="FontFamily" Value="Samsung sans" />
+      </Style>
+      <Style x:Key="backKeyInfoText" TargetType="Label" >
+        <Setter Property="FontSize" Value="62" />
+        <Setter Property="TextColor" Value="#99FFFFFF" />
+        <Setter Property="FontFamily" Value="Samsung sans" />
+      </Style>
+      <Style x:Key="buttonTextNormal" TargetType="Label" >
+        <Setter Property="FontSize" Value="62" />
+        <Setter Property="TextColor" Value="#F7F7F7" />
+        <Setter Property="FontFamily" Value="Breeze Sans Regular" />
+      </Style>
+      <Style x:Key="buttonTextPressed" TargetType="Label" >
+        <Setter Property="FontSize" Value="62" />
+        <Setter Property="TextColor" Value="#F7F7F708" />
+        <Setter Property="FontFamily" Value="Breeze Sans Regular" />
+      </Style>
+      <Style x:Key="pinnedText" TargetType="Label" >
+        <Setter Property="FontSize" Value="50" />
+        <Setter Property="TextColor" Value="#F7F7F7" />
+        <Setter Property="FontFamily" Value="Breeze Sans Regular" />
+      </Style>
+
+      <Style x:Key="button" TargetType="Button">
+        <Setter Property="BorderColor" Value="#FFFFFF"/>
+        <Setter Property="HeightRequest" Value="40"/>
+        <Setter Property="BorderWidth" Value="2" />
+        <Setter Property="HorizontalOptions" Value="Center"/>
+        <Setter Property="BackgroundColor" Value="Transparent"/>
+      </Style>
+    </ResourceDictionary>
+  </ContentPage.Resources>
+
+  <Grid>
+    <Grid.RowDefinitions>
+      <RowDefinition Height="2685*" />
+      <RowDefinition Height="83*" />
+      <RowDefinition Height="5074*" />
+      <RowDefinition Height="0981*" />
+      <RowDefinition Height="1185*" />
+    </Grid.RowDefinitions>
+    <Grid.RowSpacing>0</Grid.RowSpacing>
+    <Grid.ColumnSpacing>0</Grid.ColumnSpacing>
+
+    <Grid Grid.Row="0">
+      <Grid.ColumnDefinitions>
+        <ColumnDefinition Width="2083*" />
+        <ColumnDefinition Width="5833*" />
+        <ColumnDefinition Width="2083*" />
+      </Grid.ColumnDefinitions>
+
+      <Label Grid.Column="1"
+             Style="{StaticResource titleText}"
+             HorizontalTextAlignment="Center"
+             VerticalOptions="CenterAndExpand"
+             HorizontalOptions="CenterAndExpand"
+             Text="APPS" />
+
+      <Grid Grid.Column="2">
         <Grid.RowDefinitions>
-            <RowDefinition Height="2685*" />
-            <RowDefinition Height="83*" />
-            <RowDefinition Height="5074*" />
-            <RowDefinition Height="0981*" />
-            <RowDefinition Height="1185*" />
+          <RowDefinition Height="4482*" />
+          <RowDefinition Height="1379*" />
+          <RowDefinition Height="4137*" />
         </Grid.RowDefinitions>
+
+        <Grid.ColumnDefinitions>
+          <ColumnDefinition Width="4800*" />
+          <ColumnDefinition Width="5200*" />
+        </Grid.ColumnDefinitions>
+
         <Grid.RowSpacing>0</Grid.RowSpacing>
         <Grid.ColumnSpacing>0</Grid.ColumnSpacing>
 
-        <Grid Grid.Row="0">
-            <Grid.ColumnDefinitions>
-                <ColumnDefinition Width="2083*" />
-                <ColumnDefinition Width="5833*" />
-                <ColumnDefinition Width="2083*" />
-            </Grid.ColumnDefinitions>
-
-            <Label Grid.Column="1"
-                   Style="{StaticResource titleText}"
-                   HorizontalTextAlignment="Center"
-                   VerticalOptions="CenterAndExpand"
-                   HorizontalOptions="CenterAndExpand"
-                   Text="APPS" />
-
-            <Label Grid.Column="2"
-                x:Name="BackKeyInfo"
-                Style="{StaticResource buttonTextNormal}"
-                HorizontalTextAlignment="Center"
-                VerticalOptions="CenterAndExpand"
-                HorizontalOptions="CenterAndExpand"
-                Text="Back" />
-        </Grid>
-
-        <Controls:AppListView x:Name="AppListView"
-                              Grid.Row="2"
-                              ItemsSource="{Binding InstalledAppList}">
-            <Controls:AppListView.ItemTemplate>
-                <DataTemplate>
-                    <Controls:AppItemCell/>
-                </DataTemplate>
-            </Controls:AppListView.ItemTemplate>
-        </Controls:AppListView>
-
-        <Grid Grid.Row="4">
-            <Grid.ColumnDefinitions>
-                <ColumnDefinition Width="5*" />
-                <ColumnDefinition Width="90*" />
-                <ColumnDefinition Width="5*" />
-            </Grid.ColumnDefinitions>
-
-            <Views:FooterNormalStatus x:Name="FooterNormal"
-                               Grid.Column="1"
-                               IsVisible="true" />
-
-            <Views:FooterPinStatus x:Name="FooterPin"
-                                   Grid.Column="1"
-                                   IsVisible="false" />
-
-            <Views:FooterDeleteStatus x:Name="FooterDelete"
-                                      Grid.Column="1"
-                                      IsVisible="false" />
-        </Grid>
+        <StackLayout Grid.Row="1" Grid.Column="1"
+                     Orientation="Horizontal">
+          <Image Source="ic_tizen_apps_additional_back.png"
+                 WidthRequest="80"
+                 HeightRequest="80"
+                 VerticalOptions="CenterAndExpand"
+                 HorizontalOptions="CenterAndExpand"/>
+
+          <Label x:Name="BackKeyInfo"
+                 Style="{StaticResource backKeyInfoText}"
+                 HorizontalTextAlignment="Start"/>
+        </StackLayout>
+
+      </Grid>
+    </Grid>
+
+    <Controls:AppListView Grid.Row="2"
+                          ItemsSource="{Binding InstalledAppList}">
+      <Controls:AppListView.ItemTemplate>
+        <DataTemplate>
+          <Controls:AppItemCell/>
+        </DataTemplate>
+      </Controls:AppListView.ItemTemplate>
+    </Controls:AppListView>
+
+    <Grid Grid.Row="4">
+      <Grid.RowDefinitions>
+        <RowDefinition Height="625*" />
+        <RowDefinition Height="375*" />
+      </Grid.RowDefinitions>
+
+      <Grid.ColumnDefinitions>
+        <ColumnDefinition Width="6385*" />
+        <ColumnDefinition Width="3615*" />
+      </Grid.ColumnDefinitions>
+
+      <Views:FooterNormalStatus Grid.Row="0" Grid.Column="1"
+                                x:Name="FooterNormal"
+                                HorizontalOptions="CenterAndExpand"
+                                VerticalOptions="CenterAndExpand"
+                                IsVisible="true" />
+
+      <Views:FooterPinStatus Grid.Row="0" Grid.Column="1"
+                             x:Name="FooterPin"
+                             HorizontalOptions="CenterAndExpand"
+                             VerticalOptions="CenterAndExpand"
+                             IsVisible="false" />
+
+      <Views:FooterDeleteStatus Grid.Row="0" Grid.Column="1"
+                                x:Name="FooterDelete"
+                                HorizontalOptions="End"
+                                VerticalOptions="CenterAndExpand"
+                                IsVisible="false" />
     </Grid>
+  </Grid>
 </ContentPage>
\ No newline at end of file
index 417cbeac6d396a504796c2ddd3ad400ee2a69414..ec52db571c1314111d3c4c248f6def097138ae7b 100644 (file)
@@ -39,33 +39,39 @@ namespace TVApps.Views
         {
             InitializeComponent();
             PropertyChanged += MainPage_PropertyChanged;
+            SetCurrntStatus(AppsStatus.Default);
+        }
+
+        private void SetCurrntStatus(AppsStatus status)
+        {
+            switch (status)
+            {
+                case AppsStatus.Default:
+                    FooterNormal.IsVisible = true;
+                    FooterPin.IsVisible = false;
+                    FooterDelete.IsVisible = false;
+                    BackKeyInfo.Text = "Quit";
+                    break;
+                case AppsStatus.Pin:
+                    FooterNormal.IsVisible = false;
+                    FooterPin.IsVisible = true;
+                    FooterDelete.IsVisible = false;
+                    BackKeyInfo.Text = "Back";
+                    break;
+                case AppsStatus.Delete:
+                    FooterNormal.IsVisible = false;
+                    FooterPin.IsVisible = false;
+                    FooterDelete.IsVisible = true;
+                    BackKeyInfo.Text = "Back";
+                    break;
+            }
         }
 
         private void MainPage_PropertyChanged(object sender, PropertyChangedEventArgs e)
         {
             if (e.PropertyName.CompareTo("CurrentStatus") == 0)
             {
-                switch (CurrentStatus)
-                {
-                    case AppsStatus.Launch:
-                        FooterNormal.IsVisible = true;
-                        FooterPin.IsVisible = false;
-                        FooterDelete.IsVisible = false;
-                        BackKeyInfo.Text = "Back";
-                        break;
-                    case AppsStatus.Pin:
-                        FooterNormal.IsVisible = false;
-                        FooterPin.IsVisible = true;
-                        FooterDelete.IsVisible = false;
-                        BackKeyInfo.Text = "Front";
-                        break;
-                    case AppsStatus.Delete:
-                        FooterNormal.IsVisible = false;
-                        FooterPin.IsVisible = false;
-                        FooterDelete.IsVisible = true;
-                        BackKeyInfo.Text = "Quit";
-                        break;
-                }
+                SetCurrntStatus(CurrentStatus);
             }
         }
     }
index 1bb1c20a7deb289d55085a5eee29e75f9b81c95a..e7a45c43b93c5d8a27235e2554af76fbb1110c86 100644 (file)
Binary files a/TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk and b/TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk differ
index 09fcc8da5b5f171f505a597fe6d71993084ec7da..fa1e02a7d0fdf2ed9f1457b5ad30d0f187e20680 100644 (file)
@@ -5,6 +5,7 @@
     <privilege>http://tizen.org/privilege/network.get</privilege>\r
     <privilege>http://tizen.org/privilege/network.set</privilege>\r
     <privilege>http://tizen.org/privilege/packagemanager.info</privilege>\r
+       <privilege>http://tizen.org/privilege/packagemanager.admin</privilege>\r
     <privilege>http://tizen.org/privilege/appmanager.launch</privilege>\r
     <privilege>http://tizen.org/privilege/externalstorage</privilege>\r
   </privileges>\r
index 4abd72e5c20f35491376c06c5866363ef104ec75..f3f61025288365d49c8af487abf8d9094ebda77a 100755 (executable)
@@ -82,7 +82,7 @@ namespace TVHome.ViewModels
             MakeRecentButtons();
 
             DebuggingUtils.Dbg("Reading Apps list");
-            AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedApps();
+            AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsWithDefaultShortcuts();
             OnPropertyChanged("AppList");
 
             //SettingsList = TVHomeImpl.GetInstance.AppShortcutControllerInstnace.ReadFromFile();
@@ -95,7 +95,7 @@ namespace TVHome.ViewModels
 
         private void TestFunction(object sender, EventArgs e)
         {
-            AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedApps();
+            AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsWithDefaultShortcuts();
             OnPropertyChanged("AppList");
         }