From e81dd062d36ac8864848c84d7d3f84218e3e0e3c Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Mon, 29 Jan 2024 14:55:40 -0500 Subject: [PATCH] Refactor: move extract host into its own method to expand the extraction --- .../ui/deeplinks/handlers/SiteMonitorLinkHandler.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/handlers/SiteMonitorLinkHandler.kt b/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/handlers/SiteMonitorLinkHandler.kt index b5f329353399..1461d7db8755 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/handlers/SiteMonitorLinkHandler.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/handlers/SiteMonitorLinkHandler.kt @@ -19,12 +19,17 @@ class SiteMonitorLinkHandler } override fun buildNavigateAction(uri: UriWrapper): DeepLinkNavigator.NavigateAction { - val targetHost = uri.pathSegments[1] + val targetHost = extractHost(uri) val site: SiteModel? = deepLinkUriUtils.hostToSite(targetHost) val siteMonitorType = urlToType(uri.toString()) return DeepLinkNavigator.NavigateAction.OpenSiteMonitoringForSite(site, siteMonitorType) } + private fun extractHost(uri: UriWrapper): String { + if (uri.pathSegments.size <= 1) return "" + return uri.pathSegments[1] + } + override fun stripUrl(uri: UriWrapper): String { return buildString { val offset = if (uri.host == SITE_MONITORING_PATH) {