Adding option to show reader mode in bottom nav

Instead of clicking through, it's showing a popup to pick the reading mode

Co-Authored-By: arkon <4098258+arkon@users.noreply.github.com>
This commit is contained in:
Jays2Kings 2021-04-15 03:23:56 -04:00
parent f12be4a480
commit 5774dea854
10 changed files with 194 additions and 6 deletions

View File

@ -13,6 +13,7 @@ import android.graphics.drawable.AnimatedVectorDrawable
import android.graphics.drawable.LayerDrawable import android.graphics.drawable.LayerDrawable
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.Gravity
import android.view.KeyEvent import android.view.KeyEvent
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
@ -24,11 +25,14 @@ import android.view.animation.Animation
import android.view.animation.AnimationUtils import android.view.animation.AnimationUtils
import android.widget.SeekBar import android.widget.SeekBar
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.appcompat.view.menu.MenuBuilder
import androidx.appcompat.widget.PopupMenu
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.graphics.ColorUtils import androidx.core.graphics.ColorUtils
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.core.view.GestureDetectorCompat import androidx.core.view.GestureDetectorCompat
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import androidx.core.view.forEach
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetBehavior
@ -51,6 +55,7 @@ import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Success
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters
import eu.kanade.tachiyomi.ui.reader.settings.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.PageLayout import eu.kanade.tachiyomi.ui.reader.viewer.pager.PageLayout
@ -59,6 +64,7 @@ import eu.kanade.tachiyomi.ui.reader.viewer.pager.R2LPagerViewer
import eu.kanade.tachiyomi.ui.reader.viewer.pager.VerticalPagerViewer import eu.kanade.tachiyomi.ui.reader.viewer.pager.VerticalPagerViewer
import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonViewer import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonViewer
import eu.kanade.tachiyomi.ui.webview.WebViewActivity import eu.kanade.tachiyomi.ui.webview.WebViewActivity
import eu.kanade.tachiyomi.util.lang.tintText
import eu.kanade.tachiyomi.util.storage.getUriCompat import eu.kanade.tachiyomi.util.storage.getUriCompat
import eu.kanade.tachiyomi.util.system.GLUtil import eu.kanade.tachiyomi.util.system.GLUtil
import eu.kanade.tachiyomi.util.system.ThemeUtil import eu.kanade.tachiyomi.util.system.ThemeUtil
@ -214,6 +220,7 @@ class ReaderActivity :
enum class BottomButton(val value: String, @StringRes val stringRes: Int) { enum class BottomButton(val value: String, @StringRes val stringRes: Int) {
ViewChapters("vc", R.string.view_chapters), ViewChapters("vc", R.string.view_chapters),
WebView("wb", R.string.open_in_webview), WebView("wb", R.string.open_in_webview),
ReadingMode("rm", R.string.reading_mode),
CropBordersPaged("cbp", R.string.crop_borders_paged), CropBordersPaged("cbp", R.string.crop_borders_paged),
CropBordersWebtoon("cbw", R.string.crop_borders_webtoon), CropBordersWebtoon("cbw", R.string.crop_borders_webtoon),
PageLayout("pl", R.string.page_layout), PageLayout("pl", R.string.page_layout),
@ -420,8 +427,9 @@ class ReaderActivity :
} }
} }
private fun updateBasicShortcuts() { private fun updateBottomShortcuts() {
with(binding.chaptersSheet) { with(binding.chaptersSheet) {
readingMode.isVisible = presenter?.manga?.isLongStrip() != true && BottomButton.ReadingMode.value in preferences.readerBottomButtons().get()
doublePage.isVisible = viewer is PagerViewer && doublePage.isVisible = viewer is PagerViewer &&
BottomButton.PageLayout.value in preferences.readerBottomButtons().get() BottomButton.PageLayout.value in preferences.readerBottomButtons().get()
cropBordersSheetButton.isVisible = cropBordersSheetButton.isVisible =
@ -542,7 +550,7 @@ class ReaderActivity :
/** /**
* Initializes the reader menu. It sets up click listeners and the initial visibility. * Initializes the reader menu. It sets up click listeners and the initial visibility.
*/ */
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility", "RestrictedApi")
private fun initializeMenu() { private fun initializeMenu() {
// Set binding.toolbar // Set binding.toolbar
setSupportActionBar(binding.toolbar) setSupportActionBar(binding.toolbar)
@ -583,6 +591,38 @@ class ReaderActivity :
) preferences.cropBorders() else preferences.cropBordersWebtoon() ) preferences.cropBorders() else preferences.cropBordersWebtoon()
pref.toggle() pref.toggle()
} }
readingMode.setOnClickListener {
val popup = PopupMenu(this@ReaderActivity, readingMode, Gravity.END)
val enumConstants = ReadingModeType::class.java.enumConstants
val array = enumConstants?.map { it.stringRes }.orEmpty().toTypedArray()
array.forEachIndexed { index, entry ->
popup.menu.add(0, index, 0, entry)
}
if (popup.menu is MenuBuilder) {
val m = popup.menu as MenuBuilder
m.setOptionalIconsVisible(true)
}
val blendedAccent = ColorUtils.blendARGB(
this@ReaderActivity.getResourceColor(android.R.attr.colorAccent),
this@ReaderActivity.getResourceColor(android.R.attr.textColorPrimary),
0.5f
)
popup.menu.forEach {
it.icon = ContextCompat.getDrawable(this@ReaderActivity, R.drawable.ic_blank_24dp)
}
popup.menu.getItem(presenter.manga?.viewer ?: 0)?.let { menuItem ->
menuItem.icon =
ContextCompat.getDrawable(this@ReaderActivity, R.drawable.ic_check_24dp)
?.mutate()?.apply { setTint(blendedAccent) }
menuItem.title =
menuItem.title?.tintText(blendedAccent)
}
popup.setOnMenuItemClickListener { menuItem ->
presenter.setMangaViewer(menuItem.itemId)
true
}
popup.show()
}
} }
listOf(preferences.cropBorders(), preferences.cropBordersWebtoon()) listOf(preferences.cropBorders(), preferences.cropBordersWebtoon())
@ -870,7 +910,9 @@ class ReaderActivity :
binding.pleaseWait.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in_long)) binding.pleaseWait.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in_long))
invalidateOptionsMenu() invalidateOptionsMenu()
updateCropBordersShortcut() updateCropBordersShortcut()
updateBasicShortcuts() updateBottomShortcuts()
val viewerMode = ReadingModeType.fromPreference(presenter?.manga?.viewer ?: 0)
binding.chaptersSheet.readingMode.setImageResource(viewerMode.iconRes)
} }
override fun onPause() { override fun onPause() {
@ -1394,7 +1436,7 @@ class ReaderActivity :
preferences.readerBottomButtons().asFlow() preferences.readerBottomButtons().asFlow()
.onEach { .onEach {
updateBasicShortcuts() updateBottomShortcuts()
} }
.launchIn(scope) .launchIn(scope)
} }

