New feature : Show recently played media files on recent tab
authorKyuho Jo <kyuho.jo@samsung.com>
Wed, 3 May 2017 09:09:46 +0000 (18:09 +0900)
committerChulSeung Kim <charles0.kim@samsung.com>
Thu, 8 Jun 2017 09:34:53 +0000 (18:34 +0900)
Signed-off-by: Kyuho Jo <kyuho.jo@samsung.com>
Change-Id: Id6cd916b911b52ee8a0f61cc33d70dd178e75567

14 files changed:
LibTVRefCommonPortable/DataModels/AppControlAction.cs
LibTVRefCommonPortable/DataModels/RecentShortcutInfo.cs
LibTVRefCommonPortable/LibTVRefCommonPortable.csproj
LibTVRefCommonPortable/Models/RecentShortcutController.cs
LibTVRefCommonPortable/Utils/AppControlUtils.cs
LibTVRefCommonPortable/Utils/IAppControl.cs
LibTVRefCommonPortable/Utils/IMediaContentAPIs.cs [new file with mode: 0644]
LibTVRefCommonPortable/packages.config
LibTVRefCommonTizen/LibTVRefCommonTizen.csproj
LibTVRefCommonTizen/LibTVRefCommonTizen.project.json
LibTVRefCommonTizen/Ports/AppControlPort.cs
LibTVRefCommonTizen/Ports/MediaContentPort.cs [new file with mode: 0644]
TVHome/TVHome.TizenTV/TVHome.TizenTV.cs
TVHome/TVHome/Views/SubThumbnailPanel.xaml.cs

index dfc9969..d879dc1 100644 (file)
@@ -31,6 +31,16 @@ namespace LibTVRefCommonPortable.DataModels
         public string AppID { get; set; }
 
         /// <summary>
+        /// A file URI to be open
+        /// </summary>
+        public string FileUri { get; set; }
+
+        /// <summary>
+        /// A media id of MediaContent
+        /// </summary>
+        public string MediaId { get; set; }
+
+        /// <summary>
         /// A dictionary which has extra data for App Control
         /// </summary>
         private Dictionary<string, string> extraData;
@@ -57,17 +67,9 @@ namespace LibTVRefCommonPortable.DataModels
         /// <returns>a next state after App Control invocation</returns>
         public string Execute()
         {
-            string result = "default";
-            if (ExtraData == null)
-            {
-                AppControlUtils.SendLaunchRequest(AppID);
-            }
-            else
-            {
-                AppControlUtils.SendLaunchRequest(AppID, ExtraData);
-            }
-
-            return result;
+            // Warn : Do NOT pass 'E'xtraData, it will create a new Dictionary and it might cause unexpected situation.
+            AppControlUtils.SendLaunchRequest(AppID, extraData, FileUri);
+            return "default";
         }
     }
 }
index 96b2750..05a0180 100755 (executable)
  */
 
 using System;
+using System.Collections;
 
 namespace LibTVRefCommonPortable.DataModels
 {
     /// <summary>
+    /// Types for recent shortcut
+    /// </summary>
+    public enum RecentShortcutType
+    {
+        Application = 0,
+        Media = 1,
+    }
+
+    /// <summary>
     /// A Recent Shortcut information
     /// </summary>
-    public class RecentShortcutInfo : ShortcutInfo
+    public class RecentShortcutInfo : ShortcutInfo, IComparable
     {
         /// <summary>
-        /// An application ID
+        /// A type for the content of the shortcut
         /// </summary>
-        public string AppID { get; set; }
+        public RecentShortcutType Type { get; set; }
+
+        /// <summary>
+        /// An Id for the content of the shortcut
+        /// </summary>
+        public string Id { get; set; }
         /// <summary>
         /// A Last used Time
         /// </summary>
@@ -44,5 +59,11 @@ namespace LibTVRefCommonPortable.DataModels
         {
             SetCurrentState("default");
         }
+
+        int IComparable.CompareTo(object target)
+        {
+            var rightShortcutInfo = target as RecentShortcutInfo;
+            return Date.CompareTo(rightShortcutInfo.Date);
+        }
     }
 }
