Add comments for TVApps.ViewModels
authorHeonjae Jang <heonjae.jang@samsung.com>
Wed, 29 Mar 2017 09:21:32 +0000 (18:21 +0900)
committerChulSeung Kim <charles0.kim@samsung.com>
Thu, 8 Jun 2017 09:34:51 +0000 (18:34 +0900)
Change-Id: Iade1ac181e738f4ff01df2c5a13f491dade07ef8

TVApps/TVApps/ViewModels/AppsHolder.cs
TVApps/TVApps/ViewModels/AppsListSorter.cs
TVApps/TVApps/ViewModels/IAppsViewModel.cs
TVApps/TVApps/ViewModels/MainPageViewModel.cs

index a8be7c106fb68f66da8ee6da713bd76c607b3b0e..290c9d355bbb9b114af5eaa4e15dddb5ee30786e 100644 (file)
@@ -23,16 +23,39 @@ using Xamarin.Forms;
 
 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;
@@ -56,6 +79,10 @@ namespace TVApps.ViewModels
             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();
@@ -134,53 +161,63 @@ namespace TVApps.ViewModels
             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");
@@ -189,6 +226,11 @@ namespace TVApps.ViewModels
             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);
@@ -219,12 +261,20 @@ namespace TVApps.ViewModels
             }
         }
 
+        /// <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();
@@ -277,6 +327,9 @@ namespace TVApps.ViewModels
             ViewModel.OnPropertyChanged("InstalledAppList");
         }
 
+        /// <summary>
+        /// A method refresh InstalledApps
+        /// </summary>
         private void RefreshApps()
         {
             // Only updating elements of InstalledApps is not update the GUI.
@@ -284,17 +337,28 @@ namespace TVApps.ViewModels
             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>();
@@ -310,6 +374,10 @@ namespace TVApps.ViewModels
             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))
@@ -319,6 +387,10 @@ namespace TVApps.ViewModels
             }
         }
 
+        /// <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));
@@ -329,6 +401,10 @@ namespace TVApps.ViewModels
             }
         }
 
+        /// <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));
index fd995a292329e7c2c15b22acfd8b631ab27210a5..ddb9f169d97dae89ae915ab2dd6875dda78b8884 100644 (file)
@@ -20,29 +20,80 @@ using System.Collections.Generic;
 
 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());
index 66cb8950f5e2baaba9ecd5f5a4782045163b7d73..a9f622c7513853099629a9f69d6c5bdc544230fe 100644 (file)
 
 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);
     }
 }
index 7daa9df330c45a73a51a7a2d962b9cbac9c42883..bb579dfc53a64379c3ef94242322efcf870e65d7 100644 (file)
@@ -24,6 +24,9 @@ using TVApps.Views;
 
 namespace TVApps.ViewModels
 {
+    /// <summary>
+    /// A enumeration for status of TV Apps
+    /// </summary>
     public enum AppsStatus
     {
         Default = 0,
@@ -32,6 +35,9 @@ namespace TVApps.ViewModels
         LongPress,
     };
 
+    /// <summary>
+    /// A enumeration for flag how to sort
+    /// </summary>
     public enum SortingOptions
     {
         RecentlyInstalled = 0,
@@ -40,10 +46,19 @@ namespace TVApps.ViewModels
         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
@@ -52,6 +67,9 @@ namespace TVApps.ViewModels
             }
         }
 
+        /// <summary>
+        /// Gets count of checked applications from AppsHolder
+        /// </summary>
         public int SumOfCheckedApp
         {
             get
@@ -60,14 +78,46 @@ namespace TVApps.ViewModels
             }
         }
 
+        /// <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
@@ -81,6 +131,10 @@ namespace TVApps.ViewModels
             }
         }
 
+        /// <summary>
+        /// Gets and Sets current sorting option index
+        /// If change SortingOption index, AppsHolder sorts list
+        /// </summary>
         public int SortOptionIndex
         {
             get
@@ -102,12 +156,26 @@ namespace TVApps.ViewModels
             }
         }
 
+        /// <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");
@@ -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("<MainPageViewModel - End");
         }
 
+        /// <summary>
+        /// A method creates AppsHolder instance and initializes Sorting Option, Current Status to default
+        /// </summary>
         private void Init()
         {
             appsHolder = new AppsHolder(this);
@@ -204,12 +275,19 @@ namespace TVApps.ViewModels
             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;
@@ -217,6 +295,10 @@ namespace TVApps.ViewModels
             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;
@@ -225,7 +307,5 @@ namespace TVApps.ViewModels
                 handler(this, new PropertyChangedEventArgs(name));
             }
         }
-
-
     }
 }