Skip to content

Commit

Permalink
WPF: Player status is now saved on Dropbox; Resume Playback is now wo…
Browse files Browse the repository at this point in the history
…rking!
  • Loading branch information
ycastonguay committed Oct 25, 2013
1 parent 4ac58d6 commit b6f7270
Show file tree
Hide file tree
Showing 10 changed files with 321 additions and 109 deletions.
283 changes: 191 additions & 92 deletions MPfm/MPfm.Library/Services/DropboxCoreService.cs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions MPfm/MPfm.MVP/MPfm.MVP.csproj
Expand Up @@ -129,6 +129,7 @@
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Config\AppConfigManager.cs" />
<Compile Include="Config\IAppConfig.cs" />
<Compile Include="Messages\CloudConnectStatusChangedMessage.cs" />
<Compile Include="Messages\ConnectionStatusChangedMessage.cs" />
<Compile Include="Messages\ApplicationCloseMessage.cs" />
<Compile Include="Messages\ActivateLockScreenMessage.cs" />
Expand Down
37 changes: 37 additions & 0 deletions MPfm/MPfm.MVP/Messages/CloudConnectStatusChangedMessage.cs
@@ -0,0 +1,37 @@
// Copyright © 2011-2013 Yanick Castonguay
//
// This file is part of MPfm.
//
// MPfm is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// MPfm is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.

using MPfm.Library.Services.Interfaces;
using TinyMessenger;

namespace MPfm.MVP.Messages
{
/// <summary>
/// Message used to notify the app that the one of the cloud service connection has changed status.
/// </summary>
public class CloudConnectStatusChangedMessage : TinyMessageBase
{
public string CloudServiceName { get; set; }
public CloudAuthenticationStatusType StatusType { get; set; }
public bool IsApplicationLinked { get; set; }

public CloudConnectStatusChangedMessage(object sender)
: base(sender)
{
}
}
}
20 changes: 15 additions & 5 deletions MPfm/MPfm.MVP/Presenters/CloudConnectPresenter.cs
Expand Up @@ -17,10 +17,13 @@

using System;
using System.Threading.Tasks;
using Mono.Posix;
using MPfm.Library.Services.Interfaces;
using MPfm.MVP.Messages;
using MPfm.MVP.Models;
using MPfm.MVP.Presenters.Interfaces;
using MPfm.MVP.Views;
using TinyMessenger;

namespace MPfm.MVP.Presenters
{
Expand All @@ -29,12 +32,14 @@ namespace MPfm.MVP.Presenters
/// </summary>
public class CloudConnectPresenter : BasePresenter<ICloudConnectView>, ICloudConnectPresenter
{
private readonly ITinyMessengerHub _messengerHub;
private readonly ICloudLibraryService _cloudLibraryService;

public CloudConnectPresenter(ICloudLibraryService cloudLibraryService)
public CloudConnectPresenter(ITinyMessengerHub messengerHub, ICloudLibraryService cloudLibraryService)
{
_messengerHub = messengerHub;
_cloudLibraryService = cloudLibraryService;
_cloudLibraryService.OnCloudAuthenticationStatusChanged += CloudLibraryServiceOnOnCloudAuthenticationStatusChanged;
_cloudLibraryService.OnCloudAuthenticationStatusChanged += CloudLibraryServiceOnCloudAuthenticationStatusChanged;
}

public override void BindView(ICloudConnectView view)
Expand All @@ -54,8 +59,6 @@ private void Initialize()
IsAuthenticated = false
});

// Check if user is already authenticated?

Task.Factory.StartNew(() =>
{
try
Expand All @@ -69,14 +72,21 @@ private void Initialize()
});
}

private void CloudLibraryServiceOnOnCloudAuthenticationStatusChanged(CloudAuthenticationStatusType statusType)
private void CloudLibraryServiceOnCloudAuthenticationStatusChanged(CloudAuthenticationStatusType statusType)
{
Console.WriteLine("CloudConnectPresenter - CloudLibraryServiceOnCloudAuthenticationStatusChanged - statusType: {0}", statusType.ToString());
View.RefreshStatus(new CloudConnectEntity()
{
CloudServiceName = "Dropbox",
CurrentStep = ((int)statusType)+2,
IsAuthenticated = statusType == CloudAuthenticationStatusType.ConnectedToDropbox
});
_messengerHub.PublishAsync<CloudConnectStatusChangedMessage>(new CloudConnectStatusChangedMessage(this)
{
CloudServiceName = "Dropbox",
StatusType = statusType,
IsApplicationLinked = statusType == CloudAuthenticationStatusType.ConnectedToDropbox
});
}

private void CheckIfAccountIsLinked()
Expand Down
26 changes: 21 additions & 5 deletions MPfm/MPfm.MVP/Presenters/CloudPreferencesPresenter.cs
Expand Up @@ -15,12 +15,16 @@
// You should have received a copy of the GNU General Public License
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.ComponentModel;
using MPfm.Library.Services.Interfaces;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Messages;
using MPfm.MVP.Models;
using MPfm.MVP.Navigation;
using MPfm.MVP.Presenters.Interfaces;
using MPfm.MVP.Views;
using TinyMessenger;

namespace MPfm.MVP.Presenters
{
Expand All @@ -31,11 +35,16 @@ public class CloudPreferencesPresenter : BasePresenter<ICloudPreferencesView>, I
{
private readonly MobileNavigationManager _mobileNavigationManager;
private readonly NavigationManager _navigationManager;
private readonly ITinyMessengerHub _messengerHub;
private readonly ICloudLibraryService _cloudLibraryService;
private bool _isApplicationLinked;

public CloudPreferencesPresenter(ICloudLibraryService cloudLibraryService)
public CloudPreferencesPresenter(ITinyMessengerHub messengerHub, ICloudLibraryService cloudLibraryService)
{
_cloudLibraryService = cloudLibraryService;
_messengerHub = messengerHub;
_cloudLibraryService = cloudLibraryService;

_messengerHub.Subscribe<CloudConnectStatusChangedMessage>(CloudConnectStatusChanged);

#if IOS || ANDROID || WINDOWS_PHONE || WINDOWSSTORE
_mobileNavigationManager = Bootstrapper.GetContainer().Resolve<MobileNavigationManager>();
Expand All @@ -44,7 +53,7 @@ public CloudPreferencesPresenter(ICloudLibraryService cloudLibraryService)
#endif
}

public override void BindView(ICloudPreferencesView view)
public override void BindView(ICloudPreferencesView view)
{
view.OnDropboxLoginLogout = LoginLogoutDropbox;
view.OnSetCloudPreferences = SetCloudPreferences;
Expand All @@ -54,11 +63,18 @@ public override void BindView(ICloudPreferencesView view)
}

private void Initialize()
{
{
_isApplicationLinked = _cloudLibraryService.HasLinkedAccount;
RefreshPreferences();
RefreshState();
}

private void CloudConnectStatusChanged(CloudConnectStatusChangedMessage cloudConnectStatusChangedMessage)
{
_isApplicationLinked = cloudConnectStatusChangedMessage.IsApplicationLinked;
RefreshState();
}

private void SetCloudPreferences(CloudPreferencesEntity entity)
{
}
Expand All @@ -83,7 +99,7 @@ private void RefreshState()
{
var state = new CloudPreferencesStateEntity()
{
IsDropboxLinkedToApp = _cloudLibraryService.HasLinkedAccount
IsDropboxLinkedToApp = _isApplicationLinked
};
View.RefreshCloudPreferencesState(state);
}
Expand Down
13 changes: 11 additions & 2 deletions MPfm/MPfm.MVP/Presenters/ResumePlaybackPresenter.cs
Expand Up @@ -18,6 +18,7 @@
using System;
using MPfm.Library.Objects;
using MPfm.MVP.Presenters.Interfaces;
using MPfm.MVP.Services.Interfaces;
using MPfm.MVP.Views;
using MPfm.Library.Services.Interfaces;
using System.Threading.Tasks;
Expand All @@ -39,13 +40,15 @@ public class ResumePlaybackPresenter : BasePresenter<IResumePlaybackView>, IResu
private readonly NavigationManager _navigationManager;
private readonly ITinyMessengerHub _messengerHub;
private readonly ICloudLibraryService _cloudLibrary;
private readonly IAudioFileCacheService _audioFileCacheService;
private readonly IPlayerService _playerService;
private readonly IAudioFileCacheService _audioFileCacheService;

public ResumePlaybackPresenter(ITinyMessengerHub messengerHub, IAudioFileCacheService audioFileCacheService, ICloudLibraryService cloudLibrary)
public ResumePlaybackPresenter(ITinyMessengerHub messengerHub, IAudioFileCacheService audioFileCacheService, ICloudLibraryService cloudLibrary, IPlayerService playerService)
{
_messengerHub = messengerHub;
_audioFileCacheService = audioFileCacheService;
_cloudLibrary = cloudLibrary;
_playerService = playerService;
_cloudLibrary.OnCloudDataChanged += (data) => {
Task.Factory.StartNew(() => {
Console.WriteLine("ResumePlaybackPresenter - OnCloudDataChanged - Sleeping...");
Expand Down Expand Up @@ -107,6 +110,12 @@ private void ResumePlayback(CloudDeviceInfo device)
// Only need to create the Player view on mobile devices
#if IOS || ANDROID || WINDOWS_PHONE || WINDOWSSTORE
_mobileNavigationManager.CreatePlayerView(MobileNavigationTabType.More, onViewBindedToPresenter);
#else
var audioFiles = _audioFileCacheService.SelectAudioFiles(new LibraryQuery() {
ArtistName = device.ArtistName,
AlbumTitle = device.AlbumTitle
});
_playerService.Play(audioFiles, audioFile != null ? audioFile.FilePath : string.Empty);
#endif
}
}
Expand Down
Expand Up @@ -36,16 +36,17 @@ public SyncDeviceType GetDeviceType()
return SyncDeviceType.Windows;
}

string _deviceName = string.Empty;
public string GetDeviceName()
{
_deviceName = System.Environment.MachineName;
return _deviceName;
return System.Environment.MachineName;;
}

public string GetDeviceUniqueId()
{
return string.Empty;
string machineName = System.Environment.MachineName;
machineName = machineName.Replace(" ", "");
machineName = machineName.Normalize();
return machineName;
}

public long GetFreeSpace()
Expand Down
1 change: 1 addition & 0 deletions MPfm/MPfm.WPF/Classes/Windows/PreferencesWindow.xaml.cs
Expand Up @@ -124,6 +124,7 @@ public void RefreshCloudPreferences(CloudPreferencesEntity entity)

public void RefreshCloudPreferencesState(CloudPreferencesStateEntity entity)
{
Console.WriteLine("PreferencesWindow - IsDropboxLinkedToApp: {0}", entity.IsDropboxLinkedToApp);
Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
{
if (entity.IsDropboxLinkedToApp)
Expand Down
32 changes: 31 additions & 1 deletion MPfm/MPfm.WPF/Classes/Windows/ResumePlaybackWindow.xaml
Expand Up @@ -3,6 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:base="clr-namespace:MPfm.WPF.Classes.Windows.Base"
xmlns:controls="clr-namespace:MPfm.WPF.Classes.Controls"
xmlns:models="clr-namespace:MPfm.Library.Objects;assembly=MPfm.Library"
WindowStartupLocation="CenterScreen" Background="#FF242F35"
Title="Resume Playback" Height="426" Width="677.9" Icon="/MPfm.WPF;component/Resources/Icon.ico">
<Grid Margin="0">
Expand All @@ -11,9 +12,38 @@
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Label Grid.Row="0" Background="#FF455865" Content="Resume Playback" Foreground="White" FontSize="14" FontFamily="/Resources/Fonts/#TitilliumText22L Lt" />
<Grid Grid.Row="0" Background="#FF455865">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" x:Name="lblTitle" Content="Resume Playback" Foreground="White" FontSize="14" FontFamily="/Resources/Fonts/#TitilliumText22L Lt" />
<Button Grid.Column="1" Style="{StaticResource HeaderImageButton}" Click="btnResume_OnClick">
<StackPanel Orientation="Horizontal" Margin="4">
<Image Source="/Resources/Images/Buttons/play.png" Stretch="None" />
<TextBlock Margin="6,1,0,0">Resume</TextBlock>
</StackPanel>
</Button>
</Grid>
<Label Grid.Row="1" Content="Select a device from the list to resume playback:" Foreground="#FFCCCCCC" FontSize="12" FontFamily="/Resources/Fonts/#Junction" Padding="6,8,4,8" />
<ListView x:Name="listView" Grid.Row="2">
<ListView.Resources>
<HierarchicalDataTemplate DataType="{x:Type models:CloudDeviceInfo}" ItemsSource="{Binding SubItems}">
<StackPanel Orientation="Vertical" Margin="4">
<TextBlock Text="{Binding DeviceName}" FontSize="13" FontWeight="Bold" FontFamily="/Resources/Fonts/#Junction" Foreground="Black" Margin="0" />
<TextBlock Text="On-the-fly Playlist" FontSize="12" FontFamily="/Resources/Fonts/#Junction" Foreground="#333333" Margin="0" />
<StackPanel Orientation="Horizontal">
<StackPanel Background="DarkSlateGray" Width="54" Height="54" Margin="0,4,8,4"></StackPanel>
<StackPanel Orientation="Vertical" VerticalAlignment="Center">
<TextBlock Text="{Binding ArtistName}" FontSize="11" FontFamily="/Resources/Fonts/#Junction" Foreground="#333333" Margin="0" />
<TextBlock Text="{Binding AlbumTitle}" FontSize="11" FontFamily="/Resources/Fonts/#Junction" Foreground="#555555" Margin="0" />
<TextBlock Text="{Binding SongTitle}" FontSize="11" FontFamily="/Resources/Fonts/#Junction" Foreground="#777777" Margin="0" />
</StackPanel>
</StackPanel>
<TextBlock Text="{Binding Timestamp}" FontSize="11" FontFamily="/Resources/Fonts/#Junction" Foreground="#999999" Margin="0" />
</StackPanel>
</HierarchicalDataTemplate>
</ListView.Resources>
</ListView>
</Grid>
</base:BaseWindow>
8 changes: 8 additions & 0 deletions MPfm/MPfm.WPF/Classes/Windows/ResumePlaybackWindow.xaml.cs
Expand Up @@ -37,6 +37,14 @@ public ResumePlaybackWindow(Action<IBaseView> onViewReady)
ViewIsReady();
}

private void btnResume_OnClick(object sender, RoutedEventArgs e)
{
if (listView.SelectedItems.Count == 0)
return;

OnResumePlayback((CloudDeviceInfo) listView.SelectedItems[0]);
}

#region IResumePlaybackView implementation

public Action<CloudDeviceInfo> OnResumePlayback { get; set; }
Expand Down

0 comments on commit b6f7270

Please sign in to comment.