From 833ffd1d97ffc9969aaec2486b6496da1f52e492 Mon Sep 17 00:00:00 2001 From: Heonjae Jang Date: Wed, 29 Mar 2017 18:21:32 +0900 Subject: [PATCH] Add comments for TVApps.ViewModels Change-Id: Iade1ac181e738f4ff01df2c5a13f491dade07ef8 --- TVApps/TVApps/ViewModels/AppsHolder.cs | 104 ++++++++++++++++++++++---- TVApps/TVApps/ViewModels/AppsListSorter.cs | 53 ++++++++++++- TVApps/TVApps/ViewModels/IAppsViewModel.cs | 15 ++++ TVApps/TVApps/ViewModels/MainPageViewModel.cs | 86 ++++++++++++++++++++- 4 files changed, 240 insertions(+), 18 deletions(-) diff --git a/TVApps/TVApps/ViewModels/AppsHolder.cs b/TVApps/TVApps/ViewModels/AppsHolder.cs index a8be7c1..290c9d3 100644 --- a/TVApps/TVApps/ViewModels/AppsHolder.cs +++ b/TVApps/TVApps/ViewModels/AppsHolder.cs @@ -23,16 +23,39 @@ using Xamarin.Forms; namespace TVApps.ViewModels { + /// + /// A class contains installed, pinned application list. + /// The MainPageViewModel changes state of application item by AppsHolder's API + /// internal class AppsHolder { + /// + /// The interface for interaction with view model + /// IAppsViewModel ViewModel; + /// + /// A flag indicates how to sort InstalledApps + /// + /// public SortingOptions SortingOption; + /// + /// A list contains AppShortcutInfo about installed applications + /// + /// public List InstalledApps; + /// + /// A dictionary contains ID of pinned applications + /// public Dictionary PinnedApps; + /// + /// A constructor + /// Initializes installed and pinned app list + /// + /// The instance of MainPageViewModel public AppsHolder(IAppsViewModel ViewModel) { this.ViewModel = ViewModel; @@ -56,6 +79,10 @@ namespace TVApps.ViewModels SetApps(); } + /// + /// A method gets installed, pinned application information from AppShortcutController. + /// And adds state descriptions about pin, delete, long press state + /// private async void SetApps() { var pinnedAppsGettingTask = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsAppIDs(); @@ -134,53 +161,63 @@ namespace TVApps.ViewModels UpdateStateDescription(ViewModel.CurrentStatus); } - private void PinToggle(string key) + /// + /// A method changes pin state of AppShortcutInfo + /// And adds or removes application ID in PinnedApps + /// + /// The ID of application for changing pin state + 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) + /// + /// A method changes pin state of AppShortcutInfo by the Option Menu Pin/Unpin button + /// And adds or removes application ID in PinnedApps + /// + /// The ID of application for changing pin state + 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"); @@ -189,6 +226,11 @@ namespace TVApps.ViewModels ViewModel.ChangeCurrentStatus(AppsStatus.Default); } + /// + /// A method sends application delete request + /// If application is pinned, removes in PinnedApps + /// + /// The ID of application for deleting public void DeleteApp(string AppID) { DebuggingUtils.Dbg("Delete, " + AppID); @@ -219,12 +261,20 @@ namespace TVApps.ViewModels } } + /// + /// A method changes long press state of AppShortcutInfo + /// + /// The ID of application for showing option menu private void LongPressApp(string AppID) { // TODO: DebuggingUtils.Dbg(" +++++ long press app : " + AppID); } + /// + /// A method updates state description of applications + /// + /// The state name for updating state description public void UpdateStateDescription(AppsStatus status) { string tag = status.ToString().ToLower(); @@ -277,6 +327,9 @@ namespace TVApps.ViewModels ViewModel.OnPropertyChanged("InstalledAppList"); } + /// + /// A method refresh InstalledApps + /// private void RefreshApps() { // Only updating elements of InstalledApps is not update the GUI. @@ -284,17 +337,28 @@ namespace TVApps.ViewModels ViewModel.OnPropertyChanged("InstalledAppList"); } + /// + /// A method sorts InstalledApps according to parameter + /// + /// The option for sorting InstalledApps + /// public void SortApps(SortingOptions sortOption) { AppsListSorter.GetSortedAppsList(sortOption, ref InstalledApps); RefreshApps(); } + /// + /// A method reloads PinnedApps from AppShortcutController + /// public async void ResetPinnedApps() { PinnedApps = await TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsAppIDs(); } + /// + /// A method updates list about pinned application to AppShortcutController + /// public void UpdatePinnedApps() { List pinnedAppList = new List(); @@ -310,6 +374,10 @@ namespace TVApps.ViewModels TVHomeImpl.GetInstance.AppShortcutControllerInstance.UpdatePinnedApps(pinnedAppList); } + /// + /// A method removes a application in pinned list + /// + /// The ID of application for changing pin state to false public void RemovePinnedApp(string AppID) { if (PinnedApps.ContainsKey(AppID)) @@ -319,6 +387,10 @@ namespace TVApps.ViewModels } } + /// + /// A method changes visible state of option menu to true + /// + /// The ID of application for showing option menu public void ShowLongPressOption(string appId) { AppShortcutInfo longPressedApp = InstalledApps.Find(app => app.AppID.Equals(appId)); @@ -329,6 +401,10 @@ namespace TVApps.ViewModels } } + /// + /// A method changes visible state of option menu to false + /// + /// The ID of application for hiding option menu public void HideLongPressOption(string appId) { AppShortcutInfo longPressedApp = InstalledApps.Find(app => app.AppID.Equals(appId)); diff --git a/TVApps/TVApps/ViewModels/AppsListSorter.cs b/TVApps/TVApps/ViewModels/AppsListSorter.cs index fd995a2..ddb9f16 100644 --- a/TVApps/TVApps/ViewModels/AppsListSorter.cs +++ b/TVApps/TVApps/ViewModels/AppsListSorter.cs @@ -20,29 +20,80 @@ using System.Collections.Generic; namespace TVApps.ViewModels { + /// + /// A class for sorting list of AppShorcutInfo in AppsHolder + /// internal class AppsListSorter { - + /// + /// A method compares two labels of AppShortcutInfo + /// Sorts AppShortcutInfo by label in ascending + /// + /// A AppShortcutInfo to be compared with right + /// A AppShortcutInfo to be compared with left + /// + /// left precedes right, return lesser than 0. + /// left follows right, return greater than 0. + /// + /// private static int SortByLabelAscending(AppShortcutInfo left, AppShortcutInfo right) { return left.CurrentStateDescription.Label.CompareTo(right.CurrentStateDescription.Label); } + /// + /// A method compares two labels of AppShortcutInfo + /// Sorts AppShortcutInfo by label in descending + /// + /// A AppShortcutInfo to be compared with right + /// A AppShortcutInfo to be compared with left + /// + /// If left precedes right, return greater than 0. + /// If left follows right, return lesser than 0. + /// + /// private static int SortByLabelDescending(AppShortcutInfo left, AppShortcutInfo right) { return left.CurrentStateDescription.Label.CompareTo(right.CurrentStateDescription.Label) * -1; } + /// + /// A method compares two installed dates of AppShortcutInfo + /// Sorts AppShortcutInfo by installed date in descending + /// + /// A AppShortcutInfo to be compared with right + /// A AppShortcutInfo to be compared with left + /// + /// If left precedes right, return greater than 0. + /// If left follows right, return lesser than 0. + /// + /// private static int SortByRecentlyInstalled(AppShortcutInfo left, AppShortcutInfo right) { return left.Installed.CompareTo(right.Installed) * -1; } + /// + /// A method compares two last used dates of AppShortcutInfo + /// Sorts AppShortcutInfo by last used date in descending + /// + /// A AppShortcutInfo to be compared with right + /// A AppShortcutInfo to be compared with left + /// + /// If left precedes right, return greater than 0. + /// If left follows right, return lesser than 0. + /// + /// private static int SortByRecentlyUsed(AppShortcutInfo left, AppShortcutInfo right) { return left.LastUsed.CompareTo(right.LastUsed) * -1; } + /// + /// A method sorts list by parameter + /// + /// A flag indicates how to sort + /// A list to be sorted public static void GetSortedAppsList(SortingOptions sortOption, ref List list) { DebuggingUtils.Dbg("GetSortedAppsList, option = " + sortOption.ToString()); diff --git a/TVApps/TVApps/ViewModels/IAppsViewModel.cs b/TVApps/TVApps/ViewModels/IAppsViewModel.cs index 66cb895..a9f622c 100644 --- a/TVApps/TVApps/ViewModels/IAppsViewModel.cs +++ b/TVApps/TVApps/ViewModels/IAppsViewModel.cs @@ -16,11 +16,26 @@ namespace TVApps.ViewModels { + /// + /// A interface for TV Apps MainPageViewModel feature + /// interface IAppsViewModel { + /// + /// Gets current status of MainPageViewModel + /// AppsStatus CurrentStatus { get; } + /// + /// A method for invoking PropertyChanged event + /// + /// The name of property void OnPropertyChanged(string name); + + /// + /// A method changes CurrentStatus to parameter + /// + /// The next status name void ChangeCurrentStatus(AppsStatus newStatus); } } diff --git a/TVApps/TVApps/ViewModels/MainPageViewModel.cs b/TVApps/TVApps/ViewModels/MainPageViewModel.cs index 7daa9df..bb579df 100644 --- a/TVApps/TVApps/ViewModels/MainPageViewModel.cs +++ b/TVApps/TVApps/ViewModels/MainPageViewModel.cs @@ -24,6 +24,9 @@ using TVApps.Views; namespace TVApps.ViewModels { + /// + /// A enumeration for status of TV Apps + /// public enum AppsStatus { Default = 0, @@ -32,6 +35,9 @@ namespace TVApps.ViewModels LongPress, }; + /// + /// A enumeration for flag how to sort + /// public enum SortingOptions { RecentlyInstalled = 0, @@ -40,10 +46,19 @@ namespace TVApps.ViewModels Descending, }; + /// + /// A class for ViewModel of TV Apps + /// class MainPageViewModel : INotifyPropertyChanged, IAppsViewModel { + /// + /// A instance of AppsHolder for getting application list + /// AppsHolder appsHolder; + /// + /// Gets AppShortcutInfo list of installed applications from AppsHolder + /// public List InstalledAppList { get @@ -52,6 +67,9 @@ namespace TVApps.ViewModels } } + /// + /// Gets count of checked applications from AppsHolder + /// public int SumOfCheckedApp { get @@ -60,14 +78,46 @@ namespace TVApps.ViewModels } } + /// + /// A command will be executed if the cancel button in FooterDeleteStatus is clicked + /// + /// public Command ButtonDeleteCancelCommand { get; set; } + + /// + /// A command will be executed if the pin button in FooterNormalStatus is clicked + /// + /// public Command ButtonPinAppCommand { get; set; } + + /// + /// A command will be executed if the delete button in FooterNormalStatus is clicked + /// + /// public Command ButtonDeleteAppCommand { get; set; } + + /// + /// A command will be executed if the ok button in FooterPinStatus is clicked + /// + /// public Command ButtonPinOkCommand { get; set; } + + /// + /// A command will be executed if the cancel button in FooterPinStatus is clicked + /// + /// public Command ButtonPinCancelCommand { get; set; } + /// + /// Gets and Sets current status of MainPageViewModel + /// + /// public AppsStatus CurrentStatus { get; private set; } + /// + /// Gets and Sets current sorting option of AppsHolder + /// + /// private SortingOptions SortingOption { get @@ -81,6 +131,10 @@ namespace TVApps.ViewModels } } + /// + /// Gets and Sets current sorting option index + /// If change SortingOption index, AppsHolder sorts list + /// public int SortOptionIndex { get @@ -102,12 +156,26 @@ namespace TVApps.ViewModels } } + /// + /// Gets or Sets ShortcutInfo of Focused AppItemCell + /// public ShortcutInfo FocusedItem { get; set; } + /// + /// A event that is occurred when property of MainPageViewModel is changed + /// public event PropertyChangedEventHandler PropertyChanged; + /// + /// A flag indicates whether pin app is requested or not + /// If TV Home requests pin app to TV Apps, IsPinAppRequested will be true + /// private bool IsPinAppRequested; + /// + /// Constructor + /// Initialize Commands and EventListeners + /// public MainPageViewModel() { DebuggingUtils.Dbg(">MainPageViewModel - Start"); @@ -136,7 +204,7 @@ namespace TVApps.ViewModels 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(); } @@ -195,6 +263,9 @@ namespace TVApps.ViewModels DebuggingUtils.Dbg(" + /// A method creates AppsHolder instance and initializes Sorting Option, Current Status to default + /// private void Init() { appsHolder = new AppsHolder(this); @@ -204,12 +275,19 @@ namespace TVApps.ViewModels ChangeCurrentStatus(AppsStatus.Default); } + /// + /// A method for refresh the MainPageViewModel + /// private void RefreshView() { appsHolder.ResetPinnedApps(); ChangeCurrentStatus(CurrentStatus); } + /// + /// A method changes CurrentStatus to parameter + /// + /// The next status name public void ChangeCurrentStatus(AppsStatus newStatus) { CurrentStatus = newStatus; @@ -217,6 +295,10 @@ namespace TVApps.ViewModels OnPropertyChanged("CurrentStatus"); } + /// + /// A method for invoking PropertyChanged event + /// + /// The name of property public void OnPropertyChanged(string name) { PropertyChangedEventHandler handler = PropertyChanged; @@ -225,7 +307,5 @@ namespace TVApps.ViewModels handler(this, new PropertyChangedEventArgs(name)); } } - - } } -- 2.7.4