Improved galleryBlock loading logic
This commit is contained in:
@@ -102,21 +102,27 @@ class Cache(context: Context) : ContextWrapper(context) {
|
|||||||
suspend fun getGalleryBlock(galleryID: Int): GalleryBlock? {
|
suspend fun getGalleryBlock(galleryID: Int): GalleryBlock? {
|
||||||
val metadata = Cache(this).getCachedMetadata(galleryID)
|
val metadata = Cache(this).getCachedMetadata(galleryID)
|
||||||
|
|
||||||
val source = mapOf(
|
val sources = mapOf(
|
||||||
Code.HITOMI to { xyz.quaver.hitomi.getGalleryBlock(galleryID) },
|
Code.HITOMI to { xyz.quaver.hitomi.getGalleryBlock(galleryID) },
|
||||||
Code.HIYOBI to { xyz.quaver.hiyobi.getGalleryBlock(galleryID) }
|
Code.HIYOBI to { xyz.quaver.hiyobi.getGalleryBlock(galleryID) }
|
||||||
)
|
)
|
||||||
|
|
||||||
val galleryBlock = if (metadata?.galleryBlock == null)
|
val galleryBlock = if (metadata?.galleryBlock == null) {
|
||||||
source.entries.map {
|
CoroutineScope(Dispatchers.IO).async {
|
||||||
CoroutineScope(Dispatchers.IO).async {
|
var galleryBlock: GalleryBlock? = null
|
||||||
kotlin.runCatching {
|
|
||||||
it.value.invoke()
|
for (source in sources) {
|
||||||
}.getOrNull()
|
galleryBlock = kotlin.runCatching {
|
||||||
}
|
source.value.invoke()
|
||||||
}.firstOrNull {
|
}.getOrNull()
|
||||||
it.await() != null
|
|
||||||
}?.await()
|
if (galleryBlock != null)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
galleryBlock
|
||||||
|
}.await() ?: return null
|
||||||
|
}
|
||||||
else
|
else
|
||||||
metadata.galleryBlock
|
metadata.galleryBlock
|
||||||
|
|
||||||
@@ -164,15 +170,14 @@ class Cache(context: Context) : ContextWrapper(context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
retval
|
retval
|
||||||
}.await()
|
}.await() ?: return null
|
||||||
} else
|
} else
|
||||||
metadata.reader
|
metadata.reader
|
||||||
|
|
||||||
if (reader != null)
|
setCachedMetadata(
|
||||||
setCachedMetadata(
|
galleryID,
|
||||||
galleryID,
|
Metadata(Cache(this).getCachedMetadata(galleryID), readers = reader)
|
||||||
Metadata(Cache(this).getCachedMetadata(galleryID), readers = reader)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
return reader
|
return reader
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user