copymanga: fix crash on low android sdk level (#5571)

This commit is contained in:
sunbeams001 2021-01-28 00:46:51 +08:00 committed by GitHub
parent 73fbab2402
commit ede14d3f88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'CopyManga' extName = 'CopyManga'
pkgNameSuffix = 'zh.copymanga' pkgNameSuffix = 'zh.copymanga'
extClass = '.CopyManga' extClass = '.CopyManga'
extVersionCode = 4 extVersionCode = 5
libVersion = '1.2' libVersion = '1.2'
} }
apply from: "$rootDir/common.gradle" apply from: "$rootDir/common.gradle"

View File

@ -23,12 +23,13 @@ import org.json.JSONObject
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.time.LocalDate import java.text.SimpleDateFormat
import java.time.ZoneId import java.util.Date
import java.time.format.DateTimeFormatter import java.util.Locale
import javax.crypto.Cipher import javax.crypto.Cipher
import javax.crypto.spec.IvParameterSpec import javax.crypto.spec.IvParameterSpec
import javax.crypto.spec.SecretKeySpec import javax.crypto.spec.SecretKeySpec
import kotlin.collections.ArrayList
class CopyManga : ConfigurableSource, HttpSource() { class CopyManga : ConfigurableSource, HttpSource() {
@ -346,9 +347,13 @@ class CopyManga : ConfigurableSource, HttpSource() {
return bytes return bytes
} }
private fun stringToUnixTimestamp(string: String, pattern: String = "yyyy-MM-dd", timeZone: String = "CTT"): Long { private fun stringToUnixTimestamp(string: String, pattern: String = "yyyy-MM-dd", locale: Locale = Locale.CHINA): Long {
val date = LocalDate.parse(string, DateTimeFormatter.ofPattern(pattern)) return try {
return date.atStartOfDay(ZoneId.of(timeZone)).toInstant().epochSecond val time = SimpleDateFormat(pattern, locale).parse(string)?.time
if (time != null) time / 1000 else Date().time / 1000
} catch (ex: Exception) {
Date().time / 1000
}
} }
// thanks to unpacker toolsite, http://matthewfl.com/unPacker.html // thanks to unpacker toolsite, http://matthewfl.com/unPacker.html