pull/981/head
gedoor 4 years ago
parent 03f9eb1538
commit 1c09e1c2c7
  1. 19
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  2. 20
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt

@ -5,7 +5,6 @@ import android.view.KeyEvent
import android.view.MenuItem import android.view.MenuItem
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.adapter.FragmentStateAdapter import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2 import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.bottomnavigation.BottomNavigationView import com.google.android.material.bottomnavigation.BottomNavigationView
@ -31,7 +30,6 @@ import io.legado.app.ui.main.rss.RssFragment
import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.observeEvent import io.legado.app.utils.observeEvent
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import java.lang.reflect.Field
class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(), class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
@ -73,7 +71,6 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
bottomNavigationView.setOnNavigationItemReselectedListener(this@MainActivity) bottomNavigationView.setOnNavigationItemReselectedListener(this@MainActivity)
bottomNavigationView.menu.findItem(R.id.menu_rss).isVisible = AppConfig.isShowRSS bottomNavigationView.menu.findItem(R.id.menu_rss).isVisible = AppConfig.isShowRSS
} }
resetViewPager2TouchSlop()
} }
override fun onPostCreate(savedInstanceState: Bundle?) { override fun onPostCreate(savedInstanceState: Bundle?) {
@ -90,22 +87,6 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
}, 3000) }, 3000)
} }
/**
* 重新设置viewpager2的滑动灵敏度
*/
private fun resetViewPager2TouchSlop() = kotlin.runCatching {
val recyclerViewField: Field = ViewPager2::class.java.getDeclaredField("mRecyclerView")
recyclerViewField.isAccessible = true
val recyclerView = recyclerViewField.get(binding.viewPagerMain) as RecyclerView
val touchSlopField: Field = RecyclerView::class.java.getDeclaredField("mTouchSlop")
touchSlopField.isAccessible = true
val touchSlop = touchSlopField.get(recyclerView) as Int
touchSlopField.set(recyclerView, touchSlop * 4)
}
override fun onNavigationItemSelected(item: MenuItem): Boolean = with(binding) { override fun onNavigationItemSelected(item: MenuItem): Boolean = with(binding) {
when (item.itemId) { when (item.itemId) {
R.id.menu_bookshelf -> viewPagerMain.setCurrentItem(0, false) R.id.menu_bookshelf -> viewPagerMain.setCurrentItem(0, false)

@ -10,9 +10,7 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.adapter.FragmentStateAdapter import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator import com.google.android.material.tabs.TabLayoutMediator
import io.legado.app.R import io.legado.app.R
@ -38,7 +36,6 @@ import io.legado.app.ui.main.MainViewModel
import io.legado.app.ui.main.bookshelf.books.BooksFragment import io.legado.app.ui.main.bookshelf.books.BooksFragment
import io.legado.app.utils.* import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import java.lang.reflect.Field
/** /**
* 书架界面 * 书架界面
@ -66,23 +63,6 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
setSupportToolbar(binding.titleBar.toolbar) setSupportToolbar(binding.titleBar.toolbar)
initView() initView()
initBookGroupData() initBookGroupData()
resetViewPager2TouchSlop()
}
/**
* 重新设置viewpager2的滑动灵敏度
*/
private fun resetViewPager2TouchSlop() = kotlin.runCatching {
val recyclerViewField: Field = ViewPager2::class.java.getDeclaredField("mRecyclerView")
recyclerViewField.isAccessible = true
val recyclerView = recyclerViewField.get(binding.viewPagerBookshelf) as RecyclerView
val touchSlopField: Field = RecyclerView::class.java.getDeclaredField("mTouchSlop")
touchSlopField.isAccessible = true
val touchSlop = touchSlopField.get(recyclerView) as Int
touchSlopField.set(recyclerView, touchSlop * 4)
} }
override fun onCompatCreateOptionsMenu(menu: Menu) { override fun onCompatCreateOptionsMenu(menu: Menu) {

Loading…
Cancel
Save