Allow hitomi users to select whether they want to download images as Webp or not

This commit is contained in:
Jobobby04
2020-07-19 20:06:47 -04:00
parent 4771fa529d
commit ff1e0d7578
5 changed files with 19 additions and 2 deletions
@@ -270,4 +270,6 @@ object PreferenceKeys {
const val sourcesSort = "sources_sort"
const val recommendsInOverflow = "recommends_in_overflow"
const val hitomiAlwaysWebp = "hitomi_always_webp"
}
@@ -370,4 +370,6 @@ class PreferencesHelper(val context: Context) {
fun sourceSorting() = flowPrefs.getInt(Keys.sourcesSort, 0)
fun recommendsInOverflow() = flowPrefs.getBoolean(Keys.recommendsInOverflow, false)
fun hitomiAlwaysWebp() = flowPrefs.getBoolean(Keys.hitomiAlwaysWebp, true)
}
@@ -375,8 +375,8 @@ class Hitomi(val context: Context) : HttpSource(), LewdSource<HitomiSearchMetada
val json = JsonParser.parseString(str.removePrefix("var galleryinfo = "))
return json["files"].array.mapIndexed { index, jsonElement ->
val hash = jsonElement["hash"].string
val ext = if (jsonElement["haswebp"].string == "0") jsonElement["name"].string.split('.').last() else "webp"
val path = if (jsonElement["haswebp"].string == "0") "images" else "webp"
val ext = if (jsonElement["haswebp"].string == "0" || !prefs.hitomiAlwaysWebp().get()) jsonElement["name"].string.split('.').last() else "webp"
val path = if (jsonElement["haswebp"].string == "0" || !prefs.hitomiAlwaysWebp().get()) "images" else "webp"
val hashPath1 = hash.takeLast(1)
val hashPath2 = hash.takeLast(3).take(2)
Page(
@@ -22,5 +22,13 @@ class SettingsHlController : SettingsController() {
key = PreferenceKeys.eh_hl_useHighQualityThumbs
defaultValue = false
}
switchPreference {
titleRes = R.string.always_download_webp
summaryOn = context.getString(R.string.always_download_webp_summary_on)
summaryOff = context.getString(R.string.always_download_webp_summary_off)
key = PreferenceKeys.hitomiAlwaysWebp
defaultValue = true
}
}
}