Fixed bug caused by updated hitomi server structure
Version 4.0
This commit is contained in:
@@ -114,7 +114,7 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri
|
||||
.parse(Reader.serializer(), readerCache.invoke().readText())
|
||||
|
||||
with(galleryblock_progressbar) {
|
||||
max = reader.readerItems.size
|
||||
max = reader.galleryInfo.size
|
||||
progress = imageCache.invoke().list()?.size ?: 0
|
||||
|
||||
visibility = View.VISIBLE
|
||||
@@ -139,7 +139,7 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri
|
||||
if (visibility == View.GONE) {
|
||||
val reader = Json(JsonConfiguration.Stable)
|
||||
.parse(Reader.serializer(), readerCache.invoke().readText())
|
||||
max = reader.readerItems.size
|
||||
max = reader.galleryInfo.size
|
||||
visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
|
||||
@@ -109,11 +109,11 @@ class GalleryDialog(context: Context, private val galleryID: Int) : Dialog(conte
|
||||
}
|
||||
|
||||
Glide.with(context)
|
||||
.load(gallery.thumbnails.firstOrNull())
|
||||
.load(gallery.cover)
|
||||
.apply {
|
||||
if (BuildConfig.CENSOR)
|
||||
override(5, 8)
|
||||
}.into(gallery_thumbnail)
|
||||
}.into(gallery_cover)
|
||||
|
||||
addDetails(gallery)
|
||||
addThumbnails(gallery)
|
||||
|
||||
@@ -371,7 +371,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun checkPermissions() {
|
||||
if (this.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE))
|
||||
if (!hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE))
|
||||
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 13489)
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,6 @@ import com.andrognito.patternlockview.utils.PatternLockUtils
|
||||
import kotlinx.android.synthetic.main.fragment_pattern_lock.*
|
||||
import kotlinx.android.synthetic.main.fragment_pattern_lock.view.*
|
||||
import xyz.quaver.pupil.R
|
||||
import xyz.quaver.pupil.util.hash
|
||||
import xyz.quaver.pupil.util.hashWithSalt
|
||||
|
||||
class PatternLockFragment : Fragment(), PatternLockViewListener {
|
||||
|
||||
|
||||
@@ -249,16 +249,16 @@ class ReaderActivity : AppCompatActivity() {
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
title = it.title
|
||||
with(reader_download_progressbar) {
|
||||
max = it.readerItems.size
|
||||
max = it.galleryInfo.size
|
||||
progress = 0
|
||||
}
|
||||
with(reader_progressbar) {
|
||||
max = it.readerItems.size
|
||||
max = it.galleryInfo.size
|
||||
progress = 0
|
||||
}
|
||||
|
||||
gallerySize = it.readerItems.size
|
||||
menu?.findItem(R.id.reader_menu_page_indicator)?.title = "$currentPage/${it.readerItems.size}"
|
||||
gallerySize = it.galleryInfo.size
|
||||
menu?.findItem(R.id.reader_menu_page_indicator)?.title = "$currentPage/${it.galleryInfo.size}"
|
||||
}
|
||||
}
|
||||
onProgressHandler = {
|
||||
|
||||
@@ -29,13 +29,15 @@ import androidx.core.app.TaskStackBuilder
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.crashlytics.android.Crashlytics
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.io.IOException
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonConfiguration
|
||||
import xyz.quaver.availableInHiyobi
|
||||
import xyz.quaver.hitomi.Reader
|
||||
import xyz.quaver.hitomi.getReader
|
||||
import xyz.quaver.hitomi.getReferer
|
||||
import xyz.quaver.hitomi.urlFromUrlFromHash
|
||||
import xyz.quaver.hiyobi.cookie
|
||||
import xyz.quaver.hiyobi.createImgList
|
||||
import xyz.quaver.hiyobi.user_agent
|
||||
import xyz.quaver.pupil.Pupil
|
||||
import xyz.quaver.pupil.R
|
||||
@@ -83,7 +85,7 @@ class GalleryDownloader(
|
||||
onNotifyChangedHandler?.invoke(value)
|
||||
}
|
||||
|
||||
private val reader: Deferred<Reader>?
|
||||
private val reader: Deferred<Reader?>?
|
||||
private var downloadJob: Job? = null
|
||||
|
||||
private lateinit var notificationBuilder: NotificationCompat.Builder
|
||||
@@ -121,11 +123,8 @@ class GalleryDownloader(
|
||||
if (cache.exists()) {
|
||||
val cached = json.parse(serializer, cache.readText())
|
||||
|
||||
if (cached.readerItems.isNotEmpty()) {
|
||||
useHiyobi = when {
|
||||
cached.readerItems[0].url.contains("hitomi.la") -> false
|
||||
else -> true
|
||||
}
|
||||
if (cached.galleryInfo.isNotEmpty()) {
|
||||
useHiyobi = availableInHiyobi(galleryID)
|
||||
|
||||
onReaderLoadedHandler?.invoke(cached)
|
||||
|
||||
@@ -148,7 +147,7 @@ class GalleryDownloader(
|
||||
}
|
||||
}
|
||||
|
||||
if (reader.readerItems.isNotEmpty()) {
|
||||
if (reader.galleryInfo.isNotEmpty()) {
|
||||
//Save cache
|
||||
if (cache.parentFile?.exists() == false)
|
||||
cache.parentFile!!.mkdirs()
|
||||
@@ -159,7 +158,8 @@ class GalleryDownloader(
|
||||
reader
|
||||
} catch (e: Exception) {
|
||||
Crashlytics.logException(e)
|
||||
Reader("", listOf())
|
||||
onErrorHandler?.invoke(e)
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,29 +168,36 @@ class GalleryDownloader(
|
||||
|
||||
fun start() {
|
||||
downloadJob = CoroutineScope(Dispatchers.Default).launch {
|
||||
val reader = reader!!.await()
|
||||
val reader = reader!!.await() ?: return@launch
|
||||
|
||||
notificationBuilder.setContentTitle(reader.title)
|
||||
|
||||
if (reader.readerItems.isEmpty()) {
|
||||
onErrorHandler?.invoke(IOException(getString(R.string.unable_to_connect)))
|
||||
return@launch
|
||||
}
|
||||
|
||||
val list = ArrayList<String>()
|
||||
|
||||
onReaderLoadedHandler?.invoke(reader)
|
||||
|
||||
notificationBuilder
|
||||
.setProgress(reader.readerItems.size, 0, false)
|
||||
.setContentText("0/${reader.readerItems.size}")
|
||||
.setProgress(reader.galleryInfo.size, 0, false)
|
||||
.setContentText("0/${reader.galleryInfo.size}")
|
||||
|
||||
reader.readerItems.chunked(4).forEachIndexed { chunkIndex, chunked ->
|
||||
chunked.mapIndexed { i, it ->
|
||||
reader.galleryInfo.chunked(4).forEachIndexed { chunkIndex, chunked ->
|
||||
chunked.mapIndexed { i, galleryInfo ->
|
||||
val index = chunkIndex*4+i
|
||||
|
||||
async(Dispatchers.IO) {
|
||||
val url = if (it.galleryInfo?.haswebp == 1) webpUrlFromUrl(it.url) else it.url
|
||||
val url = when(useHiyobi) {
|
||||
true -> createImgList(galleryID, reader)[index].path
|
||||
false -> when (galleryInfo.haswebp) {
|
||||
1 -> webpUrlFromUrl(
|
||||
urlFromUrlFromHash(
|
||||
galleryID,
|
||||
galleryInfo,
|
||||
true
|
||||
)
|
||||
)
|
||||
else -> urlFromUrlFromHash(galleryID, galleryInfo)
|
||||
}
|
||||
}
|
||||
|
||||
val name = "$index".padStart(4, '0')
|
||||
val ext = url.split('.').last()
|
||||
@@ -234,8 +241,8 @@ class GalleryDownloader(
|
||||
onProgressHandler?.invoke(index)
|
||||
|
||||
notificationBuilder
|
||||
.setProgress(reader.readerItems.size, index, false)
|
||||
.setContentText("$index/${reader.readerItems.size}")
|
||||
.setProgress(reader.galleryInfo.size, index, false)
|
||||
.setContentText("$index/${reader.galleryInfo.size}")
|
||||
|
||||
if (download)
|
||||
notificationManager.notify(galleryID, notificationBuilder.build())
|
||||
|
||||
@@ -21,8 +21,6 @@ package xyz.quaver.pupil.util
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.os.Environment
|
||||
import android.provider.MediaStore
|
||||
import androidx.core.content.ContextCompat
|
||||
import java.io.File
|
||||
|
||||
fun getCachedGallery(context: Context, galleryID: Int): File {
|
||||
|
||||
Reference in New Issue
Block a user