[优化] 可选更新时不覆盖书籍类型

This commit is contained in:
HapeLee
2026-03-16 01:25:05 +08:00
parent 6922fdeed9
commit 8c46d2fd27
2 changed files with 15 additions and 1 deletions
@@ -52,6 +52,7 @@ import io.legado.app.ui.widget.components.GlassMediumFlexibleTopAppBar
import io.legado.app.ui.widget.components.button.TopBarButtonVariant
import io.legado.app.ui.widget.components.button.TopbarNavigationButton
import io.legado.app.ui.widget.components.cover.Cover
import io.legado.app.ui.widget.components.settingItem.SwitchSettingItem
import io.legado.app.utils.SelectImageContract
import io.legado.app.utils.launch
import io.legado.app.utils.showDialogFragment
@@ -180,6 +181,13 @@ fun BookInfoEditContent(
}
}
Spacer(modifier = Modifier.height(16.dp))
SwitchSettingItem(
title = "固定书籍类型",
description = "书籍更新后不覆盖书籍类型",
checked = uiState.fixedType,
onCheckedChange = { viewModel.onFixedTypeChange(it) }
)
Spacer(modifier = Modifier.height(16.dp))
OutlinedTextField(
value = uiState.name,
onValueChange = { viewModel.onNameChange(it) },
@@ -271,4 +279,3 @@ fun BookTypeDropdown(
}
}
}
@@ -33,6 +33,7 @@ data class BookInfoEditUiState(
val remark: String? = null,
val selectedType: String = "文本",
val bookTypes: List<String> = listOf("文本", "音频", "图片"),
val fixedType: Boolean = false,
val book: Book? = null,
)
@@ -57,6 +58,7 @@ class BookInfoEditViewModel(application: Application) : BaseViewModel(applicatio
intro = it.getDisplayIntro(),
remark = it.remark,
selectedType = _uiState.value.bookTypes[selectedTypeIndex],
fixedType = it.config.fixedType,
book = it
)
}
@@ -87,6 +89,10 @@ class BookInfoEditViewModel(application: Application) : BaseViewModel(applicatio
_uiState.value = _uiState.value.copy(selectedType = bookType)
}
fun onFixedTypeChange(fixed: Boolean) {
_uiState.value = _uiState.value.copy(fixedType = fixed)
}
fun resetCover() {
_uiState.value = _uiState.value.copy(coverUrl = book?.coverUrl ?: "")
}
@@ -107,6 +113,7 @@ class BookInfoEditViewModel(application: Application) : BaseViewModel(applicatio
}
book.removeType(BookType.local, BookType.image, BookType.audio, BookType.text)
book.addType(bookType)
book.config.fixedType = currentState.fixedType
book.customCoverUrl = if (currentState.coverUrl == book.coverUrl) null else currentState.coverUrl
book.customIntro = if (currentState.intro == book.intro) null else currentState.intro
BookHelp.updateCacheFolder(oldBook, book)