pull/1059/head
gedoor 4 years ago
parent fcdc167d3f
commit 13bf96c475
  1. 31
      app/src/main/java/io/legado/app/ui/book/toc/TocActivity.kt
  2. 2
      app/src/main/res/layout/activity_chapter_list.xml

@ -1,3 +1,5 @@
@file:Suppress("DEPRECATION")
package io.legado.app.ui.book.toc
import android.content.Intent
@ -8,9 +10,8 @@ import androidx.activity.viewModels
import androidx.appcompat.widget.SearchView
import androidx.core.view.isGone
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.fragment.app.FragmentPagerAdapter
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.databinding.ActivityChapterListBinding
@ -37,12 +38,7 @@ class TocActivity : VMBaseActivity<ActivityChapterListBinding, TocViewModel>() {
tabLayout.isTabIndicatorFullWidth = false
tabLayout.setSelectedTabIndicatorColor(accentColor)
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()
tabLayout.setupWithViewPager(binding.viewPager)
intent.getStringExtra("bookUrl")?.let {
viewModel.initBook(it)
}
@ -98,16 +94,25 @@ class TocActivity : VMBaseActivity<ActivityChapterListBinding, TocViewModel>() {
}
}
private inner class TabFragmentPageAdapter : FragmentStateAdapter(this) {
@Suppress("DEPRECATION")
private inner class TabFragmentPageAdapter :
FragmentPagerAdapter(supportFragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
override fun getItem(position: Int): Fragment {
return when (position) {
1 -> BookmarkFragment()
else -> ChapterListFragment()
}
}
override fun getItemCount(): Int {
override fun getCount(): Int {
return 2
}
override fun createFragment(position: Int): Fragment {
override fun getPageTitle(position: Int): CharSequence {
return when (position) {
0 -> ChapterListFragment()
else -> BookmarkFragment()
1 -> getString(R.string.bookmark)
else -> getString(R.string.chapter_list)
}
}

@ -12,7 +12,7 @@
app:contentInsetStartWithNavigation="0dp"
app:contentLayout="@layout/view_tab_layout" />
<androidx.viewpager2.widget.ViewPager2
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />

Loading…
Cancel
Save