Add SortOption selection
authorcskim <charles0.kim@samsung.com>
Fri, 10 Mar 2017 09:36:47 +0000 (18:36 +0900)
committerChulSeung Kim <charles0.kim@samsung.com>
Thu, 8 Jun 2017 09:34:46 +0000 (18:34 +0900)
Change-Id: I961cfc1eefe4a5281a47d8587e82dc394451f788

16 files changed:
.gitignore
LibTVRefCommonPortable/DataModels/AppShortcutInfo.cs
LibTVRefCommonPortable/LibTVRefCommonPortable.csproj
LibTVRefCommonPortable/Models/AppShortcutController.cs
LibTVRefCommonPortable/Utils/DateUtils.cs [new file with mode: 0644]
LibTVRefCommonTizen/Ports/DBPort.cs
TVApps/TVApps/Controls/AppItemCell.xaml.cs
TVApps/TVApps/TVApps.csproj
TVApps/TVApps/ViewModels/AppsListSorter.cs [new file with mode: 0644]
TVApps/TVApps/ViewModels/MainPageViewModel.cs
TVApps/TVApps/Views/FooterDeleteStatus.xaml.cs
TVApps/TVApps/Views/FooterNormalStatus.xaml
TVApps/TVApps/Views/FooterNormalStatus.xaml.cs
TVApps/TVApps/Views/FooterPinStatus.xaml.cs
TVApps/TVApps/Views/MainPage.xaml.cs
TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk

index 3cda4e5355e5978db0c36578b58edab820d161b6..9b85c169cf873ce84c64be21a509f038450ba88e 100644 (file)
@@ -49,3 +49,4 @@ warnings.txt
 
 *.db
 *.opendb
+Debug/
index 5852161d5754c297fff4e59ab4d2b574c384e10a..3814d7ecfd9eebf4e49c933b35a1308036494468 100644 (file)
@@ -33,6 +33,9 @@ namespace LibTVRefCommmonPortable.DataModels
 
         [XmlIgnore]
         public bool IsRemovable { get; set; }
+        public DateTime Installed { get; set; }
+
+        public DateTime LastUsed { get; set; }
 
         public override void UpdateState()
         {
index 86b7deee5e10e3140429f786a57150b1fb0e01d5..1744dc78f0a2cc2fa9bad56201b592ce5295deb1 100644 (file)
@@ -64,6 +64,7 @@
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Utils\AppControlUtils.cs" />
     <Compile Include="Utils\AppShortcutStorage.cs" />
+    <Compile Include="Utils\DateUtils.cs" />
     <Compile Include="Utils\DebuggingUtils.cs" />
     <Compile Include="Utils\IAppControl.cs" />
     <Compile Include="Utils\IApplicationManagerAPIs.cs" />
index d007abec05f218f9efd31c4903ecf20934af9edb..f9759933e4c14e57308995e7c9f24f402def4b8e 100755 (executable)
@@ -21,6 +21,7 @@ using Xamarin.Forms;
 using LibTVRefCommmonPortable.DataModels;
 using LibTVRefCommmonPortable.Utils;
 using System.Threading.Tasks;
+using LibTVRefCommonPortable.Utils;
 
 namespace LibTVRefCommmonPortable.Models
 {
@@ -51,7 +52,13 @@ namespace LibTVRefCommmonPortable.Models
                         AppID = item.Key,
                     }
                 };
-                var appShortcutInfo = new AppShortcutInfo();
+
+                var appShortcutInfo = new AppShortcutInfo()
+                {
+                    // TODO : Fill these correctly by using Tizen Device APIs
+                    Installed = DateUtils.GetRandomDate(),
+                    LastUsed = DateUtils.GetRandomDate(),
+                };
 
                 appShortcutInfo.StateDescriptions.Add("default", defaultStateDescription);
                 appShortcutInfo.CurrentStateDescription = defaultStateDescription;
@@ -117,6 +124,7 @@ namespace LibTVRefCommmonPortable.Models
 
             returnPinnedAppsInfo.Add(addPinShortcutInfo);
         }
