Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
iOS: Added marker name templates.
MarkersPresenter: Added marker name templates.

Related to issue #386 and issue #405.
  • Loading branch information
ycastonguay committed Mar 20, 2013
1 parent 579426f commit 9b0426d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
25 changes: 21 additions & 4 deletions MPfm/MPfm.MVP/Presenters/MarkersPresenter.cs
Expand Up @@ -16,6 +16,7 @@
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Linq;
using MPfm.Core;
using MPfm.Player.Objects;
using MPfm.Sound.AudioFiles;
Expand All @@ -25,6 +26,7 @@
using MPfm.MVP.Services.Interfaces;
using MPfm.MVP.Views;
using TinyMessenger;
using System.Collections.Generic;

namespace MPfm.MVP.Presenters
{
Expand All @@ -38,6 +40,7 @@ public class MarkersPresenter : BasePresenter<IMarkersView>, IMarkersPresenter
readonly ILibraryService _libraryService;
readonly IPlayerService _playerService;
Guid _audioFileId = Guid.Empty;
List<Marker> _markers = new List<Marker>();

public MarkersPresenter(ITinyMessengerHub messageHub, MobileNavigationManager navigationManager, ILibraryService libraryService, IPlayerService playerService)
{
Expand Down Expand Up @@ -71,13 +74,17 @@ private void CreateMarkerDetailsView(Guid markerId)
_navigationManager.PushDialogView(view);
}

private void AddMarker()
private void AddMarker(MarkerTemplateNameType markerTemplateNameType)
{
try
{
// Create marker name from template type (check for markers sharing the same name)
List<string> similarMarkers = _markers.Select(x => x.Name).Where(x => x.ToUpper().StartsWith(markerTemplateNameType.ToString().ToUpper())).ToList();
string markerName = markerTemplateNameType.ToString() + " " + (similarMarkers.Count + 1).ToString();

// Create marker and add to database
Marker marker = new Marker();
marker.Name = "New Marker";
marker.Name = markerName;
marker.PositionBytes = _playerService.GetPosition();
marker.PositionSamples = (uint)ConvertAudio.ToPCM(marker.PositionBytes, (uint)_playerService.CurrentPlaylistItem.AudioFile.BitsPerSample, 2);
int ms = (int)ConvertAudio.ToMS(marker.PositionSamples, (uint)_playerService.CurrentPlaylistItem.AudioFile.SampleRate);
Expand Down Expand Up @@ -117,8 +124,8 @@ private void RefreshMarkers(Guid audioFileId)
{
try
{
var markers = _libraryService.SelectMarkers(audioFileId);
View.RefreshMarkers(markers);
_markers = _libraryService.SelectMarkers(audioFileId);
View.RefreshMarkers(_markers);
}
catch(Exception ex)
{
Expand All @@ -127,5 +134,15 @@ private void RefreshMarkers(Guid audioFileId)
}
}
}

public enum MarkerTemplateNameType
{
Verse = 0,
Chorus = 1,
Bridge = 2,
Solo = 3,
Other = 4,
None = 5
}
}

3 changes: 2 additions & 1 deletion MPfm/MPfm.MVP/Views/IMarkersView.cs
Expand Up @@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using MPfm.Player.Objects;
using MPfm.MVP.Presenters;

namespace MPfm.MVP.Views
{
Expand All @@ -26,7 +27,7 @@ namespace MPfm.MVP.Views
/// </summary>
public interface IMarkersView : IBaseView
{
Action OnAddMarker { get; set; }
Action<MarkerTemplateNameType> OnAddMarker { get; set; }
Action<Marker> OnEditMarker { get; set; }
Action<Marker> OnSelectMarker { get; set; }

Expand Down
23 changes: 20 additions & 3 deletions MPfm/MPfm.iOS/Classes/Controllers/MarkersViewController.cs
Expand Up @@ -23,6 +23,8 @@
using MPfm.iOS.Classes.Controllers.Base;
using MPfm.MVP.Views;
using MPfm.Player.Objects;
using MPfm.iOS.Classes.Delegates;
using MPfm.MVP.Presenters;

namespace MPfm.iOS
{
Expand Down Expand Up @@ -105,13 +107,28 @@ public void RowSelected(UITableView tableView, NSIndexPath indexPath)

partial void actionAddMarker(NSObject sender)
{
if(OnAddMarker != null)
OnAddMarker();
// Show a list of templates for the marker name
UIActionSheet actionSheet = new UIActionSheet("Select a marker name template:", null, "Cancel", null, new string[4] { "Verse", "Chorus", "Bridge", "Solo" });
actionSheet.Style = UIActionSheetStyle.BlackTranslucent;
actionSheet.Clicked += (eventSender, e) => {
// Check for cancel
if(e.ButtonIndex == 4)
return;
// Add marker
if(OnAddMarker != null)
OnAddMarker((MarkerTemplateNameType)e.ButtonIndex);
};

// Must use the tab bar controller to spawn the action sheet correctly. Remember, we're in a UIScrollView...
AppDelegate appDelegate = (AppDelegate)UIApplication.SharedApplication.Delegate;
actionSheet.ShowFromTabBar(appDelegate.TabBarController.TabBar);
}

#region IMarkersView implementation

public Action OnAddMarker { get; set; }
public Action<MarkerTemplateNameType> OnAddMarker { get; set; }
public Action<Marker> OnEditMarker { get; set; }
public Action<Marker> OnSelectMarker { get; set; }

Expand Down
1 change: 1 addition & 0 deletions MPfm/MPfm.iOS/Classes/Delegates/AppDelegate.cs
Expand Up @@ -37,6 +37,7 @@ public partial class AppDelegate : UIApplicationDelegate
{
MPfmWindow _window;
UITabBarController _tabBarController;
public UITabBarController TabBarController { get { return _tabBarController; } }
SplashViewController _splashViewController;
iOSNavigationManager _navigationManager;
List<KeyValuePair<MobileNavigationTabType, MPfmNavigationController>> _navigationControllers = new List<KeyValuePair<MobileNavigationTabType, MPfmNavigationController>>();
Expand Down

0 comments on commit 9b0426d

Please sign in to comment.