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