+
         public IEnumerable<AppShortcutInfo> GetPinnedApps()
         {
             IApplicationManagerAPIs applicationManagerPort = DependencyService.Get<IApplicationManagerAPIs>();
diff --git a/LibTVRefCommonPortable/Utils/DateUtils.cs b/LibTVRefCommonPortable/Utils/DateUtils.cs
new file mode 100644 (file)
index 0000000..d170de3
--- /dev/null
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace LibTVRefCommonPortable.Utils
+{
+    public class DateUtils
+    {
+        private static Random seed = new Random();
+
+        public static DateTime GetRandomDate()
+        {
+            DateTime baseDate = new DateTime(2015, 1, 1);
+            return baseDate.AddDays(seed.Next((DateTime.Now - baseDate).Days));
+        }
+    }
+}
index 6b3a6acf92f1b1b98fe5cd0d67da8c7aac34f163..2327db003620fe74d700ef11d1da154d87dca4cc 100644 (file)
@@ -59,7 +59,7 @@ namespace LibTVRefCommonTizen.Ports
             }
         }
 
-        public String appDataPath
+        public String AppDataPath
         {
             get;
             private set;
@@ -67,7 +67,7 @@ namespace LibTVRefCommonTizen.Ports
 
         public DBPort(String appDataPath)
         {
-            this.appDataPath = appDataPath;
+            this.AppDataPath = appDataPath;
 
             // TODO : make a unit test for this!!!
             DebuggingPort.D("DBPort-------------------------------------");
@@ -161,7 +161,7 @@ namespace LibTVRefCommonTizen.Ports
                 return false;
             }
 
-            DBHandleRAII db = new DBHandleRAII(appDataPath, dbName);
+            DBHandleRAII db = new DBHandleRAII(AppDataPath, dbName);
             if (db.handle == IntPtr.Zero)
             {
                 DebuggingPort.E("DB open failed!!!");
@@ -201,7 +201,7 @@ namespace LibTVRefCommonTizen.Ports
                 return false;
             }
 
-            DBHandleRAII db = new DBHandleRAII(appDataPath, dbName);
+            DBHandleRAII db = new DBHandleRAII(AppDataPath, dbName);
             if (db.handle == IntPtr.Zero)
             {
                 DebuggingPort.E("DB open failed!!!");
index c1ef3b386d3a2f38f442455ff693aa59a2dc3036..250614cc216efd976ca5d25094b2a2859c1a40bd 100755 (executable)
@@ -32,6 +32,7 @@ namespace TVApps.Controls
             get { return (ICommand)GetValue(OnClickedCommandProperty); }
             set { SetValue(OnClickedCommandProperty, value); }
         }
+
         public AppItemCell()
         {
             InitializeComponent();
index 75e5a7a4d616ddbbc3dda1d57a4d452169da3e86..d4902a7877d5d0a1d46745e91472ea9c764e78ea 100644 (file)
@@ -42,6 +42,7 @@
     </Compile>
     <Compile Include="TVApps.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="ViewModels\AppsListSorter.cs" />
     <Compile Include="ViewModels\MainPageViewModel.cs" />
     <Compile Include="Views\FooterDeleteStatus.xaml.cs">
       <DependentUpon>FooterDeleteStatus.xaml</DependentUpon>
diff --git a/TVApps/TVApps/ViewModels/AppsListSorter.cs b/TVApps/TVApps/ViewModels/AppsListSorter.cs
new file mode 100644 (file)
index 0000000..9f00da6
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * 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 System.Collections.Generic;
+
+namespace TVApps.ViewModels
+{
+    public class AppsListSorter
+    {
+
+        private static int SortByLabelAscending(AppShortcutInfo left, AppShortcutInfo right)
+        {
+            return left.CurrentStateDescription.Label.CompareTo(right.CurrentStateDescription.Label);
+        }
+
+        private static int SortByLabelDescending(AppShortcutInfo left, AppShortcutInfo right)
+        {
+            return left.CurrentStateDescription.Label.CompareTo(right.CurrentStateDescription.Label) * -1;
+        }
+
+        private static int SortByRecentlyInstalled(AppShortcutInfo left, AppShortcutInfo right)
+        {
+            return left.Installed.CompareTo(right.Installed) * -1;
+        }
+
+        private static int SortByRecentlyUsed(AppShortcutInfo left, AppShortcutInfo right)
+        {
+            return left.LastUsed.CompareTo(right.LastUsed) * -1;
+        }
+
+        public static void GetSortedAppsList(SortingOptions sortOption, ref List<AppShortcutInfo> list)
+        {
+            switch (sortOption)
+            {
+                case SortingOptions.RecentlyInstalled:
+                    list.Sort(SortByRecentlyInstalled);
+                    break;
+                case SortingOptions.RecentlyUsed:
+                    list.Sort(SortByRecentlyUsed);
+                    break;
+                case SortingOptions.Ascending:
+                    list.Sort(SortByLabelAscending);
+                    break;
+                case SortingOptions.Descending:
+                    list.Sort(SortByLabelDescending);
+                    break;
+            }
+        }
+    }
+}
index 936bf3a97429de384b75d57c9715d88d30b830a2..cc96463494b661d9882c2769c49b1c81f68f33b8 100644 (file)
@@ -21,6 +21,7 @@ using System.Collections.Generic;
 using System.ComponentModel;
 using System.Linq;
 using Xamarin.Forms;
+using System;
 
 namespace TVApps.ViewModels
 {
@@ -40,23 +41,51 @@ namespace TVApps.ViewModels
 
     public enum SortingOptions
     {
-        Newest,
+        RecentlyInstalled = 0,
+        RecentlyUsed,
         Ascending,
         Descending,
     };
 
     class MainPageViewModel : INotifyPropertyChanged
     {
-        public List<AppShortcutInfo> InstalledAppList { get; private set; }
+        private List<AppShortcutInfo> installedAppList;
+        public List<AppShortcutInfo> InstalledAppList
+        {
+            get
+            {
+                return installedAppList;
+            }
+        }
+
         public List<AppShortcutInfo> PinnedAppList { get; private set; }
 
-        public Command SortCommand { get; set; }
         public Command OptionCommand { get; set; }
         public Command ButtonDelCommand { get; set; }
         public Command ButtonPinCommand { get; set; }
 
         public AppsStatus CurrentStatus { get; private set; }
-        public SortingOptions SortingOption { get; private set; }
+
+        private SortingOptions SortingOption { get; set; }
+
+        public int SortOptionIndex
+        {
+            get
+            {
+                return Convert.ToInt32(SortingOption);
+            }
+
+            set
+            {
+                SortingOption = (SortingOptions)Enum.ToObject(typeof(SortingOptions), value);
+                if (installedAppList != null)
+                {
+                    AppsListSorter.GetSortedAppsList(SortingOption, ref installedAppList);
+                    OnPropertyChanged("AppList");
+                }
+            }
+        }
+
         public BackKeyInfo BackKeyStatus { get; private set; }
 
         public ShortcutInfo FocusedItem { get; set; }
@@ -65,39 +94,34 @@ namespace TVApps.ViewModels
 
         public MainPageViewModel()
         {
-            init();
+            Init();
 
             GetInstalledApps();
 
-            SortCommand = new Command((sortType) =>
-            {
-                // 1. SortType = sortType;
-                // 2. Sorting AppsList
-                // 3. OnPropertyChanged("AppList");
-            });
-
             OptionCommand = new Command((optionType) =>
             {
                 // 1. Change current status by optionType
                 CurrentStatus = AppsStatus.Pin;
-                foreach (AppShortcutInfo item in InstalledAppList)
+                foreach (AppShortcutInfo item in installedAppList)
                 {
                     item.CurrentStateDescription = item.StateDescriptions["pin"];
                     item.SetChecked(item.IsPinned);
                     item.SetPinned(false);
                 }
+
                 OnPropertyChanged("CurrentStatus");
             });
 
             ButtonDelCommand = new Command(() =>
             {
                 CurrentStatus = AppsStatus.Launch;
-                foreach (AppShortcutInfo item in InstalledAppList)
+                foreach (AppShortcutInfo item in installedAppList)
                 {
                     item.CurrentStateDescription = item.StateDescriptions["default"];
                     item.SetPinned(item.IsChecked);
                     item.SetChecked(false);
                 }
+
                 OnPropertyChanged("CurrentStatus");
             });
 
@@ -108,11 +132,16 @@ namespace TVApps.ViewModels
             });
         }
 
-        private void init()
+        private void Init()
         {
             BackKeyStatus = BackKeyInfo.Back;
-            SortingOption = SortingOptions.Newest;
+            // TODO : set default value as RecentlyInstalled
+            SortingOption = SortingOptions.Ascending;
+            SortOptionIndex = (int)SortingOption;
             CurrentStatus = AppsStatus.Launch;
+
+            installedAppList = new List<AppShortcutInfo>();
+            PinnedAppList = new List<AppShortcutInfo>();
         }
 
         protected void OnPropertyChanged(string name)
@@ -126,8 +155,8 @@ namespace TVApps.ViewModels
 
         private async void GetInstalledApps()
         {
-            var pinnedApps = TVHomeImpl.GetInstance.AppShortcutControllerInstance.ReadFromFile();
-            var installedApps = await TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetList();
+            var pinnedApps = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetInstalledApps();
+            var installedApps = await TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetInstalledApps();
 
             foreach (AppShortcutInfo item in installedApps)
             {
@@ -164,7 +193,7 @@ namespace TVApps.ViewModels
                 item.StateDescriptions.Add("delete", deleteStateDescription);
             }
 
-            foreach (AppShortcutInfo item in pinnedApps)
+            foreach (AppShortcutInfo item in pinnedApps.Result)
             {
                 var app = installedApps.First(a => a.AppID == item.AppID);
                 if (app != null)
@@ -173,10 +202,10 @@ namespace TVApps.ViewModels
                 }
             }
 
-            InstalledAppList = installedApps.ToList();
-            PinnedAppList = pinnedApps.ToList();
+            installedAppList = installedApps.ToList();
+            PinnedAppList = pinnedApps.Result.ToList();
 
-            if (InstalledAppList != null)
+            if (installedAppList != null)
             {
                 OnPropertyChanged("InstalledAppList");
             }
@@ -187,14 +216,14 @@ namespace TVApps.ViewModels
             if (PinnedAppList.Exists(a => a.AppID == key))
             {
                 DebuggingUtils.Dbg("UnPin!");
-                InstalledAppList.FirstOrDefault(a => a.AppID == key).SetChecked(false);
+                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));
+                installedAppList.FirstOrDefault(a => a.AppID == key).SetChecked(true);
+                PinnedAppList.Add(installedAppList.FirstOrDefault(a => a.AppID == key));
             }
         }
 
index ec3d9bc6668fc2043e2d75f7b7e19626cadef581..c040508007e8e2b70b684a74f880814734a27785 100644 (file)
@@ -18,6 +18,9 @@ using Xamarin.Forms;
 
 namespace TVApps.Views
 {
+    /// <summary>
+    /// hahaha
+    /// </summary>
     public partial class FooterDeleteStatus : ContentView
     {
         public FooterDeleteStatus()
index c79f44e5e1660d9f549c4f928184c5405215dd5b..9fb2f946c77e3fc176a2dafd1b7ab5159e882a4e 100644 (file)
     </ResourceDictionary>
   </StackLayout.Resources>
 
-  <Button x:Name="ButtonSort"
-      Style="{StaticResource button}"
-      Text="SORT" />
+  <Picker Title="SORT BY" SelectedIndex="{Binding SortOptionIndex}">
+    <Picker.Items>
+      <x:String>Recently Installed</x:String>
+      <x:String>Recently Used</x:String>
+      <x:String>A - Z</x:String>
+      <x:String>Z - A</x:String>
+    </Picker.Items>
+  </Picker>
 
   <Button x:Name="ButtonOption"
       Style="{StaticResource button}"
index 1d97f402920f2a2206c1dfc5c91ca4b020e300b0..27680119fffa0ebc653f8a4282a46d83cafd4c76 100644 (file)
@@ -18,6 +18,9 @@ using Xamarin.Forms;
 
 namespace TVApps.Views
 {
+    /// <summary>
+    /// hahaha
+    /// </summary>
     public partial class FooterNormalStatus : StackLayout
     {
         public FooterNormalStatus()
index 5f5e8a43faaa6b8f090ec34b818a4cf34c1c9800..e751d9f551c742d89943429a7d2b34748f5e6b8b 100644 (file)
@@ -18,6 +18,9 @@ using Xamarin.Forms;
 
 namespace TVApps.Views
 {
+    /// <summary>
+    /// hahaha
+    /// </summary>
     public partial class FooterPinStatus : ContentView
     {
         public FooterPinStatus()
index 7d8796f7fa41ab94ea44f760f66387676a5a60c7..417cbeac6d396a504796c2ddd3ad400ee2a69414 100644 (file)
@@ -34,6 +34,7 @@ namespace TVApps.Views
             get { return (AppsStatus)GetValue(CurrentStatusProperty); }
             set { SetValue(CurrentStatusProperty, value); }
         }
+
         public MainPage()
         {
             InitializeComponent();
index 8fb783dafa9da26cbfe107ee83ca9669a7ff46ea..1bb1c20a7deb289d55085a5eee29e75f9b81c95a 100644 (file)
Binary files a/TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk and b/TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk differ