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