diff --git a/QuickPlay/Configuration.cs b/QuickPlay/Configuration.cs index d681e31..fc3ec1c 100644 --- a/QuickPlay/Configuration.cs +++ b/QuickPlay/Configuration.cs @@ -90,7 +90,20 @@ namespace QuickPlay { throw new InvalidOperationException("Schema of player config URL not supported"); } - return await cfgProvider.GetConfigurationAsync(); + PlayerConfiguration playercfg; + try + { + playercfg = await cfgProvider.GetConfigurationAsync(); + } + catch (Exception e) when (e is Java.Net.UnknownHostException) + { + var ctx = Android.App.Application.Context; + var t = Android.Widget.Toast.MakeText(ctx, "Could not load config:" + e.Message, Android.Widget.ToastLength.Long); + t.Show(); + cfgProvider = new DummyConfigurationProvider(); + playercfg = await cfgProvider.GetConfigurationAsync(); + } + return playercfg; } // We want to compare by values. diff --git a/QuickPlay/Interfaces.cs b/QuickPlay/Interfaces.cs index 3281365..6c25806 100644 --- a/QuickPlay/Interfaces.cs +++ b/QuickPlay/Interfaces.cs @@ -14,6 +14,7 @@ namespace QuickPlay public interface IPlayer { Dictionary Songs { get; } + string PlayerName { get; } void Play(string identifier); float CurrentProgress { get; } bool IsReady { get; } diff --git a/QuickPlay/MainActivity.cs b/QuickPlay/MainActivity.cs index 0670541..4420148 100644 --- a/QuickPlay/MainActivity.cs +++ b/QuickPlay/MainActivity.cs @@ -63,6 +63,9 @@ namespace QuickPlay // Initialize the RecyclerView // Since this is rather complicated, it is in a separate method InitializeRecyclerView(); + + // Refresh player info + OnPlayerUpdate(); } private void InitializeRecyclerView() @@ -108,7 +111,12 @@ namespace QuickPlay /// public void OnPlayerUpdate() { - throw new NotImplementedException("Activity should update."); + TextView playerName = FindViewById(Resource.Id.playerNameText); + playerName.Text = currentPlayer.PlayerName; + 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."); } } } diff --git a/QuickPlay/MpdPlayer.cs b/QuickPlay/MpdPlayer.cs index c91d894..b83bcb1 100644 --- a/QuickPlay/MpdPlayer.cs +++ b/QuickPlay/MpdPlayer.cs @@ -20,13 +20,14 @@ namespace QuickPlay // MpcCore uses strings, so be it string mpdIP, mpdPort; - public Dictionary Songs { 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 { - throw new NotImplementedException(); + return mpd.IsConnected; } } public void Play(string songId) { @@ -40,6 +41,7 @@ namespace QuickPlay { // Populate known fields/properties Songs = cfg.songs; + PlayerName = cfg.playerName; // NOTE: We separate the port by '@', since ':' could be part of IPv6 and we do not want to complicate parsing. var connDetails = cfg.playerConnectionDetails.Split('@'); if (connDetails.Length > 2) throw new InvalidOperationException("Bad connection details");