Tweaked SpotifyURI, moved parsing to a static method

This commit is contained in:
Johnny @PC 2016-03-21 15:48:50 +01:00
parent 8a156ff9e5
commit 8d274164c4
4 changed files with 52 additions and 39 deletions

View File

@ -50,7 +50,8 @@
this.label10 = new System.Windows.Forms.Label(); this.label10 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label(); this.label8 = new System.Windows.Forms.Label();
this.connectBtn = new System.Windows.Forms.Button(); this.connectBtn = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox(); this.trackInfoBox = new System.Windows.Forms.GroupBox();
this.advertLabel = new System.Windows.Forms.Label();
this.timeLabel = new System.Windows.Forms.Label(); this.timeLabel = new System.Windows.Forms.Label();
this.timeProgressBar = new System.Windows.Forms.ProgressBar(); this.timeProgressBar = new System.Windows.Forms.ProgressBar();
this.label5 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label();
@ -60,10 +61,9 @@
this.artistLinkLabel = new System.Windows.Forms.LinkLabel(); this.artistLinkLabel = new System.Windows.Forms.LinkLabel();
this.titleLinkLabel = new System.Windows.Forms.LinkLabel(); this.titleLinkLabel = new System.Windows.Forms.LinkLabel();
this.smallAlbumPicture = new System.Windows.Forms.PictureBox(); this.smallAlbumPicture = new System.Windows.Forms.PictureBox();
this.advertLabel = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.bigAlbumPicture)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.bigAlbumPicture)).BeginInit();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout(); this.trackInfoBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.smallAlbumPicture)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.smallAlbumPicture)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
@ -306,25 +306,33 @@
this.connectBtn.UseVisualStyleBackColor = true; this.connectBtn.UseVisualStyleBackColor = true;
this.connectBtn.Click += new System.EventHandler(this.connectBtn_Click); this.connectBtn.Click += new System.EventHandler(this.connectBtn_Click);
// //
// groupBox2 // trackInfoBox
// //
this.groupBox2.Controls.Add(this.advertLabel); this.trackInfoBox.Controls.Add(this.advertLabel);
this.groupBox2.Controls.Add(this.timeLabel); this.trackInfoBox.Controls.Add(this.timeLabel);
this.groupBox2.Controls.Add(this.timeProgressBar); this.trackInfoBox.Controls.Add(this.timeProgressBar);
this.groupBox2.Controls.Add(this.label5); this.trackInfoBox.Controls.Add(this.label5);
this.groupBox2.Controls.Add(this.label4); this.trackInfoBox.Controls.Add(this.label4);
this.groupBox2.Controls.Add(this.label3); this.trackInfoBox.Controls.Add(this.label3);
this.groupBox2.Controls.Add(this.albumLinkLabel); this.trackInfoBox.Controls.Add(this.albumLinkLabel);
this.groupBox2.Controls.Add(this.artistLinkLabel); this.trackInfoBox.Controls.Add(this.artistLinkLabel);
this.groupBox2.Controls.Add(this.titleLinkLabel); this.trackInfoBox.Controls.Add(this.titleLinkLabel);
this.groupBox2.Controls.Add(this.smallAlbumPicture); this.trackInfoBox.Controls.Add(this.smallAlbumPicture);
this.groupBox2.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.trackInfoBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.groupBox2.Location = new System.Drawing.Point(3, 349); this.trackInfoBox.Location = new System.Drawing.Point(3, 349);
this.groupBox2.Name = "groupBox2"; this.trackInfoBox.Name = "trackInfoBox";
this.groupBox2.Size = new System.Drawing.Size(318, 304); this.trackInfoBox.Size = new System.Drawing.Size(318, 304);
this.groupBox2.TabIndex = 4; this.trackInfoBox.TabIndex = 4;
this.groupBox2.TabStop = false; this.trackInfoBox.TabStop = false;
this.groupBox2.Text = "Track Info"; this.trackInfoBox.Text = "Track Info";
//
// advertLabel
//
this.advertLabel.AutoSize = true;
this.advertLabel.Location = new System.Drawing.Point(6, 67);
this.advertLabel.Name = "advertLabel";
this.advertLabel.Size = new System.Drawing.Size(0, 17);
this.advertLabel.TabIndex = 31;
// //
// timeLabel // timeLabel
// //
@ -420,19 +428,11 @@
this.smallAlbumPicture.TabIndex = 5; this.smallAlbumPicture.TabIndex = 5;
this.smallAlbumPicture.TabStop = false; this.smallAlbumPicture.TabStop = false;
// //
// advertLabel
//
this.advertLabel.AutoSize = true;
this.advertLabel.Location = new System.Drawing.Point(6, 67);
this.advertLabel.Name = "advertLabel";
this.advertLabel.Size = new System.Drawing.Size(0, 17);
this.advertLabel.TabIndex = 31;
//
// LocalControl // LocalControl
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.groupBox2); this.Controls.Add(this.trackInfoBox);
this.Controls.Add(this.connectBtn); this.Controls.Add(this.connectBtn);
this.Controls.Add(this.groupBox1); this.Controls.Add(this.groupBox1);
this.Controls.Add(this.bigAlbumPicture); this.Controls.Add(this.bigAlbumPicture);
@ -441,8 +441,8 @@
((System.ComponentModel.ISupportInitialize)(this.bigAlbumPicture)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.bigAlbumPicture)).EndInit();
this.groupBox1.ResumeLayout(false); this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout(); this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false); this.trackInfoBox.ResumeLayout(false);
this.groupBox2.PerformLayout(); this.trackInfoBox.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.smallAlbumPicture)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.smallAlbumPicture)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
@ -453,7 +453,7 @@
private System.Windows.Forms.PictureBox bigAlbumPicture; private System.Windows.Forms.PictureBox bigAlbumPicture;
private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button connectBtn; private System.Windows.Forms.Button connectBtn;
private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.GroupBox trackInfoBox;
private System.Windows.Forms.PictureBox smallAlbumPicture; private System.Windows.Forms.PictureBox smallAlbumPicture;
private System.Windows.Forms.Label label10; private System.Windows.Forms.Label label10;
private System.Windows.Forms.Label label8; private System.Windows.Forms.Label label8;

