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.OrientationType
import eu.kanade.tachiyomi.ui.reader.setting.ReaderColorFilterSheet import eu.kanade.tachiyomi.ui.reader.setting.ReaderColorFilterSheet
import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsSheet 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.BaseViewer
import eu.kanade.tachiyomi.ui.reader.viewer.pager.L2RPagerViewer import eu.kanade.tachiyomi.ui.reader.viewer.pager.L2RPagerViewer
import eu.kanade.tachiyomi.ui.reader.viewer.pager.R2LPagerViewer import eu.kanade.tachiyomi.ui.reader.viewer.pager.R2LPagerViewer
@ -81,6 +82,16 @@ import kotlin.math.abs
@RequiresPresenter(ReaderPresenter::class) @RequiresPresenter(ReaderPresenter::class)
class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>() { 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() private val preferences: PreferencesHelper by injectLazy()
/** /**
@ -113,24 +124,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
private var progressDialog: ProgressDialog? = null private var progressDialog: ProgressDialog? = null
private var rotationToast: Toast? = null private var menuToggleToast: 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)
}
}
}
/** /**
* Called when the activity is created. Initializes the presenter and configuration. * 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 { binding.actionRotation.setOnClickListener {
val newOrientation = OrientationType.getNextOrientation(preferences.rotation().get(), resources) val newOrientation = OrientationType.getNextOrientation(preferences.rotation().get(), resources)
preferences.rotation().set(newOrientation.prefValue) preferences.rotation().set(newOrientation.prefValue)
setOrientation(newOrientation.flag) setOrientation(newOrientation.flag)
rotationToast?.cancel() menuToggleToast?.cancel()
rotationToast = toast(newOrientation.stringRes) menuToggleToast = toast(newOrientation.stringRes)
} }
preferences.rotation().asImmediateFlow { updateRotationShortcut(it) } preferences.rotation().asImmediateFlow { updateRotationShortcut(it) }
.onEach { .onEach {
@ -463,10 +465,10 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
fun setManga(manga: Manga) { fun setManga(manga: Manga) {
val prevViewer = viewer val prevViewer = viewer
val newViewer = when (presenter.getMangaViewer()) { val newViewer = when (presenter.getMangaViewer()) {
RIGHT_TO_LEFT -> R2LPagerViewer(this) ReadingModeType.RIGHT_TO_LEFT.prefValue -> R2LPagerViewer(this)
VERTICAL -> VerticalPagerViewer(this) ReadingModeType.VERTICAL.prefValue -> VerticalPagerViewer(this)
WEBTOON -> WebtoonViewer(this) ReadingModeType.WEBTOON.prefValue -> WebtoonViewer(this)
VERTICAL_PLUS -> WebtoonViewer(this, isContinuous = false) ReadingModeType.CONTINUOUS_VERTICAL.prefValue -> WebtoonViewer(this, isContinuous = false)
else -> L2RPagerViewer(this) else -> L2RPagerViewer(this)
} }

View File

@ -57,7 +57,7 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BaseBottomShee
activity.presenter.setMangaViewer(position) activity.presenter.setMangaViewer(position)
val mangaViewer = activity.presenter.getMangaViewer() val mangaViewer = activity.presenter.getMangaViewer()
if (mangaViewer == ReaderActivity.WEBTOON || mangaViewer == ReaderActivity.VERTICAL_PLUS) { if (mangaViewer == ReadingModeType.WEBTOON.prefValue || mangaViewer == ReadingModeType.CONTINUOUS_VERTICAL.prefValue) {
initWebtoonPreferences() initWebtoonPreferences()
} else { } else {
initPagerPreferences() 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:layout_gravity="bottom"
android:background="?attr/colorPrimary"> android:background="?attr/colorPrimary">
<!-- <ImageButton--> <ImageButton
<!-- android:id="@+id/action_reader_mode"--> android:id="@+id/action_reader_mode"
<!-- android:layout_width="wrap_content"--> android:layout_width="wrap_content"
<!-- android:layout_height="match_parent"--> android:layout_height="match_parent"
<!-- android:background="?selectableItemBackgroundBorderless"--> android:background="?selectableItemBackgroundBorderless"
<!-- android:contentDescription="@string/viewer"--> android:contentDescription="@string/viewer"
<!-- android:padding="@dimen/material_layout_keylines_screen_edge_margin"--> android:padding="@dimen/material_layout_keylines_screen_edge_margin"
<!-- app:layout_constraintEnd_toStartOf="@id/action_rotation"--> app:layout_constraintEnd_toStartOf="@id/action_rotation"
<!-- app:layout_constraintStart_toStartOf="parent"--> app:layout_constraintStart_toStartOf="parent"
<!-- app:layout_constraintTop_toTopOf="parent"--> app:layout_constraintTop_toTopOf="parent"
<!-- app:srcCompat="@drawable/ic_book_24dp"--> app:srcCompat="@drawable/ic_book_24dp"
<!-- app:tint="?attr/colorOnPrimary" />--> app:tint="?attr/colorOnPrimary" />
<!-- app:layout_constraintStart_toEndOf="@+id/action_reader_mode" -->
<ImageButton <ImageButton
android:id="@+id/action_rotation" android:id="@+id/action_rotation"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -167,7 +166,7 @@
android:contentDescription="@string/pref_rotation_type" android:contentDescription="@string/pref_rotation_type"
android:padding="@dimen/material_layout_keylines_screen_edge_margin" android:padding="@dimen/material_layout_keylines_screen_edge_margin"
app:layout_constraintEnd_toStartOf="@id/action_custom_filter" 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:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_screen_rotation_24dp" app:srcCompat="@drawable/ic_screen_rotation_24dp"
app:tint="?attr/colorOnPrimary" /> app:tint="?attr/colorOnPrimary" />