Use MessageCenter to notify a event between View and ViewModel.
Change-Id: I089af8948db82ddc729928a4dec3405c020792f9
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");
}
}
}
continue;
}
- item.SetPinned(PinnedApps.ContainsKey(item.AppID));
+ item.IsPinned = PinnedApps.ContainsKey(item.AppID);
var pinStateDescription = new StateDescription()
{
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);
}
}
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<AppShortcutInfo>(InstalledApps);
ViewModel.OnPropertyChanged("InstalledAppList");
}
AppShortcutInfo longPressedApp = InstalledApps.Find(app => app.AppID.Equals(appId));
if (longPressedApp != null)
{
- longPressedApp.SetDim(false);
- longPressedApp.ShowOptions();
+ longPressedApp.IsDim = false;
+ longPressedApp.IsShowOptions = true;
}
}
AppShortcutInfo longPressedApp = InstalledApps.Find(app => app.AppID.Equals(appId));
if (longPressedApp != null)
{
- longPressedApp.HideOptions();
+ longPressedApp.IsShowOptions = false;
}
}
}
using System.ComponentModel;
using Xamarin.Forms;
using System;
+using TVApps.Views;
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
// 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());
});
ChangeCurrentStatus(AppsStatus.Pin);
});
+ // TODO : Need to double check this view dependency violates the MVVM policy
+ MessagingCenter.Subscribe<MainPage, string>(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("<MainPageViewModel - End");
}
}
}
+
}
}
private async Task<bool> OnBackKeyPressedAtMain()
{
+ DebuggingUtils.Dbg("OnBackKeyPressedAtMain - first item focused? " + AppList.IsFirstItemFocused);
+
+ if (CurrentStatus != AppsStatus.Default)
+ {
+ MessagingCenter.Send<MainPage, string>(this, "ChangeCurrentStatus", AppsStatus.Default.ToString());
+ }
+
if (!AppList.IsFirstItemFocused &&
IsBackKeyPressed == false)
{