Binding Reader Activity and reader view

i want to die.
This commit is contained in:
Jays2Kings 2021-03-29 02:35:01 -04:00
parent 57abbd6eda
commit 7b91a8a23b
7 changed files with 129 additions and 125 deletions

View File

@ -32,6 +32,7 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.databinding.ReaderActivityBinding
import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity
import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.main.MainActivity
@ -71,8 +72,6 @@ import eu.kanade.tachiyomi.util.view.updatePaddingRelative
import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.util.view.visible
import eu.kanade.tachiyomi.widget.SimpleAnimationListener import eu.kanade.tachiyomi.widget.SimpleAnimationListener
import eu.kanade.tachiyomi.widget.SimpleSeekBarListener import eu.kanade.tachiyomi.widget.SimpleSeekBarListener
import kotlinx.android.synthetic.main.reader_activity.*
import kotlinx.android.synthetic.main.reader_chapters_sheet.*
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
@ -101,6 +100,8 @@ class ReaderActivity :
BaseRxActivity<ReaderPresenter>(), BaseRxActivity<ReaderPresenter>(),
SystemUiHelper.OnVisibilityChangeListener { SystemUiHelper.OnVisibilityChangeListener {
lateinit var binding: ReaderActivityBinding
/** /**
* Preferences helper. * Preferences helper.
*/ */
@ -186,7 +187,8 @@ class ReaderActivity :
AppCompatDelegate.setDefaultNightMode(ThemeUtil.nightMode(preferences.theme())) AppCompatDelegate.setDefaultNightMode(ThemeUtil.nightMode(preferences.theme()))
setTheme(ThemeUtil.theme(preferences.theme())) setTheme(ThemeUtil.theme(preferences.theme()))
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.reader_activity) binding = ReaderActivityBinding.inflate(layoutInflater)
setContentView(binding.root)
val a = obtainStyledAttributes(intArrayOf(android.R.attr.windowLightStatusBar)) val a = obtainStyledAttributes(intArrayOf(android.R.attr.windowLightStatusBar))
lightStatusBar = a.getBoolean(0, false) lightStatusBar = a.getBoolean(0, false)
a.recycle() a.recycle()
@ -196,9 +198,9 @@ class ReaderActivity :
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
systemUiFlag = systemUiFlag.or(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR) systemUiFlag = systemUiFlag.or(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR)
} }
reader_layout.systemUiVisibility = when (lightStatusBar) { binding.readerLayout.systemUiVisibility = when (lightStatusBar) {
true -> reader_layout.systemUiVisibility.or(systemUiFlag) true -> binding.readerLayout.systemUiVisibility.or(systemUiFlag)
false -> reader_layout.systemUiVisibility.rem(systemUiFlag) false -> binding.readerLayout.systemUiVisibility.rem(systemUiFlag)
} }
if (presenter.needsInit()) { if (presenter.needsInit()) {
@ -212,7 +214,7 @@ class ReaderActivity :
} }
presenter.init(manga, chapter) presenter.init(manga, chapter)
} else { } else {
please_wait.visible() binding.pleaseWait.visible()
} }
} }
@ -220,9 +222,9 @@ class ReaderActivity :
menuVisible = savedInstanceState.getBoolean(::menuVisible.name) menuVisible = savedInstanceState.getBoolean(::menuVisible.name)
} }
chapters_bottom_sheet.setup(this) binding.readerChaptersSheet.chaptersBottomSheet.setup(this)
if (ThemeUtil.isBlueTheme(preferences.theme())) { if (ThemeUtil.isBlueTheme(preferences.theme())) {
chapter_recycler.setBackgroundColor(getResourceColor(android.R.attr.colorBackground)) binding.readerChaptersSheet.chapterRecycler.setBackgroundColor(getResourceColor(android.R.attr.colorBackground))
} }
config = ReaderConfig() config = ReaderConfig()
initializeMenu() initializeMenu()
@ -234,7 +236,7 @@ class ReaderActivity :
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
viewer?.destroy() viewer?.destroy()
chapters_bottom_sheet.adapter = null binding.readerChaptersSheet.chaptersBottomSheet.adapter = null
viewer = null viewer = null
config = null config = null
bottomSheet?.dismiss() bottomSheet?.dismiss()
@ -272,7 +274,7 @@ class ReaderActivity :
} }
/** /**
* Called when the options menu of the toolbar is being created. It adds our custom menu. * Called when the options menu of the binding.toolbar is being created. It adds our custom menu.
*/ */
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.reader, menu) menuInflater.inflate(R.menu.reader, menu)
@ -289,7 +291,7 @@ class ReaderActivity :
R.id.action_display_settings -> TabbedReaderSettingsSheet(this).show() R.id.action_display_settings -> TabbedReaderSettingsSheet(this).show()
R.id.action_share_page, R.id.action_set_page_as_cover, R.id.action_save_page -> { R.id.action_share_page, R.id.action_set_page_as_cover, R.id.action_save_page -> {
val currentChapter = presenter.getCurrentChapter() ?: return true val currentChapter = presenter.getCurrentChapter() ?: return true
val page = currentChapter.pages?.getOrNull(page_seekbar.progress) ?: return true val page = currentChapter.pages?.getOrNull(binding.readerChaptersSheet.pageSeekBar.progress) ?: return true
when (item.itemId) { when (item.itemId) {
R.id.action_share_page -> shareImage(page) R.id.action_share_page -> shareImage(page)
R.id.action_set_page_as_cover -> showSetCoverPrompt(page) R.id.action_set_page_as_cover -> showSetCoverPrompt(page)
@ -319,12 +321,12 @@ class ReaderActivity :
} }
/** /**
* Called when the user clicks the back key or the button on the toolbar. The call is * Called when the user clicks the back key or the button on the binding.toolbar. The call is
* delegated to the presenter. * delegated to the presenter.
*/ */
override fun onBackPressed() { override fun onBackPressed() {
if (chapters_bottom_sheet.sheetBehavior.isExpanded()) { if (binding.readerChaptersSheet.chaptersBottomSheet.sheetBehavior.isExpanded()) {
chapters_bottom_sheet.sheetBehavior?.collapse() binding.readerChaptersSheet.chaptersBottomSheet.sheetBehavior?.collapse()
return return
} }
presenter.onBackPressed() presenter.onBackPressed()
@ -363,20 +365,20 @@ 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.
*/ */
private fun initializeMenu() { private fun initializeMenu() {
// Set toolbar // Set binding.toolbar
setSupportActionBar(toolbar) setSupportActionBar(binding.toolbar)
val primaryColor = ColorUtils.setAlphaComponent( val primaryColor = ColorUtils.setAlphaComponent(
getResourceColor(R.attr.colorSecondary), getResourceColor(R.attr.colorSecondary),
200 200
) )
appbar.setBackgroundColor(primaryColor) binding.appBar.setBackgroundColor(primaryColor)
window.statusBarColor = Color.TRANSPARENT window.statusBarColor = Color.TRANSPARENT
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
toolbar.setNavigationOnClickListener { binding.toolbar.setNavigationOnClickListener {
popToMain() popToMain()
} }
toolbar.setOnClickListener { binding.toolbar.setOnClickListener {
presenter.manga?.id?.let { id -> presenter.manga?.id?.let { id ->
val intent = SearchActivity.openMangaIntent(this, id) val intent = SearchActivity.openMangaIntent(this, id)
startActivity(intent) startActivity(intent)
@ -384,7 +386,7 @@ class ReaderActivity :
} }
// Init listeners on bottom menu // Init listeners on bottom menu
page_seekbar.setOnSeekBarChangeListener( binding.readerChaptersSheet.pageSeekBar.setOnSeekBarChangeListener(
object : SimpleSeekBarListener() { object : SimpleSeekBarListener() {
override fun onProgressChanged(seekBar: SeekBar, value: Int, fromUser: Boolean) { override fun onProgressChanged(seekBar: SeekBar, value: Int, fromUser: Boolean) {
if (viewer != null && fromUser) { if (viewer != null && fromUser) {
@ -396,10 +398,10 @@ class ReaderActivity :
// Set initial visibility // Set initial visibility
setMenuVisibility(menuVisible) setMenuVisibility(menuVisible)
chapters_bottom_sheet.sheetBehavior?.isHideable = !menuVisible binding.readerChaptersSheet.chaptersBottomSheet.sheetBehavior?.isHideable = !menuVisible
if (!menuVisible) chapters_bottom_sheet.sheetBehavior?.hide() if (!menuVisible) binding.readerChaptersSheet.chaptersBottomSheet.sheetBehavior?.hide()
val peek = chapters_bottom_sheet.sheetBehavior?.peekHeight ?: 30.dpToPx val peek = binding.readerChaptersSheet.chaptersBottomSheet.sheetBehavior?.peekHeight ?: 30.dpToPx
reader_layout.doOnApplyWindowInsets { v, insets, _ -> binding.readerLayout.doOnApplyWindowInsets { v, insets, _ ->
sheetManageNavColor = when { sheetManageNavColor = when {
insets.isBottomTappable() -> { insets.isBottomTappable() -> {
window.navigationBarColor = Color.TRANSPARENT window.navigationBarColor = Color.TRANSPARENT
@ -415,21 +417,21 @@ class ReaderActivity :
} }
} }
appbar.updateLayoutParams<ViewGroup.MarginLayoutParams> { binding.appBar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
leftMargin = insets.systemWindowInsetLeft leftMargin = insets.systemWindowInsetLeft
rightMargin = insets.systemWindowInsetRight rightMargin = insets.systemWindowInsetRight
} }
toolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> { binding.toolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = insets.systemWindowInsetTop topMargin = insets.systemWindowInsetTop
} }
chapters_bottom_sheet.updateLayoutParams<ViewGroup.MarginLayoutParams> { binding.readerChaptersSheet.chaptersBottomSheet.updateLayoutParams<ViewGroup.MarginLayoutParams> {
leftMargin = insets.systemWindowInsetLeft leftMargin = insets.systemWindowInsetLeft
rightMargin = insets.systemWindowInsetRight rightMargin = insets.systemWindowInsetRight
height = 280.dpToPx + insets.systemWindowInsetBottom height = 280.dpToPx + insets.systemWindowInsetBottom
} }
chapters_bottom_sheet.sheetBehavior?.peekHeight = peek + insets.getBottomGestureInsets() binding.readerChaptersSheet.chaptersBottomSheet.sheetBehavior?.peekHeight = peek + insets.getBottomGestureInsets()
chapter_recycler.updatePaddingRelative(bottom = insets.systemWindowInsetBottom) binding.readerChaptersSheet.chapterRecycler.updatePaddingRelative(bottom = insets.systemWindowInsetBottom)
viewer_container.requestLayout() binding.viewerContainer.requestLayout()
} }
} }
@ -440,16 +442,16 @@ class ReaderActivity :
private fun setMenuVisibility(visible: Boolean, animate: Boolean = true) { private fun setMenuVisibility(visible: Boolean, animate: Boolean = true) {
menuVisible = visible menuVisible = visible
if (visible) coroutine?.cancel() if (visible) coroutine?.cancel()
viewer_container.requestLayout() binding.viewerContainer.requestLayout()
if (visible) { if (visible) {
snackbar?.dismiss() snackbar?.dismiss()
systemUi?.show() systemUi?.show()
reader_menu.visible() binding.readerMenu.visible()
if (chapters_bottom_sheet.sheetBehavior.isExpanded()) { if (binding.readerChaptersSheet.chaptersBottomSheet.sheetBehavior.isExpanded()) {
chapters_bottom_sheet.sheetBehavior?.isHideable = false binding.readerChaptersSheet.chaptersBottomSheet.sheetBehavior?.isHideable = false
} }
if (!chapters_bottom_sheet.sheetBehavior.isExpanded() && sheetManageNavColor) { if (!binding.readerChaptersSheet.chaptersBottomSheet.sheetBehavior.isExpanded() && sheetManageNavColor) {
window.navigationBarColor = Color.TRANSPARENT window.navigationBarColor = Color.TRANSPARENT
} }
if (animate) { if (animate) {
@ -462,9 +464,9 @@ class ReaderActivity :
} }
} }
) )
appbar.startAnimation(toolbarAnimation) binding.appBar.startAnimation(toolbarAnimation)
} }
chapters_bottom_sheet.sheetBehavior?.collapse() binding.readerChaptersSheet.chaptersBottomSheet.sheetBehavior?.collapse()
} }
} else { } else {
systemUi?.hide() systemUi?.hide()
@ -474,15 +476,15 @@ class ReaderActivity :
toolbarAnimation.setAnimationListener( toolbarAnimation.setAnimationListener(
object : SimpleAnimationListener() { object : SimpleAnimationListener() {
override fun onAnimationEnd(animation: Animation) { override fun onAnimationEnd(animation: Animation) {
reader_menu.gone() binding.readerMenu.gone()
} }
} }
) )
appbar.startAnimation(toolbarAnimation) binding.appBar.startAnimation(toolbarAnimation)
BottomSheetBehavior.from(chapters_bottom_sheet).isHideable = true BottomSheetBehavior.from(binding.readerChaptersSheet.chaptersBottomSheet).isHideable = true
chapters_bottom_sheet.sheetBehavior?.hide() binding.readerChaptersSheet.chaptersBottomSheet.sheetBehavior?.hide()
} else { } else {
reader_menu.gone() binding.readerMenu.gone()
} }
} }
menuStickyVisible = false menuStickyVisible = false
@ -490,7 +492,7 @@ class ReaderActivity :
/** /**
* Called from the presenter when a manga is ready. Used to instantiate the appropriate viewer * Called from the presenter when a manga is ready. Used to instantiate the appropriate viewer
* and the toolbar title. * and the binding.toolbar title.
*/ */
fun setManga(manga: Manga) { fun setManga(manga: Manga) {
val prevViewer = viewer val prevViewer = viewer
@ -506,7 +508,7 @@ class ReaderActivity :
} }
if (noDefault && presenter.manga?.viewer!! > 0) { if (noDefault && presenter.manga?.viewer!! > 0) {
snackbar = reader_layout.snack( snackbar = binding.readerLayout.snack(
getString( getString(
R.string.reading_, R.string.reading_,
getString( getString(
@ -529,13 +531,13 @@ class ReaderActivity :
// Destroy previous viewer if there was one // Destroy previous viewer if there was one
if (prevViewer != null) { if (prevViewer != null) {
prevViewer.destroy() prevViewer.destroy()
viewer_container.removeAllViews() binding.viewerContainer.removeAllViews()
} }
viewer = newViewer viewer = newViewer
viewer_container.addView(newViewer.getView()) binding.viewerContainer.addView(newViewer.getView())
navigation_overlay.isLTR = !(viewer is L2RPagerViewer) binding.navigationOverlay.isLTR = !(viewer is L2RPagerViewer)
viewer_container.setBackgroundColor( binding.viewerContainer.setBackgroundColor(
if (viewer is WebtoonViewer) { if (viewer is WebtoonViewer) {
Color.BLACK Color.BLACK
} else { } else {
@ -543,12 +545,12 @@ class ReaderActivity :
} }
) )
toolbar.title = manga.title binding.toolbar.title = manga.title
page_seekbar.isRTL = newViewer is R2LPagerViewer binding.readerChaptersSheet.pageSeekBar.isRTL = newViewer is R2LPagerViewer
please_wait.visible() binding.pleaseWait.visible()
please_wait.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in_long)) binding.pleaseWait.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in_long))
} }
override fun onPause() { override fun onPause() {
@ -558,14 +560,14 @@ class ReaderActivity :
/** /**
* Called from the presenter whenever a new [viewerChapters] have been set. It delegates the * Called from the presenter whenever a new [viewerChapters] have been set. It delegates the
* method to the current viewer, but also set the subtitle on the toolbar. * method to the current viewer, but also set the subtitle on the binding.toolbar.
*/ */
fun setChapters(viewerChapters: ViewerChapters) { fun setChapters(viewerChapters: ViewerChapters) {
please_wait.gone() binding.pleaseWait.gone()
viewer?.setChapters(viewerChapters) viewer?.setChapters(viewerChapters)
intentPageNumber?.let { moveToPageIndex(it) } intentPageNumber?.let { moveToPageIndex(it) }
intentPageNumber = null intentPageNumber = null
toolbar.subtitle = viewerChapters.currChapter.chapter.name binding.toolbar.subtitle = viewerChapters.currChapter.chapter.name
} }
/** /**
@ -581,7 +583,7 @@ class ReaderActivity :
/** /**
* Called from the presenter whenever it's loading the next or previous chapter. It shows or * Called from the presenter whenever it's loading the next or previous chapter. It shows or
* dismisses a non-cancellable dialog to prevent user interaction according to the value of * dismisses a non-cancellable dialog to prevent user interaction according to the value of
* [show]. This is only used when the next/previous buttons on the toolbar are clicked; the * [show]. This is only used when the next/previous buttons on the binding.toolbar are clicked; the
* other cases are handled with chapter transitions on the viewers and chapter preloading. * other cases are handled with chapter transitions on the viewers and chapter preloading.
*/ */
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
@ -606,7 +608,7 @@ class ReaderActivity :
} }
fun refreshChapters() { fun refreshChapters() {
chapters_bottom_sheet.refreshList() binding.readerChaptersSheet.chaptersBottomSheet.refreshList()
} }
/** /**
@ -619,21 +621,21 @@ class ReaderActivity :
val pages = page.chapter.pages ?: return val pages = page.chapter.pages ?: return
// Set bottom page number // Set bottom page number
page_number.text = "${page.number}/${pages.size}" binding.pageNumber.text = "${page.number}/${pages.size}"
// Set seekbar page number // Set seekbar page number
page_text.text = "${page.number} / ${pages.size}" binding.readerChaptersSheet.pageText.text = "${page.number} / ${pages.size}"
if (!newChapter && chapters_bottom_sheet.shouldCollapse && chapters_bottom_sheet.sheetBehavior.isExpanded()) { if (!newChapter && binding.readerChaptersSheet.chaptersBottomSheet.shouldCollapse && binding.readerChaptersSheet.chaptersBottomSheet.sheetBehavior.isExpanded()) {
chapters_bottom_sheet.sheetBehavior?.collapse() binding.readerChaptersSheet.chaptersBottomSheet.sheetBehavior?.collapse()
} }
if (chapters_bottom_sheet.selectedChapterId != page.chapter.chapter.id) { if (binding.readerChaptersSheet.chaptersBottomSheet.selectedChapterId != page.chapter.chapter.id) {
chapters_bottom_sheet.refreshList() binding.readerChaptersSheet.chaptersBottomSheet.refreshList()
} }
chapters_bottom_sheet.shouldCollapse = true binding.readerChaptersSheet.chaptersBottomSheet.shouldCollapse = true
// Set seekbar progress // Set seekbar progress
page_seekbar.max = pages.lastIndex binding.readerChaptersSheet.pageSeekBar.max = pages.lastIndex
page_seekbar.progress = page.index binding.readerChaptersSheet.pageSeekBar.progress = page.index
} }
/** /**
@ -763,7 +765,7 @@ class ReaderActivity :
} }
if (sheetManageNavColor) window.navigationBarColor = if (sheetManageNavColor) window.navigationBarColor =
getResourceColor(R.attr.colorSecondary) getResourceColor(R.attr.colorSecondary)
reader_menu.visible() binding.readerMenu.visible()
val toolbarAnimation = AnimationUtils.loadAnimation(this, R.anim.enter_from_top) val toolbarAnimation = AnimationUtils.loadAnimation(this, R.anim.enter_from_top)
toolbarAnimation.setAnimationListener( toolbarAnimation.setAnimationListener(
object : SimpleAnimationListener() { object : SimpleAnimationListener() {
@ -772,7 +774,7 @@ class ReaderActivity :
} }
} }
) )
appbar.startAnimation(toolbarAnimation) binding.appBar.startAnimation(toolbarAnimation)
} }
} else { } else {
if (menuStickyVisible && !menuVisible) { if (menuStickyVisible && !menuVisible) {
@ -922,7 +924,7 @@ class ReaderActivity :
* Sets the visibility of the bottom page indicator according to [visible]. * Sets the visibility of the bottom page indicator according to [visible].
*/ */
private fun setPageNumberVisibility(visible: Boolean) { private fun setPageNumberVisibility(visible: Boolean) {
page_number.visibility = if (visible) View.VISIBLE else View.INVISIBLE binding.pageNumber.visibility = if (visible) View.VISIBLE else View.INVISIBLE
} }
/** /**
@ -985,7 +987,7 @@ class ReaderActivity :
.onEach { setColorFilterValue(it) } .onEach { setColorFilterValue(it) }
.launchIn(scope) .launchIn(scope)
} else { } else {
color_overlay.gone() binding.colorOverlay.gone()
} }
} }
@ -1011,11 +1013,11 @@ class ReaderActivity :
// Set black overlay visibility. // Set black overlay visibility.
if (value < 0) { if (value < 0) {
brightness_overlay.visible() binding.brightnessOverlay.visible()
val alpha = (abs(value) * 2.56).toInt() val alpha = (abs(value) * 2.56).toInt()
brightness_overlay.setBackgroundColor(Color.argb(alpha, 0, 0, 0)) binding.brightnessOverlay.setBackgroundColor(Color.argb(alpha, 0, 0, 0))
} else { } else {
brightness_overlay.gone() binding.brightnessOverlay.gone()
} }
} }
@ -1023,8 +1025,8 @@ class ReaderActivity :
* Sets the color filter [value]. * Sets the color filter [value].
*/ */
private fun setColorFilterValue(value: Int) { private fun setColorFilterValue(value: Int) {
color_overlay.visible() binding.colorOverlay.visible()
color_overlay.setFilterColor(value, preferences.colorFilterMode().get()) binding.colorOverlay.setFilterColor(value, preferences.colorFilterMode().get())
} }
} }
} }

View File

@ -14,6 +14,7 @@ import com.mikepenz.fastadapter.FastAdapter
import com.mikepenz.fastadapter.adapters.ItemAdapter import com.mikepenz.fastadapter.adapters.ItemAdapter
import com.mikepenz.fastadapter.listeners.ClickEventHook import com.mikepenz.fastadapter.listeners.ClickEventHook
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.ReaderChaptersSheetBinding
import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.ui.reader.ReaderPresenter import eu.kanade.tachiyomi.ui.reader.ReaderPresenter
import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.dpToPx
@ -24,7 +25,6 @@ import eu.kanade.tachiyomi.util.view.expand
import eu.kanade.tachiyomi.util.view.isExpanded import eu.kanade.tachiyomi.util.view.isExpanded
import eu.kanade.tachiyomi.util.view.visInvisIf import eu.kanade.tachiyomi.util.view.visInvisIf
import eu.kanade.tachiyomi.util.view.visibleIf import eu.kanade.tachiyomi.util.view.visibleIf
import kotlinx.android.synthetic.main.reader_chapters_sheet.view.*
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min
import kotlin.math.roundToInt import kotlin.math.roundToInt
@ -39,13 +39,20 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
var shouldCollapse = true var shouldCollapse = true
var selectedChapterId = -1L var selectedChapterId = -1L
lateinit var binding: ReaderChaptersSheetBinding
override fun onFinishInflate() {
super.onFinishInflate()
binding = ReaderChaptersSheetBinding.bind(this)
}
fun setup(activity: ReaderActivity) { fun setup(activity: ReaderActivity) {
presenter = activity.presenter presenter = activity.presenter
val fullPrimary = activity.getResourceColor(R.attr.colorSecondary) val fullPrimary = activity.getResourceColor(R.attr.colorSecondary)
val primary = ColorUtils.setAlphaComponent(fullPrimary, 200) val primary = ColorUtils.setAlphaComponent(fullPrimary, 200)
sheetBehavior = BottomSheetBehavior.from(this) sheetBehavior = BottomSheetBehavior.from(this)
chapters_button.setOnClickListener { binding.chaptersButton.setOnClickListener {
if (sheetBehavior.isExpanded()) { if (sheetBehavior.isExpanded()) {
sheetBehavior?.collapse() sheetBehavior?.collapse()
} else { } else {
@ -53,28 +60,28 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
} }
} }
webview_button.setOnClickListener { binding.webviewButton.setOnClickListener {
activity.openMangaInBrowser() activity.openMangaInBrowser()
} }
post { post {
chapter_recycler?.alpha = if (sheetBehavior.isExpanded()) 1f else 0f binding.chapterRecycler.alpha = if (sheetBehavior.isExpanded()) 1f else 0f
chapter_recycler?.isClickable = sheetBehavior.isExpanded() binding.chapterRecycler.isClickable = sheetBehavior.isExpanded()
chapter_recycler?.isFocusable = sheetBehavior.isExpanded() binding.chapterRecycler.isFocusable = sheetBehavior.isExpanded()
} }
sheetBehavior?.addBottomSheetCallback( sheetBehavior?.addBottomSheetCallback(
object : BottomSheetBehavior.BottomSheetCallback() { object : BottomSheetBehavior.BottomSheetCallback() {
override fun onSlide(bottomSheet: View, progress: Float) { override fun onSlide(bottomSheet: View, progress: Float) {
pill.alpha = (1 - max(0f, progress)) * 0.25f binding.pill.alpha = (1 - max(0f, progress)) * 0.25f
val trueProgress = max(progress, 0f) val trueProgress = max(progress, 0f)
chapters_button.alpha = 1 - trueProgress binding.chaptersButton.alpha = 1 - trueProgress
webview_button.alpha = trueProgress binding.webviewButton.alpha = trueProgress
webview_button.visibleIf(webview_button.alpha > 0) binding.webviewButton.visibleIf(binding.webviewButton.alpha > 0)
chapters_button.visInvisIf(chapters_button.alpha > 0) binding.chaptersButton.visInvisIf(binding.chaptersButton.alpha > 0)
backgroundTintList = backgroundTintList =
ColorStateList.valueOf(lerpColor(primary, fullPrimary, trueProgress)) ColorStateList.valueOf(lerpColor(primary, fullPrimary, trueProgress))
chapter_recycler.alpha = trueProgress binding.chapterRecycler.alpha = trueProgress
if (activity.sheetManageNavColor && progress > 0f) { if (activity.sheetManageNavColor && progress > 0f) {
activity.window.navigationBarColor = activity.window.navigationBarColor =
lerpColor(ColorUtils.setAlphaComponent(primary, 0), primary, trueProgress) lerpColor(ColorUtils.setAlphaComponent(primary, 0), primary, trueProgress)
@ -85,29 +92,29 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
if (state == BottomSheetBehavior.STATE_COLLAPSED) { if (state == BottomSheetBehavior.STATE_COLLAPSED) {
shouldCollapse = true shouldCollapse = true
sheetBehavior?.isHideable = false sheetBehavior?.isHideable = false
(chapter_recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset( (binding.chapterRecycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(
adapter?.getPosition(presenter.getCurrentChapter()?.chapter?.id ?: 0L) ?: 0, adapter?.getPosition(presenter.getCurrentChapter()?.chapter?.id ?: 0L) ?: 0,
chapter_recycler.height / 2 - 30.dpToPx binding.chapterRecycler.height / 2 - 30.dpToPx
) )
chapters_button.alpha = 1f binding.chaptersButton.alpha = 1f
webview_button.alpha = 0f binding.webviewButton.alpha = 0f
} }
if (state == BottomSheetBehavior.STATE_EXPANDED) { if (state == BottomSheetBehavior.STATE_EXPANDED) {
chapter_recycler.alpha = 1f binding.chapterRecycler.alpha = 1f
chapters_button.alpha = 0f binding.chaptersButton.alpha = 0f
webview_button.alpha = 1f binding.webviewButton.alpha = 1f
if (activity.sheetManageNavColor) activity.window.navigationBarColor = primary if (activity.sheetManageNavColor) activity.window.navigationBarColor = primary
} }
chapter_recycler.isClickable = state == BottomSheetBehavior.STATE_EXPANDED binding.chapterRecycler.isClickable = state == BottomSheetBehavior.STATE_EXPANDED
chapter_recycler.isFocusable = state == BottomSheetBehavior.STATE_EXPANDED binding.chapterRecycler.isFocusable = state == BottomSheetBehavior.STATE_EXPANDED
webview_button.visibleIf(state != BottomSheetBehavior.STATE_COLLAPSED) binding.webviewButton.visibleIf(state != BottomSheetBehavior.STATE_COLLAPSED)
chapters_button.visInvisIf(state != BottomSheetBehavior.STATE_EXPANDED) binding.chaptersButton.visInvisIf(state != BottomSheetBehavior.STATE_EXPANDED)
} }
} }
) )
adapter = FastAdapter.with(itemAdapter) adapter = FastAdapter.with(itemAdapter)
chapter_recycler.adapter = adapter binding.chapterRecycler.adapter = adapter
adapter?.onClickListener = { _, _, item, _ -> adapter?.onClickListener = { _, _, item, _ ->
if (!sheetBehavior.isExpanded()) { if (!sheetBehavior.isExpanded()) {
false false
@ -146,7 +153,7 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
else fullPrimary else fullPrimary
) )
chapter_recycler.layoutManager = LinearLayoutManager(context) binding.chapterRecycler.layoutManager = LinearLayoutManager(context)
refreshList() refreshList()
} }
@ -158,9 +165,9 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
itemAdapter.clear() itemAdapter.clear()
itemAdapter.add(chapters) itemAdapter.add(chapters)
(chapter_recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset( (binding.chapterRecycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(
adapter?.getPosition(presenter.getCurrentChapter()?.chapter?.id ?: 0L) ?: 0, adapter?.getPosition(presenter.getCurrentChapter()?.chapter?.id ?: 0L) ?: 0,
chapter_recycler.height / 2 - 30.dpToPx binding.chapterRecycler.height / 2 - 30.dpToPx
) )
} }
} }

View File

@ -8,10 +8,6 @@ import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.visInvisIf import eu.kanade.tachiyomi.util.view.visInvisIf
import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.util.view.visible
import eu.kanade.tachiyomi.widget.TabbedBottomSheetDialog import eu.kanade.tachiyomi.widget.TabbedBottomSheetDialog
import kotlinx.android.synthetic.main.reader_activity.*
import kotlinx.android.synthetic.main.reader_color_filter.view.*
import kotlinx.android.synthetic.main.recycler_with_scroller.view.*
import kotlinx.android.synthetic.main.tabbed_bottom_sheet.*
class TabbedReaderSettingsSheet(val readerActivity: ReaderActivity) : TabbedBottomSheetDialog( class TabbedReaderSettingsSheet(val readerActivity: ReaderActivity) : TabbedBottomSheetDialog(
readerActivity readerActivity
@ -57,14 +53,14 @@ class TabbedReaderSettingsSheet(val readerActivity: ReaderActivity) : TabbedBott
filterView.activity = readerActivity filterView.activity = readerActivity
generalView.sheet = this generalView.sheet = this
menu.gone() binding.menu.gone()
val attrs = window?.attributes val attrs = window?.attributes
val ogDim = attrs?.dimAmount ?: 0.25f val ogDim = attrs?.dimAmount ?: 0.25f
pager.adapter?.notifyDataSetChanged() binding.pager.adapter?.notifyDataSetChanged()
tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { binding.tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab?) { override fun onTabSelected(tab: TabLayout.Tab?) {
window?.setDimAmount(if (tab?.position == 2) 0f else ogDim) window?.setDimAmount(if (tab?.position == 2) 0f else ogDim)
readerActivity.appbar.visInvisIf(tab?.position != 2) readerActivity.binding.appBar.visInvisIf(tab?.position != 2)
} }
override fun onTabUnselected(tab: TabLayout.Tab?) { override fun onTabUnselected(tab: TabLayout.Tab?) {
@ -77,12 +73,12 @@ class TabbedReaderSettingsSheet(val readerActivity: ReaderActivity) : TabbedBott
override fun dismiss() { override fun dismiss() {
super.dismiss() super.dismiss()
readerActivity.appbar.visible() readerActivity.binding.appBar.visible()
} }
fun updateTabs(isWebtoon: Boolean) { fun updateTabs(isWebtoon: Boolean) {
showWebview = isWebtoon showWebview = isWebtoon
pager.adapter?.notifyDataSetChanged() binding.pager.adapter?.notifyDataSetChanged()
pagedView.updatePrefs() pagedView.updatePrefs()
} }
} }

View File

@ -16,7 +16,6 @@ import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation
import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.util.view.visible
import kotlinx.android.synthetic.main.reader_activity.*
import timber.log.Timber import timber.log.Timber
/** /**
@ -107,9 +106,9 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
config.navigationModeChangedListener = { config.navigationModeChangedListener = {
val showOnStart = config.navigationOverlayForNewUser val showOnStart = config.navigationOverlayForNewUser
activity.navigation_overlay.setNavigation(config.navigator, showOnStart) activity.binding.navigationOverlay.setNavigation(config.navigator, showOnStart)
} }
config.navigationModeInvertedListener = { activity.navigation_overlay.showNavigationAgain() } config.navigationModeInvertedListener = { activity.binding.navigationOverlay.showNavigationAgain() }
} }
/** /**

View File

@ -16,7 +16,6 @@ import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters
import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation
import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.util.view.visible
import kotlinx.android.synthetic.main.reader_activity.*
import rx.subscriptions.CompositeSubscription import rx.subscriptions.CompositeSubscription
import timber.log.Timber import timber.log.Timber
import kotlin.math.max import kotlin.math.max
@ -126,9 +125,9 @@ class WebtoonViewer(val activity: ReaderActivity, val hasMargins: Boolean = fals
config.navigationModeChangedListener = { config.navigationModeChangedListener = {
val showOnStart = config.navigationOverlayForNewUser val showOnStart = config.navigationOverlayForNewUser
activity.navigation_overlay.setNavigation(config.navigator, showOnStart) activity.binding.navigationOverlay.setNavigation(config.navigator, showOnStart)
} }
config.navigationModeInvertedListener = { activity.navigation_overlay.showNavigationAgain() } config.navigationModeInvertedListener = { activity.binding.navigationOverlay.showNavigationAgain() }
frame.layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT) frame.layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)
frame.addView(recycler) frame.addView(recycler)

View File

@ -47,7 +47,7 @@
android:visibility="gone" > android:visibility="gone" >
<FrameLayout <FrameLayout
android:id="@+id/appbar" android:id="@+id/app_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/colorSecondary"> android:background="?attr/colorSecondary">
@ -61,7 +61,8 @@
</FrameLayout> </FrameLayout>
</FrameLayout> </FrameLayout>
<include layout="@layout/reader_chapters_sheet" /> <include layout="@layout/reader_chapters_sheet"
android:id="@+id/reader_chapters_sheet"/>
<View <View
android:id="@+id/brightness_overlay" android:id="@+id/brightness_overlay"

View File

@ -26,7 +26,7 @@
android:alpha="0.25" android:alpha="0.25"
android:contentDescription="@string/drag_handle" android:contentDescription="@string/drag_handle"
android:src="@drawable/draggable_pill" android:src="@drawable/draggable_pill"
android:tint="?actionBarTintColor" app:tint="?actionBarTintColor"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@ -38,7 +38,7 @@
android:background="?selectableItemBackgroundBorderless" android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/next_title" android:contentDescription="@string/next_title"
android:padding="@dimen/material_layout_keylines_screen_edge_margin" android:padding="@dimen/material_layout_keylines_screen_edge_margin"
android:tint="?actionBarTintColor" app:tint="?actionBarTintColor"
android:tooltipText="@string/view_chapters" android:tooltipText="@string/view_chapters"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
@ -52,7 +52,7 @@
android:background="?selectableItemBackgroundBorderless" android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/open_in_webview" android:contentDescription="@string/open_in_webview"
android:padding="@dimen/material_layout_keylines_screen_edge_margin" android:padding="@dimen/material_layout_keylines_screen_edge_margin"
android:tint="?actionBarTintColor" app:tint="?actionBarTintColor"
android:tooltipText="@string/open_in_webview" android:tooltipText="@string/open_in_webview"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
@ -61,7 +61,7 @@
app:srcCompat="@drawable/ic_open_in_webview_24dp" /> app:srcCompat="@drawable/ic_open_in_webview_24dp" />
<eu.kanade.tachiyomi.ui.reader.ReaderSeekBar <eu.kanade.tachiyomi.ui.reader.ReaderSeekBar
android:id="@+id/page_seekbar" android:id="@+id/page_seek_bar"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"