mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -12,6 +12,7 @@ import io.legado.app.help.CacheManager
|
||||
import io.legado.app.help.book.BookHelp
|
||||
import io.legado.app.help.book.ContentProcessor
|
||||
import io.legado.app.help.book.isLocal
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.help.glide.ImageLoader
|
||||
import io.legado.app.model.BookCover
|
||||
import io.legado.app.model.localBook.LocalBook
|
||||
@@ -39,7 +40,7 @@ object BookController {
|
||||
return if (books.isEmpty()) {
|
||||
returnData.setErrorMsg("还没有添加小说")
|
||||
} else {
|
||||
val data = when (appCtx.getPrefInt(PreferKey.bookshelfSort)) {
|
||||
val data = when (AppConfig.bookshelfSort) {
|
||||
1 -> books.sortedByDescending { it.latestChapterTime }
|
||||
2 -> books.sortedWith { o1, o2 ->
|
||||
o1.name.cnCompare(o2.name)
|
||||
|
||||
@@ -267,7 +267,10 @@ data class Book(
|
||||
this.tocHtml = this@Book.tocHtml
|
||||
}
|
||||
|
||||
fun changeTo(newBook: Book, toc: List<BookChapter>): Book {
|
||||
/**
|
||||
* 迁移旧的书籍的一些信息到新的书籍中
|
||||
*/
|
||||
fun migrateTo(newBook: Book, toc: List<BookChapter>): Book {
|
||||
newBook.durChapterIndex = BookHelp
|
||||
.getDurChapter(durChapterIndex, durChapterTitle, toc, totalChapterNum)
|
||||
newBook.durChapterTitle = runBlocking {
|
||||
@@ -276,6 +279,7 @@ data class Book(
|
||||
)
|
||||
}
|
||||
newBook.durChapterPos = durChapterPos
|
||||
newBook.durChapterTime = durChapterTime
|
||||
newBook.group = group
|
||||
newBook.order = order
|
||||
newBook.customCoverUrl = customCoverUrl
|
||||
|
||||
@@ -366,6 +366,12 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
appCtx.putPrefInt(PreferKey.pageTouchSlop, value)
|
||||
}
|
||||
|
||||
var bookshelfSort: Int
|
||||
get() = appCtx.getPrefInt(PreferKey.bookshelfSort, 0)
|
||||
set(value) {
|
||||
appCtx.putPrefInt(PreferKey.bookshelfSort, value)
|
||||
}
|
||||
|
||||
private fun getPrefUserAgent(): String {
|
||||
val ua = appCtx.getPrefString(PreferKey.userAgent)
|
||||
if (ua.isNullOrBlank()) {
|
||||
|
||||
@@ -214,7 +214,7 @@ class AudioPlayActivity :
|
||||
AudioPlay.stop(this)
|
||||
launch {
|
||||
withContext(IO) {
|
||||
AudioPlay.book?.changeTo(book, toc)
|
||||
AudioPlay.book?.migrateTo(book, toc)
|
||||
appDb.bookDao.insert(book)
|
||||
}
|
||||
startActivity<ReadBookActivity> {
|
||||
|
||||
@@ -78,7 +78,7 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
|
||||
|
||||
fun changeTo(source: BookSource, book: Book, toc: List<BookChapter>) {
|
||||
execute {
|
||||
AudioPlay.book?.changeTo(book, toc)
|
||||
AudioPlay.book?.migrateTo(book, toc)
|
||||
appDb.bookDao.insert(book)
|
||||
AudioPlay.book = book
|
||||
AudioPlay.bookSource = source
|
||||
|
||||
@@ -168,7 +168,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
|
||||
val booksDownload = books.filter {
|
||||
!it.isAudio
|
||||
}
|
||||
when (getPrefInt(PreferKey.bookshelfSort)) {
|
||||
when (AppConfig.bookshelfSort) {
|
||||
1 -> booksDownload.sortedByDescending { it.latestChapterTime }
|
||||
2 -> booksDownload.sortedWith { o1, o2 ->
|
||||
o1.name.cnCompare(o2.name)
|
||||
|
||||
@@ -235,7 +235,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
|
||||
changeSourceCoroutine?.cancel()
|
||||
changeSourceCoroutine = execute {
|
||||
bookSource = source
|
||||
bookData.value?.changeTo(book, toc)
|
||||
bookData.value?.migrateTo(book, toc)
|
||||
if (inBookshelf) {
|
||||
book.removeType(BookType.updateError)
|
||||
appDb.bookDao.insert(book)
|
||||
|
||||
@@ -18,6 +18,7 @@ import io.legado.app.data.entities.Book
|
||||
import io.legado.app.data.entities.BookGroup
|
||||
import io.legado.app.data.entities.BookSource
|
||||
import io.legado.app.databinding.ActivityArrangeBookBinding
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.lib.dialogs.alert
|
||||
import io.legado.app.lib.theme.primaryColor
|
||||
import io.legado.app.ui.book.group.GroupManageDialog
|
||||
@@ -134,7 +135,7 @@ class BookshelfManageActivity :
|
||||
binding.recyclerView.addItemDecoration(VerticalDivider(this))
|
||||
binding.recyclerView.adapter = adapter
|
||||
val itemTouchCallback = ItemTouchCallback(adapter)
|
||||
itemTouchCallback.isCanDrag = getPrefInt(PreferKey.bookshelfSort) == 3
|
||||
itemTouchCallback.isCanDrag = AppConfig.bookshelfSort == 3
|
||||
val dragSelectTouchHelper: DragSelectTouchHelper =
|
||||
DragSelectTouchHelper(adapter.dragSelectCallback).setSlideArea(16, 50)
|
||||
dragSelectTouchHelper.attachToRecyclerView(binding.recyclerView)
|
||||
@@ -194,7 +195,7 @@ class BookshelfManageActivity :
|
||||
it.name.contains(searchKey) || it.author.contains(searchKey)
|
||||
}
|
||||
}
|
||||
when (getPrefInt(PreferKey.bookshelfSort)) {
|
||||
when (AppConfig.bookshelfSort) {
|
||||
1 -> books.sortedByDescending {
|
||||
it.latestChapterTime
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class BookshelfManageViewModel(application: Application) : BaseViewModel(applica
|
||||
.onFailure {
|
||||
context.toastOnUi("获取目录出错\n${it.localizedMessage}")
|
||||
}.getOrNull()?.let { toc ->
|
||||
book.changeTo(newBook, toc)
|
||||
book.migrateTo(newBook, toc)
|
||||
book.removeType(BookType.updateError)
|
||||
appDb.bookDao.insert(newBook)
|
||||
appDb.bookChapterDao.insert(*toc.toTypedArray())
|
||||
|
||||
@@ -822,7 +822,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
} else {
|
||||
ReadAloud.stop(this)
|
||||
launch {
|
||||
ReadBook.book?.changeTo(book, toc)
|
||||
ReadBook.book?.migrateTo(book, toc)
|
||||
appDb.bookDao.insert(book)
|
||||
}
|
||||
startActivity<AudioPlayActivity> {
|
||||
|
||||
@@ -222,7 +222,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
||||
changeSourceCoroutine?.cancel()
|
||||
changeSourceCoroutine = execute {
|
||||
ReadBook.upMsg(context.getString(R.string.loading))
|
||||
ReadBook.book?.changeTo(book, toc)
|
||||
ReadBook.book?.migrateTo(book, toc)
|
||||
book.removeType(BookType.updateError)
|
||||
appDb.bookDao.insert(book)
|
||||
appDb.bookChapterDao.insert(*toc.toTypedArray())
|
||||
|
||||
@@ -130,7 +130,7 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
|
||||
fun configBookshelf() {
|
||||
alert(titleResource = R.string.bookshelf_layout) {
|
||||
val bookshelfLayout = getPrefInt(PreferKey.bookshelfLayout)
|
||||
val bookshelfSort = getPrefInt(PreferKey.bookshelfSort)
|
||||
val bookshelfSort = AppConfig.bookshelfSort
|
||||
val alertBinding =
|
||||
DialogBookshelfConfigBinding.inflate(layoutInflater)
|
||||
.apply {
|
||||
@@ -156,7 +156,7 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
|
||||
changed = true
|
||||
}
|
||||
if (bookshelfSort != rgSort.getCheckedIndex()) {
|
||||
putPrefInt(PreferKey.bookshelfSort, rgSort.getCheckedIndex())
|
||||
AppConfig.bookshelfSort = rgSort.getCheckedIndex()
|
||||
changed = true
|
||||
}
|
||||
if (changed) {
|
||||
|
||||
@@ -121,7 +121,7 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
||||
AppConst.bookGroupErrorId -> appDb.bookDao.flowUpdateError()
|
||||
else -> appDb.bookDao.flowByGroup(groupId)
|
||||
}.conflate().map { list ->
|
||||
when (getPrefInt(PreferKey.bookshelfSort)) {
|
||||
when (AppConfig.bookshelfSort) {
|
||||
1 -> list.sortedByDescending { it.latestChapterTime }
|
||||
2 -> list.sortedWith { o1, o2 ->
|
||||
o1.name.cnCompare(o2.name)
|
||||
|
||||
@@ -133,7 +133,7 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
|
||||
AppConst.bookGroupErrorId -> appDb.bookDao.flowUpdateError()
|
||||
else -> appDb.bookDao.flowByGroup(groupId)
|
||||
}.conflate().map { list ->
|
||||
when (getPrefInt(PreferKey.bookshelfSort)) {
|
||||
when (AppConfig.bookshelfSort) {
|
||||
1 -> list.sortedByDescending {
|
||||
it.latestChapterTime
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user