Adding back long tap reader sheet

Hope you missed it
This commit is contained in:
Jays2Kings 2021-03-30 02:16:19 -04:00
parent 2551024b20
commit a1e69e7194
8 changed files with 73 additions and 40 deletions

View File

@ -51,6 +51,8 @@ object PreferenceKeys {
const val readWithTapping = "reader_tap"
const val readWithLongTap = "reader_long_tap"
const val readWithVolumeKeys = "reader_volume_keys"
const val readWithVolumeKeysInverted = "reader_volume_keys_inverted"

View File

@ -129,6 +129,8 @@ class PreferencesHelper(val context: Context) {
fun readWithTapping() = flowPrefs.getBoolean(Keys.readWithTapping, true)
fun readWithLongTap() = flowPrefs.getBoolean(Keys.readWithLongTap, true)
fun readWithVolumeKeys() = flowPrefs.getBoolean(Keys.readWithVolumeKeys, false)
fun readWithVolumeKeysInverted() = flowPrefs.getBoolean(Keys.readWithVolumeKeysInverted, false)

View File

@ -13,7 +13,6 @@ import android.os.Build
import android.os.Bundle
import android.view.KeyEvent
import android.view.Menu
import android.view.MenuItem
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
@ -34,6 +33,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.databinding.ReaderActivityBinding
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.ui.base.MaterialMenuSheet
import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity
import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.ui.main.SearchActivity
@ -43,7 +43,6 @@ import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Success
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters
import eu.kanade.tachiyomi.ui.reader.settings.TabbedReaderSettingsSheet
import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer
import eu.kanade.tachiyomi.ui.reader.viewer.pager.L2RPagerViewer
import eu.kanade.tachiyomi.ui.reader.viewer.pager.R2LPagerViewer
@ -280,27 +279,6 @@ class ReaderActivity :
return true
}
/**
* Called when an item of the options menu was clicked. Used to handle clicks on our menu
* entries.
*/
override fun onOptionsItemSelected(item: MenuItem): Boolean {
coroutine?.cancel()
when (item.itemId) {
R.id.action_share_page, R.id.action_set_page_as_cover, R.id.action_save_page -> {
val currentChapter = presenter.getCurrentChapter() ?: return true
val page = currentChapter.pages?.getOrNull(binding.readerNav.pageSeekbar.progress) ?: return true
when (item.itemId) {
R.id.action_share_page -> shareImage(page)
R.id.action_set_page_as_cover -> showSetCoverPrompt(page)
R.id.action_save_page -> saveImage(page)
}
}
else -> return super.onOptionsItemSelected(item)
}
return true
}
private fun popToMain() {
presenter.onBackPressed()
if (fromUrl) {
@ -643,6 +621,41 @@ class ReaderActivity :
binding.readerNav.pageSeekbar.progress = page.index
}
/**
* Called from the viewer whenever a [page] is long clicked. A bottom sheet with a list of
* actions to perform is shown.
*/
fun onPageLongTap(page: ReaderPage) {
val items = listOf(
MaterialMenuSheet.MenuSheetItem(
0,
R.drawable.ic_share_24dp,
R.string.share
),
MaterialMenuSheet.MenuSheetItem(
1,
R.drawable.ic_save_24dp,
R.string.save
),
MaterialMenuSheet.MenuSheetItem(
2,
R.drawable.ic_photo_24dp,
R.string.set_as_cover
)
)
MaterialMenuSheet(this, items) { _, item ->
when (item) {
0 -> shareImage(page)
1 -> saveImage(page)
2 -> showSetCoverPrompt(page)
}
true
}.show()
if (binding.chaptersSheet.root.sheetBehavior.isExpanded()) {
binding.chaptersSheet.root.sheetBehavior?.collapse()
}
}
/**
* Called from the viewer when the given [chapter] should be preloaded. It should be called when
* the viewer is reaching the beginning or end of a chapter or the transition page is active.

View File

@ -21,6 +21,7 @@ abstract class ViewerConfig(preferences: PreferencesHelper) {
var navigationModeInvertedListener: (() -> Unit)? = null
var tappingEnabled = true
var longTapEnabled = true
var tappingInverted = ViewerNavigation.TappingInvertMode.NONE
var doubleTapAnimDuration = 500
var volumeKeysEnabled = false
@ -38,6 +39,9 @@ abstract class ViewerConfig(preferences: PreferencesHelper) {
preferences.readWithTapping()
.register({ tappingEnabled = it })
preferences.readWithLongTap()
.register({ longTapEnabled = it })
preferences.doubleTapAnimSpeed()
.register({ doubleTapAnimDuration = it })

View File

@ -99,6 +99,16 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
ViewerNavigation.NavigationRegion.LEFT -> moveLeft()
}
}
pager.longTapListener = f@{
if (activity.menuVisible || config.longTapEnabled) {
val item = adapter.items.getOrNull(pager.currentItem)
if (item is ReaderPage) {
activity.onPageLongTap(item)
return@f true
}
}
false
}
config.imagePropertyChangedListener = {
refreshAdapter()

View File

@ -114,6 +114,20 @@ class WebtoonViewer(val activity: ReaderActivity, val hasMargins: Boolean = fals
}
}
}
recycler.longTapListener = f@{ event ->
if (activity.menuVisible || config.longTapEnabled) {
val child = recycler.findChildViewUnder(event.x, event.y)
if (child != null) {
val position = recycler.getChildAdapterPosition(child)
val item = adapter.items.getOrNull(position)
if (item is ReaderPage) {
activity.onPageLongTap(item)
return@f true
}
}
}
false
}
config.imagePropertyChangedListener = {
refreshAdapter()

View File

@ -254,6 +254,11 @@ class SettingsReaderController : SettingsController() {
titleRes = R.string.tapping
defaultValue = true
}
switchPreference {
key = Keys.readWithLongTap
titleRes = R.string.long_tap_dialog
defaultValue = true
}
switchPreference {
key = Keys.readWithVolumeKeys
titleRes = R.string.volume_keys

View File

@ -2,21 +2,4 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_share_page"
android:icon="@drawable/ic_share_24dp"
android:title="@string/share_page"
app:showAsAction="never" />
<item
android:id="@+id/action_save_page"
android:icon="@drawable/ic_save_24dp"
android:title="@string/save_page"
app:showAsAction="never" />
<item
android:id="@+id/action_set_page_as_cover"
android:icon="@drawable/ic_photo_24dp"
android:title="@string/set_page_as_cover"
app:showAsAction="never" />
</menu>