修改弃用方法

pull/921/head
gedoor 4 years ago
parent 16d3a60c7f
commit e6b2272f00
  1. 31
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListActivity.kt
  2. 10
      app/src/main/java/io/legado/app/ui/filepicker/FilePickerActivity.kt
  3. 2
      app/src/main/res/layout/activity_chapter_list.xml

@ -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()
}
}

@ -116,12 +116,10 @@ class FilePickerActivity :
"*" -> types.add("*/*")
"txt", "xml" -> types.add("text/*")
else -> {
val mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension("json")
if (mime == null) {
types.add("application/octet-stream")
} else {
types.add(mime)
}
val mime = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension("json")
?: "application/octet-stream"
types.add(mime)
}
}
}

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

Loading…
Cancel
Save