Skip to content

Commit

Permalink
Mac: Fixed visible centering/sizing before windows were visible. Star…
Browse files Browse the repository at this point in the history
…ted implementing SyncMenu view.

Related to issue #381.
  • Loading branch information
ycastonguay committed Aug 13, 2013
1 parent 84a5b91 commit f564855
Show file tree
Hide file tree
Showing 14 changed files with 1,077 additions and 673 deletions.
17 changes: 14 additions & 3 deletions MPfm/MPfm.MVP/Presenters/SyncMenuPresenter.cs
Expand Up @@ -27,6 +27,7 @@
using MPfm.MVP.Models;
using MPfm.Library;
using MPfm.MVP.Navigation;
using MPfm.MVP.Bootstrap;

namespace MPfm.MVP.Presenters
{
Expand All @@ -35,21 +36,27 @@ namespace MPfm.MVP.Presenters
/// </summary>
public class SyncMenuPresenter : BasePresenter<ISyncMenuView>, ISyncMenuPresenter
{
readonly MobileNavigationManager _navigationManager;
readonly MobileNavigationManager _mobileNavigationManager;
readonly NavigationManager _navigationManager;
readonly ISyncClientService _syncClientService;
readonly ISyncDeviceSpecifications _syncDeviceSpecifications;

SyncDevice _device;
List<SyncMenuItemEntity> _items = new List<SyncMenuItemEntity>();
List<AudioFile> _audioFilesToSync = new List<AudioFile>();

public SyncMenuPresenter(MobileNavigationManager navigationManager, ISyncClientService syncClientService, ISyncDeviceSpecifications syncDeviceSpecifications)
public SyncMenuPresenter(ISyncClientService syncClientService, ISyncDeviceSpecifications syncDeviceSpecifications)
{
_navigationManager = navigationManager;
_syncClientService = syncClientService;
_syncDeviceSpecifications = syncDeviceSpecifications;
_syncClientService.OnDownloadIndexProgress += HandleOnDownloadIndexProgress;
_syncClientService.OnReceivedIndex += HandleOnReceivedIndex;

#if IOS || ANDROID
_mobileNavigationManager = Bootstrapper.GetContainer().Resolve<MobileNavigationManager>();
#else
_navigationManager = Bootstrapper.GetContainer().Resolve<NavigationManager>();
#endif
}

public override void BindView(ISyncMenuView view)
Expand Down Expand Up @@ -151,7 +158,11 @@ private void Sync()
return;
}

#if IOS || ANDROID
_mobileNavigationManager.CreateSyncDownloadView(_device, _audioFilesToSync);
#else
_navigationManager.CreateSyncDownloadView(_device, _audioFilesToSync);
#endif
}
catch(Exception ex)
{
Expand Down
150 changes: 137 additions & 13 deletions MPfm/MPfm.Mac/Windows/Controllers/SyncMenuWindowController.cs
Expand Up @@ -20,46 +20,141 @@
using MPfm.MVP.Views;
using MPfm.Library.Objects;
using MPfm.MVP.Models;
using System.Text;
using MPfm.Core;
using MPfm.Mac.Classes.Helpers;
using MonoMac.Foundation;
using MonoMac.AppKit;
using MPfm.Mac.Classes.Objects;
using System.Linq;

namespace MPfm.Mac
{
public partial class SyncMenuWindowController : BaseWindowController, ISyncMenuView
{
#region Constructors
List<SyncMenuItemEntity> _items;

// Called when created from unmanaged code
public SyncMenuWindowController(IntPtr handle)
: base (handle)
{
Initialize();
}

// Call to load from the XIB/NIB file
public SyncMenuWindowController(Action<IBaseView> onViewReady)
: base ("SyncMenuWindow", onViewReady)
{
Initialize();
}

// Shared initialization code
void Initialize()
{
this.Window.Center();
this.Window.MakeKeyAndOrderFront(this);
}

#endregion
public override void AwakeFromNib()
{
base.AwakeFromNib();

viewTable.Hidden = true;
}

public override void WindowDidLoad()
{
base.WindowDidLoad();

outlineView.WeakDelegate = this;
outlineView.WeakDataSource = this;

OnViewReady.Invoke(this);
}

[Export ("numberOfRowsInTableView:")]
public int GetRowCount(NSTableView tableView)
{
return _items.Count;
}

[Export ("tableView:heightOfRow:")]
public float GetRowHeight(NSTableView tableView, int row)
{
return 20;
}

[Export ("tableView:dataCellForTableColumn:row:")]
public NSObject GetObjectValue(NSTableView tableView, NSTableColumn tableColumn, int row)
{
return new NSString();
}

//strongly typed window accessor
public new SyncMenuWindow Window
// [Export ("tableView:viewForTableColumn:row:")]
// public NSView GetViewForItem(NSTableView tableView, NSTableColumn tableColumn, int row)

[Export("outlineView:viewForTableColumn:item:")]
public NSView GetViewForItem(NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item)
{
get
//Console.WriteLine("GetViewForItem - tableColumn: {0} row: {1}", tableColumn.Identifier.ToString(), row);
NSTableCellView view;
if(tableColumn.Identifier.ToString() == "columnTitle")
{
return (SyncMenuWindow)base.Window;
view = (NSTableCellView)outlineView.MakeView("cellTitle", this);
//view.TextField.StringValue = _items[row].ArtistName;
}
else
{
view = (NSTableCellView)outlineView.MakeView("cellSelection", this);
//view.TextField.StringValue = _items[row].Url;
}
// //view.TextField.Font = NSFont.FromFontName("Junction", 11);
//
// if (view.ImageView != null)
// {
// string iconName = string.Empty;
// switch (_items[row].ItemType)
// {
// case SyncMenuItemEntityType.Artist:
// iconName = "16_icomoon_android";
// break;
// case SyncMenuItemEntityType.Album:
// iconName = "16_icomoon_android";
// break;
// case SyncMenuItemEntityType.Song:
// iconName = "16_icomoon_android";
// break;
// }
// view.ImageView.Image = ImageResources.images16x16.FirstOrDefault(x => x.Name == iconName);
// }
return view;
}

public override void AwakeFromNib()
[Export ("tableViewSelectionDidChange:")]
public void SelectionDidChange(NSNotification notification)
{
//btnConnect.Enabled = (tableViewDevices.SelectedRow == -1) ? false : true;
}

[Export ("outlineView:numberOfChildrenOfItem:")]
public int GetChildrenCount(NSOutlineView outlineView, NSObject item)
{
base.AwakeFromNib();
return 0;
}

[Export ("outlineView:objectValueForTableColumn:byItem:")]
public NSObject GetObjectValue(NSOutlineView outlineView, NSTableColumn forTableColumn, NSObject byItem)
{
return new NSObject();
}

[Export ("outlineView:child:ofItem:")]
public NSObject GetChild(NSOutlineView outlineView, int childIndex, NSObject ofItem)
{
return new NSObject();
}

[Export ("outlineView:isItemExpandable:")]
public bool ItemExpandable(NSOutlineView outlineView, NSObject item)
{
return false;
}

#region ISyncMenuView implementation
Expand All @@ -71,33 +166,62 @@ public override void AwakeFromNib()

public void SyncMenuError(Exception ex)
{
InvokeOnMainThread(delegate {
string message = string.Format("An error occured in SyncMenu: {0}", ex);
Tracing.Log(message);
CocoaHelper.ShowCriticalAlert(message);
});
}

public void SyncEmptyError(Exception ex)
{
InvokeOnMainThread(delegate {
CocoaHelper.ShowCriticalAlert(ex.Message);
});
}

public void RefreshDevice(SyncDevice device)
{
InvokeOnMainThread(delegate {
lblTitle.StringValue = "Sync library with " + device.Name;
Window.Title = "Sync library with " + device.Name;
});
}

public void RefreshLoading(bool isLoading, int progressPercentage)
{
InvokeOnMainThread(delegate {
viewLoading.Hidden = !isLoading;
viewTable.Hidden = isLoading;

if(!isLoading)
Console.WriteLine("VIEW TABLE NOT HIDDEN ANYMORE");

if(progressPercentage < 100)
lblLoading.StringValue = String.Format("Loading index ({0}%)...", progressPercentage);
else
lblLoading.StringValue = "Processing index...";
});
}

public void RefreshSelectButton(string text)
{
}

public void RefreshItems(List<MPfm.MVP.Models.SyncMenuItemEntity> items)
public void RefreshItems(List<SyncMenuItemEntity> items)
{
Console.WriteLine("REFRESITEMS");
InvokeOnMainThread(delegate {
_items = items.ToList();
outlineView.ReloadData();
});
}

public void RefreshSyncTotal(string title, string subtitle, bool enoughFreeSpace)
{
}

public void InsertItems(int index, List<MPfm.MVP.Models.SyncMenuItemEntity> items)
public void InsertItems(int index, List<SyncMenuItemEntity> items)
{
}

Expand Down
7 changes: 5 additions & 2 deletions MPfm/MPfm.Mac/Windows/Controllers/SyncWindowController.cs
Expand Up @@ -158,9 +158,12 @@ public void SelectionDidChange(NSNotification notification)

public void SyncError(Exception ex)
{
InvokeOnMainThread(() => {
CocoaHelper.ShowCriticalAlert(ex.Message + "\n" + ex.StackTrace);
InvokeOnMainThread(delegate {
string message = string.Format("An error occured in Sync: {0}", ex);
Tracing.Log(message);
CocoaHelper.ShowCriticalAlert(message);
});

}

public void RefreshIPAddress(string address)
Expand Down

0 comments on commit f564855

Please sign in to comment.