feat: 修复bug

pull/238/head
gedoor 5 years ago
parent ebb1e2dd33
commit 57e3595601
  1. 19
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt

@ -7,7 +7,6 @@ import androidx.lifecycle.Observer
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
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.BaseFragment import io.legado.app.base.BaseFragment
@ -28,7 +27,6 @@ import io.legado.app.utils.getViewModelOfActivity
import io.legado.app.utils.observeEvent import io.legado.app.utils.observeEvent
import kotlinx.android.synthetic.main.fragment_books.* import kotlinx.android.synthetic.main.fragment_books.*
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
import kotlin.math.max
class BooksFragment : BaseFragment(R.layout.fragment_books), class BooksFragment : BaseFragment(R.layout.fragment_books),
@ -77,23 +75,6 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
booksAdapter = BooksAdapterGrid(requireContext(), this) booksAdapter = BooksAdapterGrid(requireContext(), this)
} }
rv_bookshelf.adapter = booksAdapter rv_bookshelf.adapter = booksAdapter
booksAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
val layoutManager = rv_bookshelf.layoutManager
if (positionStart == 0 && layoutManager is LinearLayoutManager) {
val scrollTo = layoutManager.findFirstVisibleItemPosition() - itemCount
rv_bookshelf.scrollToPosition(max(0, scrollTo))
}
}
override fun onItemRangeMoved(fromPosition: Int, toPosition: Int, itemCount: Int) {
val layoutManager = rv_bookshelf.layoutManager
if (toPosition == 0 && layoutManager is LinearLayoutManager) {
val scrollTo = layoutManager.findFirstVisibleItemPosition() - itemCount
rv_bookshelf.scrollToPosition(max(0, scrollTo))
}
}
})
} }
private fun upRecyclerData() { private fun upRecyclerData() {

Loading…
Cancel
Save