Fix multiple issues regarding sources loading too late
This commit is contained in:
@@ -23,15 +23,22 @@ import eu.kanade.presentation.util.Screen
|
||||
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceScreenModel
|
||||
import eu.kanade.tachiyomi.ui.category.CategoryScreen
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaScreen
|
||||
import exh.ui.ifSourcesLoaded
|
||||
import tachiyomi.core.common.util.lang.launchIO
|
||||
import tachiyomi.i18n.sy.SYMR
|
||||
import tachiyomi.presentation.core.components.material.Scaffold
|
||||
import tachiyomi.presentation.core.i18n.stringResource
|
||||
import tachiyomi.presentation.core.screens.LoadingScreen
|
||||
|
||||
class MangaDexFollowsScreen(private val sourceId: Long) : Screen() {
|
||||
|
||||
@Composable
|
||||
override fun Content() {
|
||||
if (!ifSourcesLoaded()) {
|
||||
LoadingScreen()
|
||||
return
|
||||
}
|
||||
|
||||
val navigator = LocalNavigator.currentOrThrow
|
||||
val scope = rememberCoroutineScope()
|
||||
val haptic = LocalHapticFeedback.current
|
||||
|
||||
@@ -15,15 +15,22 @@ import eu.kanade.presentation.browse.BrowseSourceContent
|
||||
import eu.kanade.presentation.browse.components.BrowseSourceSimpleToolbar
|
||||
import eu.kanade.presentation.util.Screen
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaScreen
|
||||
import exh.ui.ifSourcesLoaded
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
import tachiyomi.i18n.sy.SYMR
|
||||
import tachiyomi.presentation.core.components.material.Scaffold
|
||||
import tachiyomi.presentation.core.i18n.stringResource
|
||||
import tachiyomi.presentation.core.screens.LoadingScreen
|
||||
|
||||
class MangaDexSimilarScreen(val mangaId: Long, val sourceId: Long) : Screen() {
|
||||
|
||||
@Composable
|
||||
override fun Content() {
|
||||
if (!ifSourcesLoaded()) {
|
||||
LoadingScreen()
|
||||
return
|
||||
}
|
||||
|
||||
val screenModel = rememberScreenModel { MangaDexSimilarScreenModel(mangaId, sourceId) }
|
||||
val state by screenModel.state.collectAsState()
|
||||
val navigator = LocalNavigator.currentOrThrow
|
||||
|
||||
@@ -16,13 +16,20 @@ import eu.kanade.presentation.browse.BrowseSourceContent
|
||||
import eu.kanade.presentation.browse.components.BrowseSourceSimpleToolbar
|
||||
import eu.kanade.presentation.util.Screen
|
||||
import eu.kanade.tachiyomi.ui.browse.source.SourcesScreen
|
||||
import exh.ui.ifSourcesLoaded
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
import tachiyomi.presentation.core.components.material.Scaffold
|
||||
import tachiyomi.presentation.core.screens.LoadingScreen
|
||||
|
||||
class RecommendsScreen(val mangaId: Long, val sourceId: Long) : Screen() {
|
||||
|
||||
@Composable
|
||||
override fun Content() {
|
||||
if (!ifSourcesLoaded()) {
|
||||
LoadingScreen()
|
||||
return
|
||||
}
|
||||
|
||||
val screenModel = rememberScreenModel { RecommendsScreenModel(mangaId, sourceId) }
|
||||
val state by screenModel.state.collectAsState()
|
||||
val navigator = LocalNavigator.currentOrThrow
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package exh.ui
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.remember
|
||||
import tachiyomi.domain.source.service.SourceManager
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
@Composable
|
||||
fun ifSourcesLoaded(): Boolean {
|
||||
return remember { Injekt.get<SourceManager>().isInitialized }.collectAsState().value
|
||||
}
|
||||
@@ -28,19 +28,22 @@ import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||
import eu.kanade.tachiyomi.util.view.setComposeContent
|
||||
import exh.GalleryAddEvent
|
||||
import exh.GalleryAdder
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import tachiyomi.core.common.Constants
|
||||
import tachiyomi.core.common.i18n.stringResource
|
||||
import tachiyomi.core.common.util.lang.launchIO
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
import tachiyomi.domain.source.service.SourceManager
|
||||
import tachiyomi.i18n.MR
|
||||
import tachiyomi.i18n.sy.SYMR
|
||||
import tachiyomi.presentation.core.components.material.Scaffold
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
class InterceptActivity : BaseActivity() {
|
||||
private var statusJob: Job? = null
|
||||
@@ -108,7 +111,11 @@ class InterceptActivity : BaseActivity() {
|
||||
|
||||
private fun processLink() {
|
||||
if (Intent.ACTION_VIEW == intent.action) {
|
||||
loadGallery(intent.dataString!!)
|
||||
lifecycleScope.launchIO {
|
||||
// wait for sources to load
|
||||
Injekt.get<SourceManager>().isInitialized.first { it }
|
||||
loadGallery(intent.dataString!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,8 +174,7 @@ class InterceptActivity : BaseActivity() {
|
||||
|
||||
private val galleryAdder = GalleryAdder()
|
||||
|
||||
@Synchronized
|
||||
fun loadGallery(gallery: String) {
|
||||
suspend fun loadGallery(gallery: String) {
|
||||
// Do not load gallery if already loading
|
||||
if (status.value is InterceptResult.Idle) {
|
||||
status.value = InterceptResult.Loading
|
||||
@@ -178,7 +184,10 @@ class InterceptActivity : BaseActivity() {
|
||||
.setTitle(MR.strings.label_sources.getString(this))
|
||||
.setSingleChoiceItems(sources.map { it.toString() }.toTypedArray(), 0) { dialog, index ->
|
||||
dialog.dismiss()
|
||||
loadGalleryEnd(gallery, sources[index])
|
||||
lifecycleScope.launchIO {
|
||||
loadGalleryEnd(gallery, sources[index])
|
||||
}
|
||||
|
||||
}
|
||||
.show()
|
||||
} else {
|
||||
@@ -187,15 +196,12 @@ class InterceptActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadGalleryEnd(gallery: String, source: UrlImportableSource? = null) {
|
||||
// Load gallery async
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val result = galleryAdder.addGallery(this@InterceptActivity, gallery, forceSource = source)
|
||||
private suspend fun loadGalleryEnd(gallery: String, source: UrlImportableSource? = null) {
|
||||
val result = galleryAdder.addGallery(this@InterceptActivity, gallery, forceSource = source)
|
||||
|
||||
status.value = when (result) {
|
||||
is GalleryAddEvent.Success -> InterceptResult.Success(result.manga.id, result.manga, result.chapter)
|
||||
is GalleryAddEvent.Fail -> InterceptResult.Failure(result.logMessage)
|
||||
}
|
||||
status.value = when (result) {
|
||||
is GalleryAddEvent.Success -> InterceptResult.Success(result.manga.id, result.manga, result.chapter)
|
||||
is GalleryAddEvent.Fail -> InterceptResult.Failure(result.logMessage)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user