View File

@ -93,6 +93,10 @@ namespace SpotifyAPI.Example
albumLinkLabel.Text = track.AlbumResource.Name; albumLinkLabel.Text = track.AlbumResource.Name;
albumLinkLabel.Tag = track.AlbumResource.Uri; albumLinkLabel.Tag = track.AlbumResource.Uri;
SpotifyUri uri = track.TrackResource.ParseUri();
trackInfoBox.Text = $"Track Info - {uri.Id}";
bigAlbumPicture.Image = await track.GetAlbumArtAsync(AlbumArtSize.Size640); bigAlbumPicture.Image = await track.GetAlbumArtAsync(AlbumArtSize.Size640);
smallAlbumPicture.Image = await track.GetAlbumArtAsync(AlbumArtSize.Size160); smallAlbumPicture.Image = await track.GetAlbumArtAsync(AlbumArtSize.Size160);
} }

View File

@ -16,7 +16,7 @@ namespace SpotifyAPI.Local.Models
public SpotifyUri ParseUri() public SpotifyUri ParseUri()
{ {
return new SpotifyUri(this.Uri); return SpotifyUri.Parse(Uri);
} }
} }
} }

View File

@ -12,19 +12,28 @@ namespace SpotifyAPI.Local.Models
public string Type { get; internal set; } public string Type { get; internal set; }
public string Id { get; internal set; } public string Id { get; internal set; }
public SpotifyUri(string uri) public SpotifyUri(string uriBase, string uriType, string uriId)
{
Base = uriBase;
Type = uriType;
Id = uriId;
}
public static SpotifyUri Parse(string uri)
{ {
if (String.IsNullOrEmpty(uri)) if (String.IsNullOrEmpty(uri))
throw new ArgumentNullException("Uri"); throw new ArgumentNullException("Uri");
string[] props = uri.Split(':'); string[] props = uri.Split(':');
if (props.Length != 3) if (props.Length != 3)
throw new ArgumentException("Unexpected Uri"); throw new ArgumentException("Unexpected Uri");
Base = props[0]; return new SpotifyUri(props[0], props[1], props[2]);
Type = props[1]; }
Id = props[2];
public override string ToString()
{
return $"{Base}:{Type}:{Id}";
} }
} }
} }