index acddb50..52a8703 100755 (executable)
@@ -54,6 +54,7 @@
     <Compile Include="Utils\AppControlUtils.cs" />
     <Compile Include="Utils\ApplicationManagerUtils.cs" />
     <Compile Include="Utils\AppShortcutStorage.cs" />
+    <Compile Include="Utils\IMediaContentAPIs.cs" />
     <Compile Include="Utils\ISystemSettings.cs" />
     <Compile Include="Utils\SizeUtils.cs" />
     <Compile Include="Utils\DateUtils.cs" />
@@ -74,7 +75,7 @@
   </ItemGroup>
   <ItemGroup>
     <Reference Include="Tizen.Xamarin.Forms.Extension, Version=0.0.1.0, Culture=neutral, processorArchitecture=MSIL">
-      <HintPath>..\packages\Tizen.Xamarin.Forms.Extension.2.3.4-r214-001\lib\portable-win+net45+wp80+win81+wpa81\Tizen.Xamarin.Forms.Extension.dll</HintPath>
+      <HintPath>..\packages\Tizen.Xamarin.Forms.Extension.2.3.5-r233-002\lib\portable-win+net45+wp80+win81+wpa81\Tizen.Xamarin.Forms.Extension.dll</HintPath>
       <Private>True</Private>
     </Reference>
     <Reference Include="Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
index 6d3c399..ad50acf 100755 (executable)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+using System;
 using System.Collections.Generic;
 using LibTVRefCommonPortable.DataModels;
 using LibTVRefCommonPortable.Utils;
