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

@@ -7,7 +7,12 @@ import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import xyz.quaver.hiyobi.cookie
import xyz.quaver.hiyobi.getReader
import xyz.quaver.hiyobi.user_agent
import java.io.File import java.io.File
import java.net.URL
import javax.net.ssl.HttpsURLConnection
/** /**
* Instrumented test, which will execute on an Android device. * Instrumented test, which will execute on an Android device.
@@ -35,6 +40,17 @@ class ExampleInstrumentedTest {
@Test @Test
fun test_doSearch() { fun test_doSearch() {
val reader = getReader(1426382)
val data: ByteArray
with(URL(reader[0].url).openConnection() as HttpsURLConnection) {
setRequestProperty("User-Agent", user_agent)
setRequestProperty("Cookie", cookie)
data = inputStream.readBytes()
}
Log.d("Pupil", data.size.toString())
} }
} }

View File

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

View File

@@ -40,7 +40,8 @@ class GalleryDownloader(
_notify: Boolean = false _notify: Boolean = false
) : ContextWrapper(base) { ) : 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 var download: Boolean = false
set(value) { set(value) {
@@ -110,7 +111,22 @@ class GalleryDownloader(
} }
//Cache doesn't exist. Load from internet //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()) { if (reader.isNotEmpty()) {
//Save cache //Save cache
@@ -170,6 +186,10 @@ class GalleryDownloader(
if (!cache.exists()) if (!cache.exists())
try { try {
with(URL(url).openConnection() as HttpsURLConnection) { with(URL(url).openConnection() as HttpsURLConnection) {
if (useHiyobi) {
setRequestProperty("User-Agent", user_agent)
setRequestProperty("Cookie", cookie)
} else
setRequestProperty("Referer", getReferer(galleryBlock.id)) setRequestProperty("Referer", getReferer(galleryBlock.id))
if (!cache.parentFile.exists()) if (!cache.parentFile.exists())
@@ -180,8 +200,6 @@ class GalleryDownloader(
} catch (e: Exception) { } catch (e: Exception) {
cache.delete() cache.delete()
Log.e("Pupil", e.toString())
onErrorHandler?.invoke(e) onErrorHandler?.invoke(e)
notificationBuilder notificationBuilder

View File

@@ -2,8 +2,14 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/reader_menu_use_hiyobi"
android:title=""
android:icon="@drawable/ic_hiyobi"
app:showAsAction="always"
android:visible="false"/>
<item android:id="@+id/reader_menu_page_indicator" <item android:id="@+id/reader_menu_page_indicator"
android:title="@string/page_indicator_placeholder" android:title="@string/page_indicator_placeholder"
app:showAsAction="always|withText"/> app:showAsAction="ifRoom|withText"/>
</menu> </menu>

View File

@@ -66,5 +66,5 @@
<string name="settings_auto_export_summary">ダウンロード完了後自動的にエクスポート</string> <string name="settings_auto_export_summary">ダウンロード完了後自動的にエクスポート</string>
<string name="settings_clear_downloads">ダウンロード削除</string> <string name="settings_clear_downloads">ダウンロード削除</string>
<string name="settings_clear_downloads_alert_message">ダウンロードしたギャラリーを全て削除します。\n実行しますか</string> <string name="settings_clear_downloads_alert_message">ダウンロードしたギャラリーを全て削除します。\n実行しますか</string>
<string name="settings_use_hiyobi_summary">点検中</string> <string name="settings_use_hiyobi_summary">ロード速度を向上させるため可能であればhiyobi.meからイメージロード</string>
</resources> </resources>

View File

@@ -66,5 +66,5 @@
<string name="settings_auto_export_summary">다운로드가 끝난 후 자동 내보내기</string> <string name="settings_auto_export_summary">다운로드가 끝난 후 자동 내보내기</string>
<string name="settings_clear_downloads">다운로드 삭제</string> <string name="settings_clear_downloads">다운로드 삭제</string>
<string name="settings_clear_downloads_alert_message">다운로드 된 만화를 모두 삭제합니다.\n계속하시겠습니까?</string> <string name="settings_clear_downloads_alert_message">다운로드 된 만화를 모두 삭제합니다.\n계속하시겠습니까?</string>
<string name="settings_use_hiyobi_summary">점검중</string> <string name="settings_use_hiyobi_summary">속도 향상을 위해 가능하면 hiyobi.me에서 이미지 로드</string>
</resources> </resources>

View File

@@ -88,7 +88,7 @@
<string name="settings_clear_history_summary">%1$d histories saved</string> <string name="settings_clear_history_summary">%1$d histories saved</string>
<string name="settings_miscellaneous_title">Miscellaneous</string> <string name="settings_miscellaneous_title">Miscellaneous</string>
<string name="settings_use_hiyobi_title">Use hiyobi.me</string> <string name="settings_use_hiyobi_title">Use hiyobi.me</string>
<string name="settings_use_hiyobi_summary">Under maintenance</string> <string name="settings_use_hiyobi_summary">Load images from hiyobi.me to improve loading speed (if available)</string>
<string name="settings_export_zip_title">Export zip</string> <string name="settings_export_zip_title">Export zip</string>
<string name="settings_export_zip_summary">Export to zip instead of image folder</string> <string name="settings_export_zip_summary">Export to zip instead of image folder</string>
<string name="settings_auto_export_title">Auto Export</string> <string name="settings_auto_export_title">Auto Export</string>

View File

@@ -41,6 +41,11 @@
<PreferenceCategory <PreferenceCategory
app:title="@string/settings_miscellaneous_title"> app:title="@string/settings_miscellaneous_title">
<SwitchPreference
app:key="use_hiyobi"
app:title="@string/settings_use_hiyobi_title"
app:summary="@string/settings_use_hiyobi_summary"/>
<SwitchPreference <SwitchPreference
app:key="export_zip" app:key="export_zip"
app:title="@string/settings_export_zip_title" app:title="@string/settings_export_zip_title"