View File

@ -0,0 +1,30 @@
package eu.kanade.tachiyomi.ui.reader.settings
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.lang.next
enum class ReadingModeType(val prefValue: Int, @StringRes val stringRes: Int, @DrawableRes val iconRes: Int) {
DEFAULT(0, R.string.default_value, R.drawable.ic_reader_default_24dp),
LEFT_TO_RIGHT(1, R.string.left_to_right_viewer, R.drawable.ic_reader_ltr_24dp),
RIGHT_TO_LEFT(2, R.string.right_to_left_viewer, R.drawable.ic_reader_rtl_24dp),
VERTICAL(3, R.string.vertical_viewer, R.drawable.ic_reader_vertical_24dp),
WEBTOON(4, R.string.webtoon, R.drawable.ic_reader_webtoon_24dp),
CONTINUOUS_VERTICAL(5, R.string.continuous_vertical, R.drawable.ic_reader_continuous_vertical_24dp),
;
companion object {
fun fromPreference(preference: Int): ReadingModeType = values().find { it.prefValue == preference } ?: DEFAULT
fun getNextReadingMode(preference: Int): ReadingModeType {
val current = fromPreference(preference)
return current.next()
}
fun isPagerType(preference: Int): Boolean {
val mode = fromPreference(preference)
return mode == LEFT_TO_RIGHT || mode == RIGHT_TO_LEFT || mode == VERTICAL
}
}
}

