Skip to content

Commit

Permalink
currentplaying wp
Browse files Browse the repository at this point in the history
  • Loading branch information
DerPate2010 committed May 22, 2014
1 parent 306fd65 commit 776b82e
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 26 deletions.
15 changes: 13 additions & 2 deletions Xbmc2S.Model/MainVm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,21 @@ public IItemsSource GetMovieSource(ItemsSourceReference itemsSourceReference = n
}
return itemsSource;
}


private CurrentPlaybackVm _currentPlaybackVm;

public async Task<CurrentPlaybackVm> GetCurrentPlayingItem()
{
return new CurrentPlaybackVm(_appContext);
if (_currentPlaybackVm == null)
{
_currentPlaybackVm = new CurrentPlaybackVm(_appContext);
}
else
{
_currentPlaybackVm.RefreshNow();
}

return _currentPlaybackVm;
}

public PersonVm SearchPerson(string name)
Expand Down
25 changes: 20 additions & 5 deletions Xbmc2S.Model/Playback/CurrentPlaybackVm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using Okra.Core;
Expand Down Expand Up @@ -98,16 +99,26 @@ PlayingXbmcItemVm CurrentItemFactory(XBMCRPC.List.Item.All currentItem, int play
}
throw new NotSupportedException();
}

private CancellationTokenSource _delayCancel;

public void RefreshNow()
{
_delayCancel.Cancel();
}

private async Task CurrentPlayingLoop()
{

while (true)
{
bool failed = false;
try
{
await GetCurrentPlayingItem();
_delayCancel= new CancellationTokenSource();
await GetCurrentPlayingItem(_delayCancel.Token);
}
catch (TaskCanceledException)
{
}
catch (Exception)
{
Expand All @@ -120,7 +131,7 @@ private async Task CurrentPlayingLoop()
}
}

private async Task GetCurrentPlayingItem()
private async Task GetCurrentPlayingItem(CancellationToken delayCancel)
{
var activePlayers = await _appContext.XBMC.Player.GetActivePlayers();
if (activePlayers.Count == 0)
Expand Down Expand Up @@ -162,7 +173,7 @@ private async Task GetCurrentPlayingItem()
IsPlaying = false;
CurrentItem = null;
}
await Task.Delay(TimeSpan.FromSeconds(10));
await Task.Delay(TimeSpan.FromSeconds(10),delayCancel);
}
else
{
Expand Down Expand Up @@ -239,7 +250,11 @@ public bool IsPlaying
get { return _isPlaying; }
set
{
_isPlaying = value; OnPropertyChanged(); }
if (SetProperty(ref _isPlaying, value))
{

}
}
}

public ICommand Pause { get; private set; }
Expand Down
13 changes: 13 additions & 0 deletions Xbmc2S.RT.Shared/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ public App()
this.Suspending += OnSuspending;
Platform.Current= new Util();
SuspensionManager.KnownTypes.Add(typeof(ItemsSourceReference));

TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
UnhandledException += App_UnhandledException;
}

void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
e.Handled = true;
}

void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
e.SetObserved();
}

public static MainVm MainVm
Expand Down
10 changes: 9 additions & 1 deletion Xbmc2S.RT.Shared/Common/BooleanToVisibilityConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ public sealed class BooleanToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return (value is bool && (bool)value) ? Visibility.Visible : Visibility.Collapsed;
try
{
return (value is bool && (bool)value) ? Visibility.Visible : Visibility.Collapsed;
}
catch (Exception)
{

throw;
}
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
Expand Down
6 changes: 3 additions & 3 deletions Xbmc2S.RT.Shared/Global/HubPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
</TransitionCollection>
</Grid.ChildrenTransitions>

<Hub SectionHeaderClick="Hub_OnSectionHeaderClick">
<Hub SectionHeaderClick="Hub_OnSectionHeaderClick" Name="Hub">
<Hub.Header>
<!-- Back button and page title -->
<Grid>
Expand All @@ -169,9 +169,9 @@
</Grid>
</Hub.Header>

<HubSection Visibility="{Binding IsPlaying, Converter={StaticResource BooleanToVisibilityConverter}}" Margin="0,0,80,0" Padding=" 0 -100 0 0" VerticalContentAlignment="Stretch" DataContext="{Binding CurrentPlayingItem}">
<HubSection Name="CurrentPlayingSection" Margin="-20 0 20 0" Padding="0 -100 0 0" MinWidth="0" Width="NaN" VerticalContentAlignment="Stretch" DataContext="{Binding CurrentPlayingItem}">
<DataTemplate>
<local:CurrentPlayingCtrl x:Name="CurrentPlayingPanel"/>
<local:CurrentPlayingCtrl Margin="0 0 -20 0"/>
</DataTemplate>
</HubSection>
<HubSection VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" Width="360" DataContext="{Binding CurrentConnection}" Visibility="{Binding ConnectionFailed, Converter={StaticResource BooleanToVisibilityConverter}}">
Expand Down
38 changes: 38 additions & 0 deletions Xbmc2S.RT.Shared/Global/HubPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ public HubPage()
this.InitializeComponent();
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += navigationHelper_LoadState;
navigationHelper.SaveState += navigationHelper_SaveState;
_id = DateTime.Now.Ticks;
}

void navigationHelper_SaveState(object sender, SaveStateEventArgs e)
{
_currentPlayingItem.PropertyChanged -= _currentPlayingItem_PropertyChanged;
}


Expand All @@ -73,6 +80,8 @@ private async void navigationHelper_LoadState(object sender, LoadStateEventArgs
await ConnectViewModel();
}

