Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Deep Link support for the three screens #12

merged 2 commits into from Nov 11, 2018
Changes from all commits
File filter

Filter by extension

Filter by extension

Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -6,8 +6,8 @@ art collector displays a selection of paintings from the [Harvard Art Museum API
We need three screens:

- `/` showing a collection of paintings
- `/artist/{person_id}` showing the collection of paintings by the given artist
- `/artist/{person_id}/{object_id}` showing a single painting
- `/{person_id}` showing the collection of paintings by the given artist
- `/{person_id}/{object_id}` showing a single painting

## Why

@@ -27,6 +27,19 @@


<activity android:name=".DeepLinkActivity">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="" />
Copy link
Owner Author

@ataulm ataulm Nov 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data tags inside an intent-filter are merged so all combinations are considered:

  • http +
  • https +



@@ -0,0 +1,32 @@
package com.ataulm.artcollector

import android.os.Bundle

private const val ARTIST = 0
private const val PAINTING = 1

* Supports http/https:
* -
* -{artist-id}
* -{artist-id}/{painting-id}
class DeepLinkActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
val uri = getIntentUri()
val segments = uri.pathSegments
val intent = when (uri.pathSegments.size) {
2 -> paintingIntent(segments[ARTIST], segments[PAINTING])
1 -> artistGalleryIntent(segments[ARTIST])
else -> galleryIntent()

private fun getIntentUri() =!! // only way to open this activity
@@ -5,17 +5,20 @@ import

private const val SCHEME = "https"
private const val AUTHORITY = ""
private const val GALLERY = "${BuildConfig.APPLICATION_ID}.gallery.ui.GalleryActivity"
private const val ARTIST_GALLERY = "${BuildConfig.APPLICATION_ID}.artist.ui.ArtistActivity"
private const val PAINTING = "${BuildConfig.APPLICATION_ID}.painting.ui.PaintingActivity"

fun galleryIntent() = intent(GALLERY)

fun artistGalleryIntent(artistId: String): Intent {
val uri = Uri.Builder()

return intent(uri, ARTIST_GALLERY)
return intent(ARTIST_GALLERY, uri)

fun paintingIntent(artistId: String, paintingId: String): Intent {
@@ -25,10 +28,10 @@ fun paintingIntent(artistId: String, paintingId: String): Intent {

return intent(uri, PAINTING)
return intent(PAINTING, uri)

private fun intent(uri: Uri, componentName: String): Intent {
private fun intent(componentName: String, uri: Uri? = null): Intent {
return Intent(Intent.ACTION_VIEW)
.setClassName(BuildConfig.APPLICATION_ID, componentName)