Implement Content/Video/Image/Music provider
authorKyuho Jo <kyuho.jo@samsung.com>
Tue, 11 Apr 2017 08:49:49 +0000 (17:49 +0900)
committerKyuho Jo <kyuho.jo@samsung.com>
Tue, 11 Apr 2017 11:35:27 +0000 (20:35 +0900)
Signed-off-by: Kyuho Jo <kyuho.jo@samsung.com>
Change-Id: Ib057ce26685013ad7906703aa4515255eaad35ef

TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs [new file with mode: 0644]
TVMediaHub/TVMediaHub.Tizen/Models/GroupItem.cs
TVMediaHub/TVMediaHub.Tizen/Models/ImageProvider.cs
TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs
TVMediaHub/TVMediaHub.Tizen/Models/VideoProvider.cs
TVMediaHub/TVMediaHub.Tizen/TVMediaHub.Tizen.csproj
TVMediaHub/TVMediaHub.Tizen/TVMediaHub.Tizen.project.json
TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs

diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs
new file mode 100644 (file)
index 0000000..87e7f80
--- /dev/null
@@ -0,0 +1,215 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+using Tizen;
+using Tizen.Content.MediaContent;
+
+namespace TVMediaHub.Tizen.Models
+{
+    public enum SortOption
+    {
+        Date,   // Video, Image, Music
+        Title,  // Video, Image, Music
+        Album,  // Music
+        Artist, // Music
+        Genre,  // Video, Music
+        Folder, // Music
+        Type,   // Image
+    }
+
+    public abstract class ContentProvider
+    {
+        abstract protected string GetConditionStringForSelection();
+
+        private EventHandler UpdateListeners;
+
+        private string TAG = "MediaHub";
+        private string GetDateString(DateTime date)
+        {
+            DateTime yesterDay = DateTime.Today;
+
+            yesterDay.AddDays(-1);
+
+            if (DateTime.Today == date)
+            {
+                return "Today";
+            }
+            else if (yesterDay == date)
+            {
+                return "Yesterday";
+            }
+
+            return date.ToString("ddd. d MMMM");
+        }
+
+
+        private GroupItem GetGroupItem(SortOption sortOption, GroupItem lastGroupItem, MediaInformation mediaInformation)
+        {
+            GroupItem currentGroupItem = lastGroupItem;
+            string newTitle = null;
+            bool newGroupFlag = false;
+
+            switch (sortOption)
+            {
+                case SortOption.Title:
+                    if (lastGroupItem == null || lastGroupItem.Title != mediaInformation.DisplayName[0].ToString())
+                    {
+                        newGroupFlag = true;
+                        newTitle = mediaInformation.DisplayName[0].ToString();
+                    }
+                    break;
+                case SortOption.Date:
+                    if (lastGroupItem == null || lastGroupItem.Title != GetDateString(mediaInformation.TimeLine))
+                    {
+                        newGroupFlag = true;
+                        newTitle = GetDateString(mediaInformation.TimeLine);
+                    }
+                    break;
+                case SortOption.Genre:
+                    if (lastGroupItem == null || lastGroupItem.Title != mediaInformation.Category)
+                    {
+                        newGroupFlag = true;
+                        newTitle = mediaInformation.Category;
+                    }
+                    break;
+                case SortOption.Type:
+                    if (lastGroupItem == null || lastGroupItem.Title != mediaInformation.MediaType.ToString())
+                    {
+                        newGroupFlag = true;
+                        newTitle = mediaInformation.MediaType.ToString();
+                    }
+                    break;
+                default:
+                    throw new System.ArgumentException("Invalid sorting option.");
+            }
+
+            if (newGroupFlag == true)
+            {
+                currentGroupItem = new GroupItem();
+                currentGroupItem.Title = newTitle;
+                currentGroupItem.Contents = new List<MediaInformation>();
+            }
+
+            return currentGroupItem;
+        }
+
+        private IEnumerable<GroupItem> MakeGroups(IEnumerable<MediaInformation> mediaInformations, SortOption sortOption)
+        {
+            List<GroupItem> result = new List<GroupItem>();
+            GroupItem lastGroupItem = null;
+            GroupItem currentGroupItem = null;
+
+            foreach (MediaInformation mediaInformation in mediaInformations)
+            {
+                currentGroupItem = GetGroupItem(sortOption, currentGroupItem, mediaInformation);
+
+                if (lastGroupItem != currentGroupItem)
+                {
+                    result.Add(currentGroupItem);
+                    lastGroupItem = currentGroupItem;
+                }
+
+                if (currentGroupItem != null)
+                    currentGroupItem.Contents.Add(mediaInformation);
+                else
+                    throw new System.Exception("Something's wrong on making a GroupItem. Check your logic.");
+
+            }
+
+            return result;
+        }
+
+        public IEnumerable<MediaInformation> ReadWithoutGroup(SortOption sortOption, string storageId = null, int offset = -1, int count = -1)
+        {
+            // Makes Content Filter by arguments
+            var contentFilter = new ContentFilter();
+
+            switch (sortOption)
+            {
+                case SortOption.Title:
+                    contentFilter.OrderKey = "MEDIA_DISPLAY_NAME";
+                    break;
+                case SortOption.Date:
+                    contentFilter.OrderKey = "MEDIA_RECORDED_DATE";
+                    break;
+                case SortOption.Genre:
+                    contentFilter.OrderKey = "MEDIA_GENRE";
+                    break;
+                case SortOption.Type:
+                    contentFilter.OrderKey = "MEDIA_TYPE";
+                    break;
+                default:
+                    throw new System.ArgumentException("Invalid sorting option.");
+            }
+
+            if (offset >= 0)
+                contentFilter.Offset = offset;
+
+            if (count >= 0)
+                contentFilter.Count = count;
+
+            if (storageId != null)
+                contentFilter.StorageId = storageId;
+
+            contentFilter.Condition = GetConditionStringForSelection();
+
+            // Executes the 'select' query
+            IEnumerable<MediaInformation> mediaInformations = null;
+
+            try
+            {
+                mediaInformations = ContentManager.Database.SelectAll<MediaInformation>(contentFilter);
+            }
+            catch (Exception exception)
+            {
+                Log.Debug(TAG, exception.Message);
+            }
+
+            return mediaInformations;
+        }
+
+        public IEnumerable<GroupItem> Read(SortOption sortOption, string storageId = null, int offset = -1, int count = -1)
+        {
+            return MakeGroups(ReadWithoutGroup(sortOption, storageId, offset, count), sortOption);
+        }
+
+        public MediaInformation Read(String mediaID)
+        {
+            return ContentManager.Database.Select(mediaID);
+        }
+
+        bool Delete(MediaInformation media)
+        {
+            // TODO : delete
+            return true;
+        }
+
+        bool Update(MediaInformation media)
+        {
+            // TODO : update
+            return true;
+        }
+
+        void SetUpdateListener(EventHandler listener)
+        {
+            UpdateListeners += listener;
+        }
+    }
+}
index 8ca8231..8b16775 100644 (file)
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
- using System.Collections.Generic;
+using System.Collections.Generic;
 using Tizen.Content.MediaContent;
 
 namespace TVMediaHub.Tizen.Models
@@ -23,8 +23,6 @@ namespace TVMediaHub.Tizen.Models
     {
         public string Title { get; set; }
 
-        // TODO : revert this when platform api is adding
-        //public ICollection<MediaInformation> Contents { get; set; }
-        public ICollection<string> Contents { get; set; }
+        public ICollection<MediaInformation> Contents { get; set; }
     }
 }
index 0a5430e..104ce75 100644 (file)
  */
 
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Tizen.Content.MediaContent;
 
 namespace TVMediaHub.Tizen.Models
 {
-    public class ImageProvider
+    public class ImageProvider : ContentProvider
     {
-        // TODO :remove
-        List<GroupItem> Contents = new List<GroupItem>()
-            {
-                new GroupItem()
-                {
-                    Title = "A",
-                    Contents = new List<String>()
-                    {
-                        "AAAA_IMG_1",
-                        "AAAA_IMG_2",
-                        "AAAA_IMG_3",
-                        "AAAA_IMG_4",
-                        "AAAA_IMG_5",
-                    }
-                },
-                new GroupItem()
-                {
-                    Title = "B",
-                    Contents = new List<String>()
-                    {
-                        "BBBB_IMG_1",
-                        "BBBB_IMG_2",
-                        "BBBB_IMG_3",
-                        "BBBB_IMG_4",
-                        "BBBB_IMG_5",
-                    }
-                },
-                new GroupItem()
-                {
-                    Title = "C",
-                    Contents = new List<String>()
-                    {
-                        "CCCC_IMG_1",
-                        "CCCC_IMG_2",
-                        "CCCC_IMG_3",
-                        "CCCC_IMG_4",
-                        "CCCC_IMG_5",
-                    }
-                },
-            };
-
-        public enum SortOption
-        {
-            Date,
-            Type,
-            Name
-        }
-
-        private EventHandler UpdateListeners;
-
-        public ImageProvider()
-        {
-            // TODO : register to MediaContent.ContentDatabase to get notification
-            // {
-            //  register to MediaContent.ContentDatabase () => {
-            //    UpdateListeners.invoke();
-            //  }
-            // }
-        }
-
-        // TODO : remove this pragma
-#pragma warning disable CS1998 // 이 비동기 메서드에는 'await' 연산자가 없으며 메서드가 동시에 실행됩니다.
-        async Task<IEnumerable<GroupItem>> Read(int offset, int count)
-#pragma warning restore CS1998 // 이 비동기 메서드에는 'await' 연산자가 없으며 메서드가 동시에 실행됩니다.
-        {
-            // TODO : get content from Tizen.MediaContent
-            return Contents;
-        }
-
-        /*
-        Async Task<MediaInformation> Read(String mediaID)
-        {
-            // TODO : get media information from Tizen.MediaContent
-        }
-        */
-
-        bool Delete(MediaInformation media)
-        {
-            // TODO : delete
-            return true;
-        }
-
-        bool Update(MediaInformation media)
-        {
-            // TODO : update
-            return true;
-        }
-
-        double Count()
-        {
-            // TODO : get total amount of medias that meet with sorting filter
-            return Contents.Count;
-        }
-
-        bool Sort(SortOption sortOption)
-        {
-            // TODO : set filter which is matched with SortOption
-            //        App should get list again after calling sort().
-            return true;
-        }
-
-        void SetUpdateListener(EventHandler listener)
+        protected override string GetConditionStringForSelection()
         {
-            UpdateListeners += listener;
+            return "(MEDIA_TYPE=0)";
         }
     }
 }