@@ -71,82 +72,125 @@ namespace LibTVRefCommonPortable.Models
         public IEnumerable<RecentShortcutInfo> GetList()
         {
             List<RecentShortcutInfo> recentShortcutInfoList = new List<RecentShortcutInfo>();
+            IEnumerable<RecentApp> recentApps = null;
 
-            var defaultStateDescription = new StateDescription()
+            try
             {
-                Label = "Youtube",
-                IconPath = "ic_home_settings_all_138.png",
-                Action = new AppControlAction()
-                {
-                    AppID = "org.tizen.example.Youtube.TizenTV",
-                }
-            };
-            var recentShortcutInfo = new RecentShortcutInfo();
-            string testScreenShot = "org.tizen.example.Youtube.Tizen.png";
-
-            recentShortcutInfo.ScreenshotPath = testScreenShot;
-
-            recentShortcutInfo.StateDescriptions.Add("default", defaultStateDescription);
-            recentShortcutInfo.CurrentStateDescription = defaultStateDescription;
-            recentShortcutInfo.AppID = "org.tizen.example.Youtube.TizenTV";
-            recentShortcutInfoList.Add(recentShortcutInfo);
-
-            /*var recentApps = ApplicationManagerUtils.GetRecentApplications();
-            foreach (var item in recentApps)
+                recentApps = ApplicationManagerUtils.GetRecentApplications();
+            }
+            catch (Exception e)
             {
-                if (ManagedApps.IsHiddenRecentApp(item.AppID))
-                {
-                    continue;
-                }
+                DebuggingUtils.Err("GetRecentApplications failed. " + e.Message);
+            }
 
-                var defaultStateDescription = new StateDescription()
+            if (recentApps != null)
+            {
+                foreach (var item in recentApps)
                 {
-                    Label = item.Applabel,
-                    IconPath = item.IconPath,
-                    Action = new AppControlAction()
+                    if (ManagedApps.IsHiddenRecentApp(item.AppID))
                     {
-                        AppID = item.AppID,
+                        continue;
                     }
-                };
-                var recentShortcutInfo = new RecentShortcutInfo();
 
-                if (item.ScreenShot == null)
-                {
-                    recentShortcutInfo.ScreenshotPath = "screenshot.png";
-
-                    IFileSystemAPIs fsApi = DependencyService.Get<IFileSystemAPIs>();
-                    if (fsApi != null)
+                    var defaultStateDescription = new StateDescription()
                     {
-                        // Temporary, use preinstalled screenshot
-                        string capturedAppScreen = @"/tmp/" + item.AppID + ".jpg";
-                        if (fsApi.IsFileExist(capturedAppScreen))
+                        Label = item.Applabel,
+                        IconPath = item.IconPath,
+                        Action = new AppControlAction()
                         {
-                            recentShortcutInfo.ScreenshotPath = capturedAppScreen;
+                            AppID = item.AppID,
                         }
-                        else
+                    };
+                    var recentShortcutInfo = new RecentShortcutInfo();
+
+                    if (item.ScreenShot == null)
+                    {
+                        recentShortcutInfo.ScreenshotPath = "screenshot.png";
+
+                        IFileSystemAPIs fsApi = DependencyService.Get<IFileSystemAPIs>();
+                        if (fsApi != null)
                         {
-                            //string testScreenShot = fsApi.PlatformShareStorage + item.AppID + ".png";
-                            string testScreenShot = fsApi.AppResourceStorage + item.AppID + ".png";
-                            if (fsApi.IsFileExist(testScreenShot))
+                            // Temporary, use preinstalled screenshot
+                            string capturedAppScreen = @"/tmp/" + item.AppID + ".jpg";
+                            if (fsApi.IsFileExist(capturedAppScreen))
+                            {
+                                recentShortcutInfo.ScreenshotPath = capturedAppScreen;
+                            }
+                            else
                             {
-                                recentShortcutInfo.ScreenshotPath = testScreenShot;
+                                //string testScreenShot = fsApi.PlatformShareStorage + item.AppID + ".png";
+                                string testScreenShot = fsApi.AppResourceStorage + item.AppID + ".png";
+                                if (fsApi.IsFileExist(testScreenShot))
+                                {
+                                    recentShortcutInfo.ScreenshotPath = testScreenShot;
+                                }
                             }
                         }
                     }
+                    else
+                    {
+                        recentShortcutInfo.ScreenshotPath = item.ScreenShot;
+                    }
+
+                    recentShortcutInfo.StateDescriptions.Add("default", defaultStateDescription);
+                    recentShortcutInfo.CurrentStateDescription = defaultStateDescription;
+                    recentShortcutInfo.Id = item.AppID;
+                    recentShortcutInfoList.Add(recentShortcutInfo);
                 }
-                else
+            }
+            else
+            {
+                DebuggingUtils.Dbg("No recent apps");
+                var defaultStateDescription = new StateDescription()
                 {
-                    recentShortcutInfo.ScreenshotPath = item.ScreenShot;
-                }
+                    Label = "Youtube",
+                    IconPath = "ic_home_settings_all_138.png",
+                    Action = new AppControlAction()
+                    {
+                        AppID = "org.tizen.example.Youtube.TizenTV",
+                    }
+                };
+                var recentShortcutInfo = new RecentShortcutInfo();
+                string testScreenShot = "org.tizen.example.Youtube.Tizen.png";
+
+                recentShortcutInfo.ScreenshotPath = testScreenShot;
 
                 recentShortcutInfo.StateDescriptions.Add("default", defaultStateDescription);
                 recentShortcutInfo.CurrentStateDescription = defaultStateDescription;
-                recentShortcutInfo.AppID = item.AppID;
+                recentShortcutInfo.Id = "org.tizen.example.Youtube.TizenTV";
                 recentShortcutInfoList.Add(recentShortcutInfo);
-            }*/
+            }
 
