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