mirror of
https://github.com/gedoor/legado.git
synced 2025-01-08 11:47:32 +08:00
优化
This commit is contained in:
parent
fc7e0d3619
commit
e2bc837a04
@ -9,6 +9,7 @@ import android.view.SubMenu
|
|||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentStatePagerAdapter
|
import androidx.fragment.app.FragmentStatePagerAdapter
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import androidx.viewpager.widget.ViewPager
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.base.BaseActivity
|
import io.legado.app.base.BaseActivity
|
||||||
import io.legado.app.constant.AppLog
|
import io.legado.app.constant.AppLog
|
||||||
@ -34,6 +35,7 @@ class RssFavoritesActivity : BaseActivity<ActivityRssFavoritesBinding>() {
|
|||||||
private val adapter by lazy { TabFragmentPageAdapter() }
|
private val adapter by lazy { TabFragmentPageAdapter() }
|
||||||
private var groupList = mutableListOf<String>()
|
private var groupList = mutableListOf<String>()
|
||||||
private var groupsMenu: SubMenu? = null
|
private var groupsMenu: SubMenu? = null
|
||||||
|
private var currentGroup = ""
|
||||||
|
|
||||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
initView()
|
initView()
|
||||||
@ -42,6 +44,21 @@ class RssFavoritesActivity : BaseActivity<ActivityRssFavoritesBinding>() {
|
|||||||
|
|
||||||
private fun initView() {
|
private fun initView() {
|
||||||
binding.viewPager.adapter = adapter
|
binding.viewPager.adapter = adapter
|
||||||
|
binding.viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
||||||
|
override fun onPageScrolled(
|
||||||
|
position: Int,
|
||||||
|
positionOffset: Float,
|
||||||
|
positionOffsetPixels: Int
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPageSelected(position: Int) {
|
||||||
|
currentGroup = groupList[position]
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPageScrollStateChanged(state: Int) {}
|
||||||
|
|
||||||
|
})
|
||||||
binding.tabLayout.setupWithViewPager(binding.viewPager)
|
binding.tabLayout.setupWithViewPager(binding.viewPager)
|
||||||
binding.tabLayout.setSelectedTabIndicatorColor(accentColor)
|
binding.tabLayout.setSelectedTabIndicatorColor(accentColor)
|
||||||
}
|
}
|
||||||
@ -63,7 +80,7 @@ class RssFavoritesActivity : BaseActivity<ActivityRssFavoritesBinding>() {
|
|||||||
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
if (item.groupId == R.id.menu_group) {
|
if (item.groupId == R.id.menu_group) {
|
||||||
binding.viewPager.setCurrentItem(item.order)
|
binding.viewPager.setCurrentItem(item.order)
|
||||||
}else{
|
} else {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.menu_del_group -> deleteGroup()
|
R.id.menu_del_group -> deleteGroup()
|
||||||
R.id.menu_del_all -> deleteAll()
|
R.id.menu_del_all -> deleteAll()
|
||||||
@ -84,10 +101,17 @@ class RssFavoritesActivity : BaseActivity<ActivityRssFavoritesBinding>() {
|
|||||||
} else {
|
} else {
|
||||||
binding.tabLayout.visible()
|
binding.tabLayout.visible()
|
||||||
}
|
}
|
||||||
if (groupsMenu != null){
|
if (groupsMenu != null) {
|
||||||
upGroupsMenu()
|
upGroupsMenu()
|
||||||
}
|
}
|
||||||
|
if (groupList.isNotEmpty() && currentGroup.isEmpty()) {
|
||||||
|
currentGroup = groupList[0]
|
||||||
|
}
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
|
val item = groupList.indexOf(currentGroup)
|
||||||
|
if (item > -1) {
|
||||||
|
binding.viewPager.setCurrentItem(item)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user