From: cskim Date: Wed, 22 Mar 2017 00:12:57 +0000 (+0900) Subject: Modify AppShortcutInfo to use property instead of setter. X-Git-Tag: submit/tizen/20170808.015446~177 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=81a40d3190fde77fed164ce23c7a501c3b3ee4af;p=profile%2Ftv%2Fapps%2Fdotnet%2Fhome.git Modify AppShortcutInfo to use property instead of setter. Use MessageCenter to notify a event between View and ViewModel. Change-Id: I089af8948db82ddc729928a4dec3405c020792f9 --- diff --git a/LibTVRefCommonPortable/DataModels/AppShortcutInfo.cs b/LibTVRefCommonPortable/DataModels/AppShortcutInfo.cs index 7a0e202..4ef066a 100644 --- a/LibTVRefCommonPortable/DataModels/AppShortcutInfo.cs +++ b/LibTVRefCommonPortable/DataModels/AppShortcutInfo.cs @@ -26,68 +26,122 @@ namespace LibTVRefCommonPortable.DataModels public string AppID { get; set; } [XmlIgnore] - public bool IsChecked { get; set; } + private bool isChecked; [XmlIgnore] - public bool IsPinned { get; set; } + public bool IsChecked + { + get + { + return isChecked; + } + + set + { + if (isChecked != value) + { + isChecked = value; + OnPropertyChanged("IsChecked"); + } + } + } [XmlIgnore] - public bool IsRemovable { get; set; } + private bool isPinned; [XmlIgnore] - public bool IsVisible { get; set; } = true; + public bool IsPinned + { + get + { + return isPinned; + } + + set + { + if (isPinned != value) + { + isPinned = value; + OnPropertyChanged("IsPinned"); + } + } + } [XmlIgnore] - public bool IsDim { get; set; } + public bool IsRemovable { get; set; } [XmlIgnore] - public bool IsShowOptions { get; set; } + private bool isVisible = true; [XmlIgnore] - public DateTime Installed { get; set; } - - [XmlIgnore] - public DateTime LastUsed { get; set; } - - public override void UpdateState() + public bool IsVisible { - SetCurrentState("default"); + get + { + return isVisible; + } + + set + { + if (isVisible != value) + { + isVisible = value; + OnPropertyChanged("IsVisible"); + } + } } - public void SetChecked(bool value) - { - IsChecked = value; - OnPropertyChanged("IsChecked"); - } + [XmlIgnore] + private bool isDim; - public void SetPinned(bool value) + [XmlIgnore] + public bool IsDim { - IsPinned = value; - OnPropertyChanged("IsPinned"); + get + { + return isDim; + } + + set + { + if (isDim != value) + { + isDim = value; + OnPropertyChanged("IsDim"); + } + } } - public void SetVisible(bool value) - { - IsVisible = value; - OnPropertyChanged("IsVisible"); - } + [XmlIgnore] + private bool isShowOptions; - public void SetDim(bool value) + [XmlIgnore] + public bool IsShowOptions { - IsDim = value; - OnPropertyChanged("IsDim"); + get + { + return isShowOptions; + } + + set + { + if (isShowOptions != value) + { + isShowOptions = value; + OnPropertyChanged("IsShowOptions"); + } + } } - public void ShowOptions() - { - IsShowOptions = true; - OnPropertyChanged("IsShowOptions"); - } + [XmlIgnore] + public DateTime Installed { get; set; } - public void HideOptions() + [XmlIgnore] + public DateTime LastUsed { get; set; } + + public override void UpdateState() { - IsShowOptions = false; - OnPropertyChanged("IsShowOptions"); + SetCurrentState("default"); } } } diff --git a/TVApps/TVApps/ViewModels/AppsHolder.cs b/TVApps/TVApps/ViewModels/AppsHolder.cs index 492c3d9..603ddcc 100644 --- a/TVApps/TVApps/ViewModels/AppsHolder.cs +++ b/TVApps/TVApps/ViewModels/AppsHolder.cs @@ -75,7 +75,7 @@ namespace TVApps.ViewModels continue; } - item.SetPinned(PinnedApps.ContainsKey(item.AppID)); + item.IsPinned = PinnedApps.ContainsKey(item.AppID); var pinStateDescription = new StateDescription() { @@ -135,18 +135,25 @@ namespace TVApps.ViewModels private void PinToggle(string key) { + AppShortcutInfo selectedApp = InstalledApps.FirstOrDefault(a => a.AppID == key); + if (selectedApp == null) + { + DebuggingUtils.Err("Failed to Pin!!!, Nothing selected, AppID = " + key); + return; + } + if (PinnedApps.ContainsKey(key)) { DebuggingUtils.Dbg("UnPin!"); - InstalledApps.FirstOrDefault(a => a.AppID == key)?.SetChecked(false); - InstalledApps.FirstOrDefault(a => a.AppID == key)?.SetPinned(false); + selectedApp.IsChecked = false; + selectedApp.IsPinned = false; PinnedApps.Remove(key); } else { DebuggingUtils.Dbg("Pin!"); - InstalledApps.FirstOrDefault(a => a.AppID == key)?.SetChecked(true); - InstalledApps.FirstOrDefault(a => a.AppID == key)?.SetPinned(true); + selectedApp.IsChecked = true; + selectedApp.IsPinned = true; PinnedApps.Add(key, key); } } @@ -198,29 +205,30 @@ namespace TVApps.ViewModels switch (status) { case AppsStatus.Default: - item.SetChecked(false); - item.SetDim(false); + item.IsChecked = false; + item.IsDim = false; + item.IsShowOptions = false; break; case AppsStatus.Pin: - item.SetChecked(item.IsPinned); + item.IsChecked = item.IsPinned; break; case AppsStatus.LongPress: - item.SetDim(true); + item.IsDim = true; break; case AppsStatus.Delete: - item.SetChecked(false); + item.IsChecked = false; break; } - item.SetPinned(PinnedApps.ContainsKey(item.AppID)); + item.IsPinned = PinnedApps.ContainsKey(item.AppID); } ViewModel.OnPropertyChanged("InstalledAppList"); } - // Just use to update list view which is binding private void RefreshApps() { + // Only updating elements of InstalledApps is not update the GUI. InstalledApps = new List(InstalledApps); ViewModel.OnPropertyChanged("InstalledAppList"); } @@ -265,8 +273,8 @@ namespace TVApps.ViewModels AppShortcutInfo longPressedApp = InstalledApps.Find(app => app.AppID.Equals(appId)); if (longPressedApp != null) { - longPressedApp.SetDim(false); - longPressedApp.ShowOptions(); + longPressedApp.IsDim = false; + longPressedApp.IsShowOptions = true; } } @@ -275,7 +283,7 @@ namespace TVApps.ViewModels AppShortcutInfo longPressedApp = InstalledApps.Find(app => app.AppID.Equals(appId)); if (longPressedApp != null) { - longPressedApp.HideOptions(); + longPressedApp.IsShowOptions = false; } } } diff --git a/TVApps/TVApps/ViewModels/MainPageViewModel.cs b/TVApps/TVApps/ViewModels/MainPageViewModel.cs index f2831b9..0e5fb1b 100644 --- a/TVApps/TVApps/ViewModels/MainPageViewModel.cs +++ b/TVApps/TVApps/ViewModels/MainPageViewModel.cs @@ -20,6 +20,7 @@ using System.Collections.Generic; using System.ComponentModel; using Xamarin.Forms; using System; +using TVApps.Views; namespace TVApps.ViewModels { @@ -159,7 +160,7 @@ namespace TVApps.ViewModels ChangeCurrentStatus(AppsStatus.LongPress); // 2. The selected icon on apps list will be moved - appsHolder.ShowLongPressOption((string)appId); + appsHolder.ShowLongPressOption(appId.ToString()); // 3. The option menu will be shown @@ -171,12 +172,11 @@ namespace TVApps.ViewModels // 1. change Apps status to Default // Default of AppsStatus will change ItemCell to be normal - ChangeCurrentStatus(AppsStatus.Default); - // 2. The option menu will be hidden + ChangeCurrentStatus(AppsStatus.Default); // 3. The selected icon will be moved - appsHolder.HideLongPressOption((string)appId); + //appsHolder.HideLongPressOption(appId.ToString()); }); @@ -188,6 +188,20 @@ namespace TVApps.ViewModels ChangeCurrentStatus(AppsStatus.Pin); }); + // TODO : Need to double check this view dependency violates the MVVM policy + MessagingCenter.Subscribe(this, "ChangeCurrentStatus", (sender, arg) => + { + try + { + AppsStatus newStatus = (AppsStatus)Enum.Parse(typeof(AppsStatus), arg); + ChangeCurrentStatus(newStatus); + } + catch (Exception e) + { + DebuggingUtils.Err("Invalid argument!!!, " + arg + ", " + e.Message); + } + + }); DebuggingUtils.Dbg(" OnBackKeyPressedAtMain() { + DebuggingUtils.Dbg("OnBackKeyPressedAtMain - first item focused? " + AppList.IsFirstItemFocused); + + if (CurrentStatus != AppsStatus.Default) + { + MessagingCenter.Send(this, "ChangeCurrentStatus", AppsStatus.Default.ToString()); + } + if (!AppList.IsFirstItemFocused && IsBackKeyPressed == false) { diff --git a/TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk b/TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk index 8ac7994..b9a7114 100644 Binary files a/TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk and b/TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk differ