aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Plugins.DefaultTheme/Model/VirtualCollection.cs
diff options
context:
space:
mode:
authorLukePulverenti <luke.pulverenti@gmail.com>2013-02-20 20:33:05 -0500
committerLukePulverenti <luke.pulverenti@gmail.com>2013-02-20 20:33:05 -0500
commit767cdc1f6f6a63ce997fc9476911e2c361f9d402 (patch)
tree49add55976f895441167c66cfa95e5c7688d18ce /MediaBrowser.Plugins.DefaultTheme/Model/VirtualCollection.cs
parent845554722efaed872948a9e0f7202e3ef52f1b6e (diff)
Pushing missing changes
Diffstat (limited to 'MediaBrowser.Plugins.DefaultTheme/Model/VirtualCollection.cs')
-rw-r--r--MediaBrowser.Plugins.DefaultTheme/Model/VirtualCollection.cs90
1 files changed, 90 insertions, 0 deletions
diff --git a/MediaBrowser.Plugins.DefaultTheme/Model/VirtualCollection.cs b/MediaBrowser.Plugins.DefaultTheme/Model/VirtualCollection.cs
new file mode 100644
index 000000000..9bdf61129
--- /dev/null
+++ b/MediaBrowser.Plugins.DefaultTheme/Model/VirtualCollection.cs
@@ -0,0 +1,90 @@
+using MediaBrowser.Model.DTO;
+using MediaBrowser.UI.Controls;
+using System;
+using System.Threading;
+using System.Windows;
+
+namespace MediaBrowser.Plugins.DefaultTheme.Model
+{
+ public class VirtualCollection : ModelItem, IDisposable
+ {
+ private string _name;
+ public string Name
+ {
+ get { return _name; }
+ set
+ {
+ _name = value;
+ OnPropertyChanged("Name");
+ }
+ }
+
+ private DtoBaseItem[] _items;
+ public DtoBaseItem[] Items
+ {
+ get { return _items; }
+ set
+ {
+ _items = value;
+ OnPropertyChanged("Items");
+ CurrentItemIndex = Items.Length == 0 ? -1 : 0;
+
+ ReloadTimer();
+ }
+ }
+
+ private int _currentItemIndex;
+ public int CurrentItemIndex
+ {
+ get { return _currentItemIndex; }
+ set
+ {
+ _currentItemIndex = value;
+ OnPropertyChanged("CurrentItemIndex");
+ OnPropertyChanged("CurrentItem");
+ }
+ }
+
+ public DtoBaseItem CurrentItem
+ {
+ get { return CurrentItemIndex == -1 ? null : Items[CurrentItemIndex]; }
+ }
+
+ private Timer CurrentItemTimer { get; set; }
+
+ private void DisposeTimer()
+ {
+ if (CurrentItemTimer != null)
+ {
+ CurrentItemTimer.Dispose();
+ }
+ }
+
+ private void ReloadTimer()
+ {
+ DisposeTimer();
+
+ if (Items.Length > 0)
+ {
+ CurrentItemTimer = new Timer(state => Application.Current.Dispatcher.InvokeAsync(() => IncrementCurrentItemIndex()), null, 5000, 5000);
+ }
+ }
+
+ private void IncrementCurrentItemIndex()
+ {
+ var newIndex = CurrentItemIndex + 1;
+
+ if (newIndex >= Items.Length)
+ {
+ newIndex = 0;
+ }
+
+ CurrentItemIndex = newIndex;
+ }
+
+ public void Dispose()
+ {
+ DisposeTimer();
+ }
+ }
+}