-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19768 from wordpress-mobile/issue/add-media-deeplink
Support media deep links
- Loading branch information
Showing
9 changed files
with
158 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
WordPress/src/main/java/org/wordpress/android/ui/deeplinks/handlers/MediaLinkHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.wordpress.android.ui.deeplinks.handlers | ||
|
||
import org.wordpress.android.fluxc.model.SiteModel | ||
import org.wordpress.android.ui.deeplinks.DeepLinkNavigator.NavigateAction | ||
import org.wordpress.android.ui.deeplinks.DeepLinkNavigator.NavigateAction.OpenMedia | ||
import org.wordpress.android.ui.deeplinks.DeepLinkNavigator.NavigateAction.OpenMediaForSite | ||
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 | ||
import javax.inject.Inject | ||
|
||
class MediaLinkHandler | ||
@Inject constructor(private val deepLinkUriUtils: DeepLinkUriUtils) : DeepLinkHandler { | ||
/** | ||
* 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() == MEDIA_PATH) || uri.host == MEDIA_PATH | ||
} | ||
|
||
override fun buildNavigateAction(uri: UriWrapper): NavigateAction { | ||
val targetHost: String = uri.lastPathSegment ?: "" | ||
val site: SiteModel? = deepLinkUriUtils.hostToSite(targetHost) | ||
return if (site != null) { | ||
OpenMediaForSite(site) | ||
} else { | ||
// In other cases, launch the home view for the currently selected site. | ||
OpenMedia | ||
} | ||
} | ||
|
||
override fun stripUrl(uri: UriWrapper): String { | ||
return buildString { | ||
val offset = if (uri.host == MEDIA_PATH) { | ||
append(DeepLinkingIntentReceiverViewModel.APPLINK_SCHEME) | ||
0 | ||
} else { | ||
append("$HOST_WORDPRESS_COM/") | ||
1 | ||
} | ||
append(MEDIA_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") | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
private const val MEDIA_PATH = "media" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters