mirror of
https://github.com/tachiyomiorg/tachiyomi-extensions-inspector.git
synced 2025-01-20 12:41:10 +01:00
Revert RxJava API changes for 1.4
These will return for 1.5
This commit is contained in:
parent
1f03ebad2b
commit
1aa6775836
@ -3,16 +3,15 @@ package eu.kanade.tachiyomi.source
|
|||||||
import eu.kanade.tachiyomi.source.model.Page
|
import eu.kanade.tachiyomi.source.model.Page
|
||||||
import eu.kanade.tachiyomi.source.model.SChapter
|
import eu.kanade.tachiyomi.source.model.SChapter
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
import eu.kanade.tachiyomi.util.awaitSingle
|
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A basic interface for creating a source. It could be an online source, a local source, etc.
|
* A basic interface for creating a source. It could be an online source, a local source, etc...
|
||||||
*/
|
*/
|
||||||
interface Source {
|
interface Source {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ID for the source. Must be unique.
|
* Id for the source. Must be unique.
|
||||||
*/
|
*/
|
||||||
val id: Long
|
val id: Long
|
||||||
|
|
||||||
@ -21,81 +20,24 @@ interface Source {
|
|||||||
*/
|
*/
|
||||||
val name: String
|
val name: String
|
||||||
|
|
||||||
val lang: String
|
|
||||||
get() = ""
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the updated details for a manga.
|
|
||||||
*
|
|
||||||
* @since extensions-lib 1.4
|
|
||||||
* @param manga the manga to update.
|
|
||||||
* @return the updated manga.
|
|
||||||
*/
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
suspend fun getMangaDetails(manga: SManga): SManga {
|
|
||||||
return fetchMangaDetails(manga).awaitSingle()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all the available chapters for a manga.
|
|
||||||
*
|
|
||||||
* @since extensions-lib 1.4
|
|
||||||
* @param manga the manga to update.
|
|
||||||
* @return the chapters for the manga.
|
|
||||||
*/
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
suspend fun getChapterList(manga: SManga): List<SChapter> {
|
|
||||||
return fetchChapterList(manga).awaitSingle()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the list of pages a chapter has. Pages should be returned
|
|
||||||
* in the expected order; the index is ignored.
|
|
||||||
*
|
|
||||||
* @since extensions-lib 1.4
|
|
||||||
* @param chapter the chapter.
|
|
||||||
* @return the pages for the chapter.
|
|
||||||
*/
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
suspend fun getPageList(chapter: SChapter): List<Page> {
|
|
||||||
return fetchPageList(chapter).awaitSingle()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an observable with the updated details for a manga.
|
* Returns an observable with the updated details for a manga.
|
||||||
*
|
*
|
||||||
* @param manga the manga to update.
|
* @param manga the manga to update.
|
||||||
*/
|
*/
|
||||||
@Deprecated(
|
fun fetchMangaDetails(manga: SManga): Observable<SManga>
|
||||||
"Use the non-RxJava API instead",
|
|
||||||
ReplaceWith("getMangaDetails"),
|
|
||||||
)
|
|
||||||
fun fetchMangaDetails(manga: SManga): Observable<SManga> = throw IllegalStateException(
|
|
||||||
"Not used",
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an observable with all the available chapters for a manga.
|
* Returns an observable with all the available chapters for a manga.
|
||||||
*
|
*
|
||||||
* @param manga the manga to update.
|
* @param manga the manga to update.
|
||||||
*/
|
*/
|
||||||
@Deprecated(
|
fun fetchChapterList(manga: SManga): Observable<List<SChapter>>
|
||||||
"Use the non-RxJava API instead",
|
|
||||||
ReplaceWith("getChapterList"),
|
|
||||||
)
|
|
||||||
fun fetchChapterList(manga: SManga): Observable<List<SChapter>> = throw IllegalStateException(
|
|
||||||
"Not used",
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an observable with the list of pages a chapter has. Pages should be returned
|
* Returns an observable with the list of pages a chapter has.
|
||||||
* in the expected order; the index is ignored.
|
|
||||||
*
|
*
|
||||||
* @param chapter the chapter.
|
* @param chapter the chapter.
|
||||||
*/
|
*/
|
||||||
@Deprecated(
|
fun fetchPageList(chapter: SChapter): Observable<List<Page>>
|
||||||
"Use the non-RxJava API instead",
|
|
||||||
ReplaceWith("getPageList"),
|
|
||||||
)
|
|
||||||
fun fetchPageList(chapter: SChapter): Observable<List<Page>> = Observable.empty()
|
|
||||||
}
|
}
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
package eu.kanade.tachiyomi.source.online
|
|
||||||
|
|
||||||
import eu.kanade.tachiyomi.source.Source
|
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A source that may handle opening an SManga for a given URI.
|
|
||||||
*
|
|
||||||
* @since extensions-lib 1.5
|
|
||||||
*/
|
|
||||||
interface ResolvableSource : Source {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether this source may potentially handle the given URI.
|
|
||||||
*
|
|
||||||
* @since extensions-lib 1.5
|
|
||||||
*/
|
|
||||||
fun canResolveUri(uri: String): Boolean
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called if canHandleUri is true. Returns the corresponding SManga, if possible.
|
|
||||||
*
|
|
||||||
* @since extensions-lib 1.5
|
|
||||||
*/
|
|
||||||
suspend fun getManga(uri: String): SManga?
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
package eu.kanade.tachiyomi.util
|
|
||||||
|
|
||||||
import kotlinx.coroutines.CancellableContinuation
|
|
||||||
import kotlinx.coroutines.InternalCoroutinesApi
|
|
||||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
|
||||||
import rx.Observable
|
|
||||||
import rx.Subscriber
|
|
||||||
import rx.Subscription
|
|
||||||
import kotlin.coroutines.resume
|
|
||||||
import kotlin.coroutines.resumeWithException
|
|
||||||
|
|
||||||
suspend fun <T> Observable<T>.awaitSingle(): T = single().awaitOne()
|
|
||||||
|
|
||||||
@OptIn(InternalCoroutinesApi::class)
|
|
||||||
private suspend fun <T> Observable<T>.awaitOne(): T = suspendCancellableCoroutine { cont ->
|
|
||||||
cont.unsubscribeOnCancellation(
|
|
||||||
subscribe(
|
|
||||||
object : Subscriber<T>() {
|
|
||||||
override fun onStart() {
|
|
||||||
request(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onNext(t: T) {
|
|
||||||
cont.resume(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCompleted() {
|
|
||||||
if (cont.isActive) {
|
|
||||||
cont.resumeWithException(
|
|
||||||
IllegalStateException(
|
|
||||||
"Should have invoked onNext",
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onError(e: Throwable) {
|
|
||||||
/*
|
|
||||||
* Rx1 observable throws NoSuchElementException if cancellation happened before
|
|
||||||
* element emission. To mitigate this we try to atomically resume continuation with exception:
|
|
||||||
* if resume failed, then we know that continuation successfully cancelled itself
|
|
||||||
*/
|
|
||||||
val token = cont.tryResumeWithException(e)
|
|
||||||
if (token != null) {
|
|
||||||
cont.completeResume(token)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun <T> CancellableContinuation<T>.unsubscribeOnCancellation(sub: Subscription) =
|
|
||||||
invokeOnCancellation { sub.unsubscribe() }
|
|
Loading…
x
Reference in New Issue
Block a user