Fix the bottom sheet and remove the bookmark button at the top of the reader

This commit is contained in:
Jobobby04 2020-08-24 19:25:47 -04:00
parent 0a502fcf31
commit eafe3a62e4
6 changed files with 127 additions and 206 deletions

View File

@ -26,7 +26,6 @@ import androidx.core.view.setPadding
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
import com.elvishew.xlog.XLog import com.elvishew.xlog.XLog
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Chapter
@ -36,7 +35,6 @@ import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.asImmediateFlow import eu.kanade.tachiyomi.data.preference.asImmediateFlow
import eu.kanade.tachiyomi.databinding.ReaderActivityBinding import eu.kanade.tachiyomi.databinding.ReaderActivityBinding
import eu.kanade.tachiyomi.databinding.ReaderChaptersSheetBinding
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.source.online.HttpSource
@ -45,6 +43,7 @@ import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity
import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.AddToLibraryFirst import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.AddToLibraryFirst
import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Error import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Error
import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Success import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Success
import eu.kanade.tachiyomi.ui.reader.chapter.ReaderChapterSheet
import eu.kanade.tachiyomi.ui.reader.loader.HttpPageLoader import eu.kanade.tachiyomi.ui.reader.loader.HttpPageLoader
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
@ -67,10 +66,7 @@ import eu.kanade.tachiyomi.util.view.showBar
import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.snack
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 exh.util.collapse
import exh.util.defaultReaderType import exh.util.defaultReaderType
import exh.util.hide
import exh.util.isExpanded
import java.io.File import java.io.File
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.roundToLong import kotlin.math.roundToLong
@ -128,7 +124,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
private val logger = XLog.tag("ReaderActivity") private val logger = XLog.tag("ReaderActivity")
lateinit var readerBottomSheetBinding: ReaderChaptersSheetBinding private lateinit var chapterBottomSheet: ReaderChapterSheet
// SY <-- // SY <--
/** /**
@ -193,11 +189,6 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
// <-- EH // <-- EH
} }
// SY -->
readerBottomSheetBinding = ReaderChaptersSheetBinding.bind(binding.readerChaptersSheet.root)
readerBottomSheetBinding.chaptersBottomSheet.setup(this)
// SY <--
config = ReaderConfig() config = ReaderConfig()
initializeMenu() initializeMenu()
@ -244,7 +235,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
viewer?.destroy() viewer?.destroy()
viewer = null viewer = null
// SY --> // SY -->
readerBottomSheetBinding.chaptersBottomSheet.adapter = null chapterBottomSheet.adapter = null
// SY <-- // SY <--
config = null config = null
progressDialog?.dismiss() progressDialog?.dismiss()
@ -294,9 +285,9 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.reader, menu) menuInflater.inflate(R.menu.reader, menu)
val isChapterBookmarked = presenter?.getCurrentChapter()?.chapter?.bookmark ?: false /*val isChapterBookmarked = presenter?.getCurrentChapter()?.chapter?.bookmark ?: false
menu.findItem(R.id.action_bookmark).isVisible = !isChapterBookmarked menu.findItem(R.id.action_bookmark).isVisible = !isChapterBookmarked
menu.findItem(R.id.action_remove_bookmark).isVisible = isChapterBookmarked menu.findItem(R.id.action_remove_bookmark).isVisible = isChapterBookmarked*/
return true return true
} }
@ -307,22 +298,15 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
*/ */
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.action_bookmark -> { /*R.id.action_bookmark -> {
presenter.bookmarkCurrentChapter(true) presenter.bookmarkCurrentChapter(true)
invalidateOptionsMenu() invalidateOptionsMenu()
} }*/
R.id.action_remove_bookmark -> { R.id.action_remove_bookmark -> {
presenter.bookmarkCurrentChapter(false) presenter.bookmarkCurrentChapter(false)
invalidateOptionsMenu() invalidateOptionsMenu()
} }
R.id.action_settings -> { R.id.action_settings -> ReaderSettingsSheet(this).show()
ReaderSettingsSheet(this).show()
// SY -->
if (readerBottomSheetBinding.chaptersBottomSheet.sheetBehavior.isExpanded()) {
readerBottomSheetBinding.chaptersBottomSheet.sheetBehavior?.collapse()
}
// SY <--
}
R.id.action_custom_filter -> { R.id.action_custom_filter -> {
val sheet = ReaderColorFilterSheet(this) val sheet = ReaderColorFilterSheet(this)
// Remove dimmed backdrop so changes can be previewed // Remove dimmed backdrop so changes can be previewed
@ -333,11 +317,6 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
setMenuVisibility(false) setMenuVisibility(false)
sheet.show() sheet.show()
// SY -->
if (readerBottomSheetBinding.chaptersBottomSheet.sheetBehavior.isExpanded()) {
readerBottomSheetBinding.chaptersBottomSheet.sheetBehavior?.collapse()
}
// SY <--
} }
} }
return super.onOptionsItemSelected(item) return super.onOptionsItemSelected(item)
@ -393,7 +372,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
} }
// Init listeners on bottom menu // Init listeners on bottom menu
/* SY --> */readerBottomSheetBinding.pageSeekbar.setOnSeekBarChangeListener(object : SimpleSeekBarListener() { /* SY <-- */ binding.pageSeekbar.setOnSeekBarChangeListener(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) {
moveToPageIndex(value) moveToPageIndex(value)
@ -568,14 +547,18 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
.show() .show()
} }
.launchIn(scope) .launchIn(scope)
chapterBottomSheet = ReaderChapterSheet(this)
binding.chaptersButton.clicks()
.onEach {
chapterBottomSheet.show()
}.launchIn(scope)
// <-- EH // <-- EH
// Set initial visibility // Set initial visibility
setMenuVisibility(menuVisible) setMenuVisibility(menuVisible)
// --> EH // --> EH
readerBottomSheetBinding.chaptersBottomSheet.sheetBehavior?.isHideable = !menuVisible
if (!menuVisible) readerBottomSheetBinding.chaptersBottomSheet.sheetBehavior?.hide()
setEhUtilsVisibility(ehUtilsVisible) setEhUtilsVisibility(ehUtilsVisible)
// <-- EH // <-- EH
} }
@ -601,10 +584,6 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
} }
binding.readerMenu.isVisible = true binding.readerMenu.isVisible = true
if (readerBottomSheetBinding.chaptersBottomSheet.sheetBehavior.isExpanded()) {
readerBottomSheetBinding.chaptersBottomSheet.sheetBehavior?.isHideable = false
}
if (animate) { if (animate) {
val toolbarAnimation = AnimationUtils.loadAnimation(this, R.anim.enter_from_top) val toolbarAnimation = AnimationUtils.loadAnimation(this, R.anim.enter_from_top)
toolbarAnimation.setAnimationListener(object : SimpleAnimationListener() { toolbarAnimation.setAnimationListener(object : SimpleAnimationListener() {
@ -617,9 +596,8 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
binding.header.startAnimation(toolbarAnimation) binding.header.startAnimation(toolbarAnimation)
// EXH <-- // EXH <--
// SY --> val bottomAnimation = AnimationUtils.loadAnimation(this, R.anim.enter_from_bottom)
readerBottomSheetBinding.chaptersBottomSheet.sheetBehavior?.collapse() binding.readerMenuBottom.startAnimation(bottomAnimation)
// SY <--
} }
if (preferences.showPageNumber().get()) { if (preferences.showPageNumber().get()) {
@ -643,10 +621,8 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
binding.header.startAnimation(toolbarAnimation) binding.header.startAnimation(toolbarAnimation)
// EXH <-- // EXH <--
// SY --> val bottomAnimation = AnimationUtils.loadAnimation(this, R.anim.exit_to_bottom)
BottomSheetBehavior.from(readerBottomSheetBinding.chaptersBottomSheet).isHideable = true binding.readerMenuBottom.startAnimation(bottomAnimation)
readerBottomSheetBinding.chaptersBottomSheet.sheetBehavior?.hide()
// SY <--
} }
if (preferences.showPageNumber().get()) { if (preferences.showPageNumber().get()) {
@ -671,7 +647,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
} }
fun refreshSheetChapters() { fun refreshSheetChapters() {
readerBottomSheetBinding.chaptersBottomSheet.refreshList() chapterBottomSheet.refreshList()
} }
// SY <-- // SY <--
@ -716,9 +692,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
binding.toolbar.title = manga.title binding.toolbar.title = manga.title
// SY --> binding.pageSeekbar.isRTL = newViewer is R2LPagerViewer
readerBottomSheetBinding.pageSeekbar.isRTL = newViewer is R2LPagerViewer
// SY <--
binding.pleaseWait.isVisible = true binding.pleaseWait.isVisible = true
binding.pleaseWait.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in_long)) binding.pleaseWait.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in_long))
@ -804,22 +778,19 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
val newChapter = presenter.onPageSelected(page) val newChapter = presenter.onPageSelected(page)
val pages = page.chapter.pages ?: return val pages = page.chapter.pages ?: return
// SY -->
if (chapterBottomSheet.selectedChapterId != page.chapter.chapter.id) {
chapterBottomSheet.refreshList()
}
// SY <--
// Set bottom page number // Set bottom page number
binding.pageNumber.text = "${page.number}/${pages.size}" binding.pageNumber.text = "${page.number}/${pages.size}"
// SY --> binding.pageText.text = "${page.number}/${pages.size}"
readerBottomSheetBinding.pageText.text = "${page.number}/${pages.size}"
if (!newChapter && readerBottomSheetBinding.chaptersBottomSheet.shouldCollapse && readerBottomSheetBinding.chaptersBottomSheet.sheetBehavior.isExpanded()) {
readerBottomSheetBinding.chaptersBottomSheet.sheetBehavior?.collapse()
}
if (readerBottomSheetBinding.chaptersBottomSheet.selectedChapterId != page.chapter.chapter.id) {
readerBottomSheetBinding.chaptersBottomSheet.refreshList()
}
readerBottomSheetBinding.chaptersBottomSheet.shouldCollapse = true
// Set seekbar progress // Set seekbar progress
readerBottomSheetBinding.pageSeekbar.max = pages.lastIndex binding.pageSeekbar.max = pages.lastIndex
readerBottomSheetBinding.pageSeekbar.progress = page.index binding.pageSeekbar.progress = page.index
// SY <--
} }
/** /**
@ -835,9 +806,6 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
} catch (e: WindowManager.BadTokenException) { } catch (e: WindowManager.BadTokenException) {
logger.e("Caught and ignoring reader page sheet launch exception!", e) logger.e("Caught and ignoring reader page sheet launch exception!", e)
} }
if (readerBottomSheetBinding.chaptersBottomSheet.sheetBehavior.isExpanded()) {
readerBottomSheetBinding.chaptersBottomSheet.sheetBehavior?.collapse()
}
// EXH <-- // EXH <--
} }

View File

@ -267,7 +267,7 @@ class ReaderPresenter(
.apply { decimalSeparator = '.' } .apply { decimalSeparator = '.' }
) )
chapterList.reversed().map { chapterList.map {
ReaderChapterItem( ReaderChapterItem(
it.chapter, it.chapter,
manga!!, manga!!,
@ -389,8 +389,8 @@ class ReaderPresenter(
* read, update tracking services, enqueue downloaded chapter deletion, and updating the active chapter if this * read, update tracking services, enqueue downloaded chapter deletion, and updating the active chapter if this
* [page]'s chapter is different from the currently active. * [page]'s chapter is different from the currently active.
*/ */
fun onPageSelected(page: ReaderPage): Boolean { fun onPageSelected(page: ReaderPage) {
val currentChapters = viewerChaptersRelay.value ?: return /* SY --> */ false /* SY <-- */ val currentChapters = viewerChaptersRelay.value ?: return
val selectedChapter = page.chapter val selectedChapter = page.chapter
@ -420,10 +420,8 @@ class ReaderPresenter(
Observable.just(selectedChapter).subscribeFirst({ view, _ -> Observable.just(selectedChapter).subscribeFirst({ view, _ ->
view.refreshSheetChapters() view.refreshSheetChapters()
}) })
return true
// SY <-- // SY <--
} }
return /* SY --> */ false /* SY <-- */
} }
/** /**

View File

@ -1,108 +1,46 @@
package eu.kanade.tachiyomi.ui.reader.chapter package eu.kanade.tachiyomi.ui.reader.chapter
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.util.AttributeSet
import android.view.View import android.view.View
import android.widget.LinearLayout import android.view.ViewGroup
import androidx.core.graphics.ColorUtils import android.widget.SeekBar
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.mikepenz.fastadapter.FastAdapter 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.databinding.ReaderChaptersSheetBinding 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.lang.launchUI import eu.kanade.tachiyomi.util.lang.launchUI
import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.widget.SimpleSeekBarListener
import exh.util.collapse
import exh.util.expand
import exh.util.isExpanded import exh.util.isExpanded
import kotlin.math.max import kotlinx.coroutines.flow.launchIn
import kotlin.math.min import kotlinx.coroutines.flow.onEach
import kotlin.math.roundToInt import reactivecircus.flowbinding.android.view.clicks
import kotlinx.android.synthetic.main.reader_chapters_sheet.view.pill
class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : /**
LinearLayout(context, attrs) { * Color filter sheet to toggle custom filter and brightness overlay.
*/
class ReaderChapterSheet(private val activity: ReaderActivity) : BottomSheetDialog(activity) {
private var sheetBehavior: BottomSheetBehavior<*>? = null
lateinit var binding: ReaderChaptersSheetBinding private val binding = ReaderChaptersSheetBinding.inflate(activity.layoutInflater, null, false)
var sheetBehavior: BottomSheetBehavior<View>? = null var presenter: ReaderPresenter
lateinit var presenter: ReaderPresenter
var adapter: FastAdapter<ReaderChapterItem>? = null var adapter: FastAdapter<ReaderChapterItem>? = null
private val itemAdapter = ItemAdapter<ReaderChapterItem>() private val itemAdapter = ItemAdapter<ReaderChapterItem>()
var shouldCollapse = true var shouldCollapse = true
var selectedChapterId = -1L var selectedChapterId = -1L
fun setup(activity: ReaderActivity) { init {
setContentView(binding.root)
sheetBehavior = BottomSheetBehavior.from(binding.root.parent as ViewGroup)
presenter = activity.presenter presenter = activity.presenter
binding = activity.readerBottomSheetBinding
val fullPrimary = context.getResourceColor(R.attr.colorSurface)
val primary = ColorUtils.setAlphaComponent(fullPrimary, 200)
sheetBehavior = BottomSheetBehavior.from(this)
binding.chaptersButton.setOnClickListener {
if (sheetBehavior.isExpanded()) {
sheetBehavior?.collapse()
} else {
sheetBehavior?.expand()
}
}
binding.webviewButton.setOnClickListener {
activity.openMangaInBrowser()
}
post {
binding.chapterRecycler.alpha = if (sheetBehavior.isExpanded()) 1f else 0f
binding.chapterRecycler.isClickable = sheetBehavior.isExpanded()
binding.chapterRecycler.isFocusable = sheetBehavior.isExpanded()
}
sheetBehavior?.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
override fun onSlide(bottomSheet: View, progress: Float) {
val trueProgress = max(progress, 0f)
binding.pill.alpha = (1 - trueProgress) * 0.25f
binding.chaptersButton.alpha = 1 - trueProgress
binding.webviewButton.alpha = trueProgress
binding.webviewButton.isVisible = binding.webviewButton.alpha > 0
binding.chaptersButton.isInvisible = binding.chaptersButton.alpha <= 0
backgroundTintList =
ColorStateList.valueOf(lerpColor(primary, fullPrimary, trueProgress))
binding.chapterRecycler.alpha = trueProgress
}
override fun onStateChanged(p0: View, state: Int) {
if (state == BottomSheetBehavior.STATE_COLLAPSED) {
shouldCollapse = true
sheetBehavior?.isHideable = false
(binding.chapterRecycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(
adapter?.getPosition(presenter.getCurrentChapter()?.chapter?.id ?: 0L) ?: 0,
binding.chapterRecycler.height / 2 - 30.dpToPx
)
binding.chaptersButton.alpha = 1f
binding.webviewButton.alpha = 0f
}
if (state == BottomSheetBehavior.STATE_EXPANDED) {
binding.chapterRecycler.alpha = 1F
binding.chaptersButton.alpha = 0f
binding.webviewButton.alpha = 1f
}
binding.chapterRecycler.isClickable = state == BottomSheetBehavior.STATE_EXPANDED
binding.chapterRecycler.isFocusable = state == BottomSheetBehavior.STATE_EXPANDED
binding.webviewButton.isVisible = state != BottomSheetBehavior.STATE_COLLAPSED
binding.chaptersButton.isInvisible = state == BottomSheetBehavior.STATE_EXPANDED
}
})
adapter = FastAdapter.with(itemAdapter) adapter = FastAdapter.with(itemAdapter)
binding.chapterRecycler.adapter = adapter binding.chapterRecycler.adapter = adapter
adapter?.onClickListener = { _, _, item, _ -> adapter?.onClickListener = { _, _, item, _ ->
@ -136,18 +74,38 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
} }
}) })
backgroundTintList = ColorStateList.valueOf(
if (!sheetBehavior.isExpanded()) primary
else fullPrimary
)
binding.chapterRecycler.layoutManager = LinearLayoutManager(context) binding.chapterRecycler.layoutManager = LinearLayoutManager(context)
refreshList() refreshList()
binding.webviewButton.clicks()
.onEach { activity.openMangaInBrowser() }
.launchIn(activity.scope)
binding.pageSeekbar.setOnSeekBarChangeListener(object : SimpleSeekBarListener() {
override fun onProgressChanged(seekBar: SeekBar, value: Int, fromUser: Boolean) {
if (activity.viewer != null && fromUser) {
binding.pageSeekbar.progress = value
activity.moveToPageIndex(value)
}
}
})
}
override fun onStart() {
super.onStart()
sheetBehavior?.skipCollapsed = true
sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED
}
override fun show() {
binding.pageText.text = activity.binding.pageText.text
binding.pageSeekbar.max = activity.binding.pageSeekbar.max
binding.pageSeekbar.progress = activity.binding.pageSeekbar.progress
super.show()
} }
fun refreshList() { fun refreshList() {
launchUI { launchUI {
val chapters = presenter.getChapters(context) val chapters = presenter.getChapters(context).sortedBy { it.source_order }
selectedChapterId = chapters.find { it.isCurrent }?.chapter?.id ?: -1L selectedChapterId = chapters.find { it.isCurrent }?.chapter?.id ?: -1L
itemAdapter.clear() itemAdapter.clear()
@ -155,26 +113,8 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
(binding.chapterRecycler.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,
binding.chapterRecycler.height / 2 - 30.dpToPx (binding.chapterRecycler.height / 2).dpToPx
) )
} }
} }
fun lerpColor(colorStart: Int, colorEnd: Int, percent: Float): Int {
val perc = (percent * 100).roundToInt()
return Color.argb(
lerpColorCalc(Color.alpha(colorStart), Color.alpha(colorEnd), perc),
lerpColorCalc(Color.red(colorStart), Color.red(colorEnd), perc),
lerpColorCalc(Color.green(colorStart), Color.green(colorEnd), perc),
lerpColorCalc(Color.blue(colorStart), Color.blue(colorEnd), perc)
)
}
fun lerpColorCalc(colorStart: Int, colorEnd: Int, percent: Int): Int {
return (
min(colorStart, colorEnd) * (100 - percent) + max(
colorStart, colorEnd
) * percent
) / 100
}
} }

