diff --git a/MPfm/MPfm.Library/Services/Interfaces/ISyncDiscoveryService.cs b/MPfm/MPfm.Library/Services/Interfaces/ISyncDiscoveryService.cs index 1ce41ea8..75e22c8d 100644 --- a/MPfm/MPfm.Library/Services/Interfaces/ISyncDiscoveryService.cs +++ b/MPfm/MPfm.Library/Services/Interfaces/ISyncDiscoveryService.cs @@ -29,6 +29,8 @@ public interface ISyncDiscoveryService event SyncDiscoveryService.DiscoveryProgress OnDiscoveryProgress; event SyncDiscoveryService.DiscoveryEnded OnDiscoveryEnded; + bool IsRunning { get; } + void SearchForDevices(List ips); void SearchForDevices(string baseIP); void Cancel(); diff --git a/MPfm/MPfm.Library/Services/SyncClientService.cs b/MPfm/MPfm.Library/Services/SyncClientService.cs index 7e810370..8dd0c66c 100644 --- a/MPfm/MPfm.Library/Services/SyncClientService.cs +++ b/MPfm/MPfm.Library/Services/SyncClientService.cs @@ -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) diff --git a/MPfm/MPfm.Library/Services/SyncListenerService.cs b/MPfm/MPfm.Library/Services/SyncListenerService.cs index 19a38f76..46af8341 100644 --- a/MPfm/MPfm.Library/Services/SyncListenerService.cs +++ b/MPfm/MPfm.Library/Services/SyncListenerService.cs @@ -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; } diff --git a/MPfm/MPfm.MVP/Navigation/MobileNavigationManager.cs b/MPfm/MPfm.MVP/Navigation/MobileNavigationManager.cs index af2e3b43..416a19bb 100644 --- a/MPfm/MPfm.MVP/Navigation/MobileNavigationManager.cs +++ b/MPfm/MPfm.MVP/Navigation/MobileNavigationManager.cs @@ -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); @@ -632,10 +634,12 @@ public virtual void CreateSyncWebBrowserView() CreateSyncWebBrowserViewInternal(onViewReady); } - protected virtual void CreateSyncMenuViewInternal(Action onViewReady) + protected virtual void CreateSyncMenuViewInternal(Action onViewReady, string url) { if (_syncMenuView == null) _syncMenuView = Bootstrapper.GetContainer().Resolve(new NamedParameterOverloads() { { "onViewReady", onViewReady } }); + else + _syncMenuPresenter.SetUrl(url); #if !ANDROID PushTabView(MobileNavigationTabType.More, _syncMenuView); @@ -657,13 +661,15 @@ public virtual void CreateSyncMenuView(string url) _syncMenuPresenter.SetUrl(url); }; - CreateSyncMenuViewInternal(onViewReady); + CreateSyncMenuViewInternal(onViewReady, url); } - protected virtual void CreateSyncDownloadViewInternal(Action onViewReady) + protected virtual void CreateSyncDownloadViewInternal(Action onViewReady, string url, IEnumerable audioFiles) { if (_syncDownloadView == null) _syncDownloadView = Bootstrapper.GetContainer().Resolve(new NamedParameterOverloads() { { "onViewReady", onViewReady } }); + else + _syncDownloadPresenter.StartSync(url, audioFiles); #if !ANDROID PushTabView(MobileNavigationTabType.More, _syncDownloadView); @@ -685,7 +691,7 @@ public virtual void CreateSyncDownloadView(string url, IEnumerable au _syncDownloadPresenter.StartSync(url, audioFiles); }; - CreateSyncDownloadViewInternal(onViewReady); + CreateSyncDownloadViewInternal(onViewReady, url, audioFiles); } protected virtual void CreateAboutViewInternal(Action onViewReady) diff --git a/MPfm/MPfm.MVP/Presenters/SyncPresenter.cs b/MPfm/MPfm.MVP/Presenters/SyncPresenter.cs index 0451bb38..052546aa 100644 --- a/MPfm/MPfm.MVP/Presenters/SyncPresenter.cs +++ b/MPfm/MPfm.MVP/Presenters/SyncPresenter.cs @@ -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(); @@ -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)); diff --git a/MPfm/MPfm.MVP/Views/ISyncView.cs b/MPfm/MPfm.MVP/Views/ISyncView.cs index 35ee3d72..23c61795 100644 --- a/MPfm/MPfm.MVP/Views/ISyncView.cs +++ b/MPfm/MPfm.MVP/Views/ISyncView.cs @@ -29,6 +29,7 @@ public interface ISyncView : IBaseView { Action OnConnectDevice { get; set; } Action OnConnectDeviceManually { get; set; } + Action OnStartDiscovery { get; set; } Action OnCancelDiscovery { get; set; } void SyncError(Exception ex); diff --git a/MPfm/MPfm.iOS/Classes/Controllers/AboutViewController.cs b/MPfm/MPfm.iOS/Classes/Controllers/AboutViewController.cs index 52866b26..dc4c8d93 100644 --- a/MPfm/MPfm.iOS/Classes/Controllers/AboutViewController.cs +++ b/MPfm/MPfm.iOS/Classes/Controllers/AboutViewController.cs @@ -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 } } diff --git a/MPfm/MPfm.iOS/Classes/Controllers/Base/BaseViewController.cs b/MPfm/MPfm.iOS/Classes/Controllers/Base/BaseViewController.cs index 817a0623..53844e1e 100644 --- a/MPfm/MPfm.iOS/Classes/Controllers/Base/BaseViewController.cs +++ b/MPfm/MPfm.iOS/Classes/Controllers/Base/BaseViewController.cs @@ -35,6 +35,10 @@ public void ShowView(bool shown) public Action OnViewDestroy { get; set; } + public bool ConfirmBackButton = false; + public string ConfirmBackButtonTitle = string.Empty; + public string ConfirmBackButtonMessage = string.Empty; + #endregion protected Action OnViewReady { get; set; } @@ -45,6 +49,10 @@ public BaseViewController(Action onViewReady, string nibName, NSBundl OnViewReady = onViewReady; } + public virtual void ConfirmedBackButton() + { + } + public override void DidReceiveMemoryWarning() { base.DidReceiveMemoryWarning(); diff --git a/MPfm/MPfm.iOS/Classes/Controllers/PlayerViewController.cs b/MPfm/MPfm.iOS/Classes/Controllers/PlayerViewController.cs index e0f39585..16360e8b 100644 --- a/MPfm/MPfm.iOS/Classes/Controllers/PlayerViewController.cs +++ b/MPfm/MPfm.iOS/Classes/Controllers/PlayerViewController.cs @@ -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; diff --git a/MPfm/MPfm.iOS/Classes/Controllers/SyncDownloadViewController.cs b/MPfm/MPfm.iOS/Classes/Controllers/SyncDownloadViewController.cs index b44796d8..5062b2ae 100644 --- a/MPfm/MPfm.iOS/Classes/Controllers/SyncDownloadViewController.cs +++ b/MPfm/MPfm.iOS/Classes/Controllers/SyncDownloadViewController.cs @@ -37,6 +37,9 @@ public SyncDownloadViewController(Action 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"); @@ -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) @@ -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(); }); diff --git a/MPfm/MPfm.iOS/Classes/Controllers/SyncMenuViewController.cs b/MPfm/MPfm.iOS/Classes/Controllers/SyncMenuViewController.cs index af1ca086..186e64fe 100644 --- a/MPfm/MPfm.iOS/Classes/Controllers/SyncMenuViewController.cs +++ b/MPfm/MPfm.iOS/Classes/Controllers/SyncMenuViewController.cs @@ -74,15 +74,6 @@ 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; @@ -90,7 +81,7 @@ public override void ViewDidLoad() tableView.Hidden = true; base.ViewDidLoad(); - } + } public override void ViewWillAppear(bool animated) { @@ -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 diff --git a/MPfm/MPfm.iOS/Classes/Controllers/SyncViewController.cs b/MPfm/MPfm.iOS/Classes/Controllers/SyncViewController.cs index 3c759095..17a6159b 100644 --- a/MPfm/MPfm.iOS/Classes/Controllers/SyncViewController.cs +++ b/MPfm/MPfm.iOS/Classes/Controllers/SyncViewController.cs @@ -50,8 +50,6 @@ public override void ViewDidLoad() btnConnectDeviceManually.BackgroundColor = GlobalTheme.SecondaryColor; btnConnectDeviceManually.Layer.CornerRadius = 8; - activityIndicator.StartAnimating(); - base.ViewDidLoad(); } @@ -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:")] @@ -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); } @@ -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 OnConnectDevice { get; set; } public Action OnConnectDeviceManually { get; set; } @@ -145,9 +156,9 @@ public void RefreshDevicesEnded() { InvokeOnMainThread(() => { activityIndicator.StopAnimating(); - UIView.Animate(0.25, () => { - viewRefresh.Alpha = 0; - }); +// UIView.Animate(0.25, () => { +// viewRefresh.Alpha = 0; +// }); }); } diff --git a/MPfm/MPfm.iOS/Classes/Controls/MPfmNavigationController.cs b/MPfm/MPfm.iOS/Classes/Controls/MPfmNavigationController.cs index aca98e40..cb74c516 100644 --- a/MPfm/MPfm.iOS/Classes/Controls/MPfmNavigationController.cs +++ b/MPfm/MPfm.iOS/Classes/Controls/MPfmNavigationController.cs @@ -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 { @@ -39,6 +40,7 @@ public class MPfmNavigationController : UINavigationController bool _isPlayerPlaying; bool _viewShouldShowPlayerButton; bool _viewShouldShowEffectsButton; + bool _confirmedViewPop; UILabel _lblTitle; UILabel _lblSubtitle; MPfmFlatButton _btnBack; @@ -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); }; diff --git a/MPfm/MPfm.iOS/Classes/Helpers/iOSSyncDeviceSpecifications.cs b/MPfm/MPfm.iOS/Classes/Helpers/iOSSyncDeviceSpecifications.cs index cd38bf42..87d6f696 100644 --- a/MPfm/MPfm.iOS/Classes/Helpers/iOSSyncDeviceSpecifications.cs +++ b/MPfm/MPfm.iOS/Classes/Helpers/iOSSyncDeviceSpecifications.cs @@ -20,6 +20,7 @@ using MPfm.Library; using MPfm.Library.Objects; using MonoTouch.UIKit; +using MPfm.Library.Services; namespace MPfm.iOS.Helpers { @@ -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); + } } } diff --git a/MPfm/MPfm.iOS/Classes/Navigation/iOSNavigationManager.cs b/MPfm/MPfm.iOS/Classes/Navigation/iOSNavigationManager.cs index 1d8d6ffc..6aa6ad56 100644 --- a/MPfm/MPfm.iOS/Classes/Navigation/iOSNavigationManager.cs +++ b/MPfm/MPfm.iOS/Classes/Navigation/iOSNavigationManager.cs @@ -24,6 +24,7 @@ using MPfm.iOS.Classes.Controllers; using MPfm.iOS.Classes.Controls; using MPfm.iOS.Classes.Delegates; +using MPfm.Library.Objects; namespace MPfm.iOS.Classes.Navigation { @@ -73,12 +74,22 @@ public override void AddTab(MobileNavigationTabType type, string title, IBaseVie { AppDelegate.AddTab(type, title, (UIViewController)view); } + + public override void AddTab(MobileNavigationTabType type, string title, MobileLibraryBrowserType browserType, LibraryQuery query, IBaseView view) + { + AppDelegate.AddTab(type, title, (UIViewController)view); + } public override void PushTabView(MobileNavigationTabType type, IBaseView view) { AppDelegate.PushTabView(type, (UIViewController)view); } + public override void PushTabView(MobileNavigationTabType type, MobileLibraryBrowserType browserType, LibraryQuery query, IBaseView view) + { + AppDelegate.PushTabView(type, (UIViewController)view); + } + public override void PushDialogView(string viewTitle, IBaseView sourceView, IBaseView view) { AppDelegate.PushDialogView(viewTitle, (UIViewController)view);