Skip to content

Commit 459cf31

Browse files
committed
Deep linking for AnimeActivity and MangaActivity
1 parent d29e88b commit 459cf31

File tree

3 files changed

+120
-14
lines changed

3 files changed

+120
-14
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,76 @@
122122
</activity>
123123
<activity android:name=".activity.chat.NewChatActivity" />
124124
<activity android:name=".activity.chat.ConferenceInfoActivity" />
125-
<activity android:name=".activity.MangaActivity" />
126-
<activity android:name=".activity.AnimeActivity" />
125+
<activity android:name=".activity.MangaActivity">
126+
<intent-filter>
127+
<action android:name="android.intent.action.VIEW" />
128+
129+
<category android:name="android.intent.category.DEFAULT" />
130+
<category android:name="android.intent.category.BROWSABLE" />
131+
132+
<data
133+
android:host="proxer.me"
134+
android:pathPrefix="/chapter/"
135+
android:scheme="http" />
136+
</intent-filter>
137+
<intent-filter>
138+
<action android:name="android.intent.action.VIEW" />
139+
140+
<category android:name="android.intent.category.DEFAULT" />
141+
<category android:name="android.intent.category.BROWSABLE" />
142+
143+
<data
144+
android:host="proxer.me"
145+
android:pathPrefix="/chapter/"
146+
android:scheme="https" />
147+
</intent-filter>
148+
<intent-filter>
149+
<action android:name="android.intent.action.VIEW" />
150+
151+
<category android:name="android.intent.category.DEFAULT" />
152+
<category android:name="android.intent.category.BROWSABLE" />
153+
154+
<data
155+
android:host="proxer.me"
156+
android:pathPrefix="/read/"
157+
android:scheme="http" />
158+
</intent-filter>
159+
<intent-filter>
160+
<action android:name="android.intent.action.VIEW" />
161+
162+
<category android:name="android.intent.category.DEFAULT" />
163+
<category android:name="android.intent.category.BROWSABLE" />
164+
165+
<data
166+
android:host="proxer.me"
167+
android:pathPrefix="/read/"
168+
android:scheme="https" />
169+
</intent-filter>
170+
</activity>
171+
<activity android:name=".activity.AnimeActivity">
172+
<intent-filter>
173+
<action android:name="android.intent.action.VIEW" />
174+
175+
<category android:name="android.intent.category.DEFAULT" />
176+
<category android:name="android.intent.category.BROWSABLE" />
177+
178+
<data
179+
android:host="proxer.me"
180+
android:pathPrefix="/watch/"
181+
android:scheme="http" />
182+
</intent-filter>
183+
<intent-filter>
184+
<action android:name="android.intent.action.VIEW" />
185+
186+
<category android:name="android.intent.category.DEFAULT" />
187+
<category android:name="android.intent.category.BROWSABLE" />
188+
189+
<data
190+
android:host="proxer.me"
191+
android:pathPrefix="/watch/"
192+
android:scheme="https" />
193+
</intent-filter>
194+
</activity>
127195
<activity android:name=".activity.WebViewActivity" />
128196

129197
<service android:name=".service.NotificationService" />

app/src/main/kotlin/com/proxerme/app/activity/AnimeActivity.kt

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.proxerme.app.activity
22

33
import android.app.Activity
4+
import android.content.Intent
45
import android.os.Bundle
56
import android.support.v4.app.ShareCompat
67
import android.support.v7.widget.Toolbar
@@ -9,6 +10,7 @@ import android.view.MenuItem
910
import com.proxerme.app.R
1011
import com.proxerme.app.fragment.anime.AnimeFragment
1112
import com.proxerme.app.util.bindView
13+
import com.proxerme.library.parameters.SubDubLanguageParameter
1214
import org.jetbrains.anko.startActivity
1315

