Skip to content

Commit

Permalink
WindowsPhone: Added SyncMenu and SyncDownload pages. Far from being d…
Browse files Browse the repository at this point in the history
…one.

Related to issue #424.
  • Loading branch information
ycastonguay committed Sep 30, 2013
1 parent 475596b commit 80c18ca
Show file tree
Hide file tree
Showing 18 changed files with 764 additions and 218 deletions.
31 changes: 22 additions & 9 deletions MPfm/MPfm.Library/Services/WinRT/SyncClientService.cs
Expand Up @@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using MPfm.Core;
using MPfm.Library.Services.Interfaces;
using MPfm.Sound.AudioFiles;
using System.Linq;
Expand Down Expand Up @@ -62,7 +63,7 @@ private void Initialize()
{
_stopwatch = new Stopwatch();
_httpClient = new HttpClient();
_httpClient.Timeout = new TimeSpan(0, 0, 3);
_httpClient.Timeout = new TimeSpan(0, 0, 0, 0, 1000);

//_webClient = new WebClientTimeout(3000);
//_webClient.DownloadProgressChanged += HandleDownloadProgressChanged;
Expand Down Expand Up @@ -185,14 +186,25 @@ public void Cancel()
// _webClient.CancelAsync();
}

public void DownloadIndex(string baseUrl)
public async void DownloadIndex(string baseUrl)
{
var url = new Uri(new Uri(baseUrl), "/api/index/xml");
Cancel();

//Console.WriteLine("SyncClientService - Downloading index from {0}...", url);
//_webClient.DownloadStringAsync(url, url);
}
try
{
var url = new Uri(new Uri(baseUrl), "/api/index/xml");
Tracing.Log("SyncClientService - DownloadIndex - baseUrl: {0} url: {1}", baseUrl, url);
//Cancel();
string index = await _httpClient.GetStringAsync(url);
Tracing.Log("SyncClientService - DownloadIndex - Finished downloading index. Deserializing XML...", url);
_audioFiles = XmlSerialization.Deserialize<List<AudioFile>>(index);
Tracing.Log("SyncClientService - DownloadIndex - XML deserialized!");
if (OnReceivedIndex != null)
OnReceivedIndex(null);
}
catch (Exception ex)
{
Tracing.Log("SyncClientService - DownloadIndex - Exception: {0}", ex);
}
}

