mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Automatically scroll manga/chapter name in reader activity
This commit is contained in:
parent
a28e1b8759
commit
dbbe295559
1 changed files with 43 additions and 0 deletions
|
@ -19,6 +19,7 @@ import android.graphics.drawable.LayerDrawable
|
|||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.text.style.DynamicDrawableSpan
|
||||
import android.text.style.ImageSpan
|
||||
import android.view.Gravity
|
||||
|
@ -32,6 +33,7 @@ import android.view.ViewGroup
|
|||
import android.view.Window
|
||||
import android.view.WindowManager
|
||||
import android.view.animation.AnimationUtils
|
||||
import android.widget.TextView
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.addCallback
|
||||
import androidx.activity.viewModels
|
||||
|
@ -49,6 +51,7 @@ import androidx.core.view.WindowInsetsCompat
|
|||
import androidx.core.view.WindowInsetsCompat.Type.statusBars
|
||||
import androidx.core.view.WindowInsetsCompat.Type.systemBars
|
||||
import androidx.core.view.WindowInsetsControllerCompat
|
||||
import androidx.core.view.children
|
||||
import androidx.core.view.isInvisible
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.updateLayoutParams
|
||||
|
@ -148,6 +151,7 @@ import timber.log.Timber
|
|||
import java.io.File
|
||||
import java.text.DecimalFormat
|
||||
import java.text.DecimalFormatSymbols
|
||||
import java.util.Collections
|
||||
import java.util.Locale
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.max
|
||||
|
@ -1117,6 +1121,7 @@ class ReaderActivity : BaseActivity<ReaderActivityBinding>() {
|
|||
toolbarAnimation.doOnStart {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
||||
}
|
||||
toolbarAnimation.doOnEnd { delayTitleScroll() }
|
||||
binding.appBar.startAnimation(toolbarAnimation)
|
||||
}
|
||||
binding.chaptersSheet.chaptersBottomSheet.sheetBehavior?.collapse()
|
||||
|
@ -1136,6 +1141,9 @@ class ReaderActivity : BaseActivity<ReaderActivityBinding>() {
|
|||
} else if (!animate) {
|
||||
binding.appBar.isVisible = false
|
||||
}
|
||||
listOfNotNull(getTitleTextView(), getSubtitleTextView()).forEach { textView ->
|
||||
textView.isSelected = false
|
||||
}
|
||||
}
|
||||
menuStickyVisible = false
|
||||
}
|
||||
|
@ -1310,6 +1318,17 @@ class ReaderActivity : BaseActivity<ReaderActivityBinding>() {
|
|||
binding.toolbar.subtitle =
|
||||
chapter.preferredChapterName(this, viewModel.manga!!, preferences)
|
||||
|
||||
listOfNotNull(getTitleTextView(), getSubtitleTextView()).forEach { textView ->
|
||||
textView.ellipsize = TextUtils.TruncateAt.MARQUEE
|
||||
textView.marqueeRepeatLimit = -1
|
||||
textView.isSingleLine = true
|
||||
textView.isFocusable = true
|
||||
textView.isFocusableInTouchMode = true
|
||||
textView.isHorizontalFadingEdgeEnabled = true
|
||||
textView.setFadingEdgeLength(16.dpToPx)
|
||||
textView.setHorizontallyScrolling(true)
|
||||
}
|
||||
|
||||
if (viewerChapters.nextChapter == null && viewerChapters.prevChapter == null) {
|
||||
binding.readerNav.leftChapter.isVisible = false
|
||||
binding.readerNav.rightChapter.isVisible = false
|
||||
|
@ -1325,6 +1344,27 @@ class ReaderActivity : BaseActivity<ReaderActivityBinding>() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun getTitleTextView(): TextView? = getTextViewsWithText(binding.toolbar.title)
|
||||
private fun getSubtitleTextView(): TextView? = getTextViewsWithText(binding.toolbar.subtitle)
|
||||
private fun delayTitleScroll() {
|
||||
val list = listOfNotNull(getTitleTextView(), getSubtitleTextView())
|
||||
if (list.isNotEmpty()) {
|
||||
scope.launchUI {
|
||||
delay(1000)
|
||||
list.forEach { it.isSelected = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun getTextViewsWithText(text: CharSequence?): TextView? {
|
||||
if (text.isNullOrBlank()) return null
|
||||
val viewTopComparator = Comparator<View> { view1, view2 -> view1.top - view2.top }
|
||||
val textViews = binding.toolbar.children.filterIsInstance<TextView>()
|
||||
.filter { TextUtils.equals(it.text, text) }.toList()
|
||||
return if (textViews.isEmpty()) null else Collections.max(textViews, viewTopComparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from the view model if the initial load couldn't load the pages of the chapter. In
|
||||
* this case the activity is closed and a toast is shown to the user.
|
||||
|
@ -1723,6 +1763,9 @@ class ReaderActivity : BaseActivity<ReaderActivityBinding>() {
|
|||
toolbarAnimation.doOnStart {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
||||
}
|
||||
toolbarAnimation.doOnEnd {
|
||||
delayTitleScroll()
|
||||
}
|
||||
binding.appBar.startAnimation(toolbarAnimation)
|
||||
} else if (!visible && (menuStickyVisible || menuVisible)) {
|
||||
if (menuStickyVisible && !menuVisible) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue