namespace TVApps.ViewModels
{
+ /// <summary>
+ /// A class contains installed, pinned application list.
+ /// The MainPageViewModel changes state of application item by AppsHolder's API
+ /// </summary>
internal class AppsHolder
{
+ /// <summary>
+ /// The interface for interaction with view model
+ /// </summary>
IAppsViewModel ViewModel;
+ /// <summary>
+ /// A flag indicates how to sort InstalledApps
+ /// </summary>
+ /// <see cref="SortingOptions"/>
public SortingOptions SortingOption;
+ /// <summary>
+ /// A list contains AppShortcutInfo about installed applications
+ /// </summary>
+ /// <see cref="AppShortcutInfo"/>
public List<AppShortcutInfo> InstalledApps;
+ /// <summary>
+ /// A dictionary contains ID of pinned applications
+ /// </summary>
public Dictionary<string, string> PinnedApps;
+ /// <summary>
+ /// A constructor
+ /// Initializes installed and pinned app list
+ /// </summary>
+ /// <param name="ViewModel">The instance of MainPageViewModel</param>
public AppsHolder(IAppsViewModel ViewModel)
{
this.ViewModel = ViewModel;
SetApps();
}
+ /// <summary>
+ /// A method gets installed, pinned application information from AppShortcutController.
+ /// And adds state descriptions about pin, delete, long press state
+ /// </summary>
private async void SetApps()
{
var pinnedAppsGettingTask = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsAppIDs();
UpdateStateDescription(ViewModel.CurrentStatus);
}
- private void PinToggle(string key)
+ /// <summary>
+ /// A method changes pin state of AppShortcutInfo
+ /// And adds or removes application ID in PinnedApps
+ /// </summary>
+ /// <param name="appID">The ID of application for changing pin state</param>
+ private void PinToggle(string appID)
{
- AppShortcutInfo selectedApp = InstalledApps.FirstOrDefault(a => a.AppID == key);
+ AppShortcutInfo selectedApp = InstalledApps.FirstOrDefault(a => a.AppID == appID);
if (selectedApp == null)
{
- DebuggingUtils.Err("Failed to Pin!!!, Nothing selected, AppID = " + key);
+ DebuggingUtils.Err("Failed to Pin!!!, Nothing selected, AppID = " + appID);
return;
}
- if (PinnedApps.ContainsKey(key))
+ if (PinnedApps.ContainsKey(appID))
{
DebuggingUtils.Dbg("UnPin! : " + selectedApp);
selectedApp.IsChecked = false;
selectedApp.IsPinned = false;
- PinnedApps.Remove(key);
+ PinnedApps.Remove(appID);
}
else
{
DebuggingUtils.Dbg("Pin! : " + selectedApp);
selectedApp.IsChecked = true;
selectedApp.IsPinned = true;
- PinnedApps.Add(key, key);
+ PinnedApps.Add(appID, appID);
}
ViewModel.OnPropertyChanged("SumOfCheckedApp");
}
- public void OptionMenuPinToggle(string key)
+ /// <summary>
+ /// A method changes pin state of AppShortcutInfo by the Option Menu Pin/Unpin button
+ /// And adds or removes application ID in PinnedApps
+ /// </summary>
+ /// <param name="appID">The ID of application for changing pin state</param>
+ public void OptionMenuPinToggle(string appID)
{
- AppShortcutInfo SelectedApp = InstalledApps.FirstOrDefault(a => a.AppID.Equals(key));
+ AppShortcutInfo SelectedApp = InstalledApps.FirstOrDefault(a => a.AppID.Equals(appID));
if (SelectedApp == null)
{
- DebuggingUtils.Err("Failed to get selected app : " + key);
+ DebuggingUtils.Err("Failed to get selected app : " + appID);
return;
}
- if (PinnedApps.ContainsKey(key))
+ if (PinnedApps.ContainsKey(appID))
{
- DebuggingUtils.Dbg("Unpin : " + key);
+ DebuggingUtils.Dbg("Unpin : " + appID);
SelectedApp.IsPinned = false;
- PinnedApps.Remove(key);
+ PinnedApps.Remove(appID);
}
else
{
- DebuggingUtils.Dbg("Pin : " + key);
+ DebuggingUtils.Dbg("Pin : " + appID);
SelectedApp.IsPinned = true;
- PinnedApps.Add(key, key);
+ PinnedApps.Add(appID, appID);
}
ViewModel.OnPropertyChanged("SumOfCheckedApp");
ViewModel.ChangeCurrentStatus(AppsStatus.Default);
}
+ /// <summary>
+ /// A method sends application delete request
+ /// If application is pinned, removes in PinnedApps
+ /// </summary>
+ /// <param name="AppID">The ID of application for deleting</param>
public void DeleteApp(string AppID)
{
DebuggingUtils.Dbg("Delete, " + AppID);
}
}
+ /// <summary>
+ /// A method changes long press state of AppShortcutInfo
+ /// </summary>
+ /// <param name="AppID">The ID of application for showing option menu</param>
private void LongPressApp(string AppID)
{
// TODO:
DebuggingUtils.Dbg(" +++++ long press app : " + AppID);
}
+ /// <summary>
+ /// A method updates state description of applications
+ /// </summary>
+ /// <param name="status">The state name for updating state description</param>
public void UpdateStateDescription(AppsStatus status)
{
string tag = status.ToString().ToLower();
ViewModel.OnPropertyChanged("InstalledAppList");
}
+ /// <summary>
+ /// A method refresh InstalledApps
+ /// </summary>
private void RefreshApps()
{
// Only updating elements of InstalledApps is not update the GUI.
ViewModel.OnPropertyChanged("InstalledAppList");
}
+ /// <summary>
+ /// A method sorts InstalledApps according to parameter
+ /// </summary>
+ /// <param name="sortOption">The option for sorting InstalledApps</param>
+ /// <see cref="SortingOptions"></see>
public void SortApps(SortingOptions sortOption)
{
AppsListSorter.GetSortedAppsList(sortOption, ref InstalledApps);
RefreshApps();
}
+ /// <summary>
+ /// A method reloads PinnedApps from AppShortcutController
+ /// </summary>
public async void ResetPinnedApps()
{
PinnedApps = await TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsAppIDs();
}
+ /// <summary>
+ /// A method updates list about pinned application to AppShortcutController
+ /// </summary>
public void UpdatePinnedApps()
{
List<AppShortcutInfo> pinnedAppList = new List<AppShortcutInfo>();
TVHomeImpl.GetInstance.AppShortcutControllerInstance.UpdatePinnedApps(pinnedAppList);
}
+ /// <summary>
+ /// A method removes a application in pinned list
+ /// </summary>
+ /// <param name="AppID">The ID of application for changing pin state to false</param>
public void RemovePinnedApp(string AppID)
{
if (PinnedApps.ContainsKey(AppID))
}
}
+ /// <summary>
+ /// A method changes visible state of option menu to true
+ /// </summary>
+ /// <param name="appId">The ID of application for showing option menu</param>
public void ShowLongPressOption(string appId)
{
AppShortcutInfo longPressedApp = InstalledApps.Find(app => app.AppID.Equals(appId));
}
}
+ /// <summary>
+ /// A method changes visible state of option menu to false
+ /// </summary>
+ /// <param name="appId">The ID of application for hiding option menu</param>
public void HideLongPressOption(string appId)
{
AppShortcutInfo longPressedApp = InstalledApps.Find(app => app.AppID.Equals(appId));
namespace TVApps.ViewModels
{
+ /// <summary>
+ /// A class for sorting list of AppShorcutInfo in AppsHolder
+ /// </summary>
internal class AppsListSorter
{
-
+ /// <summary>
+ /// A method compares two labels of AppShortcutInfo
+ /// Sorts AppShortcutInfo by label in ascending
+ /// </summary>
+ /// <param name="left">A AppShortcutInfo to be compared with right</param>
+ /// <param name="right">A AppShortcutInfo to be compared with left</param>
+ /// <returns>
+ /// left precedes right, return lesser than 0.
+ /// left follows right, return greater than 0.
+ /// </returns>
+ /// <see cref="string.CompareTo(string)"/>
private static int SortByLabelAscending(AppShortcutInfo left, AppShortcutInfo right)
{
return left.CurrentStateDescription.Label.CompareTo(right.CurrentStateDescription.Label);
}
+ /// <summary>
+ /// A method compares two labels of AppShortcutInfo
+ /// Sorts AppShortcutInfo by label in descending
+ /// </summary>
+ /// <param name="left">A AppShortcutInfo to be compared with right</param>
+ /// <param name="right">A AppShortcutInfo to be compared with left</param>
+ /// <returns>
+ /// If left precedes right, return greater than 0.
+ /// If left follows right, return lesser than 0.
+ /// </returns>
+ /// <see cref="string.CompareTo(string)"/>
private static int SortByLabelDescending(AppShortcutInfo left, AppShortcutInfo right)
{
return left.CurrentStateDescription.Label.CompareTo(right.CurrentStateDescription.Label) * -1;
}
+ /// <summary>
+ /// A method compares two installed dates of AppShortcutInfo
+ /// Sorts AppShortcutInfo by installed date in descending
+ /// </summary>
+ /// <param name="left">A AppShortcutInfo to be compared with right</param>
+ /// <param name="right">A AppShortcutInfo to be compared with left</param>
+ /// <returns>
+ /// If left precedes right, return greater than 0.
+ /// If left follows right, return lesser than 0.
+ /// </returns>
+ /// <see cref="System.DateTime.CompareTo(System.DateTime)"/>
private static int SortByRecentlyInstalled(AppShortcutInfo left, AppShortcutInfo right)
{
return left.Installed.CompareTo(right.Installed) * -1;
}
+ /// <summary>
+ /// A method compares two last used dates of AppShortcutInfo
+ /// Sorts AppShortcutInfo by last used date in descending
+ /// </summary>
+ /// <param name="left">A AppShortcutInfo to be compared with right</param>
+ /// <param name="right">A AppShortcutInfo to be compared with left</param>
+ /// <returns>
+ /// If left precedes right, return greater than 0.
+ /// If left follows right, return lesser than 0.
+ /// </returns>
+ /// <see cref="System.DateTime.CompareTo(System.DateTime)"/>
private static int SortByRecentlyUsed(AppShortcutInfo left, AppShortcutInfo right)
{
return left.LastUsed.CompareTo(right.LastUsed) * -1;
}
+ /// <summary>
+ /// A method sorts list by parameter
+ /// </summary>
+ /// <param name="sortOption">A flag indicates how to sort</param>
+ /// <param name="list">A list to be sorted</param>
public static void GetSortedAppsList(SortingOptions sortOption, ref List<AppShortcutInfo> list)
{
DebuggingUtils.Dbg("GetSortedAppsList, option = " + sortOption.ToString());
namespace TVApps.ViewModels
{
+ /// <summary>
+ /// A interface for TV Apps MainPageViewModel feature
+ /// </summary>
interface IAppsViewModel
{
+ /// <summary>
+ /// Gets current status of MainPageViewModel
+ /// </summary>
AppsStatus CurrentStatus { get; }
+ /// <summary>
+ /// A method for invoking PropertyChanged event
+ /// </summary>
+ /// <param name="name">The name of property</param>
void OnPropertyChanged(string name);
+
+ /// <summary>
+ /// A method changes CurrentStatus to parameter
+ /// </summary>
+ /// <param name="newStatus">The next status name</param>
void ChangeCurrentStatus(AppsStatus newStatus);
}
}
namespace TVApps.ViewModels
{
+ /// <summary>
+ /// A enumeration for status of TV Apps
+ /// </summary>
public enum AppsStatus
{
Default = 0,
LongPress,
};
+ /// <summary>
+ /// A enumeration for flag how to sort
+ /// </summary>
public enum SortingOptions
{
RecentlyInstalled = 0,
Descending,
};
+ /// <summary>
+ /// A class for ViewModel of TV Apps
+ /// </summary>
class MainPageViewModel : INotifyPropertyChanged, IAppsViewModel
{
+ /// <summary>
+ /// A instance of AppsHolder for getting application list
+ /// </summary>
AppsHolder appsHolder;
+ /// <summary>
+ /// Gets AppShortcutInfo list of installed applications from AppsHolder
+ /// </summary>
public List<AppShortcutInfo> InstalledAppList
{
get
}
}
+ /// <summary>
+ /// Gets count of checked applications from AppsHolder
+ /// </summary>
public int SumOfCheckedApp
{
get
}
}
+ /// <summary>
+ /// A command will be executed if the cancel button in FooterDeleteStatus is clicked
+ /// </summary>
+ /// <see cref="FooterDeleteStatus"/>
public Command ButtonDeleteCancelCommand { get; set; }
+
+ /// <summary>
+ /// A command will be executed if the pin button in FooterNormalStatus is clicked
+ /// </summary>
+ /// <see cref="FooterNormalStatus"/>
public Command ButtonPinAppCommand { get; set; }
+
+ /// <summary>
+ /// A command will be executed if the delete button in FooterNormalStatus is clicked
+ /// </summary>
+ /// <see cref="FooterNormalStatus"/>
public Command ButtonDeleteAppCommand { get; set; }
+
+ /// <summary>
+ /// A command will be executed if the ok button in FooterPinStatus is clicked
+ /// </summary>
+ /// <see cref="FooterPinStatus"/>
public Command ButtonPinOkCommand { get; set; }
+
+ /// <summary>
+ /// A command will be executed if the cancel button in FooterPinStatus is clicked
+ /// </summary>
+ /// <see cref="FooterPinStatus"/>
public Command ButtonPinCancelCommand { get; set; }
+ /// <summary>
+ /// Gets and Sets current status of MainPageViewModel
+ /// </summary>
+ /// <see cref="AppsStatus"/>
public AppsStatus CurrentStatus { get; private set; }
+ /// <summary>
+ /// Gets and Sets current sorting option of AppsHolder
+ /// </summary>
+ /// <see cref="AppsHolder"/>
private SortingOptions SortingOption
{
get
}
}
+ /// <summary>
+ /// Gets and Sets current sorting option index
+ /// If change SortingOption index, AppsHolder sorts list
+ /// </summary>
public int SortOptionIndex
{
get
}
}
+ /// <summary>
+ /// Gets or Sets ShortcutInfo of Focused AppItemCell
+ /// </summary>
public ShortcutInfo FocusedItem { get; set; }
+ /// <summary>
+ /// A event that is occurred when property of MainPageViewModel is changed
+ /// </summary>
public event PropertyChangedEventHandler PropertyChanged;
+ /// <summary>
+ /// A flag indicates whether pin app is requested or not
+ /// If TV Home requests pin app to TV Apps, IsPinAppRequested will be true
+ /// </summary>
private bool IsPinAppRequested;
+ /// <summary>
+ /// Constructor
+ /// Initialize Commands and EventListeners
+ /// </summary>
public MainPageViewModel()
{
DebuggingUtils.Dbg(">MainPageViewModel - Start");
if (IsPinAppRequested)
{
- // TODO : check pinneed apps and a number of pinned apps
+ // TODO : check pinned apps and a number of pinned apps
AppControlUtils.SendAppAddedNotificationToHome("org.tizen.settings");
AppControlUtils.SelfTerminate();
}
DebuggingUtils.Dbg("<MainPageViewModel - End");
}
+ /// <summary>
+ /// A method creates AppsHolder instance and initializes Sorting Option, Current Status to default
+ /// </summary>
private void Init()
{
appsHolder = new AppsHolder(this);
ChangeCurrentStatus(AppsStatus.Default);
}
+ /// <summary>
+ /// A method for refresh the MainPageViewModel
+ /// </summary>
private void RefreshView()
{
appsHolder.ResetPinnedApps();
ChangeCurrentStatus(CurrentStatus);
}
+ /// <summary>
+ /// A method changes CurrentStatus to parameter
+ /// </summary>
+ /// <param name="newStatus">The next status name</param>
public void ChangeCurrentStatus(AppsStatus newStatus)
{
CurrentStatus = newStatus;
OnPropertyChanged("CurrentStatus");
}
+ /// <summary>
+ /// A method for invoking PropertyChanged event
+ /// </summary>
+ /// <param name="name">The name of property</param>
public void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
handler(this, new PropertyChangedEventArgs(name));
}
}
-
-
}
}