mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
up
This commit is contained in:
parent
66616dd915
commit
8b4dee9232
@ -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<MainViewModel>(), BottomNavigationView.OnNavigationItemSelectedListener {
|
||||
class MainActivity : BaseActivity<MainViewModel>(), BottomNavigationView.OnNavigationItemSelectedListener,
|
||||
ViewPager.OnPageChangeListener {
|
||||
private val mFragmentList: ArrayList<Fragment> = ArrayList()
|
||||
|
||||
override val viewModel: MainViewModel
|
||||
get() = getViewModel(MainViewModel::class.java)
|
||||
@ -21,6 +31,13 @@ class MainActivity : BaseActivity<MainViewModel>(), 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<MainViewModel>(), 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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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)
|
||||
// }
|
||||
|
||||
|
||||
}
|
@ -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)
|
||||
// }
|
||||
|
||||
}
|
@ -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)
|
||||
// }
|
||||
|
||||
}
|
@ -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)
|
||||
// }
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user