View File

@ -0,0 +1,7 @@
package eu.kanade.tachiyomi.util.lang
inline fun <reified T : Enum<T>> T.next(): T {
val values = enumValues<T>()
val nextOrdinal = (ordinal + 1) % values.size
return values[nextOrdinal]
}

View File

@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/black"
android:pathData="M17.3159,1h-10a2.0059,2.0059 0,0 0,-2 2L5.3159,21a2.0059,2.0059 0,0 0,2 2h10a2.0059,2.0059 0,0 0,2 -2L19.3159,3A2.0059,2.0059 0,0 0,17.3159 1ZM17.3159,21h-10L7.3159,3h10Z" />
<path
android:fillColor="@android:color/black"
android:pathData="M11.3083,5h2v5.5h-2z" />
<path
android:fillColor="@android:color/black"
android:pathData="M15.308,16l-2,0l0,-4.5l-2,0l0,4.5l-2,0l3,3l3,-3z" />
</vector>

View File

@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/black"
android:pathData="M6.9906,18L6.9906,6h12L18.9906,3a2.0059,2.0059 0,0 0,-2 -2h-10a2.0059,2.0059 0,0 0,-2 2L4.9906,21a2.0059,2.0059 0,0 0,2 2h10a2.0059,2.0059 0,0 0,2 -2L18.9906,18h-12ZM6.9906,3h10L16.9906,4h-10ZM16.9906,21h-10L6.9906,20h10Z" />
<path
android:fillColor="@android:color/black"
android:pathData="M21.7706,12.44l-0.02,0.03a3.5546,3.5546 0,0 0,0.05 -0.47,3.9031 3.9031,0 0,0 -0.05,-0.48l0.02,0.03 0.85,-0.68a0.5068,0.5068 0,0 0,0.12 -0.64l-0.84,-1.46a0.4986,0.4986 0,0 0,-0.61 -0.22l-1.01,0.39 0.0099,0.04a3.6135,3.6135 0,0 0,-0.8 -0.48l-0.17,-1.07a0.4879,0.4879 0,0 0,-0.49 -0.43h-1.68a0.4876,0.4876 0,0 0,-0.49 0.42l-0.17,1.08a3.6149,3.6149 0,0 0,-0.8 0.48l0.02,-0.03 -1.01,-0.39a0.4878,0.4878 0,0 0,-0.61 0.22l-0.84,1.46a0.5068,0.5068 0,0 0,0.12 0.64l0.85,0.68 0.02,-0.03a3.9148,3.9148 0,0 0,-0.05 0.48,3.915 3.915,0 0,0 0.05,0.48l-0.02,-0.03 -0.85,0.68a0.5068,0.5068 0,0 0,-0.12 0.64l0.84,1.46a0.4985,0.4985 0,0 0,0.61 0.22l1.01,-0.39 -0.02,-0.03a4.4991,4.4991 0,0 0,0.8 0.46l0.17,1.08a0.4876,0.4876 0,0 0,0.49 0.42h1.68a0.4876,0.4876 0,0 0,0.49 -0.42l0.17,-1.08a3.6138,3.6138 0,0 0,0.8 -0.48l-0.02,0.03 1.02,0.39a0.4879,0.4879 0,0 0,0.61 -0.22l0.84,-1.46a0.5068,0.5068 0,0 0,-0.12 -0.64ZM17.9906,14a2,2 0,1 1,2 -2A2.0059,2.0059 0,0 1,17.9906 14Z" />
</vector>

View File

