fixed hiyobi support

This commit is contained in:
tom5079
2019-06-06 10:00:48 +09:00
parent 01c1537ae8
commit 6f187551ee
8 changed files with 55 additions and 9 deletions

View File

@@ -169,6 +169,7 @@ class ReaderActivity : AppCompatActivity() {
onProgressHandler = {
CoroutineScope(Dispatchers.Main).launch {
reader_progressbar.progress = it
menu?.findItem(R.id.reader_menu_use_hiyobi)?.isVisible = true
}
}
onDownloadedHandler = {

View File

@@ -40,7 +40,8 @@ class GalleryDownloader(
_notify: Boolean = false
) : ContextWrapper(base) {
val downloads = (applicationContext as Pupil).downloads
private val downloads = (applicationContext as Pupil).downloads
var useHiyobi = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("use_hiyobi", false)
var download: Boolean = false
set(value) {
@@ -110,7 +111,22 @@ class GalleryDownloader(
}
//Cache doesn't exist. Load from internet
val reader = getReader(galleryBlock.id)
val reader = when {
useHiyobi -> {
xyz.quaver.hiyobi.getReader(galleryBlock.id).let {
when {
it.isEmpty() -> {
useHiyobi = false
getReader(galleryBlock.id)
}
else -> it
}
}
}
else -> {
getReader(galleryBlock.id)
}
}
if (reader.isNotEmpty()) {
//Save cache
@@ -170,7 +186,11 @@ class GalleryDownloader(
if (!cache.exists())
try {
with(URL(url).openConnection() as HttpsURLConnection) {
setRequestProperty("Referer", getReferer(galleryBlock.id))
if (useHiyobi) {
setRequestProperty("User-Agent", user_agent)
setRequestProperty("Cookie", cookie)
} else
setRequestProperty("Referer", getReferer(galleryBlock.id))
if (!cache.parentFile.exists())
cache.parentFile.mkdirs()
@@ -180,8 +200,6 @@ class GalleryDownloader(
} catch (e: Exception) {
cache.delete()
Log.e("Pupil", e.toString())
onErrorHandler?.invoke(e)
notificationBuilder