-            return recentShortcutInfoList;
+            IMediaContentAPIs apiSet = DependencyService.Get<IMediaContentAPIs>();
+            var recentPlayedMedia = DependencyService.Get<IMediaContentAPIs>().GetRecentlyPladyedMedia(10);
+
+
+            foreach (var item in recentPlayedMedia)
+            {
+                // DebuggingUtils.Dbg("media :" + item.DisplayName + ", PlayedAt : " + item.PlayedAt.ToString());
+                var defaultStateDescription = new StateDescription()
+                {
+                    Label = item.DisplayName,
+                    IconPath = "ic_launcher_mediahub_138.png",
+                    Action = new AppControlAction()
+                    {
+                        AppID = "org.tizen.xamediahub",
+                        MediaId = item.MediaId,
+                        FileUri = "file://" + item.FilePath,
+                    }
+                };
+                var recentShortcutInfo = new RecentShortcutInfo();
 
+                recentShortcutInfo.ScreenshotPath = item.ThumbnailPath;
+                recentShortcutInfo.StateDescriptions.Add("default", defaultStateDescription);
+                recentShortcutInfo.CurrentStateDescription = defaultStateDescription;
+                recentShortcutInfo.Id = "org.tizen.xamediahub";
+                recentShortcutInfoList.Add(recentShortcutInfo);
+            }
+
+            recentShortcutInfoList.Sort();
+
+            return recentShortcutInfoList;
         }
     }
 }
