Merge pull request #2444 from 821938089/little-fix

一些优化
pull/2446/head
Horis 2 years ago committed by GitHub
commit 2838bd6984
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/src/main/java/io/legado/app/api/controller/BookController.kt
  2. 6
      app/src/main/java/io/legado/app/data/entities/Book.kt
  3. 6
      app/src/main/java/io/legado/app/help/config/AppConfig.kt
  4. 2
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt
  5. 2
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt
  6. 2
      app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
  7. 2
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  8. 5
      app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageActivity.kt
  9. 2
      app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageViewModel.kt
  10. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  11. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  12. 4
      app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt
  13. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt
  14. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt

@ -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)

@ -230,7 +230,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> {

@ -211,7 +211,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
}

Loading…
Cancel
Save