[XmlIgnore]
public bool IsRemovable { get; set; }
+ public DateTime Installed { get; set; }
+
+ public DateTime LastUsed { get; set; }
public override void UpdateState()
{
<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" />
using LibTVRefCommmonPortable.DataModels;
using LibTVRefCommmonPortable.Utils;
using System.Threading.Tasks;
+using LibTVRefCommonPortable.Utils;
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;
returnPinnedAppsInfo.Add(addPinShortcutInfo);
}
+
public IEnumerable<AppShortcutInfo> GetPinnedApps()
{
IApplicationManagerAPIs applicationManagerPort = DependencyService.Get<IApplicationManagerAPIs>();
--- /dev/null
+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));
+ }
+ }
+}
}
}
- public String appDataPath
+ public String AppDataPath
{
get;
private set;
public DBPort(String appDataPath)
{
- this.appDataPath = appDataPath;
+ this.AppDataPath = appDataPath;
// TODO : make a unit test for this!!!
DebuggingPort.D("DBPort-------------------------------------");
return false;
}
- DBHandleRAII db = new DBHandleRAII(appDataPath, dbName);
+ DBHandleRAII db = new DBHandleRAII(AppDataPath, dbName);
if (db.handle == IntPtr.Zero)
{
DebuggingPort.E("DB open failed!!!");
return false;
}
- DBHandleRAII db = new DBHandleRAII(appDataPath, dbName);
+ DBHandleRAII db = new DBHandleRAII(AppDataPath, dbName);
if (db.handle == IntPtr.Zero)
{
DebuggingPort.E("DB open failed!!!");
get { return (ICommand)GetValue(OnClickedCommandProperty); }
set { SetValue(OnClickedCommandProperty, value); }
}
+
public AppItemCell()
{
InitializeComponent();
</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>
--- /dev/null
+/*
+ * 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;
+ }
+ }
+ }
+}
using System.ComponentModel;
using System.Linq;
using Xamarin.Forms;
+using System;
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; }
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");
});
});
}
- 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)
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)
{
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)
}
}
- InstalledAppList = installedApps.ToList();
- PinnedAppList = pinnedApps.ToList();
+ installedAppList = installedApps.ToList();
+ PinnedAppList = pinnedApps.Result.ToList();
- if (InstalledAppList != null)
+ if (installedAppList != null)
{
OnPropertyChanged("InstalledAppList");
}
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));
}
}
namespace TVApps.Views
{
+ /// <summary>
+ /// hahaha
+ /// </summary>
public partial class FooterDeleteStatus : ContentView
{
public FooterDeleteStatus()
</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}"
namespace TVApps.Views
{
+ /// <summary>
+ /// hahaha
+ /// </summary>
public partial class FooterNormalStatus : StackLayout
{
public FooterNormalStatus()
namespace TVApps.Views
{
+ /// <summary>
+ /// hahaha
+ /// </summary>
public partial class FooterPinStatus : ContentView
{
public FooterPinStatus()
get { return (AppsStatus)GetValue(CurrentStatusProperty); }
set { SetValue(CurrentStatusProperty, value); }
}
+
public MainPage()
{
InitializeComponent();