Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
inorichi committed Jan 1, 2019
0 parents commit 51f9bcd
Show file tree
Hide file tree
Showing 82 changed files with 1,482 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.iml
.gradle
/local.properties
/.idea/*
!/.idea/codeStyleSettings.xml
!/.idea/inspectionProfiles/
!/.idea/fileTemplates/
.DS_Store
build
/captures
.externalNativeBuild

19 changes: 19 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:3.3.0-rc03"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.11"
}
}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://dl.bintray.com/inorichi/maven" }
}
}
2 changes: 2 additions & 0 deletions buildSrc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.gradle/
build/
8 changes: 8 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
`kotlin-dsl`
}

repositories {
google()
jcenter()
}
8 changes: 8 additions & 0 deletions buildSrc/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object Config {
const val compileSdk = 28
const val minSdk = 21
const val targetSdk = 28
const val versionName = "1.0"
const val versionCode = 1
const val applicationId = "tachiyomi.app"
}
32 changes: 32 additions & 0 deletions buildSrc/src/main/kotlin/Deps.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.kotlin.dsl.DependencyHandlerScope
import org.gradle.kotlin.dsl.project

object Deps {

object kotlin {
const val version = "1.3.11"
const val stdlib = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$version"
}

object coroutines {
private const val version = "1.0.1"
const val core = "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
const val android = "org.jetbrains.kotlinx:kotlinx-coroutines-android:$version"
const val rx2 = "org.jetbrains.kotlinx:kotlinx-coroutines-rx2:$version"
}

const val autoservice = "com.google.auto.service:auto-service:1.0-rc4"

const val kotlinpoet = "com.squareup:kotlinpoet:1.0.0"

const val tachiyomiCore = "tachiyomi.sourceapi:core:1.0"
const val sourceApi = "tachiyomi.sourceapi:source-api:1.0"

const val okhttp = "com.squareup.okhttp3:okhttp:3.12.0"
const val jsoup = "org.jsoup:jsoup:1.11.3"
const val gson = "com.google.code.gson:gson:2.8.5"
const val kotson = "com.github.salomonbrys.kotson:kotson:2.5.0"

}
44 changes: 44 additions & 0 deletions buildSrc/src/main/kotlin/Extension.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import org.gradle.api.Project
import org.gradle.kotlin.dsl.extra
import java.security.MessageDigest

data class Extension(
val name: String,
val versionCode: Int,
val libVersion: String,
val lang: String,
val deepLinks: List<DeepLink> = emptyList(),
val sourceDir: String = "main",
val id: Long = generateSourceId(name, lang),
val flavor: String = getFlavorName(sourceDir, lang)
)

data class DeepLink(
val host: String,
val scheme: String = "https",
val pathPattern: String = "",
val path: String = ""
)

fun Project.register(extensions: List<Extension>) {
extra["extensionList"] = extensions
apply {
from("$rootDir/extensions/common.gradle")
from("$rootDir/extensions/aptmanifest.gradle")
}
}

fun Project.register(vararg extensions: Extension) {
register(extensions.toList())
}

private fun getFlavorName(sourceDir: String, lang: String): String {
return if (sourceDir == "main") lang else "$sourceDir-$lang"
}

private fun generateSourceId(name: String, lang: String, versionId: Int = 1): Long {
val key = "${name.toLowerCase()}/$lang/$versionId"
val bytes = MessageDigest.getInstance("MD5").digest(key.toByteArray())
return (0..7).map { bytes[it].toLong() and 0xff shl 8 * (7 - it) }
.reduce(Long::or) and Long.MAX_VALUE
}
76 changes: 76 additions & 0 deletions buildSrc/src/main/kotlin/ManifestGenerator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

import groovy.util.Node
import groovy.util.NodeList
import groovy.util.XmlNodePrinter
import groovy.util.XmlParser
import org.gradle.api.GradleException
import java.io.File
import java.io.PrintWriter

@Suppress("unused")
object ManifestGenerator {

@JvmStatic
fun process(index: String, manifest: String, extension: Extension) {
val indexFile = File(index)
val manifestFile = File(manifest)

if (!indexFile.exists() || !manifestFile.exists()) {
throw GradleException("Can't find index or manifest file for ${extension.name}")
}

val extClass = indexFile.readLines().first()
val parser = XmlParser().parse(manifestFile)

// Get package name and append the language
val packageEnding = extension.flavor.replace("-", ".").toLowerCase()
val applicationId = extClass.substringBeforeLast(".") + ".$packageEnding"
parser.attributes()["package"] = applicationId

val app = (parser["application"] as NodeList).first() as Node

// Add source class metadata
Node(app, "meta-data", mapOf(
"android:name" to "source.class",
"android:value" to extClass
))

// Add deeplinks if needed
addDeepLinks(app, extension.deepLinks)

XmlNodePrinter(manifestFile.printWriter()).print(parser)
}

private fun addDeepLinks(app: Node, deeplinks: List<DeepLink>) {
if (deeplinks.isEmpty()) return

val activity = Node(app, "activity", mapOf(
"android:name" to "tachiyomix.deeplink.SourceDeepLinkActivity",
"android:theme" to "@android:style/Theme.NoDisplay"
))

val filter = Node(activity, "intent-filter")
Node(filter, "action", mapOf("android:name" to "android.intent.action.VIEW"))
Node(filter, "category", mapOf("android:name" to "android.intent.category.DEFAULT"))
Node(filter, "category", mapOf("android:name" to "android.intent.category.BROWSABLE"))

deeplinks.forEach { link ->
val data = mutableMapOf<String, String>()
if (link.scheme.isNotEmpty()) {
data["android:scheme"] = link.scheme
}
if (link.host.isNotEmpty()) {
data["android:host"] = link.host
}
if (link.pathPattern.isNotEmpty()) {
data["android:pathPattern"] = link.pathPattern
}
if (link.path.isNotEmpty()) {
data["android:path"] = link.path
}

Node(filter, "data", data)
}
}

}
10 changes: 10 additions & 0 deletions buildSrc/src/main/kotlin/Proj.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.kotlin.dsl.DependencyHandlerScope
import org.gradle.kotlin.dsl.project

object Proj {
const val annotation = ":annotations"
const val compiler = ":compiler"
const val deeplink = ":deeplink"
const val defaultRes = ":defaultRes"
}
13 changes: 13 additions & 0 deletions deeplink/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
id("com.android.library")
}

android {
compileSdkVersion(Config.compileSdk)

libraryVariants.all {
generateBuildConfigProvider?.configure {
enabled = false
}
}
}
1 change: 1 addition & 0 deletions deeplink/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest package="tachiyomix.deeplink" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package tachiyomix.deeplink;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class SourceDeepLinkActivity extends Activity {

private static final String TAG = "SourceDeepLinkActivity";

static final String ACTION = "tachiyomi.action.HANDLE_LINK";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Intent intent = getIntent();

Intent forward = new Intent(ACTION);
forward.setData(intent.getData());
forward.putExtra(Intent.EXTRA_REFERRER, getPackageName());

try {
startActivity(forward);
} catch (ActivityNotFoundException e) {
Log.e(TAG, e.toString());
}

finish();
System.exit(0);
}

}
1 change: 1 addition & 0 deletions defaultRes/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest package="tachiyomix.defaultres" />
20 changes: 20 additions & 0 deletions defaultRes/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
plugins {
id("com.android.library")
}

android {
compileSdkVersion(Config.compileSdk)

sourceSets {
named("main") {
manifest.srcFile("AndroidManifest.xml")
res.setSrcDirs(listOf("res"))
}
}

libraryVariants.all {
generateBuildConfigProvider?.configure {
enabled = false
}
}
}
Binary file added defaultRes/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added defaultRes/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added defaultRes/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added defaultRes/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added defaultRes/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions extensions/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tachiyomix">

<uses-feature android:name="tachiyomix" />

<application
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:label="${appName}">

<meta-data
android:name="source.id"
android:value="${sourceId}" />

</application>

</manifest>
20 changes: 20 additions & 0 deletions extensions/all/mangadex/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
listOf("en", "es").map { lang ->
Extension(
name = "MangaDex",
versionCode = 44,
libVersion = "1.0",
lang = lang,
deepLinks = listOf(
DeepLink(
host = "mangadex.org",
scheme = "https",
pathPattern = "/title/.*"
),
DeepLink(
host = "mangadex.org",
scheme = "https",
pathPattern = "/chapter/.*"
)
)
)
}.also(::register)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 51f9bcd

Please sign in to comment.