Show network status and player name

develop
LEdoian 3 years ago
parent 5ca7a161cc
commit a5edd77760

@ -90,7 +90,20 @@ namespace QuickPlay
{ {
throw new InvalidOperationException("Schema of player config URL not supported"); 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. // We want to compare by values.

@ -14,6 +14,7 @@ namespace QuickPlay
public interface IPlayer public interface IPlayer
{ {
Dictionary<string, IPlayable> Songs { get; } Dictionary<string, IPlayable> Songs { get; }
string PlayerName { get; }
void Play(string identifier); void Play(string identifier);
float CurrentProgress { get; } float CurrentProgress { get; }
bool IsReady { get; } bool IsReady { get; }

@ -63,6 +63,9 @@ namespace QuickPlay
// Initialize the RecyclerView // Initialize the RecyclerView
// Since this is rather complicated, it is in a separate method // Since this is rather complicated, it is in a separate method
InitializeRecyclerView(); InitializeRecyclerView();
// Refresh player info
OnPlayerUpdate();
} }
private void InitializeRecyclerView() private void InitializeRecyclerView()
@ -108,7 +111,12 @@ namespace QuickPlay
/// </summary> /// </summary>
public void OnPlayerUpdate() public void OnPlayerUpdate()
{ {
throw new NotImplementedException("Activity should update."); TextView playerName = FindViewById<TextView>(Resource.Id.playerNameText);
playerName.Text = currentPlayer.PlayerName;
Toolbar tb = FindViewById<Toolbar>(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.");
} }
} }
} }

@ -20,13 +20,14 @@ namespace QuickPlay
// MpcCore uses strings, so be it // MpcCore uses strings, so be it
string mpdIP, mpdPort; string mpdIP, mpdPort;
public Dictionary<string, IPlayable> Songs { get; private set; } public Dictionary<string, IPlayable> Songs { get; private set; }
public string PlayerName { get; private set; }
public float CurrentProgress { get { public float CurrentProgress { get {
throw new NotImplementedException(); throw new NotImplementedException();
} } } }
public bool IsReady { get public bool IsReady { get
{ {
throw new NotImplementedException(); return mpd.IsConnected;
} } } }
public void Play(string songId) public void Play(string songId)
{ {
@ -40,6 +41,7 @@ namespace QuickPlay
{ {
// Populate known fields/properties // Populate known fields/properties
Songs = cfg.songs; 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. // 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('@'); var connDetails = cfg.playerConnectionDetails.Split('@');
if (connDetails.Length > 2) throw new InvalidOperationException("Bad connection details"); if (connDetails.Length > 2) throw new InvalidOperationException("Bad connection details");

Loading…
Cancel
Save