Add intercept activity source choosing

This commit is contained in:
Jobobby04
2020-10-19 18:41:41 -04:00
parent a4a1c2827c
commit 1dfe3890a9
2 changed files with 45 additions and 23 deletions
@@ -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 {