feat: 优化代码

pull/173/head
kunfei 5 years ago
parent fd00bf2509
commit 53b596a3e8
  1. 12
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt
  2. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt

@ -11,6 +11,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.PreferKey
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookGroup import io.legado.app.data.entities.BookGroup
import io.legado.app.help.ItemTouchCallback import io.legado.app.help.ItemTouchCallback
@ -23,6 +24,7 @@ import io.legado.app.ui.book.group.GroupSelectDialog
import io.legado.app.ui.widget.SelectActionBar import io.legado.app.ui.widget.SelectActionBar
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.applyTint import io.legado.app.utils.applyTint
import io.legado.app.utils.getPrefInt
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import kotlinx.android.synthetic.main.activity_arrange_book.* import kotlinx.android.synthetic.main.activity_arrange_book.*
@ -109,8 +111,14 @@ class ArrangeBookActivity : VMBaseActivity<ArrangeBookViewModel>(R.layout.activi
-11 -> App.db.bookDao().observeNoGroup() -11 -> App.db.bookDao().observeNoGroup()
else -> App.db.bookDao().observeByGroup(groupId) else -> App.db.bookDao().observeByGroup(groupId)
} }
booksLiveData?.observe(this, Observer { booksLiveData?.observe(this, Observer { list ->
adapter.setItems(it) val books = when (getPrefInt(PreferKey.bookshelfSort)) {
1 -> list.sortedByDescending { it.latestChapterTime }
2 -> list.sortedBy { it.name }
3 -> list.sortedBy { it.order }
else -> list
}
adapter.setItems(books)
upSelectCount() upSelectCount()
}) })
} }

@ -108,7 +108,7 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
1 -> list.sortedByDescending { it.latestChapterTime } 1 -> list.sortedByDescending { it.latestChapterTime }
2 -> list.sortedBy { it.name } 2 -> list.sortedBy { it.name }
3 -> list.sortedBy { it.order } 3 -> list.sortedBy { it.order }
else -> list.sortedByDescending { it.durChapterTime } else -> list
} }
val diffResult = DiffUtil val diffResult = DiffUtil
.calculateDiff(BooksDiffCallBack(booksAdapter.getItems(), books)) .calculateDiff(BooksDiffCallBack(booksAdapter.getItems(), books))

Loading…
Cancel
Save