From a8d9d7504d8d718e668d261693f9c859755aa764 Mon Sep 17 00:00:00 2001 From: Me on Windows Date: Mon, 5 Jul 2021 17:56:16 +0000 Subject: [PATCH] Change IsReady to Status It really isn't an ortogonal state. --- QuickPlay/Interfaces.cs | 6 +++++- QuickPlay/MainActivity.cs | 29 ++++++++++++++++++++++++++--- QuickPlay/MpdPlayer.cs | 7 +++---- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/QuickPlay/Interfaces.cs b/QuickPlay/Interfaces.cs index 1d0e079..9b3b02b 100644 --- a/QuickPlay/Interfaces.cs +++ b/QuickPlay/Interfaces.cs @@ -13,11 +13,15 @@ namespace QuickPlay /// public interface IPlayer { + public enum PlayerStatus + { + Disconnected, Playing, Stopped + } Dictionary Songs { get; } string PlayerName { get; } void Play(string identifier); float CurrentProgress { get; } - bool IsReady { get; } + PlayerStatus Status { get; } void SetReasonableOptions(); //TODO /// /// Attach to the real player. diff --git a/QuickPlay/MainActivity.cs b/QuickPlay/MainActivity.cs index 40d146c..fd86f36 100644 --- a/QuickPlay/MainActivity.cs +++ b/QuickPlay/MainActivity.cs @@ -113,10 +113,33 @@ namespace QuickPlay { TextView playerName = FindViewById(Resource.Id.playerNameText); playerName.Text = currentPlayer.PlayerName; + var bar = FindViewById(Resource.Id.currentSongBar); + switch (currentPlayer.Status) + { + case IPlayer.PlayerStatus.Disconnected: + Toolbar tb = FindViewById(Resource.Id.toolbar); + tb.SetBackgroundColor(Android.Graphics.Color.Red); + bar.Visibility = ViewStates.Invisible; + break; + case IPlayer.PlayerStatus.Playing: + ResetToolbarColor(); + // Show progress bar + bar.Visibility = ViewStates.Visible; + break; + case IPlayer.PlayerStatus.Stopped: + ResetToolbarColor(); + bar.Visibility = ViewStates.Invisible; + break; + } + } + private void ResetToolbarColor() + { Toolbar tb = FindViewById(Resource.Id.toolbar); - // This code is seriously lovely. FML. - tb.SetBackgroundColor(currentPlayer.IsReady ? new Android.Graphics.Color(Android.Support.V4.Content.ContextCompat.GetColor(this, Resource.Color.colorPrimary)) : Android.Graphics.Color.Red); - // throw new NotImplementedException("Activity should update."); + tb.SetBackgroundColor( + new Android.Graphics.Color( + Android.Support.V4.Content.ContextCompat.GetColor(this, Resource.Color.colorPrimary) + ) + ); } } } diff --git a/QuickPlay/MpdPlayer.cs b/QuickPlay/MpdPlayer.cs index 228710f..4b3dd1c 100644 --- a/QuickPlay/MpdPlayer.cs +++ b/QuickPlay/MpdPlayer.cs @@ -18,16 +18,13 @@ namespace QuickPlay MpcCoreClient mpd; // MpcCore uses strings, so be it string mpdIP, mpdPort; + public IPlayer.PlayerStatus Status { get; private set; } public Dictionary Songs { get; private set; } public string PlayerName { get; private set; } public float CurrentProgress { get { throw new NotImplementedException(); } } - public bool IsReady { get - { - return mpd.IsConnected; - } } public void Play(string songId) { throw new NotImplementedException(); @@ -47,6 +44,8 @@ namespace QuickPlay mpdIP = connDetails[0]; mpdPort = connDetails.Length >=2 ? connDetails[1] : "6600"; // XXX: Unneccessary default here... // Connecting and monitoring remote player is done in ConnectAsync. + // Therefore, we start disconnected + Status = IPlayer.PlayerStatus.Disconnected; } public async Task ConnectAsync() {