Переглянути джерело

fix: 修复开启“自定义导出”时,TXT 格式被错误导出为 EPUB 的问题

a328929 4 місяців тому
батько
коміт
790f5b46e7

+ 1 - 0
app/build.gradle.kts

@@ -173,6 +173,7 @@ dependencies {
     "baselineProfile"(project(":baselineprofile"))
     coreLibraryDesugaring(libs.desugar)
     testImplementation(libs.junit)
+    testImplementation(libs.robolectric)
     androidTestImplementation(libs.bundles.androidTest)
     implementation(libs.kotlin.stdlib)
     implementation(libs.kotlinx.collections.immutable)

+ 2 - 2
app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageScreen.kt

@@ -295,7 +295,7 @@ private fun BookshelfManageScreen(
         }
         val bookUrl = pendingExportBookUrl ?: return@rememberLauncherForActivityResult
         val book = booksByUrl[bookUrl] ?: return@rememberLauncherForActivityResult
-        if (state.exportConfig.enableCustomExport) {
+        if (state.exportConfig.isCustomEpubExportEnabled) {
             customExportPath = dirPath
             customExportBook = book
             customExportAllChapter = false
@@ -336,7 +336,7 @@ private fun BookshelfManageScreen(
         val path = ACache.get().getAsString(exportBookPathKey)
         if (path.isNullOrEmpty() || !FileDoc.fromDir(path).checkWrite()) {
             selectExportFolder(book.bookUrl)
-        } else if (state.exportConfig.enableCustomExport) {
+        } else if (state.exportConfig.isCustomEpubExportEnabled) {
             customExportPath = path
             customExportBook = book
             customExportAllChapter = false

+ 4 - 1
app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageScreenViewModel.kt

@@ -60,7 +60,10 @@ data class BookshelfManageScreenExportConfig(
     val exportCharset: String = "UTF-8",
     val bookExportFileName: String? = null,
     val episodeExportFileName: String = ""
-)
+) {
+    val isCustomEpubExportEnabled: Boolean
+        get() = enableCustomExport && exportType == 1
+}
 
 data class BookshelfManageScreenUiState(
     val groupId: Long = -1,

+ 30 - 0
app/src/test/java/io/legado/app/ui/book/manage/BookshelfManageScreenExportConfigTest.kt

@@ -0,0 +1,30 @@
+package io.legado.app.ui.book.manage
+
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+class BookshelfManageScreenExportConfigTest {
+
+    @Test
+    fun customExport_requiresEpubFormat() {
+        assertFalse(
+            BookshelfManageScreenExportConfig(
+                enableCustomExport = true,
+                exportType = 0
+            ).isCustomEpubExportEnabled
+        )
+        assertTrue(
+            BookshelfManageScreenExportConfig(
+                enableCustomExport = true,
+                exportType = 1
+            ).isCustomEpubExportEnabled
+        )
+        assertFalse(
+            BookshelfManageScreenExportConfig(
+                enableCustomExport = false,
+                exportType = 1
+            ).isCustomEpubExportEnabled
+        )
+    }
+}

+ 2 - 0
gradle/libs.versions.toml

@@ -61,6 +61,7 @@ preference = "1.2.1"
 protobufJavalite = "4.26.1"
 quickChineseTransfer = "0.2.17"
 room = "2.8.4"
+robolectric = "4.16.1"
 splitties = "3.0.0"
 rhino = "1.8.1"
 desugar = "2.1.5"
@@ -187,6 +188,7 @@ room-compiler = { module = "androidx.room:room-compiler", version.ref = "room" }
 room-ktx = { module = "androidx.room:room-ktx", version.ref = "room" }
 room-runtime = { module = "androidx.room:room-runtime", version.ref = "room" }
 room-testing = { module = "androidx.room:room-testing", version.ref = "room" }
+robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" }
 
 glide-glide = { module = "com.github.bumptech.glide:glide", version.ref = "glide" }
 glide-okhttp= { module = "com.github.bumptech.glide:okhttp3-integration", version.ref ="glide" }