This commit is contained in:
Horis
2025-04-17 11:40:34 +08:00
parent 632a46dfcb
commit 7c81d2d3a9
3 changed files with 23 additions and 8 deletions

View File

@@ -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++
}
}

View File

@@ -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)
}
}

View File

@@ -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" />