Merge remote-tracking branch 'origin/master'

This commit is contained in:
kunfei
2023-10-30 10:33:48 +08:00
7 changed files with 71 additions and 36 deletions

View File

@@ -48,6 +48,7 @@ data class RssArticle(
pubDate = pubDate,
description = description,
content = content,
image = image
image = image,
variable = variable
)
}
}

View File

@@ -39,6 +39,7 @@ data class RssStar(
pubDate = pubDate,
description = description,
content = content,
image = image
image = image,
variable = variable
)
}
}

View File

@@ -147,6 +147,7 @@ abstract class BaseReadAloudService : BaseService(),
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
upNotification()
when (intent?.action) {
IntentAction.play -> newReadAloud(
intent.getBooleanExtra("play", true),

View File

@@ -165,6 +165,7 @@ class BookInfoActivity :
}
}
}
R.id.menu_share_it -> {
viewModel.getBook()?.let {
val bookJson = GSON.toJson(it)
@@ -172,24 +173,29 @@ class BookInfoActivity :
shareWithQr(shareStr, it.name)
}
}
R.id.menu_refresh -> {
refreshBook()
}
R.id.menu_login -> viewModel.bookSource?.let {
startActivity<SourceLoginActivity> {
putExtra("type", "bookSource")
putExtra("key", it.bookSourceUrl)
}
}
R.id.menu_top -> viewModel.topBook()
R.id.menu_set_source_variable -> setSourceVariable()
R.id.menu_set_book_variable -> setBookVariable()
R.id.menu_copy_book_url -> viewModel.getBook()?.bookUrl?.let {
sendToClip(it)
}
R.id.menu_copy_toc_url -> viewModel.getBook()?.tocUrl?.let {
sendToClip(it)
}
R.id.menu_can_update -> {
viewModel.getBook()?.let {
it.canUpdate = !it.canUpdate
@@ -198,6 +204,7 @@ class BookInfoActivity :
}
}
}
R.id.menu_clear_cache -> viewModel.clearCache()
R.id.menu_log -> showDialogFragment<AppLogDialog>()
R.id.menu_split_long_chapter -> {
@@ -210,6 +217,7 @@ class BookInfoActivity :
item.isChecked = !item.isChecked
if (!item.isChecked) longToastOnUi(R.string.need_more_time_load_content)
}
R.id.menu_delete_alert -> LocalConfig.bookInfoDeleteAlert = !item.isChecked
R.id.menu_upload -> {
viewModel.getBook()?.let { book ->
@@ -298,12 +306,14 @@ class BookInfoActivity :
isLoading -> {
binding.tvToc.text = getString(R.string.toc_s, getString(R.string.loading))
}
chapterList.isNullOrEmpty() -> {
binding.tvToc.text = getString(
R.string.toc_s,
getString(R.string.error_load_toc)
)
}
else -> {
viewModel.bookData.value?.let {
if (it.durChapterIndex < chapterList.size) {
@@ -619,6 +629,7 @@ class BookInfoActivity :
.putExtra("bookUrl", book.bookUrl)
.putExtra("inBookshelf", viewModel.inBookshelf)
)
else -> readBookResult.launch(
Intent(this, ReadBookActivity::class.java)
.putExtra("bookUrl", book.bookUrl)
@@ -654,9 +665,9 @@ class BookInfoActivity :
if (viewModel.inBookshelf) {
viewModel.saveBook(book)
} else if (groupId > 0) {
viewModel.saveBook(book)
viewModel.inBookshelf = true
upTvBookshelf()
viewModel.addToBookshelf {
upTvBookshelf()
}
}
}
}

View File

@@ -143,7 +143,6 @@ class ReadBookActivity : BaseReadBookActivity(),
}
}
private var menu: Menu? = null
private var autoPageJob: Job? = null
private var backupJob: Job? = null
private var keepScreenJon: Job? = null
private var tts: TTS? = null
@@ -173,6 +172,7 @@ class ReadBookActivity : BaseReadBookActivity(),
private var bookChanged = false
private var pageChanged = false
private var reloadContent = false
private val autoPageRenderer by lazy { SyncedRenderer { doAutoPage(it) } }
//恢复跳转前进度对话框的交互结果
private var confirmRestoreProcess: Boolean? = null
@@ -961,7 +961,7 @@ class ReadBookActivity : BaseReadBookActivity(),
override fun autoPageStop() {
if (isAutoPage) {
isAutoPage = false
autoPageJob?.cancel()
autoPageRenderer.stop()
binding.readView.invalidate()
binding.readMenu.setAutoPage(false)
upScreenTimeOut()
@@ -969,33 +969,27 @@ class ReadBookActivity : BaseReadBookActivity(),
}
private fun autoPagePlus() {
autoPageJob?.cancel()
autoPageJob = lifecycleScope.launch {
while (isActive) {
var delayMillis = ReadBookConfig.autoReadSpeed * 1000L / binding.readView.height
var scrollOffset = 1
if (delayMillis < 20) {
var delayInt = delayMillis.toInt()
if (delayInt == 0) delayInt = 1
scrollOffset = 20 / delayInt
delayMillis = 20
}
delay(delayMillis)
if (!menuLayoutIsVisible) {
if (binding.readView.isScroll) {
binding.readView.curPage.scroll(-scrollOffset)
} else {
autoPageProgress += scrollOffset
if (autoPageProgress >= binding.readView.height) {
autoPageProgress = 0
if (!binding.readView.fillPage(PageDirection.NEXT)) {
autoPageStop()
}
} else {
binding.readView.invalidate()
}
}
autoPageRenderer.start()
}
private fun doAutoPage(frameTime: Double) {
if (menuLayoutIsVisible) {
return
}
val readTime = ReadBookConfig.autoReadSpeed * 1000.0
val height = binding.readView.height
val scrollOffset = (height / readTime * frameTime).toInt().coerceAtLeast(1)
if (binding.readView.isScroll) {
binding.readView.curPage.scroll(-scrollOffset)
} else {
autoPageProgress += scrollOffset
if (autoPageProgress >= height) {
autoPageProgress = 0
if (!binding.readView.fillPage(PageDirection.NEXT)) {
autoPageStop()
}
} else {
binding.readView.invalidate()
}
}
}

View File

@@ -104,7 +104,9 @@ class AutoReadDialog : BaseDialogFragment(R.layout.dialog_auto_read) {
binding.llCatalog.setOnClickListener { callBack?.openChapterList() }
binding.llAutoPageStop.setOnClickListener {
callBack?.autoPageStop()
dismissAllowingStateLoss()
binding.llAutoPageStop.post {
dismissAllowingStateLoss()
}
}
}

View File

@@ -0,0 +1,25 @@
package io.legado.app.utils
import android.view.Choreographer
class SyncedRenderer(val doFrame: (frameTime: Double) -> Unit) {
private var callback: (Long) -> Unit = {}
fun start() {
var currTime = System.nanoTime() / 1000000.0
callback = {
val currTimeMs = it / 1000000.0
val frameTime = currTimeMs - currTime
currTime = currTimeMs
doFrame(frameTime)
Choreographer.getInstance().postFrameCallback(callback)
}
Choreographer.getInstance().postFrameCallback(callback)
}
fun stop() {
Choreographer.getInstance().removeFrameCallback(callback)
callback = {}
}
}