@ -0,0 +1,21 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/black"
android:pathData="M17.3159,18h-10L7.3159,16h-2v5a2.0059,2.0059 0,0 0,2 2h10a2.0059,2.0059 0,0 0,2 -2L19.3159,16h-2ZM17.3159,21h-10L7.3159,20h10Z" />
<path
android:fillColor="@android:color/black"
android:pathData="M7.3159,6h10L17.3159,8h2L19.3159,3a2.0059,2.0059 0,0 0,-2 -2h-10a2.0059,2.0059 0,0 0,-2 2L5.3159,8h2ZM7.3159,3h10L17.3159,4h-10Z" />
<path
android:fillColor="@android:color/black"
android:pathData="M22.311,12l-3,-3l0,2l-11.99,0l0,2l11.99,0l0,2l3,-3z" />
<path
android:fillColor="@android:color/black"
android:pathData="M2.3206,11h1.5v2h-1.5z" />
<path
android:fillColor="@android:color/black"
android:pathData="M4.8206,11h1.5v2h-1.5z" />
</vector>

View File

@ -0,0 +1,21 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/black"
android:pathData="M7,6H17V8h2V3a2.0059,2.0059 0,0 0,-2 -2H7A2.0059,2.0059 0,0 0,5 3V8H7ZM7,3H17V4H7Z" />
<path
android:fillColor="@android:color/black"
android:pathData="M17,18L7,18L7,16L5,16v5a2.0059,2.0059 0,0 0,2 2L17,23a2.0059,2.0059 0,0 0,2 -2L19,16L17,16ZM17,21L7,21L7,20L17,20Z" />
<path
android:fillColor="@android:color/black"
android:pathData="M5.005,13l11.99,0l0,-2l-11.99,0l0,-2l-3,3l3,3l0,-2z" />
<path
android:fillColor="@android:color/black"
android:pathData="M20.4953,11h1.5v2h-1.5z" />
<path
android:fillColor="@android:color/black"
android:pathData="M17.9953,11h1.5v2h-1.5z" />
</vector>

View File

@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/black"
android:pathData="M17,1L7,1A2.0059,2.0059 0,0 0,5 3L5,21a2.0059,2.0059 0,0 0,2 2L17,23a2.0059,2.0059 0,0 0,2 -2L19,3A2.0059,2.0059 0,0 0,17 1ZM17,3v1.0462L7,4.0462L7,3ZM17,6.0462v12L7,18.0462v-12ZM7,21v-0.9538L17,20.0462L17,21Z" />
<path
android:fillColor="@android:color/black"
android:pathData="M9,13l3,3l3,-3l-2,0l0,-5l-2,0l0,5l-2,0z" />
</vector>

View File

@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/black"
android:pathData="M11.992,19l3,-3l-2,0l0,-11l-2,0l0,11l-2,0l3,3z" />
<path
android:fillColor="@android:color/black"
android:pathData="M17,1L7,1A2.0059,2.0059 0,0 0,5 3L5,21a2.0059,2.0059 0,0 0,2 2L17,23a2.0059,2.0059 0,0 0,2 -2L19,3A2.0059,2.0059 0,0 0,17 1ZM17,21L7,21L7,3L17,3Z" />
</vector>

View File

@ -58,10 +58,26 @@
app:layout_constraintHorizontal_chainStyle="spread" app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/chapters_button" app:layout_constraintStart_toEndOf="@id/chapters_button"
app:layout_constraintEnd_toStartOf="@id/crop_borders_sheet_button" app:layout_constraintEnd_toStartOf="@id/reading_mode"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_open_in_webview_24dp" /> app:srcCompat="@drawable/ic_open_in_webview_24dp" />
<ImageButton
android:id="@+id/reading_mode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/reading_mode"
android:padding="@dimen/material_layout_keylines_screen_edge_margin"
app:tint="?actionBarTintColor"
android:tooltipText="@string/reading_mode"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/webview_button"
app:layout_constraintEnd_toStartOf="@id/crop_borders_sheet_button"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_reader_default_24dp" />
<ImageButton <ImageButton
android:id="@+id/crop_borders_sheet_button" android:id="@+id/crop_borders_sheet_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -74,7 +90,7 @@
app:layout_constraintHorizontal_chainStyle="spread" app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
android:visibility="gone" android:visibility="gone"
app:layout_constraintStart_toEndOf="@id/webview_button" app:layout_constraintStart_toEndOf="@id/reading_mode"
app:layout_constraintEnd_toStartOf="@id/double_page" app:layout_constraintEnd_toStartOf="@id/double_page"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" tools:visibility="visible"