优化
This commit is contained in:
@@ -310,6 +310,16 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果重启太快fragment不会重建,这里更新一下书架的排序
|
||||
*/
|
||||
override fun recreate() {
|
||||
(fragmentMap[getFragmentId(0)] as? BaseBookshelfFragment)?.run {
|
||||
upSort()
|
||||
}
|
||||
super.recreate()
|
||||
}
|
||||
|
||||
override fun observeLiveBus() {
|
||||
viewModel.onUpBooksLiveData.observe(this) {
|
||||
onUpBooksBadgeView.setBadgeCount(it)
|
||||
|
||||
@@ -116,6 +116,8 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
|
||||
|
||||
abstract fun upGroup(data: List<BookGroup>)
|
||||
|
||||
abstract fun upSort()
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
fun addBookByUrl() {
|
||||
alert(titleResource = R.string.add_book_url) {
|
||||
@@ -166,16 +168,12 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
|
||||
AppConfig.showWaitUpCount = swShowWaitUpBooks.isChecked
|
||||
activityViewModel.postUpBooksLiveData(true)
|
||||
}
|
||||
var changed = false
|
||||
if (bookshelfLayout != rgLayout.getCheckedIndex()) {
|
||||
putPrefInt(PreferKey.bookshelfLayout, rgLayout.getCheckedIndex())
|
||||
changed = true
|
||||
}
|
||||
if (bookshelfSort != rgSort.getCheckedIndex()) {
|
||||
AppConfig.bookshelfSort = rgSort.getCheckedIndex()
|
||||
changed = true
|
||||
upSort()
|
||||
}
|
||||
if (changed) {
|
||||
if (bookshelfLayout != rgLayout.getCheckedIndex()) {
|
||||
putPrefInt(PreferKey.bookshelfLayout, rgLayout.getCheckedIndex())
|
||||
postEvent(EventBus.RECREATE, "")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,13 +91,6 @@ class BookshelfFragment1() : BaseBookshelfFragment(R.layout.fragment_bookshelf1)
|
||||
if (data != bookGroups) {
|
||||
bookGroups.clear()
|
||||
bookGroups.addAll(data)
|
||||
/**
|
||||
* 在书架布局对话框修改排序后,会导致书架页面刷新。但是在分组标签未修改的情况下,此处的adapter.notifyDataSetChanged()调用不会引起
|
||||
* [io.legado.app.ui.main.bookshelf.style1.BookshelfFragment1.TabFragmentPageAdapter.getItemPosition]
|
||||
* 被调用。
|
||||
* 有关方法:
|
||||
* [androidx.viewpager.widget.ViewPager.dataSetChanged]
|
||||
*/
|
||||
adapter.notifyDataSetChanged()
|
||||
selectLastTab()
|
||||
for (i in 0 until adapter.count) {
|
||||
@@ -110,6 +103,10 @@ class BookshelfFragment1() : BaseBookshelfFragment(R.layout.fragment_bookshelf1)
|
||||
}
|
||||
}
|
||||
|
||||
override fun upSort() {
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
private fun selectLastTab() {
|
||||
tabLayout.post {
|
||||
tabLayout.removeOnTabSelectedListener(this)
|
||||
|
||||
@@ -41,11 +41,8 @@ import kotlin.math.max
|
||||
class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
||||
BaseBooksAdapter.CallBack {
|
||||
|
||||
lateinit var group: BookGroup
|
||||
|
||||
constructor(position: Int, group: BookGroup) : this() {
|
||||
val bundle = Bundle()
|
||||
this.group = group
|
||||
bundle.putInt("position", position)
|
||||
bundle.putLong("groupId", group.groupId)
|
||||
bundle.putInt("bookSort", group.getRealBookSort())
|
||||
@@ -83,9 +80,6 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
||||
bookSort = it.getInt("bookSort", 0)
|
||||
binding.refreshLayout.isEnabled = it.getBoolean("enableRefresh", true)
|
||||
}
|
||||
appDb.bookGroupDao.getByID(groupId)?.apply {
|
||||
group = this
|
||||
}
|
||||
initRecyclerView()
|
||||
upRecyclerData()
|
||||
}
|
||||
@@ -199,9 +193,6 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (::group.isInitialized) {
|
||||
bookSort = group.getRealBookSort()
|
||||
}
|
||||
startLastUpdateTimeJob()
|
||||
upRecyclerData()
|
||||
}
|
||||
|
||||
@@ -116,6 +116,10 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
}
|
||||
}
|
||||
|
||||
override fun upSort() {
|
||||
initBooksData()
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun initBooksData() {
|
||||
if (groupId == -100L) {
|
||||
|
||||
Reference in New Issue
Block a user