Show server name in "Unable to connect to Home Assistant" dialog (#3995)

- Shows the server name instead of a generic "Home Assistant" to prevent confusion when the app cannot connect in the WebViewActivity, when using multiserver.
This commit is contained in:
Joris Pelgröm 2023-11-04 19:59:15 +01:00 committed by GitHub
parent 2da1a36c55
commit ac7ba33ae7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 1 deletions

View file

@ -1215,8 +1215,14 @@ class WebViewActivity : BaseActivity(), io.homeassistant.companion.android.webvi
}
isShowingError = true
val serverName = if (serverManager.defaultServers.size > 1) presenter.getActiveServerName() else null
val alert = AlertDialog.Builder(this)
.setTitle(commonR.string.error_connection_failed)
.setTitle(
getString(
commonR.string.error_connection_failed_to,
serverName ?: getString(commonR.string.app_name)
)
)
.setOnDismissListener {
isShowingError = false
alertDialog = null

View file

@ -11,6 +11,7 @@ interface WebViewPresenter {
fun onViewReady(path: String?)
fun getActiveServer(): Int
fun getActiveServerName(): String?
fun updateActiveServer()
fun setActiveServer(id: Int)
fun switchActiveServer(id: Int)

View file

@ -117,6 +117,13 @@ class WebViewPresenterImpl @Inject constructor(
override fun getActiveServer(): Int = serverId
override fun getActiveServerName(): String? =
if (serverManager.isRegistered()) {
serverManager.getServer(serverId)?.friendlyName
} else {
null
}
override fun updateActiveServer() {
if (serverManager.isRegistered()) {
serverManager.getServer()?.let {

View file

@ -244,6 +244,7 @@
<string name="entity_widget_desc">View any entity\'s current state and toggle it</string>
<string name="error_auth_revoked">It appears that your authorization was revoked, please reconnect to Home Assistant.</string>
<string name="error_connection_failed">Unable to connect to Home Assistant.</string>
<string name="error_connection_failed_to">Unable to connect to %1$s</string>
<string name="error_loading_entities">Error loading entities</string>
<string name="error_onboarding_connection_failed">Unable to connect to Home Assistant.</string>
<string name="error_ssl">Unable to communicate with Home Assistant because of a SSL error. Please ensure your certificate is valid.</string>