Skip to content

Commit

Permalink
Windows: SyncMenu - The list view showing audio files to sync now wor…
Browse files Browse the repository at this point in the history
…ks; the Add/Remove buttons also work. The scrollbar is reset when refreshing the contents but that will be fixed later. Added basic layout for SyncDownload; the progress bar is now updated as a test; the sync process completes successfully!

Related to issue #422.
  • Loading branch information
ycastonguay committed Aug 15, 2013
1 parent 097917d commit 5c11bf4
Show file tree
Hide file tree
Showing 20 changed files with 2,994 additions and 2,382 deletions.
2 changes: 1 addition & 1 deletion MPfm/MPfm.MVP/Navigation/NavigationManager.cs
Expand Up @@ -144,7 +144,7 @@ public virtual ISyncView CreateSyncView()

// The view invokes the OnViewReady action when the view is ready. This means the presenter can be created and bound to the view.
Action<IBaseView> onViewReady = (view) =>
{
{
_syncPresenter = Bootstrapper.GetContainer().Resolve<ISyncPresenter>();
_syncPresenter.BindView((ISyncView)view);
};
Expand Down
102 changes: 48 additions & 54 deletions MPfm/MPfm.MVP/Presenters/BasePresenter.cs
@@ -1,54 +1,48 @@
// 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;
using MPfm.MVP.Presenters.Interfaces;
using MPfm.MVP.Views;

namespace MPfm.MVP.Presenters
{
/// <summary>
/// Base presenter.
/// </summary>
public class BasePresenter<T> : IBasePresenter<T> where T : IBaseView
{
// Private variables
public T View { get; private set; }

#region Constructor and Dispose

public BasePresenter()
{
}

#endregion

/// <summary>
/// Binds the view to its implementation.
/// </summary>
/// <param name='view'>View implementation</param>
public virtual void BindView(T view)
{
// Validate parameters
if(view == null)
throw new ArgumentNullException("The view parameter is null!");

// Set properties
this.View = view;
}
}
}
// 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;
using MPfm.MVP.Presenters.Interfaces;
using MPfm.MVP.Views;

namespace MPfm.MVP.Presenters
{
/// <summary>
/// Base presenter.
/// </summary>
public class BasePresenter<T> : IBasePresenter<T> where T : IBaseView
{
// Private variables
public T View { get; private set; }

public BasePresenter()
{
}

/// <summary>
/// Binds the view to its implementation.
/// </summary>
/// <param name='view'>View implementation</param>
public virtual void BindView(T view)
{
if(view == null)
throw new ArgumentNullException("The view parameter is null!");

this.View = view;
}
}
}
77 changes: 55 additions & 22 deletions MPfm/MPfm.MVP/Presenters/SyncMenuPresenter.cs
Expand Up @@ -62,15 +62,18 @@ public SyncMenuPresenter(ISyncClientService syncClientService, ISyncDeviceSpecif
public override void BindView(ISyncMenuView view)
{
view.OnSelectItem = SelectItem;
view.OnRemoveItem = RemoveItem;
view.OnExpandItem = ExpandItem;
view.OnSync = Sync;
view.OnSelectButtonClick = SelectButtonClick;
view.OnSelectAll = SelectAll;
view.OnRemoveAll = RemoveAll;
base.BindView(view);

Initialize();
}
}

private void Initialize()
private void Initialize()
{

}
Expand Down Expand Up @@ -98,7 +101,7 @@ private void HandleOnReceivedIndex(Exception exception)
Console.WriteLine("SyncMenuPresenter - HandleOnReceivedIndex - Refrehsing view and sync totals...");
View.RefreshLoading(false, 0);
RefreshSyncTotal();
View.RefreshItems(_items);
RefreshItems();
}
catch(Exception ex)
{
Expand All @@ -123,24 +126,9 @@ private void SelectButtonClick()
try
{
if(_audioFilesToSync.Count > 0)
{
// Reset selection
foreach(var item in _items)
item.Selection = StateSelectionType.None;
_audioFilesToSync.Clear();
View.RefreshSelectButton("Select all");
}
RemoveAll();
else
{
// Select all items
foreach(var item in _items)
item.Selection = StateSelectionType.Selected;
_audioFilesToSync.AddRange(_syncClientService.GetAudioFiles());
View.RefreshSelectButton("Reset selection");
}

View.RefreshItems(_items);
RefreshSyncTotal();
SelectAll();
}
catch(Exception ex)
{
Expand Down Expand Up @@ -262,14 +250,46 @@ private void SelectItem(SyncMenuItemEntity item)
}

RefreshSyncTotal();
View.RefreshItems(_items);
RefreshItems();
}
catch(Exception ex)
{
Console.WriteLine("SyncMenuPresenter - SelectItem - Exception: {0}", ex);
}
}

private void RemoveItem(AudioFile audioFile)
{
_audioFilesToSync.Remove(audioFile);
View.RefreshSelection(_audioFilesToSync);
}

private void RemoveAll()
{
// Reset selection
foreach (var item in _items)
item.Selection = StateSelectionType.None;
_audioFilesToSync.Clear();
View.RefreshSelectButton("Select all");

// Refresh view
RefreshItems();
RefreshSyncTotal();
}

private void SelectAll()
{
// Select all items
foreach (var item in _items)
item.Selection = StateSelectionType.Selected;
_audioFilesToSync.AddRange(_syncClientService.GetAudioFiles());
View.RefreshSelectButton("Reset selection");

// Refresh view
RefreshItems();
RefreshSyncTotal();
}

private void ExpandItem(SyncMenuItemEntity item, object userData)
{
try
Expand Down Expand Up @@ -306,7 +326,7 @@ private void ExpandItem(SyncMenuItemEntity item, object userData)
});
}

_items.InsertRange(index, items);
//_items.InsertRange(index, items);
View.InsertItems(index + 1, items, userData);
}
break;
Expand Down Expand Up @@ -402,6 +422,19 @@ public void SetSyncDevice(SyncDevice device)
}
}

private void RefreshItems()
{
try
{
View.RefreshSelection(_audioFilesToSync);
View.RefreshItems(_items);
}
catch (Exception ex)
{
Console.WriteLine("SyncMenuPresenter - RefreshItems - Exception: {0}", ex);
}
}

private void RefreshSyncTotal()
{
try
Expand Down

0 comments on commit 5c11bf4

Please sign in to comment.