using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Net;
using MediaBrowser.UI.Controller;
using MediaBrowser.UI.Playback;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace MediaBrowser.UI.Pages
{
///
/// Provides a base class for detail pages
///
public abstract class BaseDetailPage : BasePage
{
///
/// The _item id
///
private string _itemId;
///
/// Gets or sets the id of the item being displayed
///
/// The item id.
protected string ItemId
{
get { return _itemId; }
private set
{
_itemId = value;
OnPropertyChanged("ItemId");
}
}
///
/// The _item
///
private BaseItemDto _item;
///
/// Gets or sets the item.
///
/// The item.
public BaseItemDto Item
{
get { return _item; }
set
{
_item = value;
OnPropertyChanged("Item");
OnItemChanged();
}
}
///
/// Gets a value indicating whether this instance can resume.
///
/// true if this instance can resume; otherwise, false.
protected bool CanResume
{
get { return Item.CanResume; }
}
///
/// Gets a value indicating whether this instance can queue.
///
/// true if this instance can queue; otherwise, false.
protected bool CanQueue
{
get { return true; }
}
///
/// Gets a value indicating whether this instance can play trailer.
///
/// true if this instance can play trailer; otherwise, false.
protected bool CanPlayTrailer
{
get { return Item.HasTrailer; }
}
///
/// Initializes a new instance of the class.
///
/// The item id.
protected BaseDetailPage(string itemId)
: base()
{
ItemId = itemId;
}
///
/// Called when [property changed].
///
/// The name.
public async override void OnPropertyChanged(string name)
{
base.OnPropertyChanged(name);
// Reload the item when the itemId changes
if (name.Equals("ItemId"))
{
await ReloadItem();
}
}
///
/// Reloads the item.
///
/// Task.
private async Task ReloadItem()
{
try
{
Item = await App.Instance.ApiClient.GetItemAsync(ItemId, App.Instance.CurrentUser.Id);
}
catch (HttpException)
{
App.Instance.ShowDefaultErrorMessage();
}
}
///
/// Called when [item changed].
///
protected virtual void OnItemChanged()
{
SetBackdrops(Item);
}
///
/// Plays this instance.
///
public async void Play()
{
await UIKernel.Instance.PlaybackManager.Play(new PlayOptions
{
Items = new List { Item }
});
}
///
/// Resumes this instance.
///
public async void Resume()
{
await UIKernel.Instance.PlaybackManager.Play(new PlayOptions
{
Items = new List { Item },
Resume = true
});
}
///
/// Queues this instance.
///
public void Queue()
{
}
}
}