修改弃用方法

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. 8
      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.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()
} }
} }

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

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

Loading…
Cancel
Save