Skip to content

Commit

Permalink
iOS: Updated sync views after changes on Android. The sync download c…
Browse files Browse the repository at this point in the history
…an now be canceled. Fixed bugs in MobileNavigationManager. Updated iOSSyncDeviceSpecifications with new methods. Fixed bugs in SyncClientService.

Related to issue #405.
  • Loading branch information
ycastonguay committed Jul 19, 2013
1 parent 2d7d71b commit 7b79fc5
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 32 deletions.
Expand Up @@ -29,6 +29,8 @@ public interface ISyncDiscoveryService
event SyncDiscoveryService.DiscoveryProgress OnDiscoveryProgress;
event SyncDiscoveryService.DiscoveryEnded OnDiscoveryEnded;

bool IsRunning { get; }

void SearchForDevices(List<string> ips);
void SearchForDevices(string baseIP);
void Cancel();
Expand Down
6 changes: 3 additions & 3 deletions MPfm/MPfm.Library/Services/SyncClientService.cs
Expand Up @@ -256,20 +256,20 @@ private void DownloadAudioFile(AudioFile audioFile)
{
var url = new Uri(new Uri(_baseUrl), string.Format("/api/audiofile/{0}", audioFile.Id.ToString()));
string fileName = Path.GetFileName(audioFile.FilePath);
//string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string folderPath = _deviceSpecifications.GetMusicFolderPath();

// Add artist name to the path (create folder if necessary)
folderPath += Path.Combine(folderPath, audioFile.ArtistName);
folderPath = Path.Combine(folderPath, audioFile.ArtistName);
if (!Directory.Exists(folderPath))
Directory.CreateDirectory(folderPath);

// Add album title to the path (create folder if necessary)
folderPath += Path.Combine(folderPath, audioFile.AlbumTitle);
folderPath = Path.Combine(folderPath, audioFile.AlbumTitle);
if (!Directory.Exists(folderPath))
Directory.CreateDirectory(folderPath);

string localFilePath = Path.Combine(folderPath, fileName);
Console.WriteLine("SyncClientService - DownloadAudioFile - folderPath: {0} fileName: {1} localFilePath: {2}", folderPath, fileName, localFilePath);
_lastBytesReceived = 0;

if (OnDownloadAudioFileStarted != null)
Expand Down
8 changes: 4 additions & 4 deletions MPfm/MPfm.Library/Services/SyncListenerService.cs
Expand Up @@ -565,20 +565,20 @@ public static string GetLocalIPAddress()
string address = "Not Connected";
try
{
Console.WriteLine("GetIPAddress - Detecting IP address...");
//Console.WriteLine("GetIPAddress - Detecting IP address...");
foreach (var ni in NetworkInterface.GetAllNetworkInterfaces())
{
Console.WriteLine("GetIPAddress - NetworkInterface: {0} {1}", ni.Name, ni.NetworkInterfaceType.ToString());
//Console.WriteLine("GetIPAddress - NetworkInterface: {0} {1}", ni.Name, ni.NetworkInterfaceType.ToString());
if(ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 ||
ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
{
IPAddress ip = null;
foreach (var a in ni.GetIPProperties().UnicastAddresses)
{
Console.WriteLine("GetIPAddress - Address: {0} {1}", a.Address, a.Address.AddressFamily.ToString());
//Console.WriteLine("GetIPAddress - Address: {0} {1}", a.Address, a.Address.AddressFamily.ToString());
if(a.Address.AddressFamily == AddressFamily.InterNetwork)
{
Console.WriteLine("GetIPAddress - Address **FOUND**: {0} {1}", a.Address, a.Address.AddressFamily.ToString());
//Console.WriteLine("GetIPAddress - Address **FOUND**: {0} {1}", a.Address, a.Address.AddressFamily.ToString());
ip = a.Address;
break;
}
Expand Down
14 changes: 10 additions & 4 deletions MPfm/MPfm.MVP/Navigation/MobileNavigationManager.cs
Expand Up @@ -95,7 +95,9 @@ public abstract class MobileNavigationManager

public abstract void ShowSplash(ISplashView view);
public abstract void HideSplash();
public abstract void AddTab(MobileNavigationTabType type, string title, IBaseView view);
public abstract void AddTab(MobileNavigationTabType type, string title, MobileLibraryBrowserType browserType, LibraryQuery query, IBaseView view);
public abstract void PushTabView(MobileNavigationTabType type, IBaseView view);
public abstract void PushTabView(MobileNavigationTabType type, MobileLibraryBrowserType browserType, LibraryQuery query, IBaseView view);
public abstract void PushDialogView(string viewTitle, IBaseView sourceView, IBaseView view);
public abstract void PushDialogSubview(string parentViewTitle, IBaseView view);
Expand Down Expand Up @@ -632,10 +634,12 @@ public virtual void CreateSyncWebBrowserView()
CreateSyncWebBrowserViewInternal(onViewReady);
}

protected virtual void CreateSyncMenuViewInternal(Action<IBaseView> onViewReady)
protected virtual void CreateSyncMenuViewInternal(Action<IBaseView> onViewReady, string url)
{
if (_syncMenuView == null)
_syncMenuView = Bootstrapper.GetContainer().Resolve<ISyncMenuView>(new NamedParameterOverloads() { { "onViewReady", onViewReady } });
else
_syncMenuPresenter.SetUrl(url);

#if !ANDROID
PushTabView(MobileNavigationTabType.More, _syncMenuView);
Expand All @@ -657,13 +661,15 @@ public virtual void CreateSyncMenuView(string url)
_syncMenuPresenter.SetUrl(url);
};

CreateSyncMenuViewInternal(onViewReady);
CreateSyncMenuViewInternal(onViewReady, url);
}

protected virtual void CreateSyncDownloadViewInternal(Action<IBaseView> onViewReady)
protected virtual void CreateSyncDownloadViewInternal(Action<IBaseView> onViewReady, string url, IEnumerable<AudioFile> audioFiles)
{
if (_syncDownloadView == null)
_syncDownloadView = Bootstrapper.GetContainer().Resolve<ISyncDownloadView>(new NamedParameterOverloads() { { "onViewReady", onViewReady } });
else
_syncDownloadPresenter.StartSync(url, audioFiles);

#if !ANDROID
PushTabView(MobileNavigationTabType.More, _syncDownloadView);
Expand All @@ -685,7 +691,7 @@ public virtual void CreateSyncDownloadView(string url, IEnumerable<AudioFile> au
_syncDownloadPresenter.StartSync(url, audioFiles);
};

CreateSyncDownloadViewInternal(onViewReady);
CreateSyncDownloadViewInternal(onViewReady, url, audioFiles);
}

protected virtual void CreateAboutViewInternal(Action<IBaseView> onViewReady)
Expand Down
5 changes: 4 additions & 1 deletion MPfm/MPfm.MVP/Presenters/SyncPresenter.cs
Expand Up @@ -53,6 +53,7 @@ public override void BindView(ISyncView view)
view.OnConnectDevice = ConnectDevice;
view.OnConnectDeviceManually = ConnectDeviceManually;
view.OnCancelDiscovery = CancelDiscovery;
view.OnStartDiscovery = RefreshDevices;
base.BindView(view);

Initialize();
Expand Down Expand Up @@ -104,7 +105,9 @@ private void RefreshDevices()
{
try
{
//string ip = SyncListenerService.GetLocalIPAddress().ToString();
if(_syncDiscoveryService.IsRunning)
return;

string ip = _deviceSpecifications.GetIPAddress();
View.RefreshIPAddress(String.Format("My IP address is {0}", ip));

Expand Down
1 change: 1 addition & 0 deletions MPfm/MPfm.MVP/Views/ISyncView.cs
Expand Up @@ -29,6 +29,7 @@ public interface ISyncView : IBaseView
{
Action<string> OnConnectDevice { get; set; }
Action<string> OnConnectDeviceManually { get; set; }
Action OnStartDiscovery { get; set; }
Action OnCancelDiscovery { get; set; }

void SyncError(Exception ex);
Expand Down
8 changes: 8 additions & 0 deletions MPfm/MPfm.iOS/Classes/Controllers/AboutViewController.cs
Expand Up @@ -44,5 +44,13 @@ public override void ViewWillAppear(bool animated)
MPfmNavigationController navCtrl = (MPfmNavigationController)this.NavigationController;
navCtrl.SetTitle("About Sessions", "");
}

#region IAboutView implementation

public void RefreshHTML(string html)
{
}

#endregion
}
}
8 changes: 8 additions & 0 deletions MPfm/MPfm.iOS/Classes/Controllers/Base/BaseViewController.cs
Expand Up @@ -35,6 +35,10 @@ public void ShowView(bool shown)

public Action<IBaseView> OnViewDestroy { get; set; }

public bool ConfirmBackButton = false;
public string ConfirmBackButtonTitle = string.Empty;
public string ConfirmBackButtonMessage = string.Empty;

#endregion

protected Action<IBaseView> OnViewReady { get; set; }
Expand All @@ -45,6 +49,10 @@ public BaseViewController(Action<IBaseView> onViewReady, string nibName, NSBundl
OnViewReady = onViewReady;
}

public virtual void ConfirmedBackButton()
{
}

public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
Expand Down
8 changes: 4 additions & 4 deletions MPfm/MPfm.iOS/Classes/Controllers/PlayerViewController.cs
Expand Up @@ -199,10 +199,10 @@ public override void ViewDidLoad()
attr.TextShadowColor = UIColor.DarkGray;
attr.TextShadowOffset = new UIOffset(0, 0);

// Set back button for navigation bar
_btnBack = new UIBarButtonItem("Back", UIBarButtonItemStyle.Plain, null, null);
_btnBack.SetTitleTextAttributes(attr, UIControlState.Normal);
this.NavigationItem.BackBarButtonItem = _btnBack;
// // Set back button for navigation bar
// _btnBack = new UIBarButtonItem("Back", UIBarButtonItemStyle.Plain, null, null);
// _btnBack.SetTitleTextAttributes(attr, UIControlState.Normal);
// this.NavigationItem.BackBarButtonItem = _btnBack;

// Reset temporary text
lblLength.Text = string.Empty;
Expand Down
12 changes: 11 additions & 1 deletion MPfm/MPfm.iOS/Classes/Controllers/SyncDownloadViewController.cs
Expand Up @@ -37,6 +37,9 @@ public SyncDownloadViewController(Action<IBaseView> onViewReady)
public override void ViewDidLoad()
{
this.View.BackgroundColor = GlobalTheme.BackgroundColor;
ConfirmBackButton = true;
ConfirmBackButtonTitle = "Sync download will be canceled";
ConfirmBackButtonMessage = "Are you sure you wish to exit this screen and cancel the download?";

// TODO: Detect back button press when the process is currently running. Ask the user if he wants to cancel the operation.
Console.WriteLine("SyncDownloadViewController - ViewDidLoad");
Expand All @@ -54,8 +57,15 @@ public override void ViewWillAppear(bool animated)
navCtrl.SetTitle("Sync Library", "Downloading audio files");
}

public override void ConfirmedBackButton()
{
Console.WriteLine("SyncDownloadViewController - ConfirmedBackButton");
OnCancelDownload();
}

#region ISyncDownloadView implementation

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

public void SyncDownloadError(Exception ex)
Expand Down Expand Up @@ -89,7 +99,7 @@ public void SyncCompleted()
var alertView = new UIAlertView("Sync", "Sync completed successfully.", null, "OK", null);
alertView.Clicked += (sender, e) => {
Console.WriteLine("SyncDownloadViewController - Sync completed; dismissing views");
NavigationController.PopToRootViewController(true);
NavigationController.PopViewControllerAnimated(true);
};
alertView.Show();
});
Expand Down
13 changes: 3 additions & 10 deletions MPfm/MPfm.iOS/Classes/Controllers/SyncMenuViewController.cs
Expand Up @@ -74,23 +74,14 @@ public override void ViewDidLoad()
btnSyncView.AddSubview(btnSync);
_btnSync = new UIBarButtonItem(btnSyncView);

// var btnSync = new UIButton(UIButtonType.Custom);
// btnSync.SetTitle("Sync", UIControlState.Normal);
// btnSync.Layer.CornerRadius = 8;
// btnSync.Layer.BackgroundColor = GlobalTheme.SecondaryColor.CGColor;
// btnSync.Font = UIFont.FromName("HelveticaNeue-Bold", 12);
// btnSync.Frame = new RectangleF(0, 12, 60, 30);
// btnSync.TouchUpInside += HandleButtonSyncTouchUpInside;
// _btnSync = new UIBarButtonItem(btnSync);

NavigationItem.SetRightBarButtonItem(_btnSync, true);

viewLoading.Hidden = false;
viewSync.Hidden = true;
tableView.Hidden = true;

base.ViewDidLoad();
}
}