1416
class AnimeActivity : MainActivity() {
@@ -31,19 +33,36 @@ class AnimeActivity : MainActivity() {
3133
}
3234

3335
private val id: String
34-
get() = intent.getStringExtra(EXTRA_ID)
36+
get() = when {
37+
intent.action == Intent.ACTION_VIEW -> intent.data.pathSegments.getOrElse(1, { "-1" })
38+
else -> {
39+
intent.getStringExtra(EXTRA_ID)
40+
}
41+
}
3542

3643
private var episode: Int
37-
get() = intent.getIntExtra(EXTRA_EPISODE, 1)
44+
get() = when {
45+
intent.action == Intent.ACTION_VIEW && !intent.hasExtra(EXTRA_EPISODE) -> try {
46+
intent.data.pathSegments.getOrElse(2, { "1" }).toInt()
47+
} catch (exception: NumberFormatException) {
48+
1
49+
}
50+
else -> intent.getIntExtra(EXTRA_EPISODE, 1)
51+
}
3852
set(value) {
3953
intent.putExtra(EXTRA_EPISODE, value)
4054
}
4155

42-
private val totalEpisodes: Int
43-
get() = intent.getIntExtra(EXTRA_TOTAL_EPISODES, 1)
44-
4556
private val language: String
46-
get() = intent.getStringExtra(EXTRA_LANGUAGE)
57+
get() = when {
58+
intent.action == Intent.ACTION_VIEW -> {
59+
intent.data.pathSegments.getOrElse(3, { SubDubLanguageParameter.ENGLISH_SUB })
60+
}
61+
else -> intent.getStringExtra(EXTRA_LANGUAGE)
62+
}
63+
64+
private val totalEpisodes: Int
65+
get() = intent.getIntExtra(EXTRA_TOTAL_EPISODES, -1)
4766

4867
private val toolbar: Toolbar by bindView(R.id.toolbar)
4968

app/src/main/kotlin/com/proxerme/app/activity/MangaActivity.kt

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.proxerme.app.activity
22

33
import android.app.Activity
4+
import android.content.Intent
45
import android.os.Bundle
56
import android.support.v4.app.ShareCompat
67
import android.support.v7.widget.Toolbar
@@ -9,6 +10,7 @@ import android.view.MenuItem
910
import com.proxerme.app.R
1011
import com.proxerme.app.fragment.manga.MangaFragment
1112
import com.proxerme.app.util.bindView
13+
import com.proxerme.library.parameters.SubDubLanguageParameter
1214
import org.jetbrains.anko.startActivity
1315

1416
class MangaActivity : MainActivity() {
@@ -30,19 +32,36 @@ class MangaActivity : MainActivity() {
3032
}
3133

3234
private val id: String
33-
get() = intent.getStringExtra(EXTRA_ID)
35+
get() = when {
36+
intent.action == Intent.ACTION_VIEW -> intent.data.pathSegments.getOrElse(1, { "-1" })
37+
else -> {
38+
intent.getStringExtra(EXTRA_ID)
39+
}
40+
}
3441

3542
private var episode: Int
36-
get() = intent.getIntExtra(EXTRA_EPISODE, 1)
43+
get() = when {
44+
intent.action == Intent.ACTION_VIEW && !intent.hasExtra(EXTRA_EPISODE) -> try {
45+
intent.data.pathSegments.getOrElse(2, { "1" }).toInt()
46+
} catch (exception: NumberFormatException) {
47+
1
48+
}
49+
else -> intent.getIntExtra(EXTRA_EPISODE, 1)
50+
}
3751
set(value) {
3852
intent.putExtra(EXTRA_EPISODE, value)
3953
}
4054

41-
private val totalEpisodes: Int
42-
get() = intent.getIntExtra(EXTRA_TOTAL_EPISODES, 1)
43-
4455
private val language: String
45-
get() = intent.getStringExtra(EXTRA_LANGUAGE)
56+
get() = when {
57+
intent.action == Intent.ACTION_VIEW -> {
58+
intent.data.pathSegments.getOrElse(3, { SubDubLanguageParameter.ENGLISH_SUB })
59+
}
60+
else -> intent.getStringExtra(EXTRA_LANGUAGE)
61+
}
62+
63+
private val totalEpisodes: Int
64+
get() = intent.getIntExtra(EXTRA_TOTAL_EPISODES, -1)
4665

4766
private val toolbar: Toolbar by bindView(R.id.toolbar)
4867

0 commit comments

Comments
 (0)