修改弃用方法

pull/921/head
gedoor 4 years ago
parent e6b2272f00
commit 65f2880920
  1. 13
      app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt
  2. 7
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListActivity.kt
  3. 18
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt
  4. 11
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListViewModel.kt
  5. 2
      app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt

@ -13,6 +13,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R
import io.legado.app.base.VMBaseFragment
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.Bookmark
import io.legado.app.databinding.DialogBookmarkBinding
import io.legado.app.databinding.FragmentBookmarkBinding
@ -35,7 +36,9 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
viewModel.bookMarkCallBack = this
initRecyclerView()
initData()
viewModel.bookData.observe(this) {
initData(it)
}
}
private fun initRecyclerView() {
@ -46,8 +49,7 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
binding.recyclerView.adapter = adapter
}
private fun initData() {
viewModel.book?.let { book ->
private fun initData(book: Book) {
bookmarkLiveData?.removeObservers(viewLifecycleOwner)
bookmarkLiveData =
LivePagedListBuilder(
@ -55,11 +57,12 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
).build()
bookmarkLiveData?.observe(viewLifecycleOwner, { adapter.submitList(it) })
}
}
override fun startBookmarkSearch(newText: String?) {
if (newText.isNullOrBlank()) {
initData()
viewModel.bookData.value?.let {
initData(it)
}
} else {
bookmarkLiveData?.removeObservers(viewLifecycleOwner)
bookmarkLiveData = LivePagedListBuilder(

@ -34,16 +34,15 @@ class ChapterListActivity : VMBaseActivity<ActivityChapterListBinding, ChapterLi
tabLayout = binding.titleBar.findViewById(R.id.tab_layout)
tabLayout.isTabIndicatorFullWidth = false
tabLayout.setSelectedTabIndicatorColor(accentColor)
intent.getStringExtra("bookUrl")?.let {
viewModel.initBook(it) {
binding.viewPager.adapter = TabFragmentPageAdapter()
TabLayoutMediator(tabLayout, binding.viewPager) { tab, position ->
when (position) {
0 -> tab.setText(R.string.chapter_list)
else -> tab.setText(R.string.bookmark)
}
}
}
}.attach()
intent.getStringExtra("bookUrl")?.let {
viewModel.initBook(it)
}
}

@ -49,7 +49,9 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme
ivChapterBottom.setColorFilter(btc)
initRecyclerView()
initView()
initBook()
viewModel.bookData.observe(this@ChapterListFragment) {
initBook(it)
}
}
private fun initRecyclerView() {
@ -73,15 +75,13 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme
}
@SuppressLint("SetTextI18n")
private fun initBook() {
private fun initBook(book: Book) {
launch {
initDoc()
viewModel.book?.let {
durChapterIndex = it.durChapterIndex
durChapterIndex = book.durChapterIndex
binding.tvCurrentChapterInfo.text =
"${it.durChapterTitle}(${it.durChapterIndex + 1}/${it.totalChapterNum})"
initCacheFileNames(it)
}
"${book.durChapterTitle}(${book.durChapterIndex + 1}/${book.totalChapterNum})"
initCacheFileNames(book)
}
}
@ -108,7 +108,7 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme
override fun observeLiveBus() {
observeEvent<BookChapter>(EventBus.SAVE_CONTENT) { chapter ->
viewModel.book?.bookUrl?.let { bookUrl ->
viewModel.bookData.value?.bookUrl?.let { bookUrl ->
if (chapter.bookUrl == bookUrl) {
adapter.cacheFileNames.add(chapter.getFileName())
adapter.notifyItemChanged(chapter.index, true)
@ -130,7 +130,7 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme
}
override val isLocalBook: Boolean
get() = viewModel.book?.isLocalBook() == true
get() = viewModel.bookData.value?.isLocalBook() == true
override fun durChapterIndex(): Int {
return min(durChapterIndex, adapter.itemCount)

@ -2,22 +2,23 @@ package io.legado.app.ui.book.toc
import android.app.Application
import androidx.lifecycle.MutableLiveData
import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book
class ChapterListViewModel(application: Application) : BaseViewModel(application) {
var bookUrl: String = ""
var book: Book? = null
var bookData = MutableLiveData<Book>()
var chapterCallBack: ChapterListCallBack? = null
var bookMarkCallBack: BookmarkCallBack? = null
fun initBook(bookUrl: String, success: () -> Unit) {
fun initBook(bookUrl: String) {
this.bookUrl = bookUrl
execute {
book = appDb.bookDao.getBook(bookUrl)
}.onSuccess {
success.invoke()
appDb.bookDao.getBook(bookUrl)?.let {
bookData.postValue(it)
}
}
}

@ -41,7 +41,7 @@ class RssSortActivity : VMBaseActivity<ActivityRssArtivlesBinding, RssSortViewMo
binding.viewPager.adapter = adapter
TabLayoutMediator(binding.tabLayout, binding.viewPager) { tab, position ->
tab.text = fragments.keys.elementAt(position)
}
}.attach()
viewModel.titleLiveData.observe(this, {
binding.titleBar.title = it
})

Loading…
Cancel
Save