|
|
|
@ -6,16 +6,15 @@ import androidx.activity.viewModels |
|
|
|
|
import androidx.appcompat.widget.SearchView |
|
|
|
|
import androidx.core.view.isGone |
|
|
|
|
import androidx.fragment.app.Fragment |
|
|
|
|
import androidx.fragment.app.FragmentManager |
|
|
|
|
import androidx.fragment.app.FragmentPagerAdapter |
|
|
|
|
import androidx.viewpager2.adapter.FragmentStateAdapter |
|
|
|
|
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 |
|
|
|
|
import io.legado.app.lib.theme.ATH |
|
|
|
|
import io.legado.app.lib.theme.accentColor |
|
|
|
|
import io.legado.app.lib.theme.primaryTextColor |
|
|
|
|
|
|
|
|
|
import io.legado.app.utils.gone |
|
|
|
|
import io.legado.app.utils.visible |
|
|
|
|
|
|
|
|
@ -37,8 +36,13 @@ class ChapterListActivity : VMBaseActivity<ActivityChapterListBinding, ChapterLi |
|
|
|
|
tabLayout.setSelectedTabIndicatorColor(accentColor) |
|
|
|
|
intent.getStringExtra("bookUrl")?.let { |
|
|
|
|
viewModel.initBook(it) { |
|
|
|
|
binding.viewPager.adapter = TabFragmentPageAdapter(supportFragmentManager) |
|
|
|
|
tabLayout.setupWithViewPager(binding.viewPager) |
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -72,23 +76,16 @@ class ChapterListActivity : VMBaseActivity<ActivityChapterListBinding, ChapterLi |
|
|
|
|
return super.onCompatCreateOptionsMenu(menu) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private inner class TabFragmentPageAdapter(fm: FragmentManager) : |
|
|
|
|
FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { |
|
|
|
|
override fun getItem(position: Int): Fragment { |
|
|
|
|
return when (position) { |
|
|
|
|
1 -> BookmarkFragment() |
|
|
|
|
else -> ChapterListFragment() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
private inner class TabFragmentPageAdapter : FragmentStateAdapter(this) { |
|
|
|
|
|
|
|
|
|
override fun getCount(): Int { |
|
|
|
|
override fun getItemCount(): Int { |
|
|
|
|
return 2 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun getPageTitle(position: Int): CharSequence { |
|
|
|
|
override fun createFragment(position: Int): Fragment { |
|
|
|
|
return when (position) { |
|
|
|
|
1 -> getString(R.string.bookmark) |
|
|
|
|
else -> getString(R.string.chapter_list) |
|
|
|
|
0 -> ChapterListFragment() |
|
|
|
|
else -> BookmarkFragment() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|