View File

@ -42,7 +42,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:visibility="gone" /> android:visibility="gone" />
<androidx.coordinatorlayout.widget.CoordinatorLayout <FrameLayout
android:id="@+id/reader_menu" android:id="@+id/reader_menu"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -151,11 +151,44 @@
app:srcCompat="@drawable/ic_keyboard_arrow_down_white_32dp" /> app:srcCompat="@drawable/ic_keyboard_arrow_down_white_32dp" />
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<include <LinearLayout
android:id="@+id/reader_chapters_sheet" android:id="@+id/reader_menu_bottom"
layout="@layout/reader_chapters_sheet" /> android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
android:background="?attr/colorPrimary"
android:clickable="true"
android:focusable="true">
</androidx.coordinatorlayout.widget.CoordinatorLayout> <ImageButton
android:id="@+id/chapters_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/action_next_chapter"
android:padding="@dimen/material_layout_keylines_screen_edge_margin"
android:tint="?attr/colorOnSurface"
app:srcCompat="@drawable/ic_format_list_numbered_24dp" />
<eu.kanade.tachiyomi.ui.reader.ReaderSeekBar
android:id="@+id/page_seekbar"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:maxHeight="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"/>
<TextView
android:id="@+id/page_text"
android:layout_width="100dp"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="?attr/colorOnSurface"
android:textSize="15sp"
tools:text="100 / 105" />
</LinearLayout>
</FrameLayout>
<View <View
android:id="@+id/brightness_overlay" android:id="@+id/brightness_overlay"

