Implements the method for showing toast popup source is removed 27/134027/2
authorHyerim Kim <rimi.kim@samsung.com>
Wed, 14 Jun 2017 08:24:57 +0000 (17:24 +0900)
committerHyerim Kim <rimi.kim@samsung.com>
Wed, 14 Jun 2017 08:28:34 +0000 (08:28 +0000)
Change-Id: Iff30201064801f39a2244402153ff97b6b421471
Signed-off-by: Hyerim Kim <rimi.kim@samsung.com>
TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs
TVMediaHub/TVMediaHub.Tizen/Models/ImageProvider.cs
TVMediaHub/TVMediaHub.Tizen/Models/StorageProvider.cs
TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs
TVMediaHub/TVMediaHub.Tizen/ViewModels/MediaHubMainPageViewModel.cs
TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs
TVMediaHub/TVMediaHub.Tizen/Views/MediaHubMainPage.xaml
TVMediaHub/TVMediaHub.Tizen/Views/MediaHubMainPage.xaml.cs

index 3ffb646..264090d 100755 (executable)
@@ -17,7 +17,6 @@
 using System;
 using System.Collections.Generic;
 using System.Threading.Tasks;
-using Tizen;
 using Tizen.Content.MediaContent;
 using TVMediaHub.Tizen.Utils;
 using TVMediaHub.Tizen.DataModels;
index 1db692b..ea3aa87 100755 (executable)
@@ -16,7 +16,6 @@
 
 using System;
 using System.IO;
-using Tizen.Content.MediaContent;
 using TVMediaHub.Tizen.Utils;
 using TVMediaHub.Tizen.DataModels;
 
index 39a80d1..6dbc012 100755 (executable)
  * 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
@@ -30,32 +40,82 @@ namespace TVMediaHub.Tizen.Models
         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;
         }
     }
 }
index 4e8371f..29869fe 100755 (executable)
@@ -57,6 +57,11 @@ namespace TVMediaHub.Tizen.ViewModels
         private SortOption option = SortOption.Date;
 
         /// <summary>
+        /// A storage id
+        /// </summary>
+        private string storageId = null;
+
+        /// <summary>
         /// Gets or sets the displayingImageIndex
         /// </summary>
         private int DisplayingImageIndex
@@ -381,14 +386,13 @@ namespace TVMediaHub.Tizen.ViewModels
             {
                 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);
                 }, "");
             });
 
@@ -455,7 +459,7 @@ namespace TVMediaHub.Tizen.ViewModels
             {
                 SynchronizationContext.Current.Post((o) =>
                 {
-                    ReadImageList(option);
+                    ReadImageList(option, storageId);
                 }, "");
             });
 
@@ -493,7 +497,6 @@ namespace TVMediaHub.Tizen.ViewModels
         /// </summary>
         private void AddSourceListItem()
         {
-            int index = 1;
             sourcePairList.Clear();
             List<string> tempList = new List<string>();
 
@@ -503,15 +506,13 @@ namespace TVMediaHub.Tizen.ViewModels
             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");
         }
 
index 2529331..8ed51f2 100755 (executable)
@@ -15,8 +15,9 @@
  */
 
 using System.ComponentModel;
-using Xamarin.Forms;
 using System.Runtime.CompilerServices;
+using TVMediaHub.Tizen.Models;
+using TVMediaHub.Tizen.Utils;
 
 namespace TVMediaHub.Tizen.ViewModels
 {
@@ -26,13 +27,9 @@ 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
@@ -40,53 +37,11 @@ namespace TVMediaHub.Tizen.ViewModels
         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)
@@ -96,27 +51,16 @@ namespace TVMediaHub.Tizen.ViewModels
         }
 
         /// <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");
             });
         }
     }
index 5b75e26..480aad2 100755 (executable)
@@ -25,6 +25,7 @@ using TVMediaHub.Tizen.Models;
 using TVMediaHub.Tizen.Utils;
 using TVMediaHub.Tizen.DataModels;
 using Xamarin.Forms;
+using Tizen.Xamarin.Forms.Extension;
 
 namespace TVMediaHub.Tizen.ViewModels
 {
@@ -136,6 +137,11 @@ 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; }
@@ -296,21 +302,20 @@ namespace TVMediaHub.Tizen.ViewModels
             {
                 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) =>
@@ -403,7 +408,6 @@ namespace TVMediaHub.Tizen.ViewModels
         /// </summary>
         private void AddSourceListItem()
         {
-            int index = 1;
             sourcePairList.Clear();
             List<string> tempList = new List<string>();
 
@@ -413,15 +417,13 @@ namespace TVMediaHub.Tizen.ViewModels
             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");
         }
 
index aa5f343..90bb86d 100755 (executable)
@@ -3,7 +3,8 @@
             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/>
index ad222cd..9ba4c5d 100755 (executable)
@@ -17,7 +17,9 @@
 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;
 
@@ -30,6 +32,20 @@ namespace TVMediaHub.Tizen.Views
     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;
@@ -41,9 +57,28 @@ namespace TVMediaHub.Tizen.Views
         {
             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>
@@ -51,7 +86,7 @@ namespace TVMediaHub.Tizen.Views
         /// </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();