同步上游更改:感谢 @821938089

This commit is contained in:
HapeLee
2025-10-13 22:16:41 +08:00
parent 49ae578f3f
commit fd5e218075
10 changed files with 43 additions and 15 deletions
@@ -273,7 +273,7 @@ fun Book.updateTo(newBook: Book): Book {
newBook.hasVariable(it) newBook.hasVariable(it)
} }
newBook.variableMap.putAll(variableMap) newBook.variableMap.putAll(variableMap)
newBook.variable = GSON.toJson(variableMap) newBook.variable = GSON.toJson(newBook.variableMap)
return newBook return newBook
} }
@@ -78,6 +78,7 @@ object AudioPlay : CoroutineScope by MainScope() {
chapterSize chapterSize
} }
if (durChapterIndex != book.durChapterIndex) { if (durChapterIndex != book.durChapterIndex) {
stopPlay()
durChapterIndex = book.durChapterIndex durChapterIndex = book.durChapterIndex
durChapterPos = book.durChapterPos durChapterPos = book.durChapterPos
durPlayUrl = "" durPlayUrl = ""
@@ -152,6 +153,8 @@ object AudioPlay : CoroutineScope by MainScope() {
}.onError { }.onError {
AppLog.put("获取资源链接出错\n$it", it, true) AppLog.put("获取资源链接出错\n$it", it, true)
upLoading(false) upLoading(false)
}.onCancel {
removeLoading(index)
}.onFinally { }.onFinally {
removeLoading(index) removeLoading(index)
} }
@@ -61,7 +61,7 @@ class WebService : BaseService() {
private val useWakeLock = appCtx.getPrefBoolean(PreferKey.webServiceWakeLock, false) private val useWakeLock = appCtx.getPrefBoolean(PreferKey.webServiceWakeLock, false)
private val wakeLock: PowerManager.WakeLock by lazy { private val wakeLock: PowerManager.WakeLock by lazy {
powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "legado:webService") powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "legado:WebService")
.apply { .apply {
setReferenceCounted(false) setReferenceCounted(false)
} }
@@ -853,7 +853,9 @@ class BookInfoActivity :
viewModel.bookSource?.getKey() -> viewModel.bookSource?.setVariable(variable) viewModel.bookSource?.getKey() -> viewModel.bookSource?.setVariable(variable)
viewModel.bookData.value?.bookUrl -> viewModel.bookData.value?.let { viewModel.bookData.value?.bookUrl -> viewModel.bookData.value?.let {
it.putCustomVariable(variable) it.putCustomVariable(variable)
viewModel.saveBook(it) if (viewModel.inBookshelf) {
viewModel.saveBook(it)
}
} }
} }
} }
@@ -1386,8 +1386,13 @@ class ReadBookActivity : BaseReadBookActivity(),
ReadAloud.upReadAloudClass() ReadAloud.upReadAloudClass()
val scrollPageAnim = ReadBook.pageAnim() == 3 val scrollPageAnim = ReadBook.pageAnim() == 3
if (scrollPageAnim) { if (scrollPageAnim) {
val startPos = binding.readView.getCurPagePosition() val line = binding.readView.getCurVisibleFirstLine()
ReadBook.readAloud(startPos = startPos) if (line != null) {
ReadBook.durChapterPos = line.chapterPosition
ReadBook.readAloud(startPos = line.pagePosition)
} else {
ReadBook.readAloud()
}
} else { } else {
ReadBook.readAloud() ReadBook.readAloud()
} }
@@ -1397,8 +1402,13 @@ class ReadBookActivity : BaseReadBookActivity(),
val scrollPageAnim = ReadBook.pageAnim() == 3 val scrollPageAnim = ReadBook.pageAnim() == 3
if (scrollPageAnim && pageChanged) { if (scrollPageAnim && pageChanged) {
pageChanged = false pageChanged = false
val startPos = binding.readView.getCurPagePosition() val line = binding.readView.getCurVisibleFirstLine()
ReadBook.readAloud(startPos = startPos) if (line != null) {
ReadBook.durChapterPos = line.chapterPosition
ReadBook.readAloud(startPos = line.pagePosition)
} else {
ReadBook.readAloud()
}
} else { } else {
ReadAloud.resume(this) ReadAloud.resume(this)
} }
@@ -31,6 +31,7 @@ import io.legato.kazusa.utils.share
import io.legato.kazusa.utils.toastOnUi import io.legato.kazusa.utils.toastOnUi
import io.legato.kazusa.utils.visible import io.legato.kazusa.utils.visible
import androidx.core.net.toUri import androidx.core.net.toUri
import io.legato.kazusa.constant.AppLog
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
class TextActionMenu(private val context: Context, private val callBack: CallBack) : class TextActionMenu(private val context: Context, private val callBack: CallBack) :
@@ -218,8 +219,12 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
} }
else -> item.intent?.let { else -> item.intent?.let {
it.putExtra(Intent.EXTRA_PROCESS_TEXT, callBack.selectedText) kotlin.runCatching {
context.startActivity(it) it.putExtra(Intent.EXTRA_PROCESS_TEXT, callBack.selectedText)
context.startActivity(it)
}.onFailure { e ->
AppLog.put("执行文本菜单操作出错\n$e", e, true)
}
} }
} }
} }
@@ -29,6 +29,7 @@ import io.legato.kazusa.ui.book.read.page.delegate.SimulationPageDelegate
import io.legato.kazusa.ui.book.read.page.delegate.SlidePageDelegate import io.legato.kazusa.ui.book.read.page.delegate.SlidePageDelegate
import io.legato.kazusa.ui.book.read.page.entities.PageDirection import io.legato.kazusa.ui.book.read.page.entities.PageDirection
import io.legato.kazusa.ui.book.read.page.entities.TextChapter import io.legato.kazusa.ui.book.read.page.entities.TextChapter
import io.legato.kazusa.ui.book.read.page.entities.TextLine
import io.legato.kazusa.ui.book.read.page.entities.TextPage import io.legato.kazusa.ui.book.read.page.entities.TextPage
import io.legato.kazusa.ui.book.read.page.entities.TextPos import io.legato.kazusa.ui.book.read.page.entities.TextPos
import io.legato.kazusa.ui.book.read.page.entities.column.TextColumn import io.legato.kazusa.ui.book.read.page.entities.column.TextColumn
@@ -672,8 +673,8 @@ class ReadView(context: Context, attrs: AttributeSet) :
return curPage.getCurVisiblePage() return curPage.getCurVisiblePage()
} }
fun getCurPagePosition(): Int { fun getCurVisibleFirstLine(): TextLine? {
return curPage.getCurVisibleFirstLine()?.pagePosition ?: 0 return curPage.getCurVisibleFirstLine()
} }
fun invalidateTextPage() { fun invalidateTextPage() {
@@ -293,7 +293,8 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
scrollToBottom() scrollToBottom()
return return
} }
val bottom = abs(lastView.bottom - recyclerView.height) val bottom =
abs(lastView.bottom - recyclerView.height) - recyclerView.paddingBottom
if (bottom <= 1) { if (bottom <= 1) {
scrollToBottom() scrollToBottom()
} }
@@ -12,6 +12,8 @@ import io.legato.kazusa.data.entities.Book
abstract class BaseBooksAdapter<VB : ViewBinding>(context: Context) : abstract class BaseBooksAdapter<VB : ViewBinding>(context: Context) :
DiffRecyclerAdapter<Book, VB>(context) { DiffRecyclerAdapter<Book, VB>(context) {
override val keepScrollPosition = true
override val diffItemCallback: DiffUtil.ItemCallback<Book> = override val diffItemCallback: DiffUtil.ItemCallback<Book> =
object : DiffUtil.ItemCallback<Book>() { object : DiffUtil.ItemCallback<Book>() {
@@ -13,7 +13,7 @@ import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.channelFlow import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.flatMapMerge import kotlinx.coroutines.flow.flatMapMerge
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
@@ -198,7 +198,9 @@ fun <T> Flow<T>.flowWithLifecycleFirst(
minActiveState: Lifecycle.State = Lifecycle.State.STARTED minActiveState: Lifecycle.State = Lifecycle.State.STARTED
): Flow<T> = callbackFlow { ): Flow<T> = callbackFlow {
if (!lifecycle.currentState.isAtLeast(minActiveState)) { if (!lifecycle.currentState.isAtLeast(minActiveState)) {
send(first()) firstOrNull()?.let {
send(it)
}
} }
lifecycle.repeatOnLifecycle(minActiveState) { lifecycle.repeatOnLifecycle(minActiveState) {
this@flowWithLifecycleFirst.collect { this@flowWithLifecycleFirst.collect {
@@ -244,7 +246,9 @@ fun <T> Flow<T>.flowWithLifecycleAndDatabaseChangeFirst(
.onEach { update++ } .onEach { update++ }
.produceIn(this) .produceIn(this)
if (!isActive) { if (!isActive) {
send(first()) firstOrNull()?.let {
send(it)
}
} }
lifecycle.repeatOnLifecycle(minActiveState) { lifecycle.repeatOnLifecycle(minActiveState) {
if (update == 0) { if (update == 0) {