index 1013c41..fb731c5 100644 (file)
  */
 
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Tizen.Content.MediaContent;
 
 namespace TVMediaHub.Tizen.Models
 {
-    public class MusicProvider
+    public class MusicProvider : ContentProvider
     {
-        // TODO :remove
-        List<GroupItem> Contents = new List<GroupItem>()
-            {
-                new GroupItem()
-                {
-                    Title = "A",
-                    Contents = new List<String>()
-                    {
-                        "AAAA_Video_1",
-                        "AAAA_Video_2",
-                        "AAAA_Video_3",
-                        "AAAA_Video_4",
-                        "AAAA_Video_5",
-                    }
-                },
-                new GroupItem()
-                {
-                    Title = "B",
-                    Contents = new List<String>()
-                    {
-                        "BBBB_Video_1",
-                        "BBBB_Video_2",
-                        "BBBB_Video_3",
-                        "BBBB_Video_4",
-                        "BBBB_Video_5",
-                    }
-                },
-                new GroupItem()
-                {
-                    Title = "C",
-                    Contents = new List<String>()
-                    {
-                        "CCCC_Video_1",
-                        "CCCC_Video_2",
-                        "CCCC_Video_3",
-                        "CCCC_Video_4",
-                        "CCCC_Video_5",
-                    }
-                },
-            };
-
-        public enum SortOption
-        {
-            Title,
-            Album,
-            Artist,
-            Genre,
-            Folder
-        }
-
-        private EventHandler UpdateListeners;
-
-        public MusicProvider()
-        {
-            // TODO : register to MediaContent.ContentDatabase to get notification
-            // {
-            //  register to MediaContent.ContentDatabase () => {
-            //    UpdateListeners.invoke();
-            //  }
-            // }
-        }
-
-        // TODO : remove this pragma
-#pragma warning disable CS1998 // 이 비동기 메서드에는 'await' 연산자가 없으며 메서드가 동시에 실행됩니다.
-        async Task<IEnumerable<GroupItem>> Read(int offset, int count)
-#pragma warning restore CS1998 // 이 비동기 메서드에는 'await' 연산자가 없으며 메서드가 동시에 실행됩니다.
-        {
-            // TODO : get content from Tizen.MediaContent
-            return Contents;
-        }
-
-        /*
-        Async Task<MediaInformation> Read(String mediaID)
-        {
-            // TODO : get media information from Tizen.MediaContent
-        }
-        */
-
-        bool Delete(MediaInformation media)
-        {
-            // TODO : delete
-            return true;
-        }
-
-        bool Update(MediaInformation media)
-        {
-            // TODO : update
-            return true;
-        }
-
-        double Count()
-        {
-            // TODO : get total amount of medias that meet with sorting filter
-            return Contents.Count;
-        }
-
-        bool Sort(SortOption sortOption)
-        {
-            // TODO : set filter which is matched with SortOption
-            //        App should get list again after calling sort().
-            return true;
-        }
-
-        void SetUpdateListener(EventHandler listener)
+        protected override string GetConditionStringForSelection()
         {
-            UpdateListeners += listener;
+            return "(MEDIA_TYPE=8)";
         }
     }
 }
index 1e83520..340020a 100644 (file)
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Tizen.Content.MediaContent;
 
 namespace TVMediaHub.Tizen.Models
 {
-    public class VideoProvider
+    public class VideoProvider : ContentProvider
     {
-        // TODO :remove
-        List<GroupItem> Contents = new List<GroupItem>()
-            {
-                new GroupItem()
-                {
-                    Title = "A",
-                    Contents = new List<String>()
-                    {
-                        "AAAA_Video_1",
-                        "AAAA_Video_2",
-                        "AAAA_Video_3",
-                        "AAAA_Video_4",
-                        "AAAA_Video_5",
-                    }
-                },
-                new GroupItem()
-                {
-                    Title = "B",
-                    Contents = new List<String>()
-                    {
-                        "BBBB_Video_1",
-                        "BBBB_Video_2",
-                        "BBBB_Video_3",
-                        "BBBB_Video_4",
-                        "BBBB_Video_5",
-                    }
-                },
-                new GroupItem()
-                {
-                    Title = "C",
-                    Contents = new List<String>()
-                    {
-                        "CCCC_Video_1",
-                        "CCCC_Video_2",
-                        "CCCC_Video_3",
-                        "CCCC_Video_4",
-                        "CCCC_Video_5",
-                    }
-                },
-            };
-
-        public enum SortOption
-        {
-            Name,
-            Date,
-            Genre
-        }
-
-        private EventHandler UpdateListeners;
-
-        public VideoProvider()
-        {
-            // TODO : register to MediaContent.ContentDatabase to get notification
-            // {
-            //  register to MediaContent.ContentDatabase () => {
-            //    UpdateListeners.invoke();
-            //  }
-            // }
-        }
-
-        // TODO : remove this pragma
-#pragma warning disable CS1998 // 이 비동기 메서드에는 'await' 연산자가 없으며 메서드가 동시에 실행됩니다.
-        public async Task<IEnumerable<GroupItem>> Read(int offset, int count)
-#pragma warning restore CS1998 // 이 비동기 메서드에는 'await' 연산자가 없으며 메서드가 동시에 실행됩니다.
-        {
-            // TODO : get content from Tizen.MediaContent SelectAsync
-            return Contents;
-        }
-
-        /*
-        Async Task<MediaInformation> Read(String mediaID)
-        {
-            // TODO : get media information from Tizen.MediaContent
-        }
-        */
-
-        bool Delete(MediaInformation media)
-        {
-            // TODO : delete
-            return true;
-        }
-
-        bool Update(MediaInformation media)
-        {
-            // TODO : update
-            return true;
-        }
-
-        double Count()
-        {
-            // TODO : get total amount of medias that meet with sorting filter
-            return Contents.Count;
-        }
-
-        bool Sort(SortOption sortOption)
-        {
-            // TODO : set filter which is matched with SortOption
-            //        App should get list again after calling sort().
-            return true;
-        }
-
-        void SetUpdateListener(EventHandler listener)
+        protected override string GetConditionStringForSelection()
         {
-            UpdateListeners += listener;
+            return "(MEDIA_TYPE=1)";
         }
     }
-}
+}
\ No newline at end of file
index 2d3290a..6c074ad 100755 (executable)
@@ -48,6 +48,7 @@
     <None Include="shared\res\xamediahub.png" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Models\ContentProvider.cs" />
     <Compile Include="Models\GroupItem.cs" />
     <Compile Include="Models\ImageProvider.cs" />
     <Compile Include="Models\MediaHubImpl.cs" />
index 5d9ddfd..b9eab8b 100755 (executable)
@@ -6,12 +6,13 @@
     "preserveCompilationContext": true
   },
   "dependencies": {
-    "ElmSharp": "1.1.0-beta-018",
+    "ElmSharp": "1.1.0-beta-019",
     "Microsoft.NETCore.App": "1.1.1",
-    "Tizen.Library": "1.0.0-pre2",
+    "Tizen.Content.MediaContent": "1.0.16",
+    "Tizen.Library": "1.0.0-pre3",
     "Tizen.Xamarin.Forms.Extension": "2.3.4-r214-001",
     "Xamarin.Forms": "2.3.4.214-pre5",
-    "Xamarin.Forms.Platform.Tizen": "2.3.4-r214-002"
+    "Xamarin.Forms.Platform.Tizen": "2.3.4-r214-003"
   },
   "runtimes": {
     "win": {},
index e3d00a3..7b7642c 100644 (file)
@@ -54,7 +54,7 @@ namespace TVMediaHub.Tizen.ViewModels
 
         private async void ReadVideoList()
         {
-            VideoList = await MediaHubImpl.GetInstance.VideoProviderInstance.Read(0, 0);
+            VideoList = MediaHubImpl.GetInstance.VideoProviderInstance.Read(SortOption.Title);
             OnPropertyChanged("VideoList");
         }
     }