Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gedoor committed Oct 30, 2023
2 parents 0a377cf + 4507b4b commit c5d03e5
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 36 deletions.
5 changes: 3 additions & 2 deletions app/src/main/java/io/legado/app/data/entities/RssArticle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ data class RssArticle(
pubDate = pubDate,
description = description,
content = content,
image = image
image = image,
variable = variable
)
}
}
5 changes: 3 additions & 2 deletions app/src/main/java/io/legado/app/data/entities/RssStar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ data class RssStar(
pubDate = pubDate,
description = description,
content = content,
image = image
image = image,
variable = variable
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
17 changes: 14 additions & 3 deletions app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -165,31 +165,37 @@ class BookInfoActivity :
}
}
}

R.id.menu_share_it -> {
viewModel.getBook()?.let {
val bookJson = GSON.toJson(it)
val shareStr = "${it.bookUrl}#$bookJson"
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
Expand All @@ -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 -> {
Expand All @@ -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 ->
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
}
}
}
}
Expand Down
50 changes: 22 additions & 28 deletions app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -961,41 +961,35 @@ class ReadBookActivity : BaseReadBookActivity(),
override fun autoPageStop() {
if (isAutoPage) {
isAutoPage = false
autoPageJob?.cancel()
autoPageRenderer.stop()
binding.readView.invalidate()
binding.readMenu.setAutoPage(false)
upScreenTimeOut()
}
}

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()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}

Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/io/legado/app/utils/SyncedRenderer.kt
Original file line number Diff line number Diff line change
@@ -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 = {}
}
}

0 comments on commit c5d03e5

Please sign in to comment.