void _Update() { if (MainThread.IsMainThread == false) { MainThread.BeginInvokeOnMainThread(() => { _Update(); }); return; } tbPlay.IsEnabled = App.Instance.Player.SupportsSnapclient(); tbPlay.Text = App.Instance.Player.IsPlaying() == false ? "Play" : "Stop"; Groups.Children.Clear(); if (m_Client != null && m_Client.IsConnected() && m_Client.ServerData != null) { foreach (Group g in m_Client.ServerData.groups) { Controls.Group cGroup = new Controls.Group(m_Client, g); Groups.Children.Add(cGroup); } } try { GroupsRefreshView.IsRefreshing = m_Client.IsConnected() == false && m_Client?.ConnectionFailed == false; } catch (Exception e) { Debug.WriteLine("Exc: " + e.Message); } if (m_Client?.ConnectionFailed == true) { m_ConnectionFailedLabel = new Label(); m_ConnectionFailedLabel.Text = string.Format("Couldn't connect to snapserver at {0}:{1}", SnapSettings.Server, SnapSettings.ControlPort); m_ConnectionFailedLabel.HorizontalOptions = LayoutOptions.CenterAndExpand; m_ConnectionFailedLabel.VerticalOptions = LayoutOptions.CenterAndExpand; Groups.Children.Add(m_ConnectionFailedLabel); } else { if (m_ConnectionFailedLabel != null) { Groups.Children.Remove(m_ConnectionFailedLabel); m_ConnectionFailedLabel = null; } } }
void _Update() { if (MainThread.IsMainThread == false) { MainThread.BeginInvokeOnMainThread(() => { _Update(); }); return; } if (App.Instance.Player.SupportsSnapclient() == false) { if (ToolbarItems.Contains(tbPlay)) { ToolbarItems.Remove(tbPlay); // remove "Play" button for platforms that don't support it } } tbPlay.IsEnabled = m_Client != null && m_Client.IsConnected() && m_Client.ServerData != null; tbPlay.Text = App.Instance.Player.IsPlaying() == false ? "Play" : "Stop"; _ClearConnectionFailureLabel(); Groups.Children.Clear(); if (m_Client != null && m_Client.IsConnected() && m_Client.ServerData != null) { foreach (Group g in m_Client.ServerData.groups) { Controls.Group cGroup = new Controls.Group(m_Client, g); Groups.Children.Add(cGroup); } } try { GroupsRefreshView.IsRefreshing = m_Client.IsConnected() == false && m_Client?.ConnectionFailed == false; } catch (Exception e) { Debug.WriteLine("Exc: " + e.Message); } if (m_Client?.ConnectionFailed == true) { if (m_ConnectionFailedLabel == null) { m_ConnectionFailedLabel = new Label(); } m_ConnectionFailedLabel.HorizontalTextAlignment = TextAlignment.Center; m_ConnectionFailedLabel.Margin = new Thickness(40); if (string.IsNullOrWhiteSpace(SnapSettings.Server)) { m_ConnectionFailedLabel.Text = "This app requires Snapserver to be installed and running on your local network.\n" + "Fill in the address to your server via\nMenu -> Settings.\n\n" + "For more information, visit:\n\nhttps://github.com/badaix/snapcast\nand\nhttps://github.com/stijnvdb88/snap.net"; } else { m_ConnectionFailedLabel.Text = $"Couldn't connect to snapserver at {SnapSettings.Server}:{SnapSettings.ControlPort}"; } m_ConnectionFailedLabel.HorizontalOptions = LayoutOptions.CenterAndExpand; m_ConnectionFailedLabel.VerticalOptions = LayoutOptions.CenterAndExpand; Groups.Children.Add(m_ConnectionFailedLabel); } else { _ClearConnectionFailureLabel(); } }