pull/35/head
kunfei 5 years ago
parent 33bcc77103
commit 3ebb83a6af
  1. 12
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt
  2. 11
      app/src/main/java/io/legado/app/ui/main/bookshelf/BooksFragment.kt
  3. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt
  4. 9
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt

@ -26,12 +26,12 @@ class ChangeSourceDialog : DialogFragment(),
const val tag = "changeSourceDialog"
fun newInstance(name: String, author: String): ChangeSourceDialog {
val changeSourceDialog = ChangeSourceDialog()
val bundle = Bundle()
bundle.putString("name", name)
bundle.putString("author", author)
changeSourceDialog.arguments = bundle
return changeSourceDialog
return ChangeSourceDialog().apply {
val bundle = Bundle()
bundle.putString("name", name)
bundle.putString("author", author)
arguments = bundle
}
}
}

@ -25,6 +25,17 @@ import org.jetbrains.anko.startActivity
class BooksFragment : VMBaseFragment<BooksViewModel>(R.layout.fragment_books),
BooksAdapter.CallBack {
companion object {
fun newInstance(position: Int): BooksFragment {
return BooksFragment().apply {
val bundle = Bundle()
bundle.putInt("position", position)
arguments = bundle
}
}
}
override val viewModel: BooksViewModel
get() = getViewModel(BooksViewModel::class.java)

@ -11,7 +11,7 @@ class BookshelfAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
}
override fun createFragment(position: Int): Fragment {
return BooksFragment()
return BooksFragment.newInstance(position)
}
}

@ -12,6 +12,7 @@ import androidx.lifecycle.Observer
import androidx.paging.LivePagedListBuilder
import androidx.paging.PagedList
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.viewpager2.widget.ViewPager2
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.VMBaseFragment
@ -36,6 +37,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
private lateinit var booksAdapter: BooksAdapter
private lateinit var bookGroupAdapter: BookGroupAdapter
private var bookGroupLiveData: LiveData<PagedList<BookGroup>>? = null
private var position = -1
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
setSupportToolbar(toolbar)
@ -63,6 +65,13 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
rv_book_group.adapter = bookGroupAdapter
bookGroupAdapter.callBack = this
view_pager_bookshelf.adapter = BookshelfAdapter(this)
view_pager_bookshelf.registerOnPageChangeCallback(object :
ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)
this@BookshelfFragment.position = position
}
})
observeEvent<String>(Bus.UP_BOOK) { booksAdapter.notification(it) }
}

Loading…
Cancel
Save