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