Skip to content

Commit

Permalink
Added comments and regions for code clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
AnaghSharma committed Nov 19, 2017
1 parent 701eaba commit 7b13f92
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 27 deletions.
16 changes: 15 additions & 1 deletion Carol/Controls/HyperlinkTextField.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
using System;
/*
* Custom Text field control that works as a hyperlink
*
* Author - Anagh Sharma
* http://www.anaghsharma.com
*
* 2017
*
*/

using System;
using System.ComponentModel;
using AppKit;
using Foundation;

namespace Carol.Controls
{
// DesignTimeVisible(true) makes sure that the class is visible in Xcode at design time
[Register("HyperlinkTextField"), DesignTimeVisible(true)]
public class HyperlinkTextField : NSTextField
{
Expand All @@ -23,6 +34,7 @@ public String Href
set => href = value;
}

#region Constructors
public HyperlinkTextField(IntPtr p) : base(p)
{

Expand All @@ -32,13 +44,15 @@ public HyperlinkTextField()
{

}
#endregion

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

AttributedStringValue = new NSAttributedString(StringValue, new NSStringAttributes()
{
//You can change the color of link after uncommenting the following
//ForegroundColor = NSColor.Blue,
UnderlineStyle = NSUnderlineStyle.Single.GetHashCode()
});
Expand Down
18 changes: 17 additions & 1 deletion Carol/Controls/PopoverView.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
using System;
/*
* Custom Popover control with adjustable background color
*
* Author - Anagh Sharma
* http://www.anaghsharma.com
*
* 2017
*
*/

using System;
using System.ComponentModel;
using AppKit;
using Foundation;

namespace Carol.Controls
{
// DesignTimeVisible(true) makes sure that the class is visible in Xcode at design time
[Register("PopoverView"), DesignTimeVisible(true)]
public class PopoverView : NSView
{

#region Constructors
public PopoverView()
{

Expand All @@ -17,6 +30,7 @@ public PopoverView(IntPtr p) : base(p)
{

}
#endregion

public override void ViewDidMoveToWindow()
{
Expand All @@ -29,6 +43,8 @@ public override void ViewDidMoveToWindow()
{
WantsLayer = true
};

//You can change the background color of popover below. Here it takes the color as rgba
backgroundView.Layer.BackgroundColor = new CoreGraphics.CGColor(0.07f, 0.07f, 0.07f, 1.0f);
backgroundView.AutoresizingMask = (NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable);
frameView.AddSubview(backgroundView, NSWindowOrderingMode.Below, frameView);
Expand Down
21 changes: 20 additions & 1 deletion Carol/Helpers/EventMonitor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
using AppKit;
/*
* Helper class to close the popover automatically on an external event
*
* Author - Anagh Sharma
* http://www.anaghsharma.com
*
* 2017
*
*/

using AppKit;
using Foundation;
namespace Carol.Helpers
{
Expand All @@ -8,6 +18,7 @@ public class EventMonitor
NSEventMask mask;
GlobalEventHandler handler;

#region Constructors
public EventMonitor()
{

Expand All @@ -18,17 +29,25 @@ public EventMonitor(NSEventMask mask, GlobalEventHandler handler)
this.mask = mask;
this.handler = handler;
}
#endregion

// Destructor
~EventMonitor()
{
Stop();
}

/// <summary>
/// Start monitoring events of a given mask
/// </summary>
public void Start()
{
monitor = NSEvent.AddGlobalMonitorForEventsMatchingMask(mask, handler) as NSObject;
}

/// <summary>
/// Stop monitoring events and release the resources
/// </summary>
public void Stop()
{
if (monitor != null)
Expand Down
25 changes: 24 additions & 1 deletion Carol/Helpers/LyricsHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
using System;
/*
* Helper class to get the lyrics of a track
*
* Author - Anagh Sharma
* http://www.anaghsharma.com
*
* 2017
*
*/

using System;
using System.Net.Http;
using System.Threading.Tasks;
using Carol.Models;
Expand All @@ -18,6 +28,12 @@ public LyricsHelper()
apikey = SecretsReader.GetSecrets();
}

/// <summary>
/// Method to get the track id of currently playing track
/// </summary>
/// <returns>Trackid.</returns>
/// <param name="track">Track Name.</param>
/// <param name="artist">Artist Name.</param>
public async Task GetTrackId(string track, string artist)
{
var uri = new Uri(String.Format("https://api.musixmatch.com/ws/1.1/track.search?q_track={0}&q_artist={1}&apikey={2}", track, artist, apikey));
Expand All @@ -29,6 +45,13 @@ public async Task GetTrackId(string track, string artist)
}
}

/// <summary>
/// Method to get the lyrics of a track
/// </summary>
/// <returns>Lyrics of the track.</returns>
/// <param name="track">Track.</param>
/// <param name="artist">Artist.</param>
/// <param name="onSuccess">Action.</param>
public async Task GetLyrics(string track, string artist, Action<string> onSuccess)
{
await GetTrackId(track, artist);
Expand Down
16 changes: 15 additions & 1 deletion Carol/Helpers/SecretsReader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
using System;
/*
* Helper class to retrieve API key from Secrets.json fole
*
* Author - Anagh Sharma
* http://www.anaghsharma.com
*
* 2017
*
*/

using System;
using System.IO;
using Newtonsoft.Json.Linq;

Expand All @@ -8,6 +18,10 @@ public static class SecretsReader
{
private static JObject secrets;

/// <summary>
/// Gets the API key
/// </summary>
/// <returns>API Key</returns>
public static string GetSecrets()
{
secrets = JObject.Parse(GetSecretKey());
Expand Down
29 changes: 28 additions & 1 deletion Carol/Helpers/StatusBarController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
using AppKit;
/*
* Helper class to create and maintain a Status Bar Item
*
* Author - Anagh Sharma
* http://www.anaghsharma.com
*
* 2017
*
*/

using AppKit;
using Foundation;

namespace Carol.Helpers
Expand All @@ -14,6 +24,7 @@ public class StatusBarController : NSObject
NSStoryboard storyboard;
NSWindowController windowController;

#region Constructors
public StatusBarController()
{

Expand Down Expand Up @@ -45,7 +56,9 @@ public StatusBarController(NSPopover popover, string image)
storyboard = NSStoryboard.FromName("Main", null);
windowController = storyboard.InstantiateControllerWithIdentifier("AboutWindow") as NSWindowController;
}
#endregion

//Destructor
~StatusBarController()
{
ViewController.AboutMenuItemClicked -= HandleAboutMenuItemClicked;
Expand Down Expand Up @@ -73,12 +86,21 @@ void HidePopover(NSObject sender)
eventMonitor.Stop();
}

/// <summary>
/// Hides popover on external mouse click
/// </summary>
/// <param name="_event">Event.</param>
void MouseEventHandler(NSEvent _event)
{
if (popover.Shown)
HidePopover(_event);
}

/// <summary>
/// Handles the about menu item click.
/// </summary>
/// <param name="sender">Sender.</param>
/// <param name="e">E.</param>
void HandleAboutMenuItemClicked(object sender, System.EventArgs e)
{
HidePopover(sender as NSObject);
Expand All @@ -91,6 +113,11 @@ void HandleAboutMenuItemClicked(object sender, System.EventArgs e)
windowController.ShowWindow(sender as NSObject);
}

/// <summary>
/// Handles the quit button click.
/// </summary>
/// <param name="sender">Sender.</param>
/// <param name="e">E.</param>
void HandleQuitButtonClicked(object sender, System.EventArgs e)
{
HidePopover(sender as NSObject);
Expand Down
12 changes: 11 additions & 1 deletion Carol/Models/TrackLyrics.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
using System;
/*
* Model for lyrics of a track
*
* Author - Anagh Sharma
* http://www.anaghsharma.com
*
* 2017
*
*/

using System;
using System.Collections.Generic;

namespace Carol.Models
Expand Down
12 changes: 11 additions & 1 deletion Carol/Models/Tracks.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
using System;
/*
* Model for track
*
* Author - Anagh Sharma
* http://www.anaghsharma.com
*
* 2017
*
*/

using System;
using System.Collections.Generic;

namespace Carol.Models
Expand Down
Loading

0 comments on commit 7b13f92

Please sign in to comment.