diff --git a/lib/ratelimit/build.gradle b/lib/ratelimit/build.gradle index 814d8e947..59e073853 100644 --- a/lib/ratelimit/build.gradle +++ b/lib/ratelimit/build.gradle @@ -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' } diff --git a/lib/urlhandler/build.gradle b/lib/urlhandler/build.gradle new file mode 100644 index 000000000..4d785e250 --- /dev/null +++ b/lib/urlhandler/build.gradle @@ -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" +} diff --git a/lib/urlhandler/src/main/AndroidManifest.xml b/lib/urlhandler/src/main/AndroidManifest.xml new file mode 100644 index 000000000..1bb881db9 --- /dev/null +++ b/lib/urlhandler/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + diff --git a/lib/urlhandler/src/main/java/eu/kanade/tachiyomi/lib/urlhandler/UrlHandlerActivity.kt b/lib/urlhandler/src/main/java/eu/kanade/tachiyomi/lib/urlhandler/UrlHandlerActivity.kt new file mode 100644 index 000000000..8aba8d200 --- /dev/null +++ b/lib/urlhandler/src/main/java/eu/kanade/tachiyomi/lib/urlhandler/UrlHandlerActivity.kt @@ -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 + +} diff --git a/settings.gradle b/settings.gradle index 6ef57c2a2..ebc01e913 100644 --- a/settings.gradle +++ b/settings.gradle @@ -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") diff --git a/src/all/mangadex/AndroidManifest.xml b/src/all/mangadex/AndroidManifest.xml index b3d044a0c..2d0b5ac04 100644 --- a/src/all/mangadex/AndroidManifest.xml +++ b/src/all/mangadex/AndroidManifest.xml @@ -1,8 +1,6 @@ - - - diff --git a/src/all/mangadex/build.gradle b/src/all/mangadex/build.gradle index b66737c16..5b31e2676 100644 --- a/src/all/mangadex/build.gradle +++ b/src/all/mangadex/build.gradle @@ -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' diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/Mangadex.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/Mangadex.kt index 37b954592..cae0a5a22 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/Mangadex.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/Mangadex.kt @@ -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), diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangadexUrlActivity.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangadexUrlActivity.kt index e68a5a314..3bd9ab741 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangadexUrlActivity.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangadexUrlActivity.kt @@ -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() { - 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) + override fun getQueryFromPathSegments(pathSegments: List): String { + val id = pathSegments[1] + return "${Mangadex.PREFIX_ID_SEARCH}$id" } + } diff --git a/src/all/nhentai/AndroidManifest.xml b/src/all/nhentai/AndroidManifest.xml index a548905b1..7851e6944 100644 --- a/src/all/nhentai/AndroidManifest.xml +++ b/src/all/nhentai/AndroidManifest.xml @@ -1,8 +1,6 @@ - - - diff --git a/src/all/nhentai/build.gradle b/src/all/nhentai/build.gradle index 5bbebf184..d8fc0f125 100644 --- a/src/all/nhentai/build.gradle +++ b/src/all/nhentai/build.gradle @@ -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" diff --git a/src/all/nhentai/src/eu/kanade/tachiyomi/extension/all/nhentai/NHUrlActivity.kt b/src/all/nhentai/src/eu/kanade/tachiyomi/extension/all/nhentai/NHUrlActivity.kt index 9009e102f..63bcfebe4 100644 --- a/src/all/nhentai/src/eu/kanade/tachiyomi/extension/all/nhentai/NHUrlActivity.kt +++ b/src/all/nhentai/src/eu/kanade/tachiyomi/extension/all/nhentai/NHUrlActivity.kt @@ -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) { - val id = pathSegments[1] - val mainIntent = Intent().apply { - action = "eu.kanade.tachiyomi.SEARCH" - putExtra("query", "${NHentai.PREFIX_ID_SEARCH}$id") - putExtra("filter", packageName) - } +class NHUrlActivity : UrlHandlerActivity() { - 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) + override fun getQueryFromPathSegments(pathSegments: List): String { + val id = pathSegments[1] + return "${NHentai.PREFIX_ID_SEARCH}$id" } + }