public List<string> GetDistinctArtistNames()
{
Expand Down Expand Up @@ -224,6 +236,7 @@ public void DownloadAudioFiles(string baseUrl, IEnumerable<AudioFile> audioFiles
//if (_webClient.IsBusy)
// return;

Tracing.Log("SyncClientService - DownloadAudioFiles - baseUrl: {0}", baseUrl);
_filesDownloaded = 0;
_bytesDownloaded = 0;
_errorCount = 0;
Expand All @@ -250,7 +263,7 @@ private void DownloadAudioFile(AudioFile audioFile)
{
var url = new Uri(new Uri(_baseUrl), string.Format("/api/audiofile/{0}", audioFile.Id.ToString()));
string localFilePath = GetLibraryLocalPath(audioFile);
//Console.WriteLine("SyncClientService - DownloadAudioFile - folderPath: {0} fileName: {1} localFilePath: {2}", folderPath, fileName, localFilePath);
//Tracing.Log("SyncClientService - DownloadAudioFile - folderPath: {0} fileName: {1} localFilePath: {2}", folderPath, fileName, localFilePath);
_lastBytesReceived = 0;

if (OnDownloadAudioFileStarted != null)
Expand Down
20 changes: 10 additions & 10 deletions MPfm/MPfm.Library/Services/WinRT/SyncDiscoveryService.cs
Expand Up @@ -58,25 +58,25 @@ public async void SearchForDevices(string baseIP)
{
Tracing.Log("SyncDiscoveryService - SearchForDevices - Searching for common ips in {0}.*", baseIP);
var commonIPs = new List<string>();
for(int a = 0; a < 25; a++)
commonIPs.Add(string.Format("{0}.{1}", baseIP, a));
for (int a = 100; a < 125; a++)
//for(int a = 0; a < 25; a++)
// commonIPs.Add(string.Format("{0}.{1}", baseIP, a));
for (int a = 100; a < 120; a++)
commonIPs.Add(string.Format("{0}.{1}", baseIP, a));
var commonDevices = await SearchForDevicesAsync(commonIPs);

Tracing.Log("SyncDiscoveryService - SearchForDevices - Searching for uncommon ips in {0}.*", baseIP);
var uncommonIPs = new List<string>();
for (int a = 26; a < 99; a++)
uncommonIPs.Add(string.Format("{0}.{1}", baseIP, a));
for (int a = 126; a < 255; a++)
uncommonIPs.Add(string.Format("{0}.{1}", baseIP, a));
var uncommonDevices = await SearchForDevicesAsync(uncommonIPs);
//for (int a = 26; a < 99; a++)
// uncommonIPs.Add(string.Format("{0}.{1}", baseIP, a));
//for (int a = 126; a < 255; a++)
// uncommonIPs.Add(string.Format("{0}.{1}", baseIP, a));
//var uncommonDevices = await SearchForDevicesAsync(uncommonIPs);

Tracing.Log("SyncDiscoveryService - SearchForDevices - Discovery ended!");
_isCancelling = false;
var allDevices = new List<SyncDevice>();
allDevices.AddRange(commonDevices);
allDevices.AddRange(uncommonDevices);
//allDevices.AddRange(uncommonDevices);
if (OnDiscoveryEnded != null)
OnDiscoveryEnded(allDevices);
}
Expand Down Expand Up @@ -169,7 +169,7 @@ private async Task<SyncDevice> ProcessDevice(string url, string ip)
var device = XmlSerialization.Deserialize<SyncDevice>(content);
if (device.SyncVersionId.ToUpper() == SyncListenerService.SyncVersionId.ToUpper())
{
device.Url = url;
device.Url = url.Replace("/sessionsapp.version", "");
if (OnDeviceFound != null) OnDeviceFound(device);
Tracing.Log("SyncDiscoveryService - The following host is available: {0}", ip);
}
Expand Down
6 changes: 3 additions & 3 deletions MPfm/MPfm.MVP/Presenters/SyncMenuPresenter.cs
Expand Up @@ -53,7 +53,7 @@ public SyncMenuPresenter(ISyncClientService syncClientService, ISyncDeviceSpecif
_syncClientService.OnDownloadIndexProgress += HandleOnDownloadIndexProgress;
_syncClientService.OnReceivedIndex += HandleOnReceivedIndex;

#if IOS || ANDROID
#if IOS || ANDROID || WINDOWS_PHONE
_mobileNavigationManager = Bootstrapper.GetContainer().Resolve<MobileNavigationManager>();
#else
_navigationManager = Bootstrapper.GetContainer().Resolve<NavigationManager>();
Expand Down Expand Up @@ -147,7 +147,7 @@ private void Sync()
return;
}

#if IOS || ANDROID
#if IOS || ANDROID || WINDOWS_PHONE
_mobileNavigationManager.CreateSyncDownloadView(_device, _audioFilesToSync);
#else
_navigationManager.CreateSyncDownloadView(_device, _audioFilesToSync);
Expand All @@ -161,7 +161,7 @@ private void Sync()

private void SelectItems(List<SyncMenuItemEntity> items)
{
#if IOS || ANDROID
#if IOS || ANDROID || WINDOWS_PHONE
SelectItemsMobile(items);
#else
SelectItemsDesktop(items);
Expand Down
2 changes: 1 addition & 1 deletion MPfm/MPfm.MVP/Presenters/SyncPresenter.cs
Expand Up @@ -96,7 +96,7 @@ private void HandleOnDiscoveryEnded(IEnumerable<SyncDevice> devices)

private void ConnectDevice(SyncDevice device)
{
#if IOS || ANDROID
#if IOS || ANDROID || WINDOWS_PHONE
_mobileNavigationManager.CreateSyncMenuView(device);
#else
_navigationManager.CreateSyncMenuView(device);
Expand Down
7 changes: 2 additions & 5 deletions MPfm/MPfm.WindowsPhone/App.xaml.cs
Expand Up @@ -249,10 +249,7 @@ private void InitializeLanguage()
// or RightToLeft.

if (Debugger.IsAttached)
{
Debugger.Break();
}

throw;
}
}
Expand All @@ -275,8 +272,8 @@ private void BootstrapApp()
//container.Register<IMobileLibraryBrowserView, MobileLibraryBrowserFragment>().AsMultiInstance();
//container.Register<IPlaylistView, PlaylistActivity>().AsMultiInstance();
container.Register<ISyncView, SyncPage>().AsMultiInstance();
//container.Register<ISyncDownloadView, SyncDownloadActivity>().AsMultiInstance();
//container.Register<ISyncMenuView, SyncMenuActivity>().AsMultiInstance();
container.Register<ISyncDownloadView, SyncDownloadPage>().AsMultiInstance();
container.Register<ISyncMenuView, SyncMenuPage>().AsMultiInstance();
container.Register<ISyncWebBrowserView, SyncWebBrowserPage>().AsMultiInstance();
//container.Register<IEqualizerPresetsView, EqualizerPresetsActivity>().AsMultiInstance();
//container.Register<IEqualizerPresetDetailsView, EqualizerPresetDetailsActivity>().AsMultiInstance();
Expand Down
32 changes: 32 additions & 0 deletions MPfm/MPfm.WindowsPhone/Classes/Controls/ListSyncMenuControl.xaml
@@ -0,0 +1,32 @@
<UserControl x:Class="MPfm.WindowsPhone.Classes.Controls.ListSyncMenuControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="480" d:DesignWidth="480">

<Grid x:Name="LayoutRoot">
<Grid.Background>
<SolidColorBrush Color="#20282e"/>
</Grid.Background>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="Selected">
<Storyboard>
<ColorAnimation Duration="0" To="#36454F" Storyboard.TargetProperty="(Control.Background).(SolidColorBrush.Color)" Storyboard.TargetName="LayoutRoot" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<StackPanel Margin="8,6,0,0">
<TextBlock x:Name="textBlock" Text="{Binding ArtistName}" TextWrapping="Wrap" Style="{StaticResource PhoneTextLargeStyle}" Margin="54,0,12,0" FontSize="24"/>
<TextBlock x:Name="textBlock2" Text="Subtitle" TextWrapping="Wrap" Style="{StaticResource PhoneTextSmallStyle}" Margin="54,0,12,0" FontSize="16"/>
</StackPanel>
<Image HorizontalAlignment="Left" Height="52" VerticalAlignment="Top" Width="52" Source="/Assets/Icons/icon_apple.png" Margin="0,8,0,8"/>
</Grid>
</UserControl>
@@ -0,0 +1,29 @@
// 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 System.Windows.Controls;

namespace MPfm.WindowsPhone.Classes.Controls
{
public partial class ListSyncMenuControl : UserControl
{
public ListSyncMenuControl()
{
InitializeComponent();
}
}
}
Expand Up @@ -26,6 +26,7 @@
using MPfm.Library.Objects;
using MPfm.MVP.Navigation;
using MPfm.MVP.Views;
using MPfm.Sound.AudioFiles;
using MPfm.WindowsPhone.Classes.Pages;
using MPfm.WindowsPhone.Classes.Pages.Base;

Expand All @@ -36,6 +37,8 @@ public class WindowsPhoneNavigationManager : MobileNavigationManager
private Action<IBaseView> _onSyncViewReady;
private Action<IBaseView> _onSyncWebBrowserViewReady;
private Action<IBaseView> _onPreferencesViewReady;
private Action<IBaseView> _onSyncMenuViewReady;
private Action<IBaseView> _onSyncDownloadViewReady;

public override void ShowSplash(ISplashView view)
{
Expand Down Expand Up @@ -100,6 +103,20 @@ protected override void CreateSyncViewInternal(Action<IBaseView> onViewReady)
var frame = Application.Current.RootVisual as PhoneApplicationFrame;
frame.Navigate(new Uri("/Classes/Pages/SyncPage.xaml", UriKind.Relative));
}

protected override void CreateSyncMenuViewInternal(Action<IBaseView> onViewReady, SyncDevice device)
{
_onSyncMenuViewReady = onViewReady;
var frame = Application.Current.RootVisual as PhoneApplicationFrame;
frame.Navigate(new Uri("/Classes/Pages/SyncMenuPage.xaml", UriKind.Relative));
}

protected override void CreateSyncDownloadViewInternal(Action<IBaseView> onViewReady, SyncDevice device, IEnumerable<AudioFile> audioFiles)
{
_onSyncDownloadViewReady = onViewReady;
var frame = Application.Current.RootVisual as PhoneApplicationFrame;
frame.Navigate(new Uri("/Classes/Pages/SyncDownloadPage.xaml", UriKind.Relative));
}

protected override void CreateSyncWebBrowserViewInternal(Action<IBaseView> onViewReady)
{
Expand All @@ -119,6 +136,10 @@ public void SetViewInstance(BasePage page)
{
if(page is SyncPage)
_onSyncViewReady(page);
else if (page is SyncMenuPage)
_onSyncMenuViewReady(page);
else if (page is SyncDownloadPage)
_onSyncDownloadViewReady(page);
else if (page is SyncWebBrowserPage)
_onSyncWebBrowserViewReady(page);
else if (page is PreferencesPage)
Expand Down
2 changes: 1 addition & 1 deletion MPfm/MPfm.WindowsPhone/Classes/Pages/MainPage.xaml
Expand Up @@ -86,7 +86,7 @@
<ColumnDefinition Width="61*"/>
<ColumnDefinition Width="87*"/>
</Grid.ColumnDefinitions>
<Button Content="Button" HorizontalAlignment="Left" Margin="59,0,0,463" Click="Button_Click" Height="72" VerticalAlignment="Bottom"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="59,0,0,463" Click="Button_Click" Height="72" VerticalAlignment="Bottom" />
<TextBlock x:Name="txtStuff" HorizontalAlignment="Left" Margin="56,48,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Grid.Column="1"/>
</Grid>
</phone:PivotItem>
Expand Down
89 changes: 33 additions & 56 deletions MPfm/MPfm.WindowsPhone/Classes/Pages/MainPage.xaml.cs
Expand Up @@ -25,6 +25,7 @@
using System.Windows.Controls;
using System.Windows.Media;
using Windows.Storage;
using Microsoft.Phone.BackgroundAudio;
using Microsoft.Phone.Shell;
using MPfm.Library.Services;
using MPfm.MVP.Bootstrap;
Expand Down Expand Up @@ -95,68 +96,44 @@ private void CreateDummyData()

private async void Button_Click(object sender, RoutedEventArgs e)
{
//var folder = ApplicationData.Current.LocalFolder;
//var audioFolder = await folder.GetFolderAsync("Audio");
//var files = await audioFolder.GetFilesAsync();
//foreach (var file in files)
//{
// if (file.Path.Contains(".mp3"))
// {
// Debug.WriteLine("Definitely a mp3: " + file.Path);
// AudioFile audioFile = new AudioFile(file.Path);
// txtStuff.Text = audioFile.Title;
// }
// else
// {
// Debug.WriteLine("Not mp3: " + file.Path);
// }
//}
var folder = ApplicationData.Current.LocalFolder;
var audioFolder = await folder.GetFolderAsync("Audio");
var files = await audioFolder.GetFilesAsync();
foreach (var file in files)
{
if (file.Path.Contains(".mp3"))
{
Debug.WriteLine("Definitely a mp3: " + file.Path);
AudioFile audioFile = new AudioFile(file.Path);
txtStuff.Text = audioFile.Title;
}
else
{
Debug.WriteLine("Not mp3: " + file.Path);
}
}

//CreateDummyFile();
//AudioFile audioFile = new AudioFile();

IconicTileData oIcontile = new IconicTileData();
oIcontile.Title = "Hello Iconic Tile!!";
oIcontile.Count = 7;

oIcontile.IconImage = new Uri("Assets/Tiles/LargeIconicTile.png", UriKind.Relative);
oIcontile.SmallIconImage = new Uri("Assets/Tiles/SmallIconicTile.png", UriKind.Relative);

oIcontile.WideContent1 = "windows phone 8 Live tile";
oIcontile.WideContent2 = "Icon tile";
oIcontile.WideContent3 = "All about Live tiles By WmDev";

oIcontile.BackgroundColor = Color.FromArgb(255, 54, 69, 79);

// find the tile object for the application tile that using "Iconic" contains string in it.
ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("Iconic".ToString()));

if (TileToFind != null && TileToFind.NavigationUri.ToString().Contains("Iconic"))
{
TileToFind.Delete();
ShellTile.Create(new Uri("/MainPage.xaml?id=Iconic", UriKind.Relative), oIcontile, true);
}
else
{
ShellTile.Create(new Uri("/MainPage.xaml?id=Iconic", UriKind.Relative), oIcontile, true);
}
BackgroundAudioPlayer.Instance.Play();
}

private async Task WriteToFile()
{
// Get the text data from the textbox.
string data = "hello world";
byte[] fileBytes = System.Text.Encoding.UTF8.GetBytes(data.ToCharArray());

// Get the local folder.
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;

// Create dummy data file
var dataFolder = await local.CreateFolderAsync("Audio", CreationCollisionOption.OpenIfExists);
var file = await dataFolder.CreateFileAsync("DataFile.txt", CreationCollisionOption.ReplaceExisting);
using (var s = await file.OpenStreamForWriteAsync())
s.Write(fileBytes, 0, fileBytes.Length);
}
//private async Task WriteToFile()
//{
// // Get the text data from the textbox.
// string data = "hello world";
// byte[] fileBytes = System.Text.Encoding.UTF8.GetBytes(data.ToCharArray());

// // Get the local folder.
// StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;

// // Create dummy data file
// var dataFolder = await local.CreateFolderAsync("Audio", CreationCollisionOption.OpenIfExists);
// var file = await dataFolder.CreateFileAsync("DataFile.txt", CreationCollisionOption.ReplaceExisting);
// using (var s = await file.OpenStreamForWriteAsync())
// s.Write(fileBytes, 0, fileBytes.Length);
//}

private void listArtists_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Expand Down

0 comments on commit 80c18ca

Please sign in to comment.