using System;
using System.Collections.Generic;
using System.Threading.Tasks;
-using Tizen;
using Tizen.Content.MediaContent;
using TVMediaHub.Tizen.Utils;
using TVMediaHub.Tizen.DataModels;
using System;
using System.IO;
-using Tizen.Content.MediaContent;
using TVMediaHub.Tizen.Utils;
using TVMediaHub.Tizen.DataModels;
* limitations under the License.
*/
+using System;
using System.Collections.Generic;
+using System.Linq;
using Tizen.Content.MediaContent;
namespace TVMediaHub.Tizen.Models
{
/// <summary>
+ /// A custom EventArgs with string fields
+ /// </summary>
+ public class StorageInfoEventArgs : EventArgs
+ {
+ public string storageName;
+ }
+
+ /// <summary>
/// A StorageProvider for the media hub
/// </summary>
public class StorageProvider
private IEnumerable<Storage> storageList = new List<Storage>();
/// <summary>
- /// A list of storage id
+ /// A dictionary list of storage name and storage id
+ /// Keeps the values when the media hub application is terminated.
+ /// </summary>
+ private Dictionary<string, string> storageTable = new Dictionary<string, string>();
+ private static int index = 1;
+
+ /// <summary>
+ /// A dictionary list of storage name and storage id
/// </summary>
- public List<string> StorageId { get; protected set; }
+ public Dictionary<string, string> StoragePairList { get; protected set; }
+
+ /// <summary>
+ /// An EventHandler that is occured when source is removed
+ /// </summary>
+ public EventHandler SourceRemovedEvent;
/// <summary>
/// A constructor
/// </summary>
public StorageProvider()
{
- StorageId = new List<string>();
+ StoragePairList = new Dictionary<string, string>();
CheckStorage();
}
/// <summary>
/// Returns the list of the storage id of the media storage.
/// </summary>
- /// <returns>Task with the list of the ContentCollection</returns>
public void CheckStorage()
{
- StorageId.Clear();
storageList = ContentManager.Database.SelectAll<Storage>(null);
+ if (storageList.Count() < storageTable.Count)
+ {
+ CheckRemoveStorage();
+ }
+ StoragePairList.Clear();
foreach (var item in storageList)
{
- StorageId.Add(item.Id);
+ if (!storageTable.ContainsKey(item.Id))
+ {
+ storageTable.Add(item.Id, "USB " + index++);
+ }
+
+ StoragePairList.Add(item.Id, storageTable[item.Id]);
}
+
+ StoragePairList = StoragePairList.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
+ }
+
+ /// <summary>
+ /// Checks the removed storage name and invokes the SourceRemoveedEvent with storage name.
+ /// </summary>
+ private void CheckRemoveStorage()
+ {
+ foreach (var item in storageTable)
+ {
+ Storage storage = ContentManager.Database.Select<Storage>(item.Key);
+
+ if (storage == null)
+ {
+ StorageInfoEventArgs args = new StorageInfoEventArgs();
+ args.storageName = item.Value;
+
+ SourceRemovedEvent?.Invoke(this, args);
+ }
+ }
+ }
+
+ /// <summary>
+ /// A method for handling SourceRemoveEvent
+ /// </summary>
+ /// <param name="listener">A handling method</param>
+ public void SetSourceRemoveEventListener(EventHandler listener)
+ {
+ this.SourceRemovedEvent += listener;
}
}
}
private SortOption option = SortOption.Date;
/// <summary>
+ /// A storage id
+ /// </summary>
+ private string storageId = null;
+
+ /// <summary>
/// Gets or sets the displayingImageIndex
/// </summary>
private int DisplayingImageIndex
{
if (name == null)
{
- DbgPort.D("name is null");
return;
}
- string id = sourcePairList[name];
+ storageId = sourcePairList[name];
SynchronizationContext.Current.Post((o) =>
{
- ReadImageList(option, id);
+ ReadImageList(option, storageId);
}, "");
});
{
SynchronizationContext.Current.Post((o) =>
{
- ReadImageList(option);
+ ReadImageList(option, storageId);
}, "");
});
/// </summary>
private void AddSourceListItem()
{
- int index = 1;
sourcePairList.Clear();
List<string> tempList = new List<string>();
tempList.Add("ALL SOURCE");
tempList.Add("DEVICE");
- foreach (var item in MediaHubImpl.GetInstance.StorageProviderInstance.StorageId)
+ foreach (var item in MediaHubImpl.GetInstance.StorageProviderInstance.StoragePairList)
{
- sourcePairList.Add("USB " + index, item);
- tempList.Add("USB " + index);
- index++;
+ sourcePairList.Add(item.Value, item.Key);
+ tempList.Add(item.Value);
}
SourceList = tempList;
-
OnPropertyChanged("SourceList");
}
*/
using System.ComponentModel;
-using Xamarin.Forms;
using System.Runtime.CompilerServices;
+using TVMediaHub.Tizen.Models;
+using TVMediaHub.Tizen.Utils;
namespace TVMediaHub.Tizen.ViewModels
{
class MediaHubMainPageViewModel : INotifyPropertyChanged
{
/// <summary>
- /// A flag that whether footer is normal mode or not
+ /// A name of source
/// </summary>
- bool isFooterNor;
- /// <summary>
- /// A flag that whether footer is select mode or not
- /// </summary>
- bool isFooterSel;
+ public string SourceName { get; set; }
/// <summary>
/// An event that is occurred when property of MediaHubMainPageViewModel is changed
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
- /// Gets or sets the isFooterNor
- /// </summary>
- public bool IsFooterNorStatus
- {
- set
- {
- if (isFooterNor != value)
- {
- isFooterNor = value;
- OnPropertyChanged();
- IsFooterSelStatus = !IsFooterNorStatus;
- }
- }
-
- get
- {
- return isFooterNor;
- }
- }
-
- /// <summary>
- /// Gets or sets the isFooterSel
- /// </summary>
- public bool IsFooterSelStatus
- {
- set
- {
- if (isFooterSel != value)
- {
- isFooterSel = value;
- OnPropertyChanged();
- }
- }
-
- get
- {
- return isFooterSel;
- }
- }
-
- /// <summary>
/// A method for invoking PropertyChanged event
/// </summary>
/// <param name="propertyName">The name of property</param>
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
-
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
}
/// <summary>
- /// A Command for changing footer's status to select mode.
- /// </summary>
- public Command OnSeleteModeCommand { get; set; }
-
- /// <summary>
/// A consturctor
- /// Initializes OnSelectModeCommand that is called to change the footer to select mode
+ /// Implements the SourceRemoveEventListener
/// </summary>
public MediaHubMainPageViewModel()
{
- IsFooterNorStatus = true;
- OnSeleteModeCommand = new Command(() =>
+ MediaHubImpl.GetInstance.StorageProviderInstance.SetSourceRemoveEventListener((sender, arg) =>
{
- if (IsFooterNorStatus)
- {
- IsFooterNorStatus = false;
- }
- else
- {
- IsFooterNorStatus = true;
- }
+ StorageInfoEventArgs e = arg as StorageInfoEventArgs;
+ SourceName = e.storageName;
+ OnPropertyChanged("SourceName");
});
}
}
using TVMediaHub.Tizen.Utils;
using TVMediaHub.Tizen.DataModels;
using Xamarin.Forms;
+using Tizen.Xamarin.Forms.Extension;
namespace TVMediaHub.Tizen.ViewModels
{
private SortOption option = SortOption.Title;
/// <summary>
+ /// A storage id
+ /// </summary>
+ private string storageId = null;
+
+ /// <summary>
/// Gets or sets the MediaInformationEx of current video
/// </summary>
public MediaInformationEx CurrentVideo { get; set; }
{
SynchronizationContext.Current.Post((o) =>
{
- ReadVideoList(option);
+ ReadVideoList(option, storageId);
}, "");
});
ChangeSourceCommand = new Command<string>((name) =>
{
if (name == null)
{
- DbgPort.D("name is null");
return;
}
- string id = sourcePairList[name];
+ storageId = sourcePairList[name];
SynchronizationContext.Current.Post((o) =>
{
- ReadVideoList(option, id);
+ ReadVideoList(option, storageId);
}, "");
});
SetCurrentVideoInfo = new Command<MediaInformationEx>((info) =>
/// </summary>
private void AddSourceListItem()
{
- int index = 1;
sourcePairList.Clear();
List<string> tempList = new List<string>();
tempList.Add("ALL SOURCE");
tempList.Add("DEVICE");
- foreach (var item in MediaHubImpl.GetInstance.StorageProviderInstance.StorageId)
+ foreach (var item in MediaHubImpl.GetInstance.StorageProviderInstance.StoragePairList)
{
- sourcePairList.Add("USB " + index, item);
- tempList.Add("USB " + index);
- index++;
+ sourcePairList.Add(item.Value, item.Key);
+ tempList.Add(item.Value);
}
SourceList = tempList;
-
OnPropertyChanged("SourceList");
}
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TVMediaHub.Tizen.Views.MediaHubMainPage"
xmlns:Views="clr-namespace:TVMediaHub.Tizen.Views"
- Title="MEDIA HUB">
+ Title="MEDIA HUB"
+ SourceName="{Binding SourceName}">
<Views:VideoTab/>
<Views:ImageTab/>
<Views:MusicTab/>
using System;
using System.Threading;
using System.Threading.Tasks;
+using Tizen.Xamarin.Forms.Extension;
using TVMediaHub.Tizen.Controls;
+using TVMediaHub.Tizen.ViewModels;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
public partial class MediaHubMainPage : TabbedPage
{
/// <summary>
+ /// Identifies the SourceName bindable property
+ /// </summary>
+ public static readonly BindableProperty SourceNameProperty = BindableProperty.Create("SourceName", typeof(string), typeof(MediaHubMainPage), null, BindingMode.TwoWay);
+
+ /// <summary>
+ /// Gets or sets the source name
+ /// </summary>
+ public string SourceName
+ {
+ get { return (string)GetValue(SourceNameProperty); }
+ set { SetValue(SourceNameProperty, value); }
+ }
+
+ /// <summary>
/// A flag that whether app is loaded or not
/// </summary>
private bool IsAppLoaded;
{
IsAppLoaded = false;
InitializeComponent();
+ BindingContext = new MediaHubMainPageViewModel();
NavigationPage.SetHasBackButton(this, false);
NavigationPage.SetHasNavigationBar(this, true);
- CurrentPageChanged += MediaHubMainPage_CurrentPageChanged;
+ CurrentPageChanged += MediaHubMainPageCurrentPageChanged;
+ PropertyChanged += MediaHubMainPagePropertyChanged;
+ }
+
+ /// <summary>
+ /// This method is called when the properties is changed
+ /// </summary>
+ /// <param name="sender">The source of the event</param>
+ /// <param name="e">A propertyChanged event argument</param>
+ private void MediaHubMainPagePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
+ {
+ if (e.PropertyName.Equals("SourceName"))
+ {
+ if (SourceName != null)
+ {
+ Toast.DisplayText(SourceName + " Disconnected.");
+ SourceName = null;
+ }
+ }
}
/// <summary>
/// </summary>
/// <param name="sender">The source of event</param>
/// <param name="e">An event argument</param>
- private void MediaHubMainPage_CurrentPageChanged(object sender, EventArgs e)
+ private void MediaHubMainPageCurrentPageChanged(object sender, EventArgs e)
{
var page = CurrentPage as ContentPageEx;
page.RunShowAnimation();