private long _id;

private async Task ConnectViewModel()
{
this.DefaultViewModel["Settings"] = App.MainVm.Settings;
Expand All @@ -90,9 +99,37 @@ private async Task ConnectViewModel()
this.DefaultViewModel["AdvancedSteps"] = advancedSteps;
DefaultViewModel["CurrentConnection"] = App.MainVm.CurrentConnection;
_currentPlayingItem = await App.MainVm.GetCurrentPlayingItem();
_currentPlayingItem.PropertyChanged += _currentPlayingItem_PropertyChanged;
RefreshCurrentPlayingVisibility();
DefaultViewModel["CurrentPlayingItem"] = _currentPlayingItem;
}

void _currentPlayingItem_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsPlaying")
{
RefreshCurrentPlayingVisibility();
}
}

private void RefreshCurrentPlayingVisibility()
{
if (_currentPlayingItem.IsPlaying)
{
if (!Hub.Sections.Contains(CurrentPlayingSection))
{
Hub.Sections.Insert(0, CurrentPlayingSection);
}
}
else
{
if (Hub.Sections.Contains(CurrentPlayingSection))
{
Hub.Sections.Remove(CurrentPlayingSection);
}
}
}

private void GotoUserVoice()
{
Launcher.LaunchUriAsync(new Uri("https://xbmc2screen.uservoice.com/"));
Expand Down Expand Up @@ -297,6 +334,7 @@ private void ToggleFlyout(object sender, RoutedEventArgs e)
{
RcButton.Flyout.Hide();
}

}


Expand Down
7 changes: 0 additions & 7 deletions Xbmc2S.RT.Shared/Xbmc2S.RT.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@
<Compile Include="$(MSBuildThisFileDirectory)Files\MissingFilesPage.xaml.cs">
<DependentUpon>MissingFilesPage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Global\CurrentPlayingCtrl.xaml.cs">
<DependentUpon>CurrentPlayingCtrl.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Global\GeneralDetailsView.xaml.cs">
<DependentUpon>GeneralDetailsView.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -179,10 +176,6 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Global\CurrentPlayingCtrl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Global\GeneralDetailsView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
1 change: 0 additions & 1 deletion Xbmc2S.RT.WindowsPhone/Common/PlatformStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,4 @@
<TextBlock Margin="6 0 0 0" Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Style="{StaticResource SubheaderTextBlockStyle}" FontWeight="SemiBold"/>
</StackPanel>
</DataTemplate>

</ResourceDictionary>
10 changes: 5 additions & 5 deletions Xbmc2S.RT.WindowsPhone/ProgressIndicator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Threading;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml.Controls;
Expand Down Expand Up @@ -56,7 +57,7 @@ private void RefreshIsActive()
if (!_refreshPending)
{
_refreshPending = true;
DoRefresh();
SmartDispatcher.RunAsync(DoRefresh);
}
}

Expand All @@ -71,14 +72,14 @@ private async void DoRefresh()
}
else
{
_progressIndicator.ProgressValue = null;
await _progressIndicator.ShowAsync();
_progressIndicator.ProgressValue = null;
await _progressIndicator.ShowAsync();
}
}

public void SetError(string message)
{
DisplayError(message);
SmartDispatcher.RunAsync(()=>DisplayError(message));
}


Expand All @@ -90,7 +91,6 @@ private async void DisplayError(string message)
await _progressIndicator.ShowAsync();
await Task.Delay(4000);
_progressIndicator.Text = "";

}
}
}
Expand Down
9 changes: 8 additions & 1 deletion Xbmc2S.RT.WindowsPhone/Xbmc2S.RT.WindowsPhone.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants>
<DefineConstants>TRACE;DEBUG;NETFX_CORE;WINDOWS_PHONE_APP;DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
Expand Down Expand Up @@ -113,6 +113,9 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Global\CurrentPlayingCtrl.xaml.cs">
<DependentUpon>CurrentPlayingCtrl.xaml</DependentUpon>
</Compile>
<Compile Include="HubPage.WP.cs" />
<Compile Include="ProgressIndicator.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand All @@ -138,6 +141,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Global\CurrentPlayingCtrl.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Search\GlobalSearchBox.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ResourceDictionary>
</UserControl.Resources>

<Grid Name="CurrentPlayingPanel" Width="1200" Visibility="{Binding IsPlaying, Converter={StaticResource BooleanToVisibilityConverter}}" >
<Grid Width="1200" Visibility="{Binding IsPlaying, Converter={StaticResource BooleanToVisibilityConverter}}" >
<Image Source="{Binding CurrentItem.Images.FanArt}" Grid.RowSpan="2" Stretch="UniformToFill"/>
<Border>
<Border.Background>
Expand Down
7 changes: 7 additions & 0 deletions Xbmc2S.RT/Xbmc2S.RT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="App.RT.cs" />
<Compile Include="Global\CurrentPlayingCtrl.xaml.cs">
<DependentUpon>CurrentPlayingCtrl.xaml</DependentUpon>
</Compile>
<Compile Include="Global\HubPage.RT.cs" />
<Compile Include="Global\ProgressIndicator.xaml.cs">
<DependentUpon>ProgressIndicator.xaml</DependentUpon>
Expand Down Expand Up @@ -151,6 +154,10 @@
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Page>
<Page Include="Global\CurrentPlayingCtrl.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Global\ProgressIndicator.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down

0 comments on commit 776b82e

Please sign in to comment.