From e6b2272f00b10ad1702fdf3544848d751ebcaadd Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 30 Mar 2021 11:41:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BC=83=E7=94=A8=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/toc/ChapterListActivity.kt | 31 +++++++++---------- .../app/ui/filepicker/FilePickerActivity.kt | 10 +++--- .../main/res/layout/activity_chapter_list.xml | 2 +- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListActivity.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListActivity.kt index dfe49d6e7..94077fba5 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListActivity.kt @@ -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 + when (position) { + 0 -> tab.setText(R.string.chapter_list) + else -> tab.setText(R.string.bookmark) + } + } } } } @@ -72,23 +76,16 @@ class ChapterListActivity : VMBaseActivity 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() } } diff --git a/app/src/main/java/io/legado/app/ui/filepicker/FilePickerActivity.kt b/app/src/main/java/io/legado/app/ui/filepicker/FilePickerActivity.kt index f66a6494c..7f15b115f 100644 --- a/app/src/main/java/io/legado/app/ui/filepicker/FilePickerActivity.kt +++ b/app/src/main/java/io/legado/app/ui/filepicker/FilePickerActivity.kt @@ -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) } } } diff --git a/app/src/main/res/layout/activity_chapter_list.xml b/app/src/main/res/layout/activity_chapter_list.xml index c78973583..ff03b765e 100644 --- a/app/src/main/res/layout/activity_chapter_list.xml +++ b/app/src/main/res/layout/activity_chapter_list.xml @@ -12,7 +12,7 @@ app:contentInsetStartWithNavigation="0dp" app:contentLayout="@layout/view_tab_layout" /> -