View File

@ -1,20 +1,17 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<eu.kanade.tachiyomi.ui.reader.chapter.ReaderChapterSheet xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/chapters_bottom_sheet"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="300dp" android:layout_height="300dp"
android:background="?attr/colorSurface" android:layout_gravity="bottom"
android:orientation="vertical" android:orientation="vertical">
android:alpha="1"
app:behavior_peekHeight="?attr/actionBarSize"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/topbar_layout" android:id="@+id/topbar_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorSurface"
android:clickable="true" android:clickable="true"
android:focusable="true"> android:focusable="true">
@ -23,7 +20,6 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
android:alpha="0.25"
android:contentDescription="@string/action_sort_drag_and_drop" android:contentDescription="@string/action_sort_drag_and_drop"
android:src="@drawable/ic_drag_pill_24dp" android:src="@drawable/ic_drag_pill_24dp"
android:tint="?attr/colorOnSurface" android:tint="?attr/colorOnSurface"
@ -31,19 +27,6 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/chapters_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/action_next_chapter"
android:padding="@dimen/material_layout_keylines_screen_edge_margin"
android:tint="?attr/colorOnSurface"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_format_list_numbered_24dp" />
<ImageButton <ImageButton
android:id="@+id/webview_button" android:id="@+id/webview_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -55,7 +38,6 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
android:alpha="0.0"
app:srcCompat="@drawable/ic_public_24dp" /> app:srcCompat="@drawable/ic_public_24dp" />
<eu.kanade.tachiyomi.ui.reader.ReaderSeekBar <eu.kanade.tachiyomi.ui.reader.ReaderSeekBar
@ -64,7 +46,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/page_text" app:layout_constraintEnd_toStartOf="@id/page_text"
app:layout_constraintStart_toEndOf="@id/chapters_button" app:layout_constraintStart_toEndOf="@id/webview_button"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
@ -83,9 +65,9 @@
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/chapter_recycler" android:id="@+id/chapter_recycler"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="244dp"
android:background="?attr/colorSurface" android:background="?attr/colorSurface"
android:clipToPadding="false" android:clipToPadding="false"
android:alpha="0"
tools:listitem="@layout/reader_chapter_item" /> tools:listitem="@layout/reader_chapter_item" />
</eu.kanade.tachiyomi.ui.reader.chapter.ReaderChapterSheet>
</LinearLayout>

View File

@ -2,7 +2,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item <!--<item
android:id="@+id/action_bookmark" android:id="@+id/action_bookmark"
android:icon="@drawable/ic_bookmark_border_24dp" android:icon="@drawable/ic_bookmark_border_24dp"
android:title="@string/action_bookmark" android:title="@string/action_bookmark"
@ -14,7 +14,7 @@
android:icon="@drawable/ic_bookmark_24dp" android:icon="@drawable/ic_bookmark_24dp"
android:title="@string/action_remove_bookmark" android:title="@string/action_remove_bookmark"
app:iconTint="?attr/colorOnPrimary" app:iconTint="?attr/colorOnPrimary"
app:showAsAction="ifRoom" /> app:showAsAction="ifRoom" />-->
<item <item
android:id="@+id/action_custom_filter" android:id="@+id/action_custom_filter"