[新增] 可以选择默认换源行为

This commit is contained in:
HapeLee
2025-12-04 18:21:12 +08:00
parent e8ebfa2c0e
commit 0a70685343
6 changed files with 41 additions and 1 deletions
@@ -224,4 +224,6 @@ object PreferKey {
const val exploreFilterState = "explore_filter_state"
const val exploreLayoutState = "exploreLayoutState"
const val defaultSourceChangeAll = "defaultSourceChangeAll"
}
@@ -909,5 +909,10 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
appCtx.putPrefInt(PreferKey.exploreLayoutState, value)
}
var defaultSourceChangeAll: Boolean
get() = appCtx.getPrefBoolean(PreferKey.defaultSourceChangeAll, true)
set(value) {
appCtx.putPrefBoolean(PreferKey.defaultSourceChangeAll, value)
}
}
@@ -522,12 +522,34 @@ class ReadBookActivity : BaseReadBookActivity(),
}
}
private fun defaultChangeSource() {
if (AppConfig.defaultSourceChangeAll)
{
binding.readMenu.runMenuOut()
ReadBook.book?.let {
showDialogFragment(ChangeBookSourceDialog(it.name, it.author))
}
} else {
lifecycleScope.launch {
val book = ReadBook.book ?: return@launch
val chapter =
appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex)
?: return@launch
binding.readMenu.runMenuOut()
showDialogFragment(
ChangeChapterSourceDialog(book.name, book.author, chapter.index, chapter.title)
)
}
}
}
/**
* 菜单
*/
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_change_source,
R.id.menu_change_source -> { defaultChangeSource() }
R.id.menu_book_change_source -> {
binding.readMenu.runMenuOut()
ReadBook.book?.let {