From 8b4dee923292fc90ede542ef0d4b14826ad8cb2a Mon Sep 17 00:00:00 2001 From: GKF Date: Mon, 3 Jun 2019 17:11:13 +0800 Subject: [PATCH] up --- .../io/legado/app/ui/main/MainActivity.kt | 46 ++++++++++++++++++- .../ui/main/bookshelf/BookshelfFragment.kt | 19 +++----- .../ui/main/booksource/BookSourceFragment.kt | 19 +++----- .../app/ui/main/findbook/FindBookFragment.kt | 19 +++----- .../app/ui/main/myconfig/MyConfigFragment.kt | 19 +++----- 5 files changed, 73 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 0daa58ad6..ea95d0256 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -3,16 +3,26 @@ package io.legado.app.ui.main import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentManager +import androidx.fragment.app.FragmentPagerAdapter +import androidx.viewpager.widget.ViewPager import com.google.android.material.bottomnavigation.BottomNavigationView import io.legado.app.R import io.legado.app.base.BaseActivity import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat import io.legado.app.help.storage.Restore +import io.legado.app.ui.main.bookshelf.BookshelfFragment +import io.legado.app.ui.main.booksource.BookSourceFragment +import io.legado.app.ui.main.findbook.FindBookFragment +import io.legado.app.ui.main.myconfig.MyConfigFragment import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_main.* -class MainActivity : BaseActivity(), BottomNavigationView.OnNavigationItemSelectedListener { +class MainActivity : BaseActivity(), BottomNavigationView.OnNavigationItemSelectedListener, + ViewPager.OnPageChangeListener { + private val mFragmentList: ArrayList = ArrayList() override val viewModel: MainViewModel get() = getViewModel(MainViewModel::class.java) @@ -21,6 +31,13 @@ class MainActivity : BaseActivity(), BottomNavigationView.OnNavig get() = R.layout.activity_main override fun onViewModelCreated(viewModel: MainViewModel, savedInstanceState: Bundle?) { + mFragmentList.add(BookshelfFragment()) + mFragmentList.add(FindBookFragment()) + mFragmentList.add(BookSourceFragment()) + mFragmentList.add(MyConfigFragment()) + view_pager_main.adapter = + TabFragmentPageAdapter(supportFragmentManager, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) + view_pager_main.addOnPageChangeListener(this) bottom_navigation_view.setOnNavigationItemSelectedListener(this) } @@ -50,4 +67,31 @@ class MainActivity : BaseActivity(), BottomNavigationView.OnNavig .onGranted { Restore.importYueDuData(this) }.request() } + override fun onPageScrollStateChanged(state: Int) { + + } + + + override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) { + + } + + + override fun onPageSelected(position: Int) { + bottom_navigation_view.menu.getItem(position).isChecked = true + } + + inner class TabFragmentPageAdapter internal constructor(fm: FragmentManager, behavior: Int) : + FragmentPagerAdapter(fm, behavior) { + + override fun getItem(position: Int): Fragment { + return mFragmentList[position] + } + + override fun getCount(): Int { + return mFragmentList.size + } + + } + } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 348f286fb..4d9c7492f 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -1,21 +1,16 @@ package io.legado.app.ui.main.bookshelf -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup import androidx.fragment.app.Fragment -import io.legado.app.R class BookshelfFragment : Fragment() { - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - return inflater.inflate(R.layout.fragment_bookshelf, container) - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - } +// override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { +// return inflater.inflate(R.layout.fragment_bookshelf, container) +// } +// +// override fun onViewCreated(view: View, savedInstanceState: Bundle?) { +// super.onViewCreated(view, savedInstanceState) +// } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt b/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt index ccbfd00fb..85c0c7110 100644 --- a/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt @@ -1,20 +1,15 @@ package io.legado.app.ui.main.booksource -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup import androidx.fragment.app.Fragment -import io.legado.app.R class BookSourceFragment : Fragment() { - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - return inflater.inflate(R.layout.fragment_book_source, container) - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - } +// override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { +// return inflater.inflate(R.layout.fragment_book_source, container) +// } +// +// override fun onViewCreated(view: View, savedInstanceState: Bundle?) { +// super.onViewCreated(view, savedInstanceState) +// } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/findbook/FindBookFragment.kt b/app/src/main/java/io/legado/app/ui/main/findbook/FindBookFragment.kt index 0bb4a42ce..f37d79941 100644 --- a/app/src/main/java/io/legado/app/ui/main/findbook/FindBookFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/findbook/FindBookFragment.kt @@ -1,20 +1,15 @@ package io.legado.app.ui.main.findbook -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup import androidx.fragment.app.Fragment -import io.legado.app.R class FindBookFragment : Fragment() { - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - return inflater.inflate(R.layout.fragment_find_book, container) - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - } +// override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { +// return inflater.inflate(R.layout.fragment_find_book, container) +// } +// +// override fun onViewCreated(view: View, savedInstanceState: Bundle?) { +// super.onViewCreated(view, savedInstanceState) +// } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/myconfig/MyConfigFragment.kt b/app/src/main/java/io/legado/app/ui/main/myconfig/MyConfigFragment.kt index 154b21ab6..6bd23077c 100644 --- a/app/src/main/java/io/legado/app/ui/main/myconfig/MyConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/myconfig/MyConfigFragment.kt @@ -1,20 +1,15 @@ package io.legado.app.ui.main.myconfig -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup import androidx.fragment.app.Fragment -import io.legado.app.R class MyConfigFragment : Fragment() { - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - return inflater.inflate(R.layout.fragment_my_config, container) - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - } +// override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { +// return inflater.inflate(R.layout.fragment_my_config, container) +// } +// +// override fun onViewCreated(view: View, savedInstanceState: Bundle?) { +// super.onViewCreated(view, savedInstanceState) +// } } \ No newline at end of file