public class AppShortcutInfo : ShortcutInfo
{
public string AppID { get; set; }
-
+ public bool IsChecked { get; set; }
+ public bool IsPinned { get; set; }
+ public bool IsRemovable { get; set; }
+
public override void UpdateState()
{
SetCurrentState("default");
using LibTVRefCommmonPortable.DataModels;
using LibTVRefCommmonPortable.Utils;
-
+using System.Threading.Tasks;
namespace LibTVRefCommmonPortable.Models
{
}
+ public async Task<IEnumerable<AppShortcutInfo>> GetList()
+ {
+ // TODO : This is a clone of AppShorcutController.ReadFromFile(). Write new code by using RUA
+ IApplicationManagerAPIs applicationManagerPort = DependencyService.Get<IApplicationManagerAPIs>();
+ List<AppShortcutInfo> appShortcutInfoList = new List<AppShortcutInfo>();
+
+ var installedAppList = await applicationManagerPort.GetAllInstalledApplication();
+
+ foreach (KeyValuePair<string, string[]> item in installedAppList)
+ {
+ var defaultStateDescription = new StateDescription()
+ {
+ Label = item.Value[0],
+ IconPath = item.Value[2],
+ Action = new AppControlAction()
+ {
+ AppID = item.Key,
+ }
+ };
+ var appShortcutInfo = new AppShortcutInfo();
+
+ appShortcutInfo.StateDescriptions.Add("default", defaultStateDescription);
+ appShortcutInfo.CurrentStateDescription = defaultStateDescription;
+ appShortcutInfoList.Add(appShortcutInfo);
+ }
+
+ return appShortcutInfoList;
+ }
+
public IEnumerable<AppShortcutInfo> ReadFromFile()
{
IApplicationManagerAPIs applicationManagerPort = DependencyService.Get<IApplicationManagerAPIs>();
{
public interface IApplicationManagerAPIs
{
+ Task<Dictionary<string, string[]>> GetAllInstalledApplication();
Task<Dictionary<string, string[]>> GetRecentApplications();
Dictionary<string, string> GetInstalledApplication(string applicationId);
}
return result;
}
- /*
- public async Task<IEnumerable<AppItem>> GetAllInstalledApplication()
+
+ public async Task<Dictionary<string, string[]>> GetAllInstalledApplication()
{
try
{
- List<AppItem> appItemList = new List<AppItem>();
+ Dictionary<string, string[]> resultList = new Dictionary<string, string[]>();
Task<IEnumerable<ApplicationInfo>> task = ApplicationManager.GetInstalledApplicationsAsync();
+ string[] result;
+
if (task == null)
{
DebuggingPort.D("GetInstalledApplication failed");
}
DebuggingPort.D("ADD" + appInfo.ToString());
- AppItem item = new AppItem();
- item.Title = appInfo.Label;
- item.IconUrl = appInfo.IconPath;
- item.IconColor = "#00000000";
- appItemList.Add(item);
+
+
+ result = new string[3];
+
+ result[0] = (appInfo.Label != null) ? appInfo.Label : null;
+ result[1] = (appInfo.ApplicationId != null) ? appInfo.ApplicationId : null;
+ result[2] = (System.IO.File.Exists(appInfo.IconPath)) ? appInfo.IconPath : "AppIcon.png";
+ resultList.Add(appInfo.ApplicationId, result);
}
- return appItemList;
+ return resultList;
}
catch (Exception exception)
{
DebuggingPort.E(exception.Message);
return null;
}
- }*/
+ }
}
}
\ No newline at end of file
+++ /dev/null
-/*
- * 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 LibTVRefCommonTizen.Ports;
-using System;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using Tizen.Applications;
-using TVApps.Models;
-using TVApps.Utils;
-
-namespace TVApps.TizenTV
-{
- class ApplicationManagerPort : IApplicationManagerAPIs
- {
- public async Task<IEnumerable<AppItem>> GetAllInstalledApplication()
- {
- try
- {
- List<AppItem> appItemList = new List<AppItem>();
- Task<IEnumerable<ApplicationInfo>> task = ApplicationManager.GetInstalledApplicationsAsync();
- if (task == null)
- {
- DebuggingPort.D("GetInstalledApplication failed");
- return null;
- }
-
- IEnumerable<ApplicationInfo> installedList = await task;
-
- foreach (var appInfo in installedList)
- {
- DebuggingPort.D("-------------------------------------");
- DebuggingPort.D("TRY" + appInfo.ToString());
- if (appInfo.IsNoDisplay)
- {
- continue;
- }
-
- Package pkgInfo = PackageManager.GetPackage(appInfo.PackageId);
- if (pkgInfo == null)
- {
- continue;
- }
-
- DebuggingPort.D("TRY" + pkgInfo.ToString());
-
- if (pkgInfo.IsSystemPackage)
- {
- continue;
- }
-
- DebuggingPort.D("ADD" + appInfo.ToString());
- AppItem item = new AppItem();
- item.Title = appInfo.Label;
- item.IconUrl = appInfo.IconPath;
- item.IconColor = "#00000000";
- appItemList.Add(item);
- }
-
- return appItemList;
- }
- catch (Exception exception)
- {
- DebuggingPort.E(exception.Message);
- return null;
- }
- }
-
- }
-}
\ No newline at end of file
<None Include="shared\res\TVApps.TizenTV.png" />
</ItemGroup>
<ItemGroup>
- <Compile Include="ApplicationManagerPort.cs" />
<Compile Include="TVApps.TizenTV.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ViewCell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TVApps.Controls.AppItemCell">
- <RelativeLayout BackgroundColor="#000000">
- <BoxView x:Name="ButtonBox"
- WidthRequest="240"
- HeightRequest="266"
- Opacity="0"/>
- <Image x:Name="ButtonImage"
- RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Height, Factor=0.6165}"
- RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Width, Factor=0.6833}"
- RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Height, Factor=0.0977}"
- RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Width, Factor=0.1583}"
- Source="{Binding IconUrl}" />
- <Label x:Name="ButtonTitle"
- RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Height, Factor=0.78195}"
- RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Width, Factor=0.1167}"
- RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Width, Factor=0.7667}"
- RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Height, Factor=0.1203}"
- Opacity="1"
- FontSize="58"
- TextColor="White"
- LineBreakMode="TailTruncation"
- HorizontalTextAlignment="Center"
- Text="{Binding Title}" />
- <Image x:Name="PinnedIcon"
- RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Height, Factor=0.075}"
- RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Width, Factor=0.075}"
- RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Height, Factor=0.78195}"
- RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonTitle, Property=Width, Factor=0}"
- Source="{Binding IconUrl}"
- Opacity="0"/>
- <Button x:Name = "ButtonFocusArea"
- RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Height, Factor=1}"
- RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Width, Factor=1}"
- Focused="OnFocused"
- Unfocused="OnUnFocused"
- Opacity="0" />
- </RelativeLayout>
+ <RelativeLayout BackgroundColor="#000000">
+ <BoxView x:Name="ButtonBox"
+ WidthRequest="240"
+ HeightRequest="266"
+ Opacity="0"/>
+ <Image x:Name="ButtonImage"
+ RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Height, Factor=0.6165}"
+ RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Width, Factor=0.6833}"
+ RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Height, Factor=0.0977}"
+ RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Width, Factor=0.1583}"
+ Source="{Binding CurrentStateDescription.IconPath}" />
+ <Label x:Name="ButtonTitle"
+ RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Height, Factor=0.78195}"
+ RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Width, Factor=0.1167}"
+ RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Width, Factor=0.7667}"
+ RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Height, Factor=0.1203}"
+ Opacity="1"
+ FontSize="58"
+ TextColor="White"
+ LineBreakMode="TailTruncation"
+ HorizontalTextAlignment="Center"
+ Text="{Binding CurrentStateDescription.Label}" />
+ <Image x:Name="PinnedIcon"
+ RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Height, Factor=0.075}"
+ RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Width, Factor=0.075}"
+ RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Height, Factor=0.78195}"
+ RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonTitle, Property=Width, Factor=0}"
+ Source="{Binding IconUrl}"
+ Opacity="0"/>
+ <Button x:Name = "ButtonFocusArea"
+ RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Height, Factor=1}"
+ RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Width, Factor=1}"
+ Focused="OnFocused"
+ Unfocused="OnUnFocused"
+ Opacity="0" />
+ </RelativeLayout>
</ViewCell>
xmlns:VM="clr-namespace:TVApps.ViewModels"
x:Class="TVApps.Controls.AppListView"
HorizontalOptions="Fill"
- Orientation="Horizontal"
- ItemsSource="{Binding AppItems}">
- <ScrollView.BindingContext>
- <VM:AppsListViewModel />
- </ScrollView.BindingContext>
+ Orientation="Horizontal">
+ <Grid x:Name="AppListGrid"
+ HorizontalOptions="Start">
+ <Grid.RowDefinitions>
+ <RowDefinition Height="4863*" />
+ <RowDefinition Height="274*" />
+ <RowDefinition Height="4863*" />
+ </Grid.RowDefinitions>
+ <Grid.RowSpacing>0</Grid.RowSpacing>
+ <Grid.ColumnSpacing>0</Grid.ColumnSpacing>
- <Controls:AppListView.ItemTemplate>
- <DataTemplate>
- <Controls:AppItemCell />
- </DataTemplate>
- </Controls:AppListView.ItemTemplate>
-
- <Grid x:Name="AppListGrid"
- HorizontalOptions="Start">
- <Grid.RowDefinitions>
- <RowDefinition Height="4863*" />
- <RowDefinition Height="274*" />
- <RowDefinition Height="4863*" />
- </Grid.RowDefinitions>
- <Grid.RowSpacing>0</Grid.RowSpacing>
- <Grid.ColumnSpacing>0</Grid.ColumnSpacing>
-
- <StackLayout x:Name="AppUpperList"
- Grid.Row="0"
- Orientation="Horizontal"
- HorizontalOptions="Start"
- Spacing="0"/>
- <BoxView Grid.Row="1"/>
- <StackLayout x:Name="AppLowerList"
- Grid.Row="2"
- Orientation="Horizontal"
- HorizontalOptions="Start"
- Spacing="0"/>
- </Grid>
+ <StackLayout x:Name="AppUpperList"
+ Grid.Row="0"
+ Orientation="Horizontal"
+ HorizontalOptions="Start"
+ Spacing="0"/>
+ <BoxView Grid.Row="1"/>
+ <StackLayout x:Name="AppLowerList"
+ Grid.Row="2"
+ Orientation="Horizontal"
+ HorizontalOptions="Start"
+ Spacing="0"/>
+ </Grid>
</ScrollView>
using System.Linq;
using Xamarin.Forms;
-using TVApps.Models;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
+using LibTVRefCommmonPortable.DataModels;
+using LibTVRefCommmonPortable.Utils;
+using System.Collections.Generic;
namespace TVApps.Controls
{
/// <summary>
- /// hahaha
+ /// TV Apps Custom ListView
/// </summary>
public partial class AppListView : ScrollView
{
- public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create("ItemsSource", typeof(ObservableCollection<AppItem>), typeof(AppListView), default(ObservableCollection<AppItem>));
- public ObservableCollection<AppItem> ItemsSource
+ public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create("ItemsSource", typeof(IEnumerable<ShortcutInfo>), typeof(AppListView), default(ObservableCollection<ShortcutInfo>));
+ public IEnumerable<ShortcutInfo> ItemsSource
{
- get { return (ObservableCollection<AppItem>)GetValue(ItemsSourceProperty); }
+ get { return (IEnumerable<ShortcutInfo>)GetValue(ItemsSourceProperty); }
set { SetValue(ItemsSourceProperty, value); }
}
InitializeComponent();
AppCount = 0;
PropertyChanged += OnPropertyChange;
- ItemsSource.CollectionChanged += OnItemSourceCollectionChange;
- }
-
- private void OnItemSourceCollectionChange(object sender, NotifyCollectionChangedEventArgs e)
- {
- if (e.Action == NotifyCollectionChangedAction.Add)
- {
- foreach (var item in e.NewItems)
- {
- var viewCell = ItemTemplate.CreateContent() as ViewCell;
- viewCell.View.BindingContext = item;
-
- if (AppCount % 2 == 0)
- {
- AppUpperList.Children.Add(viewCell.View);
- }
- else
- {
- AppLowerList.Children.Add(viewCell.View);
- }
-
- AppCount = AppCount + 1;
- }
- }
- else if (e.Action == NotifyCollectionChangedAction.Remove)
- {
- var isUpper = (e.OldStartingIndex % 2) == 0;
- var itemIndex = e.OldStartingIndex / 2;
- var upperItemCount = AppUpperList.Children.Count;
- var lowerItemCount = AppLowerList.Children.Count;
-
- if (isUpper)
- {
- AppUpperList.Children.RemoveAt(itemIndex);
- upperItemCount = upperItemCount - 1;
- }
- else
- {
- AppLowerList.Children.RemoveAt(itemIndex);
- lowerItemCount = lowerItemCount - 1;
- }
-
- for (var i = itemIndex; i < upperItemCount; i++)
- {
- AppLowerList.Children.Add(AppUpperList.Children.ElementAt(itemIndex));
- }
-
- for (var i = itemIndex; i < lowerItemCount; i++)
- {
- AppUpperList.Children.Add(AppLowerList.Children.ElementAt(itemIndex));
- }
-
- AppCount = AppCount - 1;
- }
}
void OnPropertyChange(object sender, PropertyChangedEventArgs e)
+++ /dev/null
-/*
- * 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;
-
-namespace TVApps.Models
-{
- public class AppItem
- {
- string[] titles = { "Hello", "Tizen", "C#" };
- string[] images = {"t1.png", "t2.png", "t3.png"};
- string[] colors = { "#ffc0cb", "#d3ffce", "#20b2aa", "#cbbeb5", "#66cccc", "#4169e1" };
- public string Title { get; set; }
- public int ID { get; set; }
- public string IconUrl { get; set; }
- public DateTime InstallDate { get; set; }
- public string IconColor { get; set; }
-
- public AppItem()
- {
- Random r = new Random();
- Title = titles[r.Next(0, 3)];
- InstallDate = DateTime.Now;
- IconUrl = images[r.Next(0, 3)];
- IconColor = colors[r.Next(0, 6)];
- }
- }
-}
<Compile Include="Controls\AppListView.xaml.cs">
<DependentUpon>AppListView.xaml</DependentUpon>
</Compile>
- <Compile Include="Models\AppItem.cs" />
<Compile Include="TVApps.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="Utils\DebuggingUtils.cs" />
- <Compile Include="Utils\IApplicationManagerAPIs.cs" />
- <Compile Include="Utils\IDebuggingAPIs.cs" />
- <Compile Include="ViewModels\AppsListViewModel.cs" />
+ <Compile Include="ViewModels\MainPageViewModel.cs" />
<Compile Include="Views\MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\LibTVRefCommonPortable\LibTVRefCommonPortable.csproj">
+ <Project>{67F9D3A8-F71E-4428-913F-C37AE82CDB24}</Project>
+ <Name>LibTVRefCommonPortable</Name>
+ </ProjectReference>
+ </ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<Import Project="..\..\packages\Xamarin.Forms.2.3.3.193\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets" Condition="Exists('..\..\packages\Xamarin.Forms.2.3.3.193\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
+++ /dev/null
-/*
- * 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 Xamarin.Forms;
-
-namespace TVApps.Utils
-{
- /// <summary>
- /// A debugging utility class.
- /// </summary>
- public sealed class DebuggingUtils
- {
- private static IDebuggingAPIs ism;
- private static readonly DebuggingUtils instance = new DebuggingUtils();
-
- /// <summary>
- /// A method provides instance of DebuggingUtils. </summary>
- public static DebuggingUtils Instance
- {
- get { return instance; }
- }
-
- /// <summary>
- /// Default implementation of IDebuggingAPIs interface .
- /// This is required for the unit testing of the Calculator application. </summary>
- private class DefaultSM : IDebuggingAPIs
- {
- public void Dbg(string message)
- {
- }
-
- public void Err(string message)
- {
- }
-
- public void Popup(string message)
- {
- }
- }
-
- /// <summary>
- /// DebuggingUtils constructor which set interface instance. </summary>
- private DebuggingUtils()
- {
- if (DependencyService.Get<IDebuggingAPIs>() != null)
- {
- ism = DependencyService.Get<IDebuggingAPIs>();
- }
- else
- {
- ism = new DefaultSM();
- }
- }
-
- /// <summary>
- /// A method displays a debugging message </summary>
- /// <param name="message"> A list of command line arguments.</param>
- public static void Dbg(string message)
- {
- ism.Dbg(message);
- }
-
- /// <summary>
- /// A method displays a error message </summary>
- /// <param name="message"> A list of command line arguments.</param>
- public static void Err(string message)
- {
- ism.Err(message);
- }
-
- /// <summary>
- /// A method displays a pop up message </summary>
- /// <param name="message"> A list of command line arguments.</param>
- public static void Popup(string message)
- {
- ism.Popup(message);
- }
- }
-}
+++ /dev/null
-/*
- * 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.Collections.Generic;
-using System.Threading.Tasks;
-using TVApps.Models;
-
-namespace TVApps.Utils
-{
- public interface IApplicationManagerAPIs
- {
- Task<IEnumerable<AppItem>> GetAllInstalledApplication();
- }
-}
+++ /dev/null
-/*
- * 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.
- */
-
-namespace TVApps.Utils
-{
- /// <summary>
- /// A interface contains debugging methods which are using platform subsystems.
- /// </summary>
- /// <remarks>
- /// Implementing this class should be occurred in platform project.
- /// Also the implementation should be registered to the DependencyService in a app initialization.
- /// Please refer to Xamarin Dependency Service
- /// https://developer.xamarin.com/guides/xamarin-forms/dependency-service/introduction/
- /// </remarks>
- public interface IDebuggingAPIs
- {
- /// <summary>
- /// A method displays a debugging log. </summary>
- /// <param name="message"> A debugging message.</param>
- void Popup(string message);
-
- /// <summary>
- /// A method displays a error log. </summary>
- /// <param name="message"> A error message.</param>
- void Dbg(string message);
-
- /// <summary>
- /// A method displays a dialog with a given message. </summary>
- /// <param name="message"> A debugging message.</param>
- void Err(string message);
- }
-}
+++ /dev/null
-/*
- * 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.Collections;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Linq;
-using System.Threading.Tasks;
-using TVApps.Models;
-using TVApps.Utils;
-using Xamarin.Forms;
-
-namespace TVApps.ViewModels
-{
- class AppsListViewModel
- {
- public ObservableCollection<AppItem> AppItems { get; set; }
-
- public AppsListViewModel()
- {
- AppItems = new ObservableCollection<AppItem>();
-
- GetInstalledApps();
- }
-
- private async void GetInstalledApps()
- {
- IApplicationManagerAPIs applicationManagerPort = DependencyService.Get<IApplicationManagerAPIs>();
-
- IEnumerable<AppItem> appList = await applicationManagerPort.GetAllInstalledApplication();
- foreach (var item in appList)
- {
- AppItems.Add(item);
- DebuggingUtils.Dbg("ADD " + item.Title + ", " + item.IconUrl);
- }
- }
-
- public void AddItem()
- {
- AppItems.Add(new AppItem());
- }
-
- public void RemoveItem()
- {
- if (AppItems.Count > 0)
- {
- AppItems.RemoveAt(0);
- }
- }
-
- public void SortItem()
- {
- AppItems = new ObservableCollection<AppItem>(AppItems.OrderByDescending(AppItem => AppItem.Title));
- }
- }
-}
--- /dev/null
+/*
+ * 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 LibTVRefCommmonPortable.DataModels;
+using LibTVRefCommmonPortable.Utils;
+using System.Collections;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.Linq;
+using System.Threading.Tasks;
+using Xamarin.Forms;
+
+namespace TVApps.ViewModels
+{
+ class MainPageViewModel : INotifyPropertyChanged
+ {
+ public IEnumerable<ShortcutInfo> AppList { get; set; }
+
+ public event PropertyChangedEventHandler PropertyChanged;
+ protected void OnPropertyChanged(string name)
+ {
+ PropertyChangedEventHandler handler = PropertyChanged;
+ if (handler != null)
+ {
+ handler(this, new PropertyChangedEventArgs(name));
+ }
+ }
+
+ public MainPageViewModel()
+ {
+ GetInstalledApps();
+ }
+
+ private async void GetInstalledApps()
+ {
+ AppList = await TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetList();
+ if (AppList != null)
+ {
+ OnPropertyChanged("AppList");
+ }
+ }
+ }
+}
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+ xmlns:ViewModels="clr-namespace:TVApps.ViewModels"
xmlns:Controls="clr-namespace:TVApps.Controls"
x:Class="TVApps.Views.MainPage"
BackgroundColor="#000000">
+ <ContentPage.BindingContext>
+ <ViewModels:MainPageViewModel />
+ </ContentPage.BindingContext>
- <ContentPage.Resources>
- <ResourceDictionary>
- <Style x:Key="titleText" TargetType="Label" >
- <Setter Property="FontSize" Value="187" />
- <Setter Property="TextColor" Value="#FFFFFF" />
- <Setter Property="FontFamily" Value="Samsung sans" />
- </Style>
- <Style x:Key="buttonTextNormal" TargetType="Label" >
- <Setter Property="FontSize" Value="62" />
- <Setter Property="TextColor" Value="#F7F7F7" />
- <Setter Property="FontFamily" Value="Breeze Sans Regular" />
- </Style>
- <Style x:Key="buttonTextPressed" TargetType="Label" >
- <Setter Property="FontSize" Value="62" />
- <Setter Property="TextColor" Value="#F7F7F708" />
- <Setter Property="FontFamily" Value="Breeze Sans Regular" />
- </Style>
+ <ContentPage.Resources>
+ <ResourceDictionary>
+ <Style x:Key="titleText" TargetType="Label" >
+ <Setter Property="FontSize" Value="187" />
+ <Setter Property="TextColor" Value="#FFFFFF" />
+ <Setter Property="FontFamily" Value="Samsung sans" />
+ </Style>
+ <Style x:Key="buttonTextNormal" TargetType="Label" >
+ <Setter Property="FontSize" Value="62" />
+ <Setter Property="TextColor" Value="#F7F7F7" />
+ <Setter Property="FontFamily" Value="Breeze Sans Regular" />
+ </Style>
+ <Style x:Key="buttonTextPressed" TargetType="Label" >
+ <Setter Property="FontSize" Value="62" />
+ <Setter Property="TextColor" Value="#F7F7F708" />
+ <Setter Property="FontFamily" Value="Breeze Sans Regular" />
+ </Style>
- <Style x:Key="button" TargetType="Button">
- <Setter Property="BorderColor" Value="#FFFFFF"/>
- <Setter Property="HeightRequest" Value="40"/>
- <Setter Property="BorderWidth" Value="2" />
- <Setter Property="HorizontalOptions" Value="Center"/>
- <Setter Property="BackgroundColor" Value="Transparent"/>
- </Style>
- </ResourceDictionary>
- </ContentPage.Resources>
+ <Style x:Key="button" TargetType="Button">
+ <Setter Property="BorderColor" Value="#FFFFFF"/>
+ <Setter Property="HeightRequest" Value="40"/>
+ <Setter Property="BorderWidth" Value="2" />
+ <Setter Property="HorizontalOptions" Value="Center"/>
+ <Setter Property="BackgroundColor" Value="Transparent"/>
+ </Style>
+ </ResourceDictionary>
+ </ContentPage.Resources>
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="2685*" />
- <RowDefinition Height="83*" />
- <RowDefinition Height="5074*" />
- <RowDefinition Height="0981*" />
- <RowDefinition Height="1185*" />
- </Grid.RowDefinitions>
- <Grid.RowSpacing>0</Grid.RowSpacing>
- <Grid.ColumnSpacing>0</Grid.ColumnSpacing>
+ <Grid>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="2685*" />
+ <RowDefinition Height="83*" />
+ <RowDefinition Height="5074*" />
+ <RowDefinition Height="0981*" />
+ <RowDefinition Height="1185*" />
+ </Grid.RowDefinitions>
+ <Grid.RowSpacing>0</Grid.RowSpacing>
+ <Grid.ColumnSpacing>0</Grid.ColumnSpacing>
- <StackLayout Grid.Row="0"
- HorizontalOptions="FillAndExpand"
- VerticalOptions="FillAndExpand">
- <Label
- Style="{StaticResource titleText}"
- HorizontalTextAlignment="Center"
- VerticalOptions="CenterAndExpand"
- HorizontalOptions="CenterAndExpand"
- Text="APPS" />
- </StackLayout>
+ <StackLayout Grid.Row="0"
+ HorizontalOptions="FillAndExpand"
+ VerticalOptions="FillAndExpand">
+ <Label
+ Style="{StaticResource titleText}"
+ HorizontalTextAlignment="Center"
+ VerticalOptions="CenterAndExpand"
+ HorizontalOptions="CenterAndExpand"
+ Text="APPS" />
+ </StackLayout>
- <BoxView Grid.Row="1"/>
+ <BoxView Grid.Row="1"/>
- <Controls:AppListView Grid.Row="2"
- x:Name="AppListView"/>
+ <Controls:AppListView x:Name="AppListView"
+ Grid.Row="2"
+ ItemsSource="{Binding AppList}">
+ <Controls:AppListView.ItemTemplate>
+ <DataTemplate>
+ <Controls:AppItemCell/>
+ </DataTemplate>
+ </Controls:AppListView.ItemTemplate>
+ </Controls:AppListView>
- <BoxView Grid.Row="3"/>
+ <BoxView Grid.Row="3"/>
- <Grid Grid.Row="4">
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="987*" />
- <ColumnDefinition Width="701*" />
- <ColumnDefinition Width="88*" />
- </Grid.ColumnDefinitions>
+ <Grid Grid.Row="4">
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="987*" />
+ <ColumnDefinition Width="701*" />
+ <ColumnDefinition Width="88*" />
+ </Grid.ColumnDefinitions>
- <BoxView Grid.Column="0"/>
+ <BoxView Grid.Column="0"/>
- <StackLayout Grid.Column="1"
- HorizontalOptions="FillAndExpand"
- VerticalOptions="FillAndExpand"
- Orientation="Horizontal">
- <Button Style="{StaticResource button}"
- Text="ADD"
- Clicked="OnClickButtonAdd"/>
- <Button Style="{StaticResource button}"
- Text="REMOVE"
- Clicked="OnClickButtonRemove"/>
- <Button Style="{StaticResource button}"
- Text="SORT"
- Clicked="OnClickButtonSort"/>
- </StackLayout>
+ <StackLayout Grid.Column="1"
+ HorizontalOptions="FillAndExpand"
+ VerticalOptions="FillAndExpand"
+ Orientation="Horizontal">
+ <Button Style="{StaticResource button}"
+ Text="ADD"/>
+ <Button Style="{StaticResource button}"
+ Text="REMOVE"/>
+ <Button Style="{StaticResource button}"
+ Text="SORT"/>
+ </StackLayout>
- <BoxView Grid.Column="2"/>
+ <BoxView Grid.Column="2"/>
+ </Grid>
</Grid>
- </Grid>
</ContentPage>
\ No newline at end of file
{
InitializeComponent();
}
-
- private void OnClickButtonAdd(object sender, EventArgs e)
- {
- var vm = (AppsListViewModel)AppListView.BindingContext;
- vm.AddItem();
- }
-
- private void OnClickButtonRemove(object sender, EventArgs e)
- {
- var vm = (AppsListViewModel)AppListView.BindingContext;
- vm.RemoveItem();
- }
-
- private void OnClickButtonSort(object sender, EventArgs e)
- {
- var vm = (AppsListViewModel)AppListView.BindingContext;
- vm.SortItem();
- }
}
}