Abstract URL handling intent logic to library (#1128)
This commit is contained in:
parent
336a9be09f
commit
b48900b8b7
|
@ -24,6 +24,6 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
compileOnly 'com.squareup.okhttp3:okhttp:3.10.0'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
|
||||
android {
|
||||
compileSdkVersion 27
|
||||
buildToolsVersion '28.0.3'
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 27
|
||||
versionCode 1
|
||||
versionName '1.0.0'
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="eu.kanade.tachiyomi.lib.urlhandler">
|
||||
</manifest>
|
|
@ -0,0 +1,37 @@
|
|||
package eu.kanade.tachiyomi.lib.urlhandler
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
|
||||
abstract class UrlHandlerActivity : Activity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val pathSegments = intent?.data?.pathSegments
|
||||
if (pathSegments != null && pathSegments.size > 1) {
|
||||
val query = getQueryFromPathSegments(pathSegments)
|
||||
val mainIntent = Intent().apply {
|
||||
action = "eu.kanade.tachiyomi.SEARCH"
|
||||
putExtra("query", query)
|
||||
putExtra("filter", packageName)
|
||||
}
|
||||
|
||||
try {
|
||||
startActivity(mainIntent)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
Log.e(localClassName, e.toString())
|
||||
}
|
||||
} else {
|
||||
Log.e(localClassName, "Could not parse uri from intent: $intent")
|
||||
}
|
||||
|
||||
finish()
|
||||
System.exit(0)
|
||||
}
|
||||
|
||||
abstract fun getQueryFromPathSegments(pathSegments: List<String>): String
|
||||
|
||||
}
|
|
@ -8,6 +8,8 @@ new File(rootDir, "src").eachDir { dir ->
|
|||
include ':duktape-stub'
|
||||
include ':preference-stub'
|
||||
include ':lib-ratelimit'
|
||||
include ':lib-urlhandler'
|
||||
project(':duktape-stub').projectDir = new File("lib/duktape-stub")
|
||||
project(':preference-stub').projectDir = new File("lib/preference-stub")
|
||||
project(':lib-ratelimit').projectDir = new File("lib/ratelimit")
|
||||
project(':lib-urlhandler').projectDir = new File("lib/urlhandler")
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<application>
|
||||
|
||||
<activity
|
||||
android:name=".MangadexUrlActivity"
|
||||
android:theme="@android:style/Theme.NoDisplay"
|
||||
|
@ -18,5 +16,4 @@
|
|||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
|
@ -5,12 +5,13 @@ ext {
|
|||
appName = 'Tachiyomi: MangaDex'
|
||||
pkgNameSuffix = 'all.mangadex'
|
||||
extClass = '.MangadexFactory'
|
||||
extVersionCode = 57
|
||||
extVersionCode = 58
|
||||
libVersion = '1.2'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(':lib-ratelimit')
|
||||
implementation project(':lib-urlhandler')
|
||||
compileOnly project(':preference-stub')
|
||||
compileOnly 'com.google.code.gson:gson:2.8.2'
|
||||
compileOnly 'com.github.salomonbrys.kotson:kotson:2.5.0'
|
||||
|
|
|
@ -686,7 +686,7 @@ open class Mangadex(override val lang: String, private val internalLang: String,
|
|||
private const val API_MANGA = "/api/manga/"
|
||||
private const val API_CHAPTER = "/api/chapter/"
|
||||
|
||||
private const val PREFIX_ID_SEARCH = "id:"
|
||||
const val PREFIX_ID_SEARCH = "id:"
|
||||
|
||||
private val sortables = listOf(
|
||||
Triple("Update date", 0, 1),
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
package eu.kanade.tachiyomi.extension.all.mangadex
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import eu.kanade.tachiyomi.lib.urlhandler.UrlHandlerActivity
|
||||
|
||||
/**
|
||||
* Springboard that accepts https://mangadex.com/title/xxx intents and redirects them to
|
||||
|
@ -15,28 +11,11 @@ import android.util.Log
|
|||
* Main goal was to make it easier to open manga in Tachiyomi in spite of the DDoS blocking
|
||||
* the usual search screen from working.
|
||||
*/
|
||||
class MangadexUrlActivity : Activity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val pathSegments = intent?.data?.pathSegments
|
||||
if (pathSegments != null && pathSegments.size > 1) {
|
||||
val titleid = pathSegments[1]
|
||||
val mainIntent = Intent().apply {
|
||||
action = "eu.kanade.tachiyomi.SEARCH"
|
||||
putExtra("query", "id:$titleid")
|
||||
putExtra("filter", packageName)
|
||||
class MangadexUrlActivity : UrlHandlerActivity() {
|
||||
|
||||
override fun getQueryFromPathSegments(pathSegments: List<String>): String {
|
||||
val id = pathSegments[1]
|
||||
return "${Mangadex.PREFIX_ID_SEARCH}$id"
|
||||
}
|
||||
|
||||
try {
|
||||
startActivity(mainIntent)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
Log.e("MangadexUrlActivity", e.toString())
|
||||
}
|
||||
} else {
|
||||
Log.e("MangadexUrlActivity", "could not parse uri from intent $intent")
|
||||
}
|
||||
|
||||
finish()
|
||||
System.exit(0)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<application>
|
||||
|
||||
<activity
|
||||
android:name=".NHUrlActivity"
|
||||
android:theme="@android:style/Theme.NoDisplay"
|
||||
|
@ -18,5 +16,4 @@
|
|||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
|
@ -5,8 +5,12 @@ ext {
|
|||
appName = 'Tachiyomi: NHentai'
|
||||
pkgNameSuffix = 'all.nhentai'
|
||||
extClass = '.NHEnglish; .NHJapanese; .NHChinese'
|
||||
extVersionCode = 10
|
||||
extVersionCode = 11
|
||||
libVersion = '1.2'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(':lib-urlhandler')
|
||||
}
|
||||
|
||||
apply from: "$rootDir/common.gradle"
|
||||
|
|
|
@ -1,37 +1,16 @@
|
|||
package eu.kanade.tachiyomi.extension.all.nhentai
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import eu.kanade.tachiyomi.lib.urlhandler.UrlHandlerActivity
|
||||
|
||||
/**
|
||||
* Springboard that accepts https://nhentai.net/g/xxxxxx intents and redirects them to
|
||||
* the main Tachiyomi process.
|
||||
*/
|
||||
class NHUrlActivity : Activity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val pathSegments = intent?.data?.pathSegments
|
||||
if (pathSegments != null && pathSegments.size > 1) {
|
||||
class NHUrlActivity : UrlHandlerActivity() {
|
||||
|
||||
override fun getQueryFromPathSegments(pathSegments: List<String>): String {
|
||||
val id = pathSegments[1]
|
||||
val mainIntent = Intent().apply {
|
||||
action = "eu.kanade.tachiyomi.SEARCH"
|
||||
putExtra("query", "${NHentai.PREFIX_ID_SEARCH}$id")
|
||||
putExtra("filter", packageName)
|
||||
return "${NHentai.PREFIX_ID_SEARCH}$id"
|
||||
}
|
||||
|
||||
try {
|
||||
startActivity(mainIntent)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
Log.e("NHUrlActivity", e.toString())
|
||||
}
|
||||
} else {
|
||||
Log.e("NHUrlActivity", "could not parse uri from intent $intent")
|
||||
}
|
||||
|
||||
finish()
|
||||
System.exit(0)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue