Add intercept activity source choosing
This commit is contained in:
parent
a4a1c2827c
commit
1dfe3890a9
@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.online.UrlImportableSource
|
||||
import eu.kanade.tachiyomi.source.online.all.EHentai
|
||||
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
|
||||
import exh.source.EnhancedHttpSource.Companion.getMainSource
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.util.Date
|
||||
|
||||
@ -19,6 +20,20 @@ class GalleryAdder {
|
||||
|
||||
private val sourceManager: SourceManager by injectLazy()
|
||||
|
||||
fun pickSource(url: String): List<UrlImportableSource> {
|
||||
val uri = Uri.parse(url)
|
||||
return sourceManager.getVisibleCatalogueSources()
|
||||
.map { it.getMainSource() }
|
||||
.filterIsInstance<UrlImportableSource>()
|
||||
.filter {
|
||||
try {
|
||||
it.matchesUri(uri)
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun addGallery(
|
||||
context: Context,
|
||||
url: String,
|
||||
@ -41,21 +56,12 @@ class GalleryAdder {
|
||||
}
|
||||
} else {
|
||||
sourceManager.getVisibleCatalogueSources()
|
||||
.map { it.getMainSource() }
|
||||
.filterIsInstance<UrlImportableSource>()
|
||||
.find {
|
||||
try {
|
||||
it.matchesUri(uri)
|
||||
} catch (e: Exception) {
|
||||
XLog.e(context.getString(R.string.gallery_adder_source_uri_must_match), e)
|
||||
false
|
||||
}
|
||||
} ?: sourceManager.getDelegatedCatalogueSources()
|
||||
.filterIsInstance<UrlImportableSource>()
|
||||
.find {
|
||||
try {
|
||||
it.matchesUri(uri)
|
||||
} catch (e: Exception) {
|
||||
XLog.e(context.getString(R.string.gallery_adder_source_uri_must_match), e)
|
||||
false
|
||||
}
|
||||
} ?: return GalleryAddEvent.Fail.UnknownType(url, context)
|
||||
|
@ -7,8 +7,10 @@ import androidx.core.view.isVisible
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.callbacks.onCancel
|
||||
import com.afollestad.materialdialogs.callbacks.onDismiss
|
||||
import com.afollestad.materialdialogs.list.listItemsSingleChoice
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.databinding.EhActivityInterceptBinding
|
||||
import eu.kanade.tachiyomi.source.online.UrlImportableSource
|
||||
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
|
||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||
@ -93,29 +95,43 @@ class InterceptActivity : BaseActivity<EhActivityInterceptBinding>() {
|
||||
|
||||
private val galleryAdder = GalleryAdder()
|
||||
|
||||
val status: BehaviorSubject<InterceptResult> = BehaviorSubject.create<InterceptResult>(InterceptResult.Idle)
|
||||
val status: BehaviorSubject<InterceptResult> = BehaviorSubject.create(InterceptResult.Idle)
|
||||
|
||||
@Synchronized
|
||||
fun loadGallery(gallery: String) {
|
||||
// Do not load gallery if already loading
|
||||
if (status.value is InterceptResult.Idle) {
|
||||
status.onNext(InterceptResult.Loading)
|
||||
|
||||
// Load gallery async
|
||||
thread {
|
||||
val result = galleryAdder.addGallery(this, gallery)
|
||||
|
||||
status.onNext(
|
||||
when (result) {
|
||||
is GalleryAddEvent.Success -> result.manga.id?.let {
|
||||
InterceptResult.Success(it)
|
||||
} ?: InterceptResult.Failure(this.getString(R.string.manga_id_is_null))
|
||||
is GalleryAddEvent.Fail -> InterceptResult.Failure(result.logMessage)
|
||||
val sources = galleryAdder.pickSource(gallery)
|
||||
if (sources.size > 1) {
|
||||
MaterialDialog(this)
|
||||
.title(R.string.select_source)
|
||||
.listItemsSingleChoice(items = sources.map { it.toString() }) { _, index, _ ->
|
||||
loadGalleryEnd(gallery, sources[index])
|
||||
}
|
||||
)
|
||||
.show()
|
||||
} else {
|
||||
loadGalleryEnd(gallery)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private fun loadGalleryEnd(gallery: String, source: UrlImportableSource? = null) {
|
||||
// Load gallery async
|
||||
thread {
|
||||
val result = galleryAdder.addGallery(this, gallery, forceSource = source)
|
||||
|
||||
status.onNext(
|
||||
when (result) {
|
||||
is GalleryAddEvent.Success -> result.manga.id?.let {
|
||||
InterceptResult.Success(it)
|
||||
} ?: InterceptResult.Failure(this.getString(R.string.manga_id_is_null))
|
||||
is GalleryAddEvent.Fail -> InterceptResult.Failure(result.logMessage)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class InterceptResult {
|
||||
|
Loading…
x
Reference in New Issue
Block a user