fix an API change (status[playing][updated] changed to status[updated_at]), add ability to see your vote on the currently playing track (thanks mr.plaza!). finally, only allow like/dislike buttons to be clickable if user is logged in.
This commit is contained in:
parent
a8dcd3a150
commit
e691687ee1
|
@ -32,8 +32,8 @@
|
|||
<Slider x:Name="slDuration" Margin="0,87,0,0" VerticalAlignment="Top" IsEnabled="False" Grid.ColumnSpan="2" Height="18" Grid.Column="1" AutoToolTipPlacement="TopLeft"/>
|
||||
<Label x:Name="lbElapsed" Content="00:00" HorizontalAlignment="Left" Margin="0,99,0,0" VerticalAlignment="Top" FontStyle="Italic" FontSize="9" Grid.Column="1"/>
|
||||
<Label x:Name="lbTime" Content="00:00" Margin="0,99,0,0" VerticalAlignment="Top" HorizontalAlignment="Right" FontStyle="Italic" FontSize="9" Grid.Column="2"/>
|
||||
<Button x:Name="btLike" Content="❤" ToolTip="Like this track" HorizontalAlignment="Right" Margin="0,40,2,0" Width="22" Height="20" VerticalAlignment="Top" FontSize="10" Grid.Column="2" Click="BtLike_Click"/>
|
||||
<Button x:Name="btDislike" Content="💔" ToolTip="Dislike this track" HorizontalAlignment="Right" Margin="0,64,2,0" Width="22" Height="20" VerticalAlignment="Top" FontSize="10" Grid.Column="2" Click="BtDislike_Click"/>
|
||||
<Button x:Name="btLike" Content="❤" ToolTip="Like this track" IsEnabled="False" HorizontalAlignment="Right" Margin="0,40,2,0" Width="22" Height="20" VerticalAlignment="Top" FontSize="10" Grid.Column="2" Click="BtLike_Click"/>
|
||||
<Button x:Name="btDislike" Content="💔" ToolTip="Dislike this track" IsEnabled="False" HorizontalAlignment="Right" Margin="0,64,2,0" Width="22" Height="20" VerticalAlignment="Top" FontSize="10" Grid.Column="2" Click="BtDislike_Click"/>
|
||||
<Label x:Name="lbLikeCt" Content="0" HorizontalAlignment="Right" Margin="0,36.5,22,0" VerticalAlignment="Top" Grid.Column="2" Grid.ColumnSpan="2"/>
|
||||
<Label x:Name="lbDislikeCt" Content="0" HorizontalAlignment="Right" Margin="0,60.5,22,0" VerticalAlignment="Top" Grid.Column="2" Grid.ColumnSpan="2"/>
|
||||
<Image x:Name="imLogin" Source="{DynamicResource imUsr}" IsHitTestVisible="False" Panel.ZIndex="1" Width="18" Height="18" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,17,3,0" Grid.Column="2"/>
|
||||
|
@ -54,6 +54,7 @@
|
|||
<StackPanel Orientation="Horizontal">
|
||||
<!--TODO implement tracking of time spent listening (this session and all-time)
|
||||
<TextBlock x:Name="sbListeningTimers" Text="00:00 (00:00)"/>-->
|
||||
<TextBlock x:Name="sbVote" Margin="0,0,4,0"/>
|
||||
<ToggleButton x:Name="sbOnTop" Content="📌" ToolTip="Toggle always-on-top" Checked="SbOnTop_Click" Margin="0,-2,4,-2"/>
|
||||
<ToggleButton x:Name="sbMute" Content="🔊" ToolTip="Toggle mute" Checked="SbMute_Click" Unchecked="SbMute_Click" Margin="0,-2,0,-2"/>
|
||||
<Separator Width="6" Background="{x:Null}" Foreground="{x:Null}"/>
|
||||
|
|
|
@ -23,7 +23,6 @@ namespace WinPlaza {
|
|||
private Timer tGfx;
|
||||
private Timer tLogon;
|
||||
private bool AudioInit=false;
|
||||
private bool LikedCTrack=false;
|
||||
#endregion
|
||||
#region Delegates
|
||||
private delegate void dgtNoParam();
|
||||
|
@ -54,6 +53,8 @@ namespace WinPlaza {
|
|||
btLogin.Visibility = Visibility.Hidden;
|
||||
imLogin.IsEnabled = false;
|
||||
imLogin.Visibility = Visibility.Hidden;
|
||||
btDislike.IsEnabled = true;
|
||||
btLike.IsEnabled = true;
|
||||
SetStatus($"Logged in as {await plaza.GetUser()}");
|
||||
}
|
||||
private async void DgtRefresh(bool Force = false) {
|
||||
|
@ -75,6 +76,22 @@ namespace WinPlaza {
|
|||
lbDislikeCt.Content = s.Dislikes;
|
||||
lbElapsed.Content = $"{(s.CalculatedElapsed / 60).ToString("D")}:{(s.CalculatedElapsed % 60).ToString("D2")}";
|
||||
if(LastArtwork != s.ArtworkUri || Force) {
|
||||
Nightwave.Vote v = await plaza.GetVote() ?? Nightwave.Vote.Neutral;
|
||||
switch(v) {
|
||||
case Nightwave.Vote.Dislike:
|
||||
sbVote.Text = "👎";
|
||||
break;
|
||||
case Nightwave.Vote.Like:
|
||||
sbVote.Text = "👍";
|
||||
break;
|
||||
case Nightwave.Vote.Favourite:
|
||||
sbVote.Text = "💖";
|
||||
break;
|
||||
default:
|
||||
sbVote.Text = "🤷♀️";
|
||||
break;
|
||||
}
|
||||
//TODO visual effect on the like/dislike buttons to indicate user's vote
|
||||
lbArtist.Content = s.Artist;
|
||||
lbTitle.Content = s.Title;
|
||||
lbAlbum.Content = s.Album;
|
||||
|
@ -83,12 +100,10 @@ namespace WinPlaza {
|
|||
slDuration.Maximum = s.Duration;
|
||||
lbTime.Content = $"{(s.Duration / 60).ToString("D")}:{(s.Duration % 60).ToString("D2")}";
|
||||
if(LastArtwork != s.ArtworkUri) {
|
||||
if(btPlayPause.IsChecked == true)
|
||||
SetStatus("Playing");
|
||||
LikedCTrack = false;
|
||||
art.Source = new BitmapImage(new Uri(s.ArtworkUri));
|
||||
LastArtwork = s.ArtworkUri;
|
||||
}
|
||||
SetStatus("");
|
||||
}
|
||||
}
|
||||
private void DgtAudio() {
|
||||
|
@ -228,16 +243,21 @@ namespace WinPlaza {
|
|||
btLogin.Visibility = Visibility.Hidden;
|
||||
imLogin.IsEnabled = false;
|
||||
imLogin.Visibility = Visibility.Hidden;
|
||||
btDislike.IsEnabled = true;
|
||||
btLike.IsEnabled = true;
|
||||
SetStatus($"Logged in as {await plaza.GetUser()}");
|
||||
}
|
||||
private async void BtLike_Click(object sender, RoutedEventArgs e) {
|
||||
_ = Dispatcher.BeginInvoke(new dgtCtrl(DgtToggleEnabled), btLike);
|
||||
Nightwave.Vote v = Nightwave.Vote.Like;
|
||||
if(LikedCTrack)
|
||||
Nightwave.Vote v = await plaza.GetVote() ?? Nightwave.Vote.Neutral;
|
||||
if(v == Nightwave.Vote.Like)
|
||||
v = Nightwave.Vote.Favourite;
|
||||
else if(v == Nightwave.Vote.Favourite)
|
||||
v = Nightwave.Vote.Neutral;
|
||||
else
|
||||
v = Nightwave.Vote.Like;
|
||||
if(await plaza.CastVote(v)) {
|
||||
SetStatus($"Submitted {v}!");
|
||||
LikedCTrack = !LikedCTrack;
|
||||
} else
|
||||
SetStatus($"Something went weird while casting {v}");
|
||||
_ = Dispatcher.BeginInvoke(new dgtCtrl(DgtToggleEnabled), btLike);
|
||||
|
@ -245,12 +265,14 @@ namespace WinPlaza {
|
|||
}
|
||||
private async void BtDislike_Click(object sender, RoutedEventArgs e) {
|
||||
_ = Dispatcher.BeginInvoke(new dgtCtrl(DgtToggleEnabled), btDislike);
|
||||
if(await plaza.CastVote(Nightwave.Vote.Dislike))
|
||||
SetStatus("Song disliked!");
|
||||
Nightwave.Vote v = Nightwave.Vote.Dislike;
|
||||
if(await plaza.GetVote() == Nightwave.Vote.Dislike)
|
||||
v = Nightwave.Vote.Neutral;
|
||||
if(await plaza.CastVote(v))
|
||||
SetStatus($"Submitted {v}!");
|
||||
else
|
||||
SetStatus("Something went weird while disliking");
|
||||
SetStatus($"Something went weird while casting {v}");
|
||||
_ = Dispatcher.BeginInvoke(new dgtCtrl(DgtToggleEnabled), btDislike);
|
||||
LikedCTrack = false;
|
||||
_ = Dispatcher.BeginInvoke(new dgtBool(DgtRefresh), true);
|
||||
}
|
||||
private void SbOnTop_Click(object sender, RoutedEventArgs e) {
|
||||
|
|
|
@ -31,8 +31,8 @@
|
|||
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
|
||||
<WebPage>index.html</WebPage>
|
||||
<OpenBrowserOnPublish>false</OpenBrowserOnPublish>
|
||||
<ApplicationRevision>4</ApplicationRevision>
|
||||
<ApplicationVersion>1.5.0.%2a</ApplicationVersion>
|
||||
<ApplicationRevision>1</ApplicationRevision>
|
||||
<ApplicationVersion>1.6.0.%2a</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<CreateDesktopShortcut>true</CreateDesktopShortcut>
|
||||
<PublishWizardCompleted>true</PublishWizardCompleted>
|
||||
|
@ -73,7 +73,7 @@
|
|||
<GenerateManifests>true</GenerateManifests>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignManifests>false</SignManifests>
|
||||
<SignManifests>true</SignManifests>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject>WinPlaza.App</StartupObject>
|
||||
|
|
|
@ -16,7 +16,6 @@ namespace libplaza {
|
|||
public string album;
|
||||
public int length;
|
||||
public int position;
|
||||
public long updated;
|
||||
public string artwork;
|
||||
public string artwork_s;
|
||||
public int likes;
|
||||
|
@ -25,6 +24,7 @@ namespace libplaza {
|
|||
public class PlazaJson {
|
||||
public bool maintenance;
|
||||
public int listeners;
|
||||
public long updated_at;
|
||||
[JsonProperty]
|
||||
public PlazaPlayback playback;
|
||||
}
|
||||
|
@ -39,6 +39,9 @@ namespace libplaza {
|
|||
public string status;
|
||||
public int[] ratings;
|
||||
}
|
||||
public class PlazaGetVote {
|
||||
public int rate;
|
||||
}
|
||||
public class PlazaLogonResult {
|
||||
public string status;
|
||||
public string username;
|
||||
|
@ -102,7 +105,6 @@ namespace libplaza {
|
|||
_bc.FaultOccurred = true;
|
||||
}
|
||||
}
|
||||
public async void EvtUpdate() => await Update();
|
||||
public async Task<Status> GetNightwaveAsync() {
|
||||
Status status;
|
||||
HttpResponseMessage _r=await _hcl.GetAsync("/status");
|
||||
|
@ -118,7 +120,7 @@ namespace libplaza {
|
|||
Artist = j.playback.artist,
|
||||
Elapsed = j.playback.position,
|
||||
Duration = j.playback.length,
|
||||
Since = j.playback.updated,
|
||||
Since = j.updated_at,
|
||||
Likes = j.playback.likes,
|
||||
Dislikes = j.playback.hates,
|
||||
Listeners = j.listeners,
|
||||
|
@ -127,6 +129,15 @@ namespace libplaza {
|
|||
};
|
||||
return status;
|
||||
}
|
||||
public async Task<Vote?> GetVote() {
|
||||
if(!await CheckSession())
|
||||
return null;
|
||||
HttpResponseMessage _r=await _hcl.GetAsync("/vote");
|
||||
if(!_r.IsSuccessStatusCode)
|
||||
return null;
|
||||
PlazaGetVote r=JsonConvert.DeserializeObject<PlazaGetVote>(await _r.Content.ReadAsStringAsync());
|
||||
return (Vote)r.rate;
|
||||
}
|
||||
public async Task<bool> CastVote(Vote v) {
|
||||
if(!await CheckSession())
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue