Imgur intent filter for Guya (#6277)

This commit is contained in:
Andreas 2021-03-25 00:18:50 +01:00 committed by GitHub
parent a4e5480260
commit 3b02f95c02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 17 deletions

View File

@ -22,7 +22,16 @@
android:host="guya.moe"
android:pathPattern="/proxy/..*"
android:scheme="https" />
<data
android:host="*imgur.com"
android:pathPattern="/a/..*"
android:scheme="https" />
<data
android:host="*imgur.com"
android:pathPattern="/gallery/..*"
android:scheme="https" />
</intent-filter>
</activity>
</application>
</manifest>
</manifest>

View File

@ -5,7 +5,7 @@ ext {
extName = 'Guya'
pkgNameSuffix = "en.guya"
extClass = '.Guya'
extVersionCode = 16
extVersionCode = 17
libVersion = '1.2'
}

View File

@ -17,23 +17,21 @@ class GuyaUrlActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val host = intent?.data?.host
val pathSegments = intent?.data?.pathSegments
if (pathSegments != null && pathSegments.size >= 3) {
Log.d("GuyaUrlActivity", pathSegments[0])
val query = when (pathSegments[0]) {
"proxy" -> {
val source = pathSegments[1]
val id = pathSegments[2]
"${Guya.PROXY_PREFIX}$source/$id"
}
else -> {
val slug = pathSegments[2]
"${Guya.SLUG_PREFIX}$slug"
}
if (host != null && pathSegments != null) {
val query = when (host) {
"m.imgur.com", "imgur.com" -> fromImgur(pathSegments)
else -> fromGuya(pathSegments)
}
if (query == null) {
Log.e("GuyaUrlActivity", "Unable to parse URI from intent $intent")
finish()
exitProcess(1)
}
// Gotta do it like this since slug title != actual title
val mainIntent = Intent().apply {
action = "eu.kanade.tachiyomi.SEARCH"
putExtra("query", query)
@ -45,11 +43,35 @@ class GuyaUrlActivity : Activity() {
} catch (e: ActivityNotFoundException) {
Log.e("GuyaUrlActivity", e.toString())
}
} else {
Log.e("GuyaUrlActivity", "Unable to parse URI from intent $intent")
}
finish()
exitProcess(0)
}
private fun fromImgur(pathSegments: List<String>): String? {
if (pathSegments.size >= 2) {
val id = pathSegments[1]
return "${Guya.PROXY_PREFIX}imgur/$id"
}
return null
}
private fun fromGuya(pathSegments: MutableList<String>): String? {
if (pathSegments.size >= 3) {
return when (pathSegments[0]) {
"proxy" -> {
val source = pathSegments[1]
val id = pathSegments[2]
"${Guya.PROXY_PREFIX}$source/$id"
}
else -> {
val slug = pathSegments[2]
"${Guya.SLUG_PREFIX}$slug"
}
}
}
return null
}
}