index f6188d3..7add8b7 100644 (file)
@@ -25,32 +25,19 @@ namespace LibTVRefCommonPortable.Utils
     public sealed class AppControlUtils
     {
         /// <summary>
-        /// A method makes the package ID's app to be launched.
+        /// A method makes the app to be launched.
         /// </summary>
-        /// <param name="pkgID">A package ID of the targeted application.</param>
-        public static void SendLaunchRequest(string pkgID)
-        {
-            if (DependencyService.Get<IAppControl>() == null)
-            {
-                return;
-            }
-
-            DependencyService.Get<IAppControl>().SendLaunchRequest(pkgID);
-        }
-
-        /// <summary>
-        /// A method makes the package ID's app to be launched.
-        /// </summary>
-        /// <param name="pkgID">A package ID of the targeted application.</param>
+        /// <param name="appID">A application ID of the targeted application.</param>
         /// <param name="extraData">A extra data for App Control invoking.</param>
-        public static void SendLaunchRequest(string pkgID, IDictionary<string, string> extraData)
+        /// <param name="fileUri">A file Uri to be opened.</param>
+        public static void SendLaunchRequest(string appID, IDictionary<string, string> extraData = null, string fileUri = null)
         {
             if (DependencyService.Get<IAppControl>() == null)
             {
                 return;
             }
 
-            DependencyService.Get<IAppControl>().SendLaunchRequest(pkgID, extraData);
+            DependencyService.Get<IAppControl>().SendLaunchRequest(appID, extraData, fileUri);
         }
 
         /// <summary>
index ea57a98..dca0693 100644 (file)
@@ -25,17 +25,12 @@ namespace LibTVRefCommonPortable.Utils
     public interface IAppControl
     {
         /// <summary>
-        /// A method makes the package ID's app to be launched.
-        /// </summary>
-        /// <param name="pkgID">A package ID of the targeted application.</param>
-        void SendLaunchRequest(string pkgID);
-
-        /// <summary>
         /// Sends the launch request
         /// </summary>
-        /// <param name="AppId"> The app ID to explicitly launch</param>
+        /// <param name="appId"> The app ID to explicitly launch</param>
         /// <param name="extraData">The extra data for the app control</param>
-        void SendLaunchRequest(string AppId, IDictionary<string, string> extraData);
+        /// <param name="fileUri">The file uri to be opened</param>
+        void SendLaunchRequest(string appId, IDictionary<string, string> extraData, string fileUri);
 
         /// <summary>
         /// A method sends a add pin request App Control to TVApps app.
diff --git a/LibTVRefCommonPortable/Utils/IMediaContentAPIs.cs b/LibTVRefCommonPortable/Utils/IMediaContentAPIs.cs
new file mode 100644 (file)
index 0000000..520f3fa
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+namespace LibTVRefCommonPortable.Utils
+{
+    public struct RecentlyPlayedMedia
+    {
+        public string MediaId;
+        public string ThumbnailPath;
+        public string FilePath;
+        public string DisplayName;
+        public DateTime PlayedAt;
+    }
+
+    public interface IMediaContentAPIs
+    {
+        IEnumerable<RecentlyPlayedMedia> GetRecentlyPladyedMedia(int limitation);
+    }
+}
index 4a9eb5e..0dc7a5a 100755 (executable)
@@ -1,4 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
+  <package id="Tizen.Xamarin.Forms.Extension" version="2.3.5-r233-002" targetFramework="portable45-net45+win8+wp8+wpa81" />
   <package id="Xamarin.Forms" version="2.3.5-r233-003" targetFramework="portable45-net45+win8+wp8+wpa81" />
 </packages>
\ No newline at end of file
index 4e881cd..88bb468 100755 (executable)
@@ -48,6 +48,7 @@
     <Compile Include="Ports\AppControlPort.cs" />
     <Compile Include="Ports\ApplicationManagerPort.cs" />
     <Compile Include="Ports\DbgPort.cs" />
+    <Compile Include="Ports\MediaContentPort.cs" />
     <Compile Include="Ports\SystemSettingsPort.cs" />
     <Compile Include="Ports\WindowPort.cs" />
     <Compile Include="Ports\FileSystemPort.cs" />
index 1ecb182..4ec4d98 100644 (file)
@@ -4,6 +4,7 @@
     "Microsoft.NETCore.App": "1.1.0",
     "Tizen": "1.0.3",
     "Tizen.Applications": "1.5.1",
+    "Tizen.Content.MediaContent": "1.0.19",
     "Xamarin.Forms": "2.3.5-r233-003",
     "Xamarin.Forms.Platform.Tizen": "2.3.5-r233-003"
   },
index 978d4cb..e689253 100644 (file)
@@ -56,40 +56,15 @@ namespace LibTVRefCommonTizen.Ports
         /// Sends the launch request
         /// </summary>
         /// <param name="AppId"> The app ID to explicitly launch</param>
-        public void SendLaunchRequest(string AppId)
-        {
-            try
-            {
-                AppControl appControl = new AppControl();
-
-                if (AppId == null || AppId.Length <= 0)
-                {
-                    DebuggingUtils.Err("The AppID is null or blank");
-                    return;
-                }
-
-                appControl.ApplicationId = AppId;
-
-                AppControl.SendLaunchRequest(appControl);
-            }
-            catch (InvalidOperationException)
-            {
-                DebuggingUtils.Err("Failed to create AppControl");
-            }
-        }
-
-        /// <summary>
-        /// Sends the launch request
-        /// </summary>
-        /// <param name="AppId"> The app ID to explicitly launch</param>
         /// <param name="extraData">The extra data for the app control</param>
-        public void SendLaunchRequest(string AppId, IDictionary<string, string> extraData)
+        /// <param name="fileUri">The file URI to be opened</param>
+        public void SendLaunchRequest(string appId, IDictionary<string, string> extraData = null, string fileUri = null)
         {
             try
             {
                 AppControl appControl = new AppControl();
 
-                if (AppId == null || AppId.Length <= 0)
+                if (appId == null || appId.Length <= 0)
                 {
                     DebuggingUtils.Err("The AppID is null or blank");
                     return;
@@ -97,15 +72,27 @@ namespace LibTVRefCommonTizen.Ports
 
                 string value;
 
-                appControl.ApplicationId = AppId;
-                foreach (var key in extraData.Keys)
+                appControl.ApplicationId = appId;
+
+                if (extraData != null)
                 {
-                    if (extraData.TryGetValue(key, out value))
+                    foreach (var key in extraData.Keys)
                     {
-                        appControl.ExtraData.Add(key, value);
+                        if (extraData.TryGetValue(key, out value))
+                        {
+                            appControl.ExtraData.Add(key, value);
+                        }
                     }
                 }
 
+                if (fileUri != null && fileUri.Length != 0)
+                {
+                    appControl.Uri = fileUri;
+                    appControl.LaunchMode = AppControlLaunchMode.Group;
+                    appControl.Mime = "video/*";
+                    appControl.Operation = AppControlOperations.View;
+                }
+
                 AppControl.SendLaunchRequest(appControl);
             }
             catch (InvalidOperationException)
diff --git a/LibTVRefCommonTizen/Ports/MediaContentPort.cs b/LibTVRefCommonTizen/Ports/MediaContentPort.cs
new file mode 100644 (file)
index 0000000..3fad80f
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * 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 Tizen;
+using Tizen.Content.MediaContent;
+using LibTVRefCommonPortable.Utils;
+
+namespace LibTVRefCommonTizen.Ports
+{
+    public class MediaContentPort : IMediaContentAPIs
+    {
+        public MediaContentPort()
+        {
+            DbgPort.D("MediaContentPort");
+            ContentDatabase.Connect();
+        }
+
+        public IEnumerable<RecentlyPlayedMedia> GetRecentlyPladyedMedia(int limitation)
+        {
+            var recentlyPlayedVideos = new List<RecentlyPlayedMedia>();
+            var contentFilter = new ContentFilter();
+
+            contentFilter.OrderKey = "MEDIA_LAST_PLAYED_TIME";
+            contentFilter.Order = ContentOrder.Desc;
+            contentFilter.Condition = "MEDIA_TYPE=1 AND MEDIA_LAST_PLAYED_TIME!=0";
+            contentFilter.Offset = 0;
+            contentFilter.Count = limitation;
+
+            IEnumerable<MediaInformation> mediaInformations = null;
+
+            try
+            {
+                mediaInformations = ContentManager.Database.SelectAll<MediaInformation>(contentFilter);
+            }
+            catch (Exception exception)
+            {
+                DbgPort.E(exception.Message);
+            }
+
+            foreach (var mediaInformation in mediaInformations)
+            {
+                recentlyPlayedVideos.Add(new RecentlyPlayedMedia()
+                    {
+                        MediaId = mediaInformation.MediaId,
+                        ThumbnailPath = mediaInformation.ThumbnailPath,
+                        DisplayName = mediaInformation.DisplayName,
+                        PlayedAt = mediaInformation.PlayedAt,
+                        FilePath = mediaInformation.FilePath,
+                    }
+                );
+            }
+
+            return recentlyPlayedVideos;
+        }
+    }
+}
index c7a02d2..293b11b 100755 (executable)
@@ -195,6 +195,7 @@ namespace TVHome.TizenTV
             global::Xamarin.Forms.DependencyService.Register<FileSystemPort>();
             global::Xamarin.Forms.DependencyService.Register<WindowPort>();
             global::Xamarin.Forms.DependencyService.Register<SystemSettingsPort>();
+            global::Xamarin.Forms.DependencyService.Register<MediaContentPort>();
             TizenFormsExtension.Init();
             global::Xamarin.Forms.Platform.Tizen.Forms.Init(app);
             app.Run(args);
index 1be9477..8f7acef 100755 (executable)
@@ -126,7 +126,7 @@ namespace TVHome.Views
                 });
                 button.OnClearCommand = new Command(() =>
                 {
-                    OnClearVMCommand.Execute(item.AppID);
+                    OnClearVMCommand.Execute(item.Id);
                 });
                 button.OnClearAllCommand = new Command(() =>
                 {