public override void ViewWillAppear(bool animated)
{
Expand Down Expand Up @@ -250,10 +241,12 @@ public void SyncMenuError(Exception ex)

public void RefreshLoading(bool isLoading, int progressPercentage)
{
//Console.WriteLine("SyncMenuViewController - isLoading: {0} progressPercentage: {1}", isLoading, progressPercentage);
InvokeOnMainThread(() => {
tableView.Hidden = isLoading;
viewLoading.Hidden = !isLoading;
viewSync.Hidden = isLoading;
if(isLoading)
NavigationItem.SetRightBarButtonItem(null, true);
else
Expand Down
21 changes: 16 additions & 5 deletions MPfm/MPfm.iOS/Classes/Controllers/SyncViewController.cs
Expand Up @@ -50,8 +50,6 @@ public override void ViewDidLoad()
btnConnectDeviceManually.BackgroundColor = GlobalTheme.SecondaryColor;
btnConnectDeviceManually.Layer.CornerRadius = 8;

activityIndicator.StartAnimating();

base.ViewDidLoad();
}

Expand All @@ -61,6 +59,16 @@ public override void ViewWillAppear(bool animated)

MPfmNavigationController navCtrl = (MPfmNavigationController)this.NavigationController;
navCtrl.SetTitle("Sync Library", "Connect to a device");

OnStartDiscovery();
activityIndicator.StartAnimating();
}

public override void ViewWillDisappear(bool animated)
{
base.ViewWillDisappear(animated);

OnCancelDiscovery();
}

[Export ("tableView:numberOfRowsInSection:")]
Expand Down Expand Up @@ -97,6 +105,7 @@ public UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
public void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
tableView.DeselectRow(indexPath, true);
OnCancelDiscovery();
OnConnectDevice(_devices[indexPath.Row].Url);
}

Expand All @@ -108,6 +117,8 @@ public void RowSelected(UITableView tableView, NSIndexPath indexPath)

#region ISyncView implementation

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

Expand Down Expand Up @@ -145,9 +156,9 @@ public void RefreshDevicesEnded()
{
InvokeOnMainThread(() => {
activityIndicator.StopAnimating();
UIView.Animate(0.25, () => {
viewRefresh.Alpha = 0;
});
// UIView.Animate(0.25, () => {
// viewRefresh.Alpha = 0;
// });
});
}

Expand Down
25 changes: 25 additions & 0 deletions MPfm/MPfm.iOS/Classes/Controls/MPfmNavigationController.cs
Expand Up @@ -30,6 +30,7 @@
using MonoTouch.CoreAnimation;
using MPfm.iOS.Classes.Objects;
using MPfm.iOS.Helpers;
using MPfm.iOS.Classes.Controllers.Base;

namespace MPfm.iOS.Classes.Controls
{
Expand All @@ -39,6 +40,7 @@ public class MPfmNavigationController : UINavigationController
bool _isPlayerPlaying;
bool _viewShouldShowPlayerButton;
bool _viewShouldShowEffectsButton;
bool _confirmedViewPop;
UILabel _lblTitle;
UILabel _lblSubtitle;
MPfmFlatButton _btnBack;
Expand Down Expand Up @@ -94,6 +96,29 @@ public MPfmNavigationController(MobileNavigationTabType tabType) : base(typeof(M
_btnBack.Alpha = 0;
_btnBack.Frame = new RectangleF(0, 0, 70, 44);
_btnBack.OnButtonClick += () => {
var viewController = (BaseViewController)VisibleViewController;
if (viewController.ConfirmBackButton && !_confirmedViewPop)
{
var alertView = new UIAlertView(viewController.ConfirmBackButtonTitle, viewController.ConfirmBackButtonMessage, null, "OK", new string[1] { "Cancel" });
alertView.Clicked += (object sender, UIButtonEventArgs e) => {
Console.WriteLine(">>>>>>>> AlertView button index: {0}", e.ButtonIndex);
switch(e.ButtonIndex)
{
case 0:
viewController.ConfirmedBackButton();
_confirmedViewPop = true;
PopViewControllerAnimated(true);
break;
default:
break;
}
};
alertView.Show();
return;
}
_confirmedViewPop = false;
if(ViewControllers.Length > 1)
PopViewControllerAnimated(true);
};
Expand Down
11 changes: 11 additions & 0 deletions MPfm/MPfm.iOS/Classes/Helpers/iOSSyncDeviceSpecifications.cs
Expand Up @@ -20,6 +20,7 @@
using MPfm.Library;
using MPfm.Library.Objects;
using MonoTouch.UIKit;
using MPfm.Library.Services;

namespace MPfm.iOS.Helpers
{
Expand Down Expand Up @@ -54,5 +55,15 @@ public long GetFreeSpace()
});
return freeSpace;
}

public string GetIPAddress()
{
return SyncListenerService.GetLocalIPAddress().ToString();
}

public string GetMusicFolderPath()
{
return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
}
}
}

0 comments on commit 7b79fc5

Please sign in to comment.