[优化] 可选更新时不覆盖书籍类型
This commit is contained in:
@@ -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.TopBarButtonVariant
|
||||||
import io.legado.app.ui.widget.components.button.TopbarNavigationButton
|
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.cover.Cover
|
||||||
|
import io.legado.app.ui.widget.components.settingItem.SwitchSettingItem
|
||||||
import io.legado.app.utils.SelectImageContract
|
import io.legado.app.utils.SelectImageContract
|
||||||
import io.legado.app.utils.launch
|
import io.legado.app.utils.launch
|
||||||
import io.legado.app.utils.showDialogFragment
|
import io.legado.app.utils.showDialogFragment
|
||||||
@@ -180,6 +181,13 @@ fun BookInfoEditContent(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
SwitchSettingItem(
|
||||||
|
title = "固定书籍类型",
|
||||||
|
description = "书籍更新后不覆盖书籍类型",
|
||||||
|
checked = uiState.fixedType,
|
||||||
|
onCheckedChange = { viewModel.onFixedTypeChange(it) }
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = uiState.name,
|
value = uiState.name,
|
||||||
onValueChange = { viewModel.onNameChange(it) },
|
onValueChange = { viewModel.onNameChange(it) },
|
||||||
@@ -271,4 +279,3 @@ fun BookTypeDropdown(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ data class BookInfoEditUiState(
|
|||||||
val remark: String? = null,
|
val remark: String? = null,
|
||||||
val selectedType: String = "文本",
|
val selectedType: String = "文本",
|
||||||
val bookTypes: List<String> = listOf("文本", "音频", "图片"),
|
val bookTypes: List<String> = listOf("文本", "音频", "图片"),
|
||||||
|
val fixedType: Boolean = false,
|
||||||
val book: Book? = null,
|
val book: Book? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -57,6 +58,7 @@ class BookInfoEditViewModel(application: Application) : BaseViewModel(applicatio
|
|||||||
intro = it.getDisplayIntro(),
|
intro = it.getDisplayIntro(),
|
||||||
remark = it.remark,
|
remark = it.remark,
|
||||||
selectedType = _uiState.value.bookTypes[selectedTypeIndex],
|
selectedType = _uiState.value.bookTypes[selectedTypeIndex],
|
||||||
|
fixedType = it.config.fixedType,
|
||||||
book = it
|
book = it
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -87,6 +89,10 @@ class BookInfoEditViewModel(application: Application) : BaseViewModel(applicatio
|
|||||||
_uiState.value = _uiState.value.copy(selectedType = bookType)
|
_uiState.value = _uiState.value.copy(selectedType = bookType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onFixedTypeChange(fixed: Boolean) {
|
||||||
|
_uiState.value = _uiState.value.copy(fixedType = fixed)
|
||||||
|
}
|
||||||
|
|
||||||
fun resetCover() {
|
fun resetCover() {
|
||||||
_uiState.value = _uiState.value.copy(coverUrl = book?.coverUrl ?: "")
|
_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.removeType(BookType.local, BookType.image, BookType.audio, BookType.text)
|
||||||
book.addType(bookType)
|
book.addType(bookType)
|
||||||
|
book.config.fixedType = currentState.fixedType
|
||||||
book.customCoverUrl = if (currentState.coverUrl == book.coverUrl) null else currentState.coverUrl
|
book.customCoverUrl = if (currentState.coverUrl == book.coverUrl) null else currentState.coverUrl
|
||||||
book.customIntro = if (currentState.intro == book.intro) null else currentState.intro
|
book.customIntro = if (currentState.intro == book.intro) null else currentState.intro
|
||||||
BookHelp.updateCacheFolder(oldBook, book)
|
BookHelp.updateCacheFolder(oldBook, book)
|
||||||
|
|||||||
Reference in New Issue
Block a user