Skip to content

Commit

Permalink
Support ?server=name in homeassistant navigate deeplink (#4969)
Browse files Browse the repository at this point in the history
* Support ?server=name in homeassistant navigate deeplink

 - Support the server query parameter for specifying which server should open a homeassistant://navigate deeplink and skipping the chooser. Matches iOS app functionality.

* Support default, ignore case

 - Support default/empty server param to pick last used and skip chooser
 - Ignore case when comparing server names
  • Loading branch information
jpelgrom authored Jan 15, 2025
1 parent e9fb3b0 commit 9a2d737
Showing 1 changed file with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,37 @@ class LaunchActivity : AppCompatActivity(), LaunchView {
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(carIntent)
} else if (presenter.hasMultipleServers() && intent.data?.path?.isNotBlank() == true) {
supportFragmentManager.setFragmentResultListener(ServerChooserFragment.RESULT_KEY, this) { _, bundle ->
val serverId = if (bundle.containsKey(ServerChooserFragment.RESULT_SERVER)) {
bundle.getInt(ServerChooserFragment.RESULT_SERVER)
var serverParameter: Int? = null
if (intent.data?.queryParameterNames.orEmpty().contains("server")) {
val serverName = intent.data?.getQueryParameter("server").takeIf { !it.isNullOrBlank() }
if (serverName == "default" || serverName == null) {
serverParameter = serverManager.getServer()?.id
} else {
null
serverManager.defaultServers
.firstOrNull { it.friendlyName.equals(serverName, ignoreCase = true) }
?.let {
serverParameter = it.id
}
}
supportFragmentManager.clearFragmentResultListener(ServerChooserFragment.RESULT_KEY)
startActivity(WebViewActivity.newInstance(this, intent.data?.path, serverId))
finish()
overridePendingTransition(0, 0) // Disable activity start/stop animation
}
ServerChooserFragment().show(supportFragmentManager, ServerChooserFragment.TAG)
return

if (serverParameter != null) {
startActivity(WebViewActivity.newInstance(this, intent.data?.path, serverParameter))
} else { // Show server chooser
supportFragmentManager.setFragmentResultListener(ServerChooserFragment.RESULT_KEY, this) { _, bundle ->
val serverId = if (bundle.containsKey(ServerChooserFragment.RESULT_SERVER)) {
bundle.getInt(ServerChooserFragment.RESULT_SERVER)
} else {
null
}
supportFragmentManager.clearFragmentResultListener(ServerChooserFragment.RESULT_KEY)
startActivity(WebViewActivity.newInstance(this, intent.data?.path, serverId))
finish()
overridePendingTransition(0, 0) // Disable activity start/stop animation
}
ServerChooserFragment().show(supportFragmentManager, ServerChooserFragment.TAG)
return
}
} else {
startActivity(WebViewActivity.newInstance(this, intent.data?.path))
}
Expand Down

0 comments on commit 9a2d737

Please sign in to comment.