Skip to content

Commit

Permalink
iOS: ReachabilityHelper is now used to detect connection change and r…
Browse files Browse the repository at this point in the history
…estart the HTTP server when wifi comes available. Updated views after changes on Android.

Updated project files after changes on Android.

Related to issue #405.
  • Loading branch information
ycastonguay committed Jul 22, 2013
1 parent 4945faa commit e0a4f51
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 33 deletions.
1 change: 1 addition & 0 deletions MPfm/MPfm.Library/MPfm.Library.csproj
Expand Up @@ -160,6 +160,7 @@
<Compile Include="Database\Interfaces\ISQLiteGateway.cs" />
<Compile Include="Database\DatabaseFacade.cs" />
<Compile Include="ILibrary.cs" />
<Compile Include="Objects\NetworkState.cs" />
<Compile Include="Objects\PlaylistFile.cs" />
<Compile Include="Objects\History.cs" />
<Compile Include="Objects\Setting.cs" />
Expand Down
7 changes: 4 additions & 3 deletions MPfm/MPfm.Library/MPfm.Library.iOS.csproj
Expand Up @@ -198,12 +198,16 @@
<EmbeddedResource Include="WebApp\js\jquery.upload-1.0.2.min.js" />
<EmbeddedResource Include="WebApp\images\app_logo.png" />
</ItemGroup>
<ItemGroup>
<None Include="Lib\iOS\Newtonsoft.Json.dll" />
</ItemGroup>
<ItemGroup>
<Compile Include="Database\MonoSQLiteGateway.cs" />
<Compile Include="Database\Interfaces\IDatabaseFacade.cs" />
<Compile Include="Database\Interfaces\ISQLiteGateway.cs" />
<Compile Include="Database\DatabaseFacade.cs" />
<Compile Include="ILibrary.cs" />
<Compile Include="Objects\NetworkState.cs" />
<Compile Include="Objects\PlaylistFile.cs" />
<Compile Include="Objects\History.cs" />
<Compile Include="Objects\Setting.cs" />
Expand Down Expand Up @@ -238,7 +242,4 @@
<Compile Include="Objects\UpdateLibraryEntity.cs" />
<Compile Include="Objects\SyncClientDownloadAudioFileProgressEntity.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Lib\iOS\Newtonsoft.Json.dll" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions MPfm/MPfm.MVP/MPfm.MVP.csproj
Expand Up @@ -108,6 +108,7 @@
</ProjectExtensions>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Messages\ConnectionStatusChangedMessage.cs" />
<Compile Include="Messages\MobileLibraryBrowserItemClickedMessage.cs" />
<Compile Include="Navigation\MobileNavigationManager.cs" />
<Compile Include="Presenters\AudioPreferencesPresenter.cs" />
Expand Down
5 changes: 3 additions & 2 deletions MPfm/MPfm.MVP/MPfm.MVP.iOS.csproj
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -175,6 +175,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Messages\ConnectionStatusChangedMessage.cs" />
<Compile Include="Messages\MobileLibraryBrowserItemClickedMessage.cs" />
<Compile Include="Navigation\MobileNavigationManager.cs" />
<Compile Include="Presenters\AudioPreferencesPresenter.cs" />
Expand Down Expand Up @@ -297,4 +298,4 @@
<Compile Include="Presenters\SyncDownloadPresenter.cs" />
<Compile Include="Messages\PlayerPlaylistUpdatedMessage.cs" />
</ItemGroup>
</Project>
</Project>
3 changes: 0 additions & 3 deletions MPfm/MPfm.Player/MPfm.Player.iOS.csproj
Expand Up @@ -138,9 +138,6 @@
<HintPath>..\MPfm.Sound\Lib\iOS\Bass.Net.iOS.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Content Include="Lib\Bass.Net.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
17 changes: 8 additions & 9 deletions MPfm/MPfm.Sound/BassNetKey.cs
@@ -1,12 +1,11 @@

// To build MPfm correctly, you need to generate your own BASS.NET key at this website: http://bass.radio42.com/bass_register.html
// Simply uncomment this file and add your email/key.

namespace MPfm.Sound
{
public static class BassNetKey
{
public const string Email = "yanick.castonguay@gmail.com";
public const string RegistrationKey = "2X3433427152222";
}
}
//namespace MPfm.Sound
//{
// public static class BassNetKey
// {
// public const string Email = "";
// public const string RegistrationKey = "";
// }
//}
1 change: 0 additions & 1 deletion MPfm/MPfm.Sound/MPfm.Sound.csproj
Expand Up @@ -150,7 +150,6 @@
<Compile Include="BassNetWrapper\WASAPI\BaseWASAPI.cs" />
<Compile Include="Readers\XingInfoHeaderReader.cs" />
<Compile Include="BassNetKey.cs" />
<Compile Include="MyBassNetKey.cs" />
<Compile Include="BassNetWrapper\BassWrapper.cs" />
<Compile Include="BassNetWrapper\BaseFx.cs" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion MPfm/MPfm.Sound/MPfm.Sound.iOS.csproj
Expand Up @@ -212,8 +212,8 @@
<Compile Include="BassNetWrapper\WASAPI\BaseWASAPI.cs" />
<Compile Include="Readers\XingInfoHeaderReader.cs" />
<Compile Include="BassNetKey.cs" />
<Compile Include="MyBassNetKey.cs" />
<Compile Include="BassNetWrapper\BassWrapper.cs" />
<Compile Include="BassNetWrapper\BaseFx.cs" />
<Compile Include="MyBassNetKey.cs" />
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion MPfm/MPfm.iOS/Classes/Controllers/SplashViewController.cs
Expand Up @@ -82,10 +82,11 @@ public void RefreshStatus(string message)
});
}

public void InitDone()
public void InitDone(bool isAppFirstStart)
{
}

#endregion

}
}
Expand Up @@ -66,7 +66,6 @@ public override void ConfirmedBackButton()
#region ISyncDownloadView implementation

public Action OnCancelDownload { get; set; }
public Action OnButtonPressed { get; set; }

public void SyncDownloadError(Exception ex)
{
Expand All @@ -76,6 +75,10 @@ public void SyncDownloadError(Exception ex)
});
}

public void RefreshDevice(SyncDevice device)
{
}

public void RefreshStatus(SyncClientDownloadAudioFileProgressEntity entity)
{
InvokeOnMainThread(() => {
Expand Down
13 changes: 13 additions & 0 deletions MPfm/MPfm.iOS/Classes/Controllers/SyncMenuViewController.cs
Expand Up @@ -26,6 +26,7 @@
using MPfm.Sound.AudioFiles;
using MPfm.MVP.Models;
using MPfm.iOS.Classes.Controls;
using MPfm.Library.Objects;

namespace MPfm.iOS
{
Expand Down Expand Up @@ -239,6 +240,18 @@ public void SyncMenuError(Exception ex)
});
}

public void SyncEmptyError(Exception ex)
{
InvokeOnMainThread(() => {
var alertView = new UIAlertView("Sync Error", ex.Message, null, "OK", null);
alertView.Show();
});
}

public void RefreshDevice(SyncDevice device)
{
}

public void RefreshLoading(bool isLoading, int progressPercentage)
{
//Console.WriteLine("SyncMenuViewController - isLoading: {0} progressPercentage: {1}", isLoading, progressPercentage);
Expand Down
4 changes: 2 additions & 2 deletions MPfm/MPfm.iOS/Classes/Controllers/SyncViewController.cs
Expand Up @@ -106,7 +106,7 @@ public void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
tableView.DeselectRow(indexPath, true);
OnCancelDiscovery();
OnConnectDevice(_devices[indexPath.Row].Url);
OnConnectDevice(_devices[indexPath.Row]);
}

partial void actionConnectDeviceManually(NSObject sender)
Expand All @@ -119,7 +119,7 @@ public void RowSelected(UITableView tableView, NSIndexPath indexPath)

public Action OnStartDiscovery { get; set; }
public Action OnCancelDiscovery { get; set; }
public Action<string> OnConnectDevice { get; set; }
public Action<SyncDevice> OnConnectDevice { get; set; }
public Action<string> OnConnectDeviceManually { get; set; }

public void SyncError(Exception ex)
Expand Down
23 changes: 13 additions & 10 deletions MPfm/MPfm.iOS/Classes/Helpers/ReachabilityHelper.cs
@@ -1,5 +1,3 @@
// This code is taken from https://github.com/xamarin/monotouch-samples/blob/master/ReachabilitySample/reachability.cs

using System;
using System.Net;
using MonoTouch.Foundation;
Expand All @@ -9,7 +7,18 @@

namespace MPfm.iOS.Helpers
{
public static class ReachabilityHelper {
public enum NetworkStatus {
NotReachable,
ReachableViaCarrierDataNetwork,
ReachableViaWiFiNetwork
}

/// <summary>
/// Reachability helper class, taken from:
/// https://github.com/xamarin/monotouch-samples/blob/master/ReachabilitySample/reachability.cs
/// </summary>
public static class ReachabilityHelper
{
public static string HostName = "www.google.com";

public static bool IsReachableWithoutRequiringConnection (NetworkReachabilityFlags flags)
Expand Down Expand Up @@ -86,7 +95,7 @@ static bool IsNetworkAvailable (out NetworkReachabilityFlags flags)
defaultRouteReachability.SetCallback (OnChange);
defaultRouteReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
}
if (!defaultRouteReachability.TryGetFlags (out flags))
if (defaultRouteReachability.TryGetFlags (out flags))
return false;
return IsReachableWithoutRequiringConnection (flags);
}
Expand Down Expand Up @@ -145,10 +154,4 @@ public static NetworkStatus LocalWifiConnectionStatus ()
return NetworkStatus.NotReachable;
}
}

public enum NetworkStatus {
NotReachable,
ReachableViaCarrierDataNetwork,
ReachableViaWiFiNetwork
}
}
19 changes: 19 additions & 0 deletions MPfm/MPfm.iOS/Classes/Helpers/iOSSyncDeviceSpecifications.cs
Expand Up @@ -29,6 +29,19 @@ namespace MPfm.iOS.Helpers
/// </summary>
public class iOSSyncDeviceSpecifications : NSObject, ISyncDeviceSpecifications
{
public event NetworkStateChanged OnNetworkStateChanged;

public iOSSyncDeviceSpecifications()
{
Console.WriteLine(">>>>>>>>>>>>>>>>>> SETTING REACHABILITY EVENT");
ReachabilityHelper.ReachabilityChanged += HandleReachabilityChanged;
}

private void HandleReachabilityChanged(object sender, EventArgs e)
{
Console.WriteLine(">>>>>>>>>>>>>>>>>> REACHABILITY CHANGED");
}

public SyncDeviceType GetDeviceType()
{
return SyncDeviceType.iOS;
Expand Down Expand Up @@ -65,5 +78,11 @@ public string GetMusicFolderPath()
{
return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
}

public void ReportNetworkStateChange(NetworkState networkState)
{
if(OnNetworkStateChanged != null)
OnNetworkStateChanged(networkState);
}
}
}

0 comments on commit e0a4f51

Please sign in to comment.