Skip to content

Commit

Permalink
Support media link with and without site
Browse files Browse the repository at this point in the history
  • Loading branch information
zwarm committed Dec 11, 2023
1 parent 9bcd6c6 commit e88fdf9
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.wordpress.android.ui.deeplinks.DeepLinkNavigator.NavigateAction
import org.wordpress.android.ui.deeplinks.DeepLinkNavigator.NavigateAction.OpenMediaForSite
import org.wordpress.android.ui.deeplinks.DeepLinkNavigator.NavigateAction.OpenMedia
import org.wordpress.android.ui.deeplinks.DeepLinkUriUtils
import org.wordpress.android.ui.deeplinks.DeepLinkingIntentReceiverViewModel
import org.wordpress.android.ui.deeplinks.DeepLinkingIntentReceiverViewModel.Companion.HOST_WORDPRESS_COM
import org.wordpress.android.ui.deeplinks.DeepLinkingIntentReceiverViewModel.Companion.SITE_DOMAIN
import org.wordpress.android.util.UriWrapper
Expand All @@ -16,8 +17,8 @@ class MediaLinkHandler
* Returns true if the URI looks like `wordpress.com/media`
*/
override fun shouldHandleUrl(uri: UriWrapper): Boolean {
return uri.host == HOST_WORDPRESS_COM &&
uri.pathSegments.firstOrNull() == NEDIA_PATH
return (uri.host == HOST_WORDPRESS_COM &&
uri.pathSegments.firstOrNull() == NEDIA_PATH) || uri.host == NEDIA_PATH
}

override fun buildNavigateAction(uri: UriWrapper): NavigateAction {
Expand All @@ -33,8 +34,18 @@ class MediaLinkHandler

override fun stripUrl(uri: UriWrapper): String {
return buildString {
append("$HOST_WORDPRESS_COM/$NEDIA_PATH")
if (uri.pathSegments.size > 1) {
val offset = if (uri.host == NEDIA_PATH) {
append(DeepLinkingIntentReceiverViewModel.APPLINK_SCHEME)
0
} else {
append("$HOST_WORDPRESS_COM/")
1
}
append(NEDIA_PATH)
val pathSegments = uri.pathSegments
val size = pathSegments.size
val hasSiteUrl = if (size > offset + 1) pathSegments.getOrNull(offset + 1) != null else false
if (hasSiteUrl) {
append("/$SITE_DOMAIN")
}
}
Expand Down

0 comments on commit e88fdf9

Please sign in to comment.