Add reading mode toggle

This commit is contained in:
arkon 2021-03-13 16:47:16 -05:00
parent 938919bd9b
commit 1e58b05ead
4 changed files with 65 additions and 39 deletions

View file

@ -47,6 +47,7 @@ import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters
import eu.kanade.tachiyomi.ui.reader.setting.OrientationType
import eu.kanade.tachiyomi.ui.reader.setting.ReaderColorFilterSheet
import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsSheet
import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType
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
@ -81,6 +82,16 @@ import kotlin.math.abs
@RequiresPresenter(ReaderPresenter::class)
class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>() {
companion object {
fun newIntent(context: Context, manga: Manga, chapter: Chapter): Intent {
return Intent(context, ReaderActivity::class.java).apply {
putExtra("manga", manga.id)
putExtra("chapter", chapter.id)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
}
}
}
private val preferences: PreferencesHelper by injectLazy()
/**
@ -113,24 +124,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
@Suppress("DEPRECATION")
private var progressDialog: ProgressDialog? = null
private var rotationToast: Toast? = null
companion object {
@Suppress("unused")
const val LEFT_TO_RIGHT = 1
const val RIGHT_TO_LEFT = 2
const val VERTICAL = 3
const val WEBTOON = 4
const val VERTICAL_PLUS = 5
fun newIntent(context: Context, manga: Manga, chapter: Chapter): Intent {
return Intent(context, ReaderActivity::class.java).apply {
putExtra("manga", manga.id)
putExtra("chapter", chapter.id)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
}
}
}
private var menuToggleToast: Toast? = null
/**
* Called when the activity is created. Initializes the presenter and configuration.
@ -348,14 +342,22 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
}
}
binding.actionReaderMode.setOnClickListener {
val newReadingMode = ReadingModeType.getNextReadingMode(presenter.manga?.viewer ?: 0)
presenter.setMangaViewer(newReadingMode.prefValue)
menuToggleToast?.cancel()
menuToggleToast = toast(newReadingMode.stringRes)
}
binding.actionRotation.setOnClickListener {
val newOrientation = OrientationType.getNextOrientation(preferences.rotation().get(), resources)
preferences.rotation().set(newOrientation.prefValue)
setOrientation(newOrientation.flag)
rotationToast?.cancel()
rotationToast = toast(newOrientation.stringRes)
menuToggleToast?.cancel()
menuToggleToast = toast(newOrientation.stringRes)
}
preferences.rotation().asImmediateFlow { updateRotationShortcut(it) }
.onEach {
@ -463,10 +465,10 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
fun setManga(manga: Manga) {
val prevViewer = viewer
val newViewer = when (presenter.getMangaViewer()) {
RIGHT_TO_LEFT -> R2LPagerViewer(this)
VERTICAL -> VerticalPagerViewer(this)
WEBTOON -> WebtoonViewer(this)
VERTICAL_PLUS -> WebtoonViewer(this, isContinuous = false)
ReadingModeType.RIGHT_TO_LEFT.prefValue -> R2LPagerViewer(this)
ReadingModeType.VERTICAL.prefValue -> VerticalPagerViewer(this)
ReadingModeType.WEBTOON.prefValue -> WebtoonViewer(this)
ReadingModeType.CONTINUOUS_VERTICAL.prefValue -> WebtoonViewer(this, isContinuous = false)
else -> L2RPagerViewer(this)
}

View file

@ -57,7 +57,7 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BaseBottomShee
activity.presenter.setMangaViewer(position)
val mangaViewer = activity.presenter.getMangaViewer()
if (mangaViewer == ReaderActivity.WEBTOON || mangaViewer == ReaderActivity.VERTICAL_PLUS) {
if (mangaViewer == ReadingModeType.WEBTOON.prefValue || mangaViewer == ReadingModeType.CONTINUOUS_VERTICAL.prefValue) {
initWebtoonPreferences()
} else {
initPagerPreferences()

View file

@ -0,0 +1,25 @@
package eu.kanade.tachiyomi.ui.reader.setting
import androidx.annotation.StringRes
import eu.kanade.tachiyomi.R
import kotlin.math.max
enum class ReadingModeType(val prefValue: Int, @StringRes val stringRes: Int) {
DEFAULT(0, R.string.default_viewer),
LEFT_TO_RIGHT(1, R.string.left_to_right_viewer),
RIGHT_TO_LEFT(2, R.string.right_to_left_viewer),
VERTICAL(3, R.string.vertical_viewer),
WEBTOON(4, R.string.webtoon_viewer),
CONTINUOUS_VERTICAL(5, R.string.vertical_plus_viewer),
;
companion object {
fun fromPreference(preference: Int): ReadingModeType = values().find { it.prefValue == preference } ?: DEFAULT
fun getNextReadingMode(preference: Int): ReadingModeType {
// There's only 6 options (0 to 5)
val newReadingMode = max(0, (preference + 1) % 6)
return fromPreference(newReadingMode)
}
}
}

View file

@ -145,20 +145,19 @@
android:layout_gravity="bottom"
android:background="?attr/colorPrimary">
<!-- <ImageButton-->
<!-- android:id="@+id/action_reader_mode"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="match_parent"-->
<!-- android:background="?selectableItemBackgroundBorderless"-->
<!-- android:contentDescription="@string/viewer"-->
<!-- android:padding="@dimen/material_layout_keylines_screen_edge_margin"-->
<!-- app:layout_constraintEnd_toStartOf="@id/action_rotation"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent"-->
<!-- app:srcCompat="@drawable/ic_book_24dp"-->
<!-- app:tint="?attr/colorOnPrimary" />-->
<ImageButton
android:id="@+id/action_reader_mode"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/viewer"
android:padding="@dimen/material_layout_keylines_screen_edge_margin"
app:layout_constraintEnd_toStartOf="@id/action_rotation"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_book_24dp"
app:tint="?attr/colorOnPrimary" />
<!-- app:layout_constraintStart_toEndOf="@+id/action_reader_mode" -->
<ImageButton
android:id="@+id/action_rotation"
android:layout_width="wrap_content"
@ -167,7 +166,7 @@
android:contentDescription="@string/pref_rotation_type"
android:padding="@dimen/material_layout_keylines_screen_edge_margin"
app:layout_constraintEnd_toStartOf="@id/action_custom_filter"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="@+id/action_reader_mode"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_screen_rotation_24dp"
app:tint="?attr/colorOnPrimary" />