mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -250,9 +250,13 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
curMangaChapter?.let {
|
||||
curFinish = true
|
||||
items.addAll(it.pages)
|
||||
durChapterPos = durChapterPos.coerceIn(0, it.imageCount - 1)
|
||||
durChapterPos = if (it.imageCount > 0) {
|
||||
durChapterPos.coerceIn(0, it.imageCount - 1)
|
||||
} else {
|
||||
0
|
||||
}
|
||||
pos += durChapterPos
|
||||
if (!AppConfig.hideMangaTitle) {
|
||||
if (!AppConfig.hideMangaTitle && it.imageCount > 0) {
|
||||
pos++
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.text.TextUtils
|
||||
import io.legado.app.lib.icu4j.CharsetDetector
|
||||
import org.jsoup.Jsoup
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
|
||||
/**
|
||||
* 自动获取文件的编码
|
||||
@@ -70,18 +69,30 @@ object EncodingDetect {
|
||||
*/
|
||||
fun getEncode(file: File): String {
|
||||
val tempByte = getFileBytes(file)
|
||||
if (tempByte.isEmpty()) {
|
||||
return "UTF-8"
|
||||
}
|
||||
return getEncode(tempByte)
|
||||
}
|
||||
|
||||
private fun getFileBytes(file: File?): ByteArray {
|
||||
private fun getFileBytes(file: File): ByteArray {
|
||||
val byteArray = ByteArray(8000)
|
||||
var pos = 0
|
||||
try {
|
||||
FileInputStream(file).use {
|
||||
it.read(byteArray)
|
||||
file.inputStream().buffered().use {
|
||||
while (pos < byteArray.size) {
|
||||
val n = it.read(byteArray, pos, 1)
|
||||
if (n == -1) {
|
||||
break
|
||||
}
|
||||
if (byteArray[pos] < 0) {
|
||||
pos++
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
System.err.println("Error: $e")
|
||||
}
|
||||
return byteArray
|
||||
return byteArray.copyOf(pos)
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:adjustViewBounds="true"
|
||||
android:scaleType="fitXY" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user