Skip to content

Commit

Permalink
initial commit, eu.kanade.tachiyomi.srource packge build works
Browse files Browse the repository at this point in the history
  • Loading branch information
AriaMoradi committed Dec 23, 2020
0 parents commit 960ffd2
Show file tree
Hide file tree
Showing 31 changed files with 1,661 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# These are explicitly windows files and should use crlf
*.bat text eol=crlf

6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Ignore Gradle project-specific cache directory
.gradle
.idea

# Ignore Gradle build output directory
build
46 changes: 46 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
plugins {
id("org.jetbrains.kotlin.jvm") version "1.4.21"
application
}

repositories {
// gradlePluginPortal()
// google()
mavenCentral()
jcenter()
}

dependencies {
// implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")

// Source models and interfaces from Tachiyomi 1.x
// using source class from tachiyomi commit 9493577de27c40ce8b2b6122cc447d025e34c477 to not depend on tachiyomi.sourceapi
// implementation("tachiyomi.sourceapi:source-api:1.1")

// implementation("com.github.inorichi.injekt:injekt-core:65b0440")

val okhttp_version = "4.10.0-RC1"
implementation( "com.squareup.okhttp3:okhttp:$okhttp_version")
implementation( "com.squareup.okhttp3:logging-interceptor:$okhttp_version")
implementation( "com.squareup.okhttp3:okhttp-dnsoverhttps:$okhttp_version")
implementation ("com.squareup.okio:okio:2.9.0")

implementation("io.reactivex:rxjava:1.3.8")
// implementation 'io.reactivex:rxandroid:1.2.1'
// implementation ("com.jakewharton.rxrelay:rxrelay:1.2.0")
// implementation ("com.github.pwittchen:reactivenetwork:0.13.0")

implementation("org.jsoup:jsoup:1.13.1")
implementation("com.google.code.gson:gson:2.8.6")
implementation("com.github.salomonbrys.kotson:kotson:2.5.0")
implementation("com.squareup.duktape:duktape-android:1.3.0")


testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}

application {
mainClass.set("ir.armor.tachidesk.Main")
}
70 changes: 70 additions & 0 deletions app/src/main/kotlin/eu/kanade/tachiyomi/network/NetworkHelper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package eu.kanade.tachiyomi.network

//import android.content.Context
//import eu.kanade.tachiyomi.BuildConfig
//import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import okhttp3.Cache
//import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
//import okhttp3.dnsoverhttps.DnsOverHttps
//import okhttp3.logging.HttpLoggingInterceptor
//import uy.kohesive.injekt.injectLazy
import java.io.File
import java.net.InetAddress
import java.util.concurrent.TimeUnit

class NetworkHelper() {

// private val preferences: PreferencesHelper by injectLazy()

// private val cacheDir = File(context.cacheDir, "network_cache")

private val cacheSize = 5L * 1024 * 1024 // 5 MiB

// val cookieManager = AndroidCookieJar()

val client by lazy {
val builder = OkHttpClient.Builder()
// .cookieJar(cookieManager)
// .cache(Cache(cacheDir, cacheSize))
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
// .addInterceptor(UserAgentInterceptor())

// if (BuildConfig.DEBUG) {
// val httpLoggingInterceptor = HttpLoggingInterceptor().apply {
// level = HttpLoggingInterceptor.Level.HEADERS
// }
// builder.addInterceptor(httpLoggingInterceptor)
// }

// if (preferences.enableDoh()) {
// builder.dns(
// DnsOverHttps.Builder().client(builder.build())
// .url("https://cloudflare-dns.com/dns-query".toHttpUrl())
// .bootstrapDnsHosts(
// listOf(
// InetAddress.getByName("162.159.36.1"),
// InetAddress.getByName("162.159.46.1"),
// InetAddress.getByName("1.1.1.1"),
// InetAddress.getByName("1.0.0.1"),
// InetAddress.getByName("162.159.132.53"),
// InetAddress.getByName("2606:4700:4700::1111"),
// InetAddress.getByName("2606:4700:4700::1001"),
// InetAddress.getByName("2606:4700:4700::0064"),
// InetAddress.getByName("2606:4700:4700::6400")
// )
// )
// .build()
// )
// }

builder.build()
}

// val cloudflareClient by lazy {
// client.newBuilder()
// .addInterceptor(CloudflareInterceptor(context))
// .build()
// }
}
121 changes: 121 additions & 0 deletions app/src/main/kotlin/eu/kanade/tachiyomi/network/OkHttpExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package eu.kanade.tachiyomi.network

//import kotlinx.coroutines.suspendCancellableCoroutine
import okhttp3.Call
import okhttp3.Callback
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import rx.Observable
import rx.Producer
import rx.Subscription
import java.io.IOException
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException

fun Call.asObservable(): Observable<Response> {
return Observable.unsafeCreate { subscriber ->
// Since Call is a one-shot type, clone it for each new subscriber.
val call = clone()

// Wrap the call in a helper which handles both unsubscription and backpressure.
val requestArbiter = object : AtomicBoolean(), Producer, Subscription {
override fun request(n: Long) {
if (n == 0L || !compareAndSet(false, true)) return

try {
val response = call.execute()
if (!subscriber.isUnsubscribed) {
subscriber.onNext(response)
subscriber.onCompleted()
}
} catch (error: Exception) {
if (!subscriber.isUnsubscribed) {
subscriber.onError(error)
}
}
}

override fun unsubscribe() {
call.cancel()
}

override fun isUnsubscribed(): Boolean {
return call.isCanceled()
}
}

subscriber.add(requestArbiter)
subscriber.setProducer(requestArbiter)
}
}

// Based on https://github.com/gildor/kotlin-coroutines-okhttp
//suspend fun Call.await(assertSuccess: Boolean = false): Response {
// return suspendCancellableCoroutine { continuation ->
// enqueue(
// object : Callback {
// override fun onResponse(call: Call, response: Response) {
// if (assertSuccess && !response.isSuccessful) {
// continuation.resumeWithException(Exception("HTTP error ${response.code}"))
// return
// }
//
// continuation.resume(response)
// }
//
// override fun onFailure(call: Call, e: IOException) {
// // Don't bother with resuming the continuation if it is already cancelled.
// if (continuation.isCancelled) return
// continuation.resumeWithException(e)
// }
// }
// )
//
// continuation.invokeOnCancellation {
// try {
// cancel()
// } catch (ex: Throwable) {
// // Ignore cancel exception
// }
// }
// }
//}

fun Call.asObservableSuccess(): Observable<Response> {
return asObservable().doOnNext { response ->
if (!response.isSuccessful) {
response.close()
throw Exception("HTTP error ${response.code}")
}
}
}

//fun OkHttpClient.newCallWithProgress(request: Request, listener: ProgressListener): Call {
// val progressClient = newBuilder()
// .cache(null)
// .addNetworkInterceptor { chain ->
// val originalResponse = chain.proceed(chain.request())
// originalResponse.newBuilder()
// .body(ProgressResponseBody(originalResponse.body!!, listener))
// .build()
// }
// .build()
//
// return progressClient.newCall(request)
//}

fun OkHttpClient.newCallWithProgress(request: Request, listener: ProgressListener): Call {
val progressClient = newBuilder()
.cache(null)
// .addNetworkInterceptor { chain ->
// val originalResponse = chain.proceed(chain.request())
// originalResponse.newBuilder()
// .body(ProgressResponseBody(originalResponse.body!!, listener))
// .build()
// }
.build()

return progressClient.newCall(request)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package eu.kanade.tachiyomi.network

interface ProgressListener {
fun update(bytesRead: Long, contentLength: Long, done: Boolean)
}
38 changes: 38 additions & 0 deletions app/src/main/kotlin/eu/kanade/tachiyomi/network/Requests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package eu.kanade.tachiyomi.network

import okhttp3.CacheControl
import okhttp3.FormBody
import okhttp3.Headers
import okhttp3.Request
import okhttp3.RequestBody
import java.util.concurrent.TimeUnit.MINUTES

private val DEFAULT_CACHE_CONTROL = CacheControl.Builder().maxAge(10, MINUTES).build()
private val DEFAULT_HEADERS = Headers.Builder().build()
private val DEFAULT_BODY: RequestBody = FormBody.Builder().build()

fun GET(
url: String,
headers: Headers = DEFAULT_HEADERS,
cache: CacheControl = DEFAULT_CACHE_CONTROL
): Request {
return Request.Builder()
.url(url)
.headers(headers)
.cacheControl(cache)
.build()
}

fun POST(
url: String,
headers: Headers = DEFAULT_HEADERS,
body: RequestBody = DEFAULT_BODY,
cache: CacheControl = DEFAULT_CACHE_CONTROL
): Request {
return Request.Builder()
.url(url)
.post(body)
.headers(headers)
.cacheControl(cache)
.build()
}
46 changes: 46 additions & 0 deletions app/src/main/kotlin/eu/kanade/tachiyomi/source/CatalogueSource.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package eu.kanade.tachiyomi.source

import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.MangasPage
import rx.Observable

interface CatalogueSource : Source {

/**
* An ISO 639-1 compliant language code (two letters in lower case).
*/
val lang: String

/**
* Whether the source has support for latest updates.
*/
val supportsLatest: Boolean

/**
* Returns an observable containing a page with a list of manga.
*
* @param page the page number to retrieve.
*/
fun fetchPopularManga(page: Int): Observable<MangasPage>

/**
* Returns an observable containing a page with a list of manga.
*
* @param page the page number to retrieve.
* @param query the search query.
* @param filters the list of filters to apply.
*/
fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage>

/**
* Returns an observable containing a page with a list of latest manga updates.
*
* @param page the page number to retrieve.
*/
fun fetchLatestUpdates(page: Int): Observable<MangasPage>

/**
* Returns the list of filters for the source.
*/
fun getFilterList(): FilterList
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package eu.kanade.tachiyomi.source

//import androidx.preference.PreferenceScreen

interface ConfigurableSource : Source {

// fun setupPreferenceScreen(screen: PreferenceScreen)
}
Loading

0 comments on commit 960ffd2

Please sign in to comment.