From: cskim Date: Fri, 10 Mar 2017 09:36:47 +0000 (+0900) Subject: Add SortOption selection X-Git-Tag: submit/tizen/20170808.015446~207 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6085f050005f8b772817f8f61839f52c75a2b48d;p=profile%2Ftv%2Fapps%2Fdotnet%2Fhome.git Add SortOption selection Change-Id: I961cfc1eefe4a5281a47d8587e82dc394451f788 --- diff --git a/.gitignore b/.gitignore index 3cda4e5..9b85c16 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ warnings.txt *.db *.opendb +Debug/ diff --git a/LibTVRefCommonPortable/DataModels/AppShortcutInfo.cs b/LibTVRefCommonPortable/DataModels/AppShortcutInfo.cs index 5852161..3814d7e 100644 --- a/LibTVRefCommonPortable/DataModels/AppShortcutInfo.cs +++ b/LibTVRefCommonPortable/DataModels/AppShortcutInfo.cs @@ -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() { diff --git a/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj b/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj index 86b7dee..1744dc7 100644 --- a/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj +++ b/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj @@ -64,6 +64,7 @@ + diff --git a/LibTVRefCommonPortable/Models/AppShortcutController.cs b/LibTVRefCommonPortable/Models/AppShortcutController.cs index d007abe..f975993 100755 --- a/LibTVRefCommonPortable/Models/AppShortcutController.cs +++ b/LibTVRefCommonPortable/Models/AppShortcutController.cs @@ -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 GetPinnedApps() { IApplicationManagerAPIs applicationManagerPort = DependencyService.Get(); diff --git a/LibTVRefCommonPortable/Utils/DateUtils.cs b/LibTVRefCommonPortable/Utils/DateUtils.cs new file mode 100644 index 0000000..d170de3 --- /dev/null +++ b/LibTVRefCommonPortable/Utils/DateUtils.cs @@ -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)); + } + } +} diff --git a/LibTVRefCommonTizen/Ports/DBPort.cs b/LibTVRefCommonTizen/Ports/DBPort.cs index 6b3a6ac..2327db0 100644 --- a/LibTVRefCommonTizen/Ports/DBPort.cs +++ b/LibTVRefCommonTizen/Ports/DBPort.cs @@ -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!!!"); diff --git a/TVApps/TVApps/Controls/AppItemCell.xaml.cs b/TVApps/TVApps/Controls/AppItemCell.xaml.cs index c1ef3b3..250614c 100755 --- a/TVApps/TVApps/Controls/AppItemCell.xaml.cs +++ b/TVApps/TVApps/Controls/AppItemCell.xaml.cs @@ -32,6 +32,7 @@ namespace TVApps.Controls get { return (ICommand)GetValue(OnClickedCommandProperty); } set { SetValue(OnClickedCommandProperty, value); } } + public AppItemCell() { InitializeComponent(); diff --git a/TVApps/TVApps/TVApps.csproj b/TVApps/TVApps/TVApps.csproj index 75e5a7a..d4902a7 100644 --- a/TVApps/TVApps/TVApps.csproj +++ b/TVApps/TVApps/TVApps.csproj @@ -42,6 +42,7 @@ + FooterDeleteStatus.xaml diff --git a/TVApps/TVApps/ViewModels/AppsListSorter.cs b/TVApps/TVApps/ViewModels/AppsListSorter.cs new file mode 100644 index 0000000..9f00da6 --- /dev/null +++ b/TVApps/TVApps/ViewModels/AppsListSorter.cs @@ -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 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; + } + } + } +} diff --git a/TVApps/TVApps/ViewModels/MainPageViewModel.cs b/TVApps/TVApps/ViewModels/MainPageViewModel.cs index 936bf3a..cc96463 100644 --- a/TVApps/TVApps/ViewModels/MainPageViewModel.cs +++ b/TVApps/TVApps/ViewModels/MainPageViewModel.cs @@ -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 InstalledAppList { get; private set; } + private List installedAppList; + public List InstalledAppList + { + get + { + return installedAppList; + } + } + public List 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(); + PinnedAppList = new List(); } 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)); } } diff --git a/TVApps/TVApps/Views/FooterDeleteStatus.xaml.cs b/TVApps/TVApps/Views/FooterDeleteStatus.xaml.cs index ec3d9bc..c040508 100644 --- a/TVApps/TVApps/Views/FooterDeleteStatus.xaml.cs +++ b/TVApps/TVApps/Views/FooterDeleteStatus.xaml.cs @@ -18,6 +18,9 @@ using Xamarin.Forms; namespace TVApps.Views { + /// + /// hahaha + /// public partial class FooterDeleteStatus : ContentView { public FooterDeleteStatus() diff --git a/TVApps/TVApps/Views/FooterNormalStatus.xaml b/TVApps/TVApps/Views/FooterNormalStatus.xaml index c79f44e..9fb2f94 100644 --- a/TVApps/TVApps/Views/FooterNormalStatus.xaml +++ b/TVApps/TVApps/Views/FooterNormalStatus.xaml @@ -16,9 +16,14 @@ -