Scroll articles using the volume keys (#401)
This commit is contained in:
parent
3b47a4a2f0
commit
4826ed0355
@ -48,6 +48,8 @@
|
||||
|
||||
- Dropped support for android 4, the last version supporting it is v1721030811
|
||||
|
||||
- Added ability to scroll articles up and down using the volume keys #400
|
||||
|
||||
**1.6.x**
|
||||
|
||||
- Handling hidden tags.
|
||||
|
@ -4,6 +4,7 @@ import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.view.KeyEvent
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.view.Menu
|
||||
@ -135,13 +136,30 @@ class ReaderActivity : AppCompatActivity() {
|
||||
private inner class ScreenSlidePagerAdapter(fa: FragmentActivity) :
|
||||
FragmentStateAdapter(fa) {
|
||||
|
||||
|
||||
override fun getItemCount(): Int = allItems.size
|
||||
|
||||
override fun createFragment(position: Int): Fragment = ArticleFragment.newInstance(allItems[position])
|
||||
|
||||
}
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
return when (keyCode) {
|
||||
KeyEvent.KEYCODE_VOLUME_DOWN -> {
|
||||
val currentFragment = supportFragmentManager.findFragmentByTag("f" + binding.pager.currentItem) as ArticleFragment
|
||||
currentFragment.scrollDown()
|
||||
true
|
||||
}
|
||||
KeyEvent.KEYCODE_VOLUME_UP -> {
|
||||
val currentFragment = supportFragmentManager.findFragmentByTag("f" + binding.pager.currentItem) as ArticleFragment
|
||||
currentFragment.scrollUp()
|
||||
true
|
||||
}
|
||||
else -> {
|
||||
super.onKeyDown(keyCode, event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun alignmentMenu(showJustify: Boolean) {
|
||||
toolbarMenu.findItem(R.id.align_left).isVisible = !showJustify
|
||||
toolbarMenu.findItem(R.id.align_justify).isVisible = showJustify
|
||||
|
@ -511,6 +511,16 @@ class ArticleFragment : Fragment() {
|
||||
)
|
||||
}
|
||||
|
||||
fun scrollDown() {
|
||||
val height = binding.nestedScrollView.measuredHeight
|
||||
binding.nestedScrollView.smoothScrollBy(0, height/2)
|
||||
}
|
||||
|
||||
fun scrollUp() {
|
||||
val height = binding.nestedScrollView.measuredHeight
|
||||
binding.nestedScrollView.smoothScrollBy(0, -height/2)
|
||||
}
|
||||
|
||||
private fun openInBrowserAfterFailing(customTabsIntent: CustomTabsIntent) {
|
||||
binding.progressBar.visibility = View.GONE
|
||||
requireActivity().openItemUrlInternalBrowser(
|
||||
|
Loading…